Page 1 of 1
Lua question. (Solved)
Posted: Mon Jan 26, 2009 10:30 am
by Yodakid
Is there a code for killing all AI on one team?
Re: Lua question.
Posted: Mon Jan 26, 2009 12:35 pm
by [RDH]Zerted
Loop through all the players on the team. If the player is an AI and is alive, kill its unit.
Re: Lua question.
Posted: Mon Jan 26, 2009 3:28 pm
by Yodakid
Uh, I don't really understand what to do.
Also the exactely thing I'm trying to do is, in one objective in campaign, all AI units on one team gets killed.
Re: Lua question.
Posted: Mon Jan 26, 2009 3:46 pm
by (RAPTOR)BENSTWO{SGT}
Not sure if this is what you mean, but you could do it with fake councel.
Re: Lua question.
Posted: Mon Jan 26, 2009 3:58 pm
by Yodakid
I mean a lua code for it. To use in campaign mode.
Re: Lua question.
Posted: Mon Jan 26, 2009 4:25 pm
by G_M_StYlEr_M
Yodakid wrote:I mean a lua code for it. To use in campaign mode.
make it with the fake consol its easyer

(nice)
Re: Lua question.
Posted: Mon Jan 26, 2009 4:35 pm
by Master_Ben
It doesn't matter if it's easier, he's making a map to be distributed and the people playing it wouldn't know to do that.
Re: Lua question.
Posted: Mon Jan 26, 2009 5:23 pm
by Yodakid
Master_Ben wrote:It doesn't matter if it's easier, he's making a map to be distributed and the people playing it wouldn't know to do that.
That's exactely what I mean.
Re: Lua question. (Still unsolved)
Posted: Tue Jan 27, 2009 12:47 am
by Frisbeetarian
Your question was answered in the first reply. He would know; he had to do it using Lua for the fake console.
Re: Lua question. (Still unsolved)
Posted: Tue Jan 27, 2009 4:27 pm
by Master_Ben
Frisbeetarian wrote:Your question was answered in the first reply. He would know; he had to do it using Lua for the fake console.
Then came the second post:
Yodakid wrote:Uh, I don't really understand what to do.
Also the exactely thing I'm trying to do is, in one objective in campaign, all AI units on one team gets killed.
Re: Lua question. (Still unsolved)
Posted: Tue Jan 27, 2009 4:57 pm
by Yodakid
Anyone that can help me? I've tryed many of my own codes such as: KillAllUnits(DEF), KillAIUnits(CIS, true) and
DEF_UnitCount = GetUnitCount(DEF) SetUnitCount(DEF, DEF_UnitCount - 100)
and KillAIUnits(Team = CIS). But no succes.
Re: Lua question. (Still unsolved)
Posted: Wed Jan 28, 2009 2:44 pm
by Master_Ben
I dunno still, but you can't just make up codes off the top of your head.
Re: Lua question. (Still unsolved)
Posted: Wed Jan 28, 2009 3:15 pm
by Yodakid
Yeah, I know, I know... They were just some desperate tryes.

Re: Lua question. (Still unsolved)
Posted: Wed Jan 28, 2009 3:36 pm
by Eggman
I'd recommend just waiting for Zerted to explain his solution to you.
I'd been wondering how to do this same thing not too long ago though, and while I haven't tried it out yet, one possibility I thought of was to use 'SetClassProperty' to set health for all units of a class to zero. It would look something like this:
SetClassProperty( <unit class> , "CurHealth", 0)
If it worked the way I was hoping it would, every unit from the class you specify would be killed. So say if you wanted to kill every unit on the field that was called "all_inf_rifleman," you would use:
SetClassProperty( "all_inf_rifleman" , "CurHealth", 0)
Again, I haven't tried this myself, so I can't guarantee it will work. But if you want to play around with ideas besides what Zerted is talking about, you might as well give it a try.
EDIT: If this were to work though, keep in mind that it affects ALL units of the class you want to kill. So make sure you don't try to kill the units in a class that you're playing as, because you'll be killed as well.
Re: Lua question.
Posted: Wed Jan 28, 2009 4:56 pm
by [RDH]Zerted
[RDH]Zerted wrote:Loop through all the players on the team. If the player is an AI and is alive, kill its unit.
That is exact logic you want to use. I still haven't reinstalled the mod tools since December, so I can't give you the exact code.
You use the functions similar to:
GetTeamSize( <team #> )
char = GetTeamMember( <team #>, <player #> )
IsCharacterAlive( char )
IsCharacterAIOrHuman( char )
unit = GetCharacterUnit( char )
KillObject( unit )
Look at the function lists on GT, the scripting documentation, and use the Example Finder to see how those functions are used.
Re: Lua question. (Still unsolved)
Posted: Wed Jan 28, 2009 5:25 pm
by Yodakid
Thank you!
