How to do... Mission scripting

23 replies [Last post]
francot514
User offline. Last seen 2 years 2 weeks ago. Offline
Joined: 2015-03-20
Posts: 163

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...

sheepluva
sheepluva's picture
User offline. Last seen 21 weeks 5 days ago. Offline
Joined: 2009-07-18
Posts: 563

In Lua?

You can set such things like GameFlags (click here for list) in the event handler onGameInit (click here for more Info)

wiki allegedly wrote:
EnableGameFlags(gfSolidLand, gfArtillery) - sets the GameFlags (just 2 of them in this example)

  sheepluva <- me  my code stats -> 
a Hedgewars Developer


   <- where I'm from  what I speak -> 

francot514
User offline. Last seen 2 years 2 weeks ago. Offline
Joined: 2015-03-20
Posts: 163

Ok, just to confirm that only works for game flags, becuase lua api for general variables says this:

Quote:
Here are some unsorted variables or constants which are available in Lua. You shouldn’t write to most of them.

sheepluva
sheepluva's picture
User offline. Last seen 21 weeks 5 days ago. Offline
Joined: 2009-07-18
Posts: 563

francot514 allegedly wrote:

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


   <- where I'm from  what I speak -> 

francot514
User offline. Last seen 2 years 2 weeks ago. Offline
Joined: 2015-03-20
Posts: 163

Quote:
TurnTimeLeft can be written to directly and WaterLine via SetWaterLine().

All other Globals are read-only if I'm not mistaken.

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??

sheepluva
sheepluva's picture
User offline. Last seen 21 weeks 5 days ago. Offline
Joined: 2009-07-18
Posts: 563

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):

(Lua API Wiki: Globally available variables) allegedly wrote:
TotalRounds Number of rounds that have passed

francot514 allegedly wrote:

-How to do ally teams, and there should be always player team and 1 enemy team??

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:

(Lua API Wiki: GameFlags) allegedly wrote:
gfOneClanMode Used when only one clan is in the game. This game flag is primarily used for training missions.

  sheepluva <- me  my code stats -> 
a Hedgewars Developer


   <- where I'm from  what I speak -> 

francot514
User offline. Last seen 2 years 2 weeks ago. Offline
Joined: 2015-03-20
Posts: 163

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

h3oCharles
h3oCharles's picture
User offline. Last seen 4 weeks 1 day ago. Offline
Joined: 2012-10-19
Posts: 140

sheepluva allegedly wrote:

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):

(Lua API Wiki: Globally available variables) allegedly wrote:
TotalRounds Number of rounds that have passed

francot514 allegedly wrote:

-How to do ally teams, and there should be always player team and 1 enemy team??

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:

(Lua API Wiki: GameFlags) allegedly wrote:
gfOneClanMode Used when only one clan is in the game. This game flag is primarily used for training missions.

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.

francot514 allegedly wrote:

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

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

francot514
User offline. Last seen 2 years 2 weeks ago. Offline
Joined: 2015-03-20
Posts: 163

Quote:
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.

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...

mikade
mikade's picture
User offline. Last seen 45 weeks 1 day ago. Offline
Joined: 2010-10-22
Posts: 355

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

francot514
User offline. Last seen 2 years 2 weeks ago. Offline
Joined: 2015-03-20
Posts: 163

Please some help, i need example of how to OnNewTurn() and check for turn number..

mikade
mikade's picture
User offline. Last seen 45 weeks 1 day ago. Offline
Joined: 2010-10-22
Posts: 355

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:

Quote:

local turnN = 0

function onNewTurn()
turnN = turnN +1
AddCaption("It is now turn: " .. turnN)
end

mikade
Hedgewars Developer

h3oCharles
h3oCharles's picture
User offline. Last seen 4 weeks 1 day ago. Offline
Joined: 2012-10-19
Posts: 140

mikade allegedly wrote:

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: [...]

Thing is, is that on var TotalRounds, the first turn has value of -1. Watch out with that.

oh hi

francot514
User offline. Last seen 2 years 2 weeks ago. Offline
Joined: 2015-03-20
Posts: 163

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...

mikade
mikade's picture
User offline. Last seen 45 weeks 1 day ago. Offline
Joined: 2010-10-22
Posts: 355

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

francot514
User offline. Last seen 2 years 2 weeks ago. Offline
Joined: 2015-03-20
Posts: 163

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

mikade
mikade's picture
User offline. Last seen 45 weeks 1 day ago. Offline
Joined: 2010-10-22
Posts: 355

Strange trigger, but seems like it would work.
Let us know if you need more help.

mikade
Hedgewars Developer

francot514
User offline. Last seen 2 years 2 weeks ago. Offline
Joined: 2015-03-20
Posts: 163

Quote:
Strange trigger, but seems like it would work.
Let us know if you need more help.

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??

mikade
mikade's picture
User offline. Last seen 45 weeks 1 day ago. Offline
Joined: 2010-10-22
Posts: 355

function onGameInit()
TurnTime = 30000
SuddenDeathTurns = 1
WaterRise = 47
end

mikade
Hedgewars Developer

h3oCharles
h3oCharles's picture
User offline. Last seen 4 weeks 1 day ago. Offline
Joined: 2012-10-19
Posts: 140

francot514 allegedly wrote:

Quote:
Strange trigger, but seems like it would work.
Let us know if you need more help.

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??

I would recommend going HERE. In this case, look for 'onGameInit'.

mikade allegedly wrote:

function onGameInit()
TurnTime = 30000
SuddenDeathTurns = 1
WaterRise = 47
end

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

francot514
User offline. Last seen 2 years 2 weeks ago. Offline
Joined: 2015-03-20
Posts: 163

Quote:
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.

Ok i know TurnTime, but there is RoundTime, for timed missions, this can be done in Hedgewars???

h3oCharles
h3oCharles's picture
User offline. Last seen 4 weeks 1 day ago. Offline
Joined: 2012-10-19
Posts: 140

francot514 allegedly wrote:

Quote:
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.

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

mikade
mikade's picture
User offline. Last seen 45 weeks 1 day ago. Offline
Joined: 2010-10-22
Posts: 355

francot514 allegedly wrote:

Ok i know TurnTime, but there is RoundTime, for timed missions, this can be done in Hedgewars???

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

francot514
User offline. Last seen 2 years 2 weeks ago. Offline
Joined: 2015-03-20
Posts: 163

Quote:
here 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.

Good video showcase, thanks for help.

User login

Copyright © 2004-2024 Hedgewars Project. All rights reserved. [ contact ]