Lua Help

2 replies [Last post]
yellowcrash10
yellowcrash10's picture
User offline. Last seen 6 years 11 weeks ago. Offline
Joined: 2012-01-14
Posts: 20

Hello! I'm trying to make a new training mission and I need some help. I'm trying to change the rope length option so ropes are longer, but I can't figure out what the option is called in Lua.

Also, is there any way to make a hedgehog equip a weapon and fire it? I'm trying to make a short "movie" with the Lua API and I need some of the hedgehogs to attack.

And is there a way to bind keys to actions? For example:

Quote:
function onKeyPress()
if key = "k" then
createACircle (somewhere, red, 5)
wait (5)
deleteACircle (somewhere)
end
end

I know that isn't real code. I'm working on that Smile

Aww, man!

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

I'm unaware of whether or not rope length has been exposed to lua.
You can make a hog equip and fire using a weapon using parsecommand and/or gear messages.
You can't bind generic keys to actions, but there are hooks in most of the player-based actions (which are fired when you push the keys associated with those actions).

mikade
Hedgewars Developer

yellowcrash10
yellowcrash10's picture
User offline. Last seen 6 years 11 weeks ago. Offline
Joined: 2012-01-14
Posts: 20

mikade allegedly wrote:

I'm unaware of whether or not rope length has been exposed to lua.
You can make a hog equip and fire using a weapon using parsecommand and/or gear messages.
You can't bind generic keys to actions, but there are hooks in most of the player-based actions (which are fired when you push the keys associated with those actions).

Thanks for the reply! How would I use a gear message or parse a command to change the currently equipped weapon? I have about seven tabs open with information about Hedgewar's Lua API and they don't really tell you very much about commands you can use with them. Would it be something like this?

Quote:
SetGearMessage(enemy1, "equip gtAmmo_Grenade")

Thanks!

EDIT:
I was searching through the Hedgewars source code and discovered this:

Quote:
RegisterVariable('ropepct' , vtLongInt, @cRopePercent , false);

and this:
Quote:
procedure chSetWeapon(var s: shortstring);
begin
if (s[0] <> #1) or CheckNoTeamOrHH then
exit;

if TAmmoType(s[1]) > High(TAmmoType) then
exit;

if not CurrentTeam^.ExtDriven then
SendIPC('w' + s);

with CurrentHedgehog^.Gear^ do
begin
Message:= Message or (gmWeapon and InputMask);
MsgParam:= byte(s[1]);
ScriptCall('onSetWeapon', MsgParam);
end;
end;


and this:
Quote:
RegisterVariable('setweap' , vtCommand, @chSetWeapon , false);

Is this what you were telling to me about? There wasn't a thing for the @cRopePercent, but there also isn't one for the @cExplosives either.

Aww, man!

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