How to do... Mission scripting
Fri, 2015-07-03 20:38
Hi, im doing some custom mission testing and want to know if there is a way (function) or else, to modify the global variables or game flags like indestructible terrain on others...
In Lua?
You can set such things like GameFlags (click here for list) in the event handler onGameInit (click here for more Info)
sheepluva <- me my code stats ->
a Hedgewars Developer
click here to message me
<- where I'm from what I speak ->
Ok, just to confirm that only works for game flags, becuase lua api for general variables says this:
GameFlags can be accessed via functions.
(for backwards-compatibility reasons the variable can also be accessed directly)
TurnTimeLeft can be written to directly and WaterLine via SetWaterLine().
All other Globals are read-only if I'm not mistaken.
sheepluva <- me my code stats ->
a Hedgewars Developer
click here to message me
<- where I'm from what I speak ->
Ok, i understand it, now i have to modify post name to mission scripting general, because i want to ask something else.
-How to use the onNewTurn() function, and how to control the turn number...
-How to do ally teams, and there should be always player team and 1 enemy team??
Just define a function onNewTurn() and it will be called automagically whenever the turn of a hedgehog starts.
I think you mean number of passed rounds (in each round every team gets to turn once):
As far as I know same color teams = team are allies (clan).
I think you can have any amount of player teams or AI teams, as long as there are not more than 8 teams in total.
If you only want one team:
sheepluva <- me my code stats ->
a Hedgewars Developer
click here to message me
<- where I'm from what I speak ->
Thanks for your help, i will now starty uploading my mission script progress, to allow you check for it and give me suggestions if needed:
https://www.dropbox.com/s/e67fanm41etedpm/User_Mission_-_Testing.lua?dl=0
you can use GetTeamHogName(gearUid) for checking name, GetTeamName(gearUid) for team name, and GetHogClan(gearUid) for clan's UUID, finally GetClanColor(clan) for getting color.
Sheepluva, that is incorrect, my sir. You can have at most 8 teams OR at most 48 hedgehogs. If any of those numbers are too high, engine is going to crash.
A thing i discovered about gfOneClanMode is that when thats enabled and there are 2 clans, if one of them is going to die, the game will continue.
Looking at your script, you have EnableGameFlags(lfBouncy), which is bad. In fact, you have 2 EnableGameFlags function, which is also bad. There should be only 1 of them in onGameInit(). AND lfBouncy is a Land Flag, and dont use that, because it is not going to modify a map like you would expect. If you want to make the entire map bouncy, you need to make a new map with that modified mask. The RGB code for it is 0,255,0.
oh hi
Ok, thanks i get it now, this will need a better coding for detect teamclans while doing events using event handlers, will post code when test it...
Don't forget you can also use the methods provided by the Tracker library. That should allow you to iterate over hogs and or hogs in a given team/clan.
https://code.google.com/p/hedgewars/wiki/LuaLibraries#Tracker
mikade
Hedgewars Developer
Please some help, i need example of how to OnNewTurn() and check for turn number..
The global TotalRounds shows the number of rounds, but if you just want to get the number of turns you would probably have to declare/check that yourself as a variable. You could try something like:
mikade
Hedgewars Developer
Thing is, is that on var TotalRounds, the first turn has value of -1. Watch out with that.
oh hi
Good, thanks for the example, now i can allow events occurs at selected turn, for some kind of objects added or maybe messages to show...
Yep. Should be pretty trivial using AddGear for objects and either AddCaption or ShowMission for messages. You could even use HogSay to get a specific hog to say, e.g. "What's taking you so long, come and get me!" on turn 5.
mikade
Hedgewars Developer
I have done a little event trigger in the new mission script, check for it:
https://dl.dropbox.com/s/e67fanm41etedpm/User_Mission_-_Testing.lua?dl=1
Strange trigger, but seems like it would work.
Let us know if you need more help.
mikade
Hedgewars Developer
Yes, that is an example of event based on turn count. Also I need to know if there is a way to set round time, or sudden death time left??
function onGameInit()
TurnTime = 30000
SuddenDeathTurns = 1
WaterRise = 47
end
mikade
Hedgewars Developer
I would recommend going HERE. In this case, look for 'onGameInit'.
TurnTime is in milliseconds. In this case, everyone has 30 seconds of turn. If you want to change time left, use TurnTimeLeft, as mentioned earlier.
SuddenDeathTurns determines after how much rounds of turns Sudden Death will begin. In this case, its 1 round
WaterRise is in pixels. When there is Sudden Death, after each turn water will rise 47 pixels in this case
oh hi
Ok i know TurnTime, but there is RoundTime, for timed missions, this can be done in Hedgewars???
Don't know about that one, however you can on 2nd turn set Human's team hogs health to 0, just so they will die.
oh hi
I'm not really sure what you mean, but in addition to TurnTime, there is also GameTime which refers to the total number of game ticks. Either TurnTime or GameTime could be used to create timed missions fairly trivially. You could also define your own timer and increment/decrement it on onGameTick() or onGameTick20().
Try this one, as an example: https://dl.dropboxusercontent.com/u/15139166/EndOfTheWorld.lua
Verifiable and visually viewable: https://youtu.be/vR0qwnPMCYU
mikade
Hedgewars Developer
Good video showcase, thanks for help.