Killing a random citizen
Thank you,
Aasfresser
procedure KillARandomCitizen;
var P: Integer; // P - player
var Units: array of Integer;
Units := States.PlayerGetAllUnits(P); //or just "0" instead of "P", if you want to get all units of player 1 (game counts locations from 0 :P)
UnitToBeKilled := Units[ KaMRandomI( Length(Units) ) ]; //we assign one of the units to a variale here - we randomly choose the number in "[ ]", which is the number of the unit from that player
if ( States.UnitType(UnitToBeKilled) < 14 ) then //we're checking for unit types < 14 - all military types have IDs greater than or equal to 14
Actions.UnitKill(UnitToBeKilled, False) //so if the unit is not a soldier, we kill it. Notice lack of ";" because we're before "else"
else
KillARandomCitizen; // if the unit was a soldier, we just try to kill another guy, until we find a citizen. This thing - using the function itself - is called recursion, you may want to google on that if you're interested ;)
Users browsing this forum: No registered users and 3 guests
Powered by phpBB® Forum Software © phpBB Group Designed by ST Software |
![]() |