Lua API suggestions

7 replies [Last post]
Wuzzy
Wuzzy's picture
User offline. Last seen 3 weeks 2 days ago. Offline
Joined: 2012-06-20
Posts: 1301

Lua scripters, suggest here additions you want to see in the Lua API.


I begin by suggesting a bunch of new functions. (Green = implemented, either in current or dev version)

CALLBACK FUNCTIONS:

  • onEndTurn(): Called when turn has ended (after retreat time)
  • onRetreat(): Called when retreat time started (I am not sure about this)
  • onReadyOver(): When the ready timer's up
  • onEffectChange(gear, effectType, oldState, newState): When the effect of an hedgehog has changed (i.e. became poisoned)

Not strictly needed callbacks (since could be detected by other means), just some convenience functions:

  • onNewRound(): new round (NOT TURN!) started
  • onSuddenDeath(): Sudden Death started
  • onCrateCollect(gear, crateType, crateContent): Crate was collected by gear. CrateType says if it is a health, utility or ammo crate. CrateContent is the ammo type of the crate (if ammo/utility) oder the health (if health crate). CrateContent is nil for fake crates (spawned with SpawnFakeAmmoCrate, etc.).

ACTION FUNCTIONS:

  • SuddenDeath(): Starts Sudden Death (no-op if already in Sudden Death)
  • TurnVampire(): Activates vampirism for current hog for free (lasts till end of turn)
  • EnableLaserSight(): Activates laser sight for current hog for free (lasts till end of turn)
  • EndTurn(retreat): Ends the turn of the current hedgehog (as if it had attacked with something) with an optional retreat argument. This argument specifies the retreat time in milliseconds, this time is also subject to change by the retreat time percentage of the game scheme. By default, there is no retreat time and the turn ends immediately. No-op when there is no “current hedgehog”. Example: EndTurn(3000) with 200% retreat time ends the turn with 6 seconds retreat time.
  • HogSwitch(): Enables hog switching for free (does not actually switch) for the current hedgehog. No-op if there is no current hedgehog or if it is already active. It is as if the player has activated hog switching manually.

HELPER FUNCTIONS:

  • GetTeams(): Returns a list of all team names
  • GetHogTeamNumber(hog): Returns the hog ID of hog (gear) in its team (the hog number is specified in the team editor. 0 = first hog in team, 1 = second hog in team, etc.)
  • GetHogByTeamNumber(int, teamName): Returns the int-th hog gear in the team of name teamName, but nil if it does not exist. Example: getHogByTeamName(0, "Awesome Team") returns the first hog of Awesome Team. Again, hog numbering depends on the team definition and does not change throughout the game.

EXPOSE NEW GAME VARIABLES:

  • InitHealth: Initial health
  • RopePercent: Rope length in percent
  • LandCurvyness: “Curvyness” level of landscape (what you can set with the slider below the random map preview)
  • WorldWrap: World wrap mode. I suggest using these additional variables for convenience:
    • wwNone: No border
    • wwOcean: Ocean border
    • wwBounce: Bouncy border
    • wwWrap: Wrap-around border

Hi, I am a Hedgewars developer. Smile

sheepluva
sheepluva's picture
User offline. Last seen 3 days 14 hours ago. Offline
Joined: 2009-07-18
Posts: 563

"LandCurvyness" will be exposed in 0.9.22 during onGameInit and onPreviewInit as MapFeatureSize

Smaller values means the generated map will have more (small detail).

Wuzzy via live-chat allegedly wrote:
minimum position is 1, max position is 25, default (???????????????) position is 12

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


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

Wuzzy
Wuzzy's picture
User offline. Last seen 3 weeks 2 days ago. Offline
Joined: 2012-06-20
Posts: 1301

Idea for another helper function:

AddStandardCaption(code, ...)

This shows a caption like AddCaption, but the text will automatically selected from Data/Locale/en.txt (or whatever the client language is). The color and caption group is also automatically selecteed based on the code. The code is the number to identify the messages in en.txt (i.e. “02:00”).

Additional arguments are used to fill in the string parameters (“%1”, “%2”, etc.) in the respective order (so argument 2 of the function will be mapped to “%1” in the string, argument 3 to “%2”, etc.).

Example:

AddStandardCaption("02:02")

Shows one of the “round starts” messages, i.e. “Let's fight!”, “May the best hog win”, etc.

Example:

AddStandardCaption("02:00", "Awesome Hog")

This displays one of the “death” messages (as if Awesome Hog has actually died). “Awesome Hog” is filled in for “%1”, so this might result in:

“Awesome Hog has kicked the bucket”
“Awesome Hog could have used an extra life”
etc.

Returns true on success, false otherwise (i.e. code not found).

Hi, I am a Hedgewars developer. Smile

francot514
User offline. Last seen 1 year 24 weeks ago. Offline
Joined: 2015-03-20
Posts: 163

Quote:

onEndTurn(): Called when turn has ended (after retreat time)

onNewRound(): new round (NOT TURN!) started
onSuddenDeath(): Sudden Death started

I support this ones, they are needed for do end turn special events, or new round /sudden death triggers!

nemo
nemo's picture
User offline. Last seen 3 weeks 21 hours ago. Offline
Joined: 2009-01-28
Posts: 1861

So. What sort of end turn triggers are you thinking about?
'cause onEndTurn is awfully close to onNewTurn - I mean, I see the distinction, there's a small number of things that happen after hog loses control, like crate spawn, poison. But, lua could do those things in onNewTurn too, just slightly delayed is all.

--
Oh, what the heck. 1PLXzL1CBUD1kdEWqMrwNUfGrGiirV1WpH <= tip a hedgewars dev

Wuzzy
Wuzzy's picture
User offline. Last seen 3 weeks 2 days ago. Offline
Joined: 2012-06-20
Posts: 1301

Well, first of all, when onNewTurn happens, the old CurrentHedgehog is lost.

So I want onEndTurn to still have the CurrentHedgehog hold the hog for which the turn ended.

I am looking for a callback for the exact moment when the hog lost control, that is, when the retreat timer went to 0. This means, it is before all the turn-based stuff like crate drops, poisoning etc. Also, the shot bazooka (for example) could still by flying in this moment.

I admit it is mostly a convenience callback, but it would a lot of tasks much more straight-forward to do. Also, there are some situations where you don't want the next turn to start at all (maybe you want to end the game).

Hi, I am a Hedgewars developer. Smile

francot514
User offline. Last seen 1 year 24 weeks ago. Offline
Joined: 2015-03-20
Posts: 163

Quote:
I am looking for a callback for the exact moment when the hog lost control, that is, when the retreat timer went to 0. This means, it is before all the turn-based stuff like crate drops, poisoning etc. Also, the shot bazooka (for example) could still by flying in this moment.

You can do this only with Lua or you have to change source code?? If no source code changes is requiered for this changes, will be good see this included in your game Hack.

Wuzzy
Wuzzy's picture
User offline. Last seen 3 weeks 2 days ago. Offline
Joined: 2012-06-20
Posts: 1301

francol514, I don't quite understand what you are saying. This is a thread for requestion new features in the Lua API. My Game Hacks script itself is written in Lua, so this is not really the place to extend the Lua API. Wink Smiley

Anyways, another request:

It would be useful if all of the enumeration variables (gear types, ammo types, etc) would be accessible in a table to easily iterate through all of them.
Useful if you need to remove all weapons or something like this.

Without this, I'd have to hardcode the number of weapons into my scripts, for example, which is very ugly, of course. Sad Smiley

Hi, I am a Hedgewars developer. Smile

User login

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