lua scripting -- onHogAttack(ammoType)

3 replies [Last post]
CheezeMonkey
User offline. Last seen 4 years 17 weeks ago. Offline
Joined: 2010-11-19
Posts: 117

Hey, its been a while since I posted here...

First off, since I didn't get the chance to say it yet, thanks to all the devs for cranking out the latest version of Hedgewars... and yes, I am a bit late. Smile

According to the LuaAPI at: https://code.google.com/p/hedgewars/wiki/LuaAPI#onHogAttack%28ammoType%29

Quote:
onHogAttack(ammoType)

This function is called when you press the attack key. Beginning with 0.9.21, the parameter ammoType is provided. It contains the ammo type of the weapon used for the attack.

However, it seems like the check for the ammo type occurs AFTER the weapon is used, so if you only have one ammo for the weapon used then ammoType returns "amNothing".

That doesn't really seem intentional... Wink Smiley

If anyone can think of a workaround I could use in the mean time that would be appreciated. I basically want to check to see if ammoType is one of the elements in an array (specifically all the weapons and utilities that end the turn).
Thanks in advance! Smile

sheepluva
sheepluva's picture
User offline. Last seen 1 hour 48 min ago. Offline
Joined: 2009-07-18
Posts: 562

Welcome back pal ^^

And huh, interesting, I shall look into it later today Smile

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


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

sheepluva
sheepluva's picture
User offline. Last seen 1 hour 48 min ago. Offline
Joined: 2009-07-18
Posts: 562

I wrote a fix that should go into next release.

For now you can probably work around it by caching the result of GetCurAmmoType() e.g. whenever onSetWeapon() is called or something.
Then use that cached value when handling onHogAttack().

The argument "AmmoType" for onHogAttack() is rather new anyway, so there might be existing scripts working using a workaround similar to the one above.

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


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

TheMadCharles
TheMadCharles's picture
User offline. Last seen 2 hours 1 min ago. Offline
Joined: 2012-10-19
Posts: 127

As sheepluva says, thats what you have to do

try this:

local AmmoType = nil

function onHogAttack()
     AmmoType = GetCurAmmoType()
     HogSay(CurrentHedgehog,'Weapon: '..AmmoType..'',SAY_SAY,2)
end

If everything is right, then hog once attack, he/she/it will say a number, or a value starting with 'am'.

Good Luck

oh hi

if any staff is reading this, plz rename me to "h3oCharles", thx in advance

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