Scripting - check enemy hedgehogs are dead

8 replies [Last post]
FanMarioPL
User offline. Last seen 9 years 33 weeks ago. Offline
Joined: 2013-04-13
Posts: 4

How do i check enemy hedgehogs are dead?
I want to make new mission unlock in my campaign when enemies are dead.

Vatten
Vatten's picture
User offline. Last seen 1 year 11 weeks ago. Offline
Joined: 2009-09-02
Posts: 48

Hello there!
try:

function onGearDelete(gearUid)
if(GetGearType(gearUid) == gtHedgehog and GetHogTeamName(gearUid) == "Enemy_team_name" and GetHogName(gearUid) == "Hogname")
then
AddCaption("Hogname died, oh noes!")
end
end

//Have fun!

Vattenania, my beloved motherland, my beloved homeland! You are always with me in my thoughts and in my heart!

FanMarioPL
User offline. Last seen 9 years 33 weeks ago. Offline
Joined: 2013-04-13
Posts: 4

Vatten allegedly wrote:

Hello there!
try:

function onGearDelete(gearUid)
if(GetGearType(gearUid) == gtHedgehog and GetHogTeamName(gearUid) == "Enemy_team_name" and GetHogName(gearUid) == "Hogname")
then
AddCaption("Hogname died, oh noes!")
end
end

//Have fun!


Thanks! Here is my full code if someone needs it:

function onGameStart()
enemies = 3
end

function onGameTick()
if(enemies < 1)
then
SaveCampaignVar("Progress", "1")
end
end

function onGearDelete(gearUid)
if(GetGearType(gearUid) == gtHedgehog and GetHogTeamName(gearUid) == "Enemies")
then
enemies = enemies - 1
end
end

sphrix
sphrix's picture
User offline. Last seen 2 weeks 17 min ago. Offline
Joined: 2011-04-07
Posts: 207

do vatten tip work ?

if it don't (but i'm sure it work Wink Smiley )
here is the thing i use in my campaign to check when a enemy die, thanks to mikade by the way

hogskilled = 0

onGameTick
if hogsKilled == 3 then
SaveCampaignVar("Progress", "1")
end
end

onGearDelete
if (GetGearType(gear) == gtHedgehog) and (gear ~= hhs[0]) then
hogskilled = hogskilled + 1
end
end

explaintation : ongeardelete : check that the deleted gear is an hedgehog, and that its not you (gear~= 'yourplayernameorsth'); so it gave +1 to hogskilled,
ongametick : check if you reach the number of hogkilled you want to unlock next mission

the beachs hogs surfin hedgewars

mikade
mikade's picture
User offline. Last seen 26 weeks 2 days ago. Offline
Joined: 2010-10-22
Posts: 355

Er, well, what you check and how you check it is obviously dependent on your end goals. Whether or not there are multiple hogs in multiple teams will affect what is the most efficient way of checking things.

FanMarioPL doesn't really explain the specifics of his mission, but as he wants to check for "enemy" hogs, I would probably suggest a check for a clan that is different to the player's clan using GetHogClan(hog). This way you can take into account allied hogs, or a mission using multiple enemy teams etc pretty easily. Hogs on the player's team / allied teams will share the same clan, and hogs who are enemies will not.

You guys probably shouldn't be checking hogskilled/enemies in onGameTick(), either. I don't see any reason why you would need to check that data at such a crazy rate. Rather just do the comparison in onGearDelete(), where the value itself is actually changing.

Good luck, and happy scripting.

mikade
Hedgewars Developer

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

As well as what mikade said about onGameTick (since, yes, that would repeatedly save the variable every tick Oo)

I would like to request that if a script doesn't require checking things each onGameTick, to try using onGameTick20.

onGameTick20 runs on tick 0, 20, 40...

A completely empty onGameTick function adds like 10% overhead to running the game.

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

FanMarioPL
User offline. Last seen 9 years 33 weeks ago. Offline
Joined: 2013-04-13
Posts: 4

I want to make a normal deathmatch campaign :p

sphrix
sphrix's picture
User offline. Last seen 2 weeks 17 min ago. Offline
Joined: 2011-04-07
Posts: 207

nemo, yes we can write it in geardelete instead of gametick,
i think i did it for some of my actual mission in work, maybe not the one where i copy this lines aha, but, i don't know if my next argument is good or not, cause i didnt verify : for my shoppa mission, its about time, so its faster to check in ongametick instead of geardelete, but as i said, not sure about what i say
i'll try to put things not in ongametick for the future if i can Wink Smiley

aslo : is it possible to have in a script :
ongametick()
XXXX
xxxx
end

ongametick20()
xxxx
xxxxx
yyreh
end

?

the beachs hogs surfin hedgewars

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

It is possible to have both, but it offers little benefit. Is actually a slight negative.
Basically, once you invoke onGameTick we are paying the cost.

At that point, you might as well just do a mod 20 inside onGameTick for the stuff you are calling less frequently.

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

User login

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