Page 1 of 1
If Champ alive if Champ dead
Posted: Thu Feb 05, 2015 7:12 am
by Eleven Warrior
Hi all I need two different Scripts please. I want to be able to see if a Champ is Dead or Alive eg...
1 - Champs 1-4 check if they are dead or alive, then something happens
Script 1
if champ 1 is alive then
hudPrint("I am here")
elseif champ 1 is dead then
-- Another random champs says Boris is dead -- The random must be alive lol --
hudPrint('Boris is dead.")
end
Script 2
1 - Champs 1-4 check if they are dead or alive, then something happens.
if champ 1 is alive then
hudPrint("I can see the writing.")
elseif champ 1 is dead then
hudPrint('")
end
I need these scripts badly so any help would be most appreciated thxs

Re: If Champ alive if Champ dead
Posted: Thu Feb 05, 2015 8:11 am
by Frenchie
I think this will suffice for script 1:
Code: Select all
for i=1,4 do local ch = party.party:getChampion( i )
if ch:isAlive() do hudprint( ch:getName().." says he is here" )
else hudprint( ch:getName()..' is dead" ) end end end
I think the random option is possible but it would complicate things. To get a random number use this:
Edit : I was still trying to improve my script till minmay came to the rescue (I already tested it that %5 didn't work)
I thought I wanted to put the names of all the living and dead into 2-dimentional strings (living[1] to living[4] and dead[1] to dead[4]). Then use counters li and de to see how many of each I had. This is how far I got :
Code: Select all
living = { } dead = { } li = 0 de = 0
for i=1,4 do local ch = party.party:getChampion( i )
if ch:isAlive living[ i ] = ch:getName() li = li +1
else dead[ i ] = getName() de = de +1
end end
j = math.random ( 1, li )
- - if all dead this won't work
for i=1,li do local ch = party.party:getChampion( j )
hudprint ...
Re: If Champ alive if Champ dead
Posted: Thu Feb 05, 2015 9:16 am
by minmay
that won't work: 5 % 5 is equal to 0, not 1
also, you presumably didn't mean to make x a permanent field
also, you have a typo in there that will prevent it from running at all
here's a quick solution:
script 1:
Code: Select all
do
local ch = party.party:getChampion(1)
if ch:isAlive() then
hudPrint(ch:getName()..": I am here.")
else
local alive = {}
for i = 2,4 do if party.party:getChampion(i):isAlive() then table.insert(alive,i) end end -- skip champion 1, we already know they're dead
hudPrint(party.party:getChampion(alive[math.random(1,#alive)])..": "..ch:getName().." is dead.")
end
end
script 2:
Code: Select all
do
local ch = party.party:getChampion(1)
if ch:isAlive() then
hudPrint(ch:getName()..": I can see the writing.")
else
hudPrint("")
end
end
Re: If Champ alive if Champ dead
Posted: Thu Feb 05, 2015 10:11 am
by Eleven Warrior
Thank you very much guys most appreciated
EDIT: In fact this script(s) are awesome

Re: If Champ alive if Champ dead
Posted: Fri Feb 06, 2015 7:05 am
by Frenchie
A long long time ago (25 yrs or so) when I learned diagrams (psd and pss) to make a program work flows with arrows, I would first solve any problems before actually writing the code. Then you would see which approach would work and which not.
For example if you picked a random number between 1 and 4, then checked if that champion was alive it would be the speaker reporting the status of all other champions including himself. If he was dead what then? Do another random or go to the next champion. With another random the loop might take a long time. With the next champion you would first need to make sure that after the 4th champion you need to start again at the first and then check if he's alive. But you also must stop after 4 checks.
You probably will make a few flows on paper or in your head that don't work after testing and then think about which variables to use. Then after coding experience will let you optimize it. Maybe someone should pick up the
Lua Scripting Lesson again and optimize it for LoG2.
Re: If Champ alive if Champ dead
Posted: Fri Feb 06, 2015 8:34 am
by msyblade
minmay, you impress me more and more each and every day. Just. . .wow man.