Page 1 of 1

Kill all AI

Posted: Thu Nov 21, 2013 6:51 pm
by Lorul1
So, I have one of these things below (I call them scripts)

animateobja = OnObjectKill(
function(object, killer)
if GetEntityName(object) == "objectBnameinZeroEditor" then
PlayAnimation("whateveranimationgroup")
end
end
)

I need a new "script" (like the one above) to kill all the units that are AI when the object that I want gets destroyed.

[AND ONLY THE AI WILL BE KILLED, ALL HUMAN PLAYERS WONT DIE(this map will be played online that's why)]

anyway is there an function that will do this. Also when all the AI die I want them to never spawn again (like the "disable AI spawning" button on the fake console) . I'm guessing that will require another "script"
so...
What are the functions that I will need for both disable AI spawning, and killing all (and olny) AI
and if there are no functions for this how can i achieve my two goals above through my lua?

Re: Kill all AI

Posted: Fri Nov 22, 2013 9:16 am
by JimmyAngler
I'm not quite sure about all this 'causei'm new but here's my guess at it.

To begin, look at a script that has something destroyed when another object is destroyed. (Mygeeto shield for example.)
Find the part with the destruction of the object destroys another object part. And paste that in your script.
Second, Look at the scripts of the fake console (if that's possible) and find out how it disables AI spawning and kills all AI. My guess would be to take those command scripts and put them in place of the destruction of the shield (again referring to mygeeto campaign.)

Last, thank me if I got it right (probably not but I wanted to type a bit this morning)
or give me a :cpu:

Re: Kill all AI

Posted: Sun Nov 24, 2013 4:09 pm
by Lorul1
I found out how to disable and enable AI spawning from looking at the geonosis campaign lua.
8)

kill = OnObjectKill(
function(object, killer)
if GetEntityName(object) == "objectBnameinZeroEditor" then
PlayAnimation("whateveranimationgroup")
end
end
)

This means now all I need is the part that is highlighted in green above needs to kill all AI.
NOW my overall question is simply this:

What do I put in place of the green above that kill all the AI (OR all the AI on just 1 team, I can always make two "scripts")

Re: Kill all AI

Posted: Sun Nov 24, 2013 4:15 pm
by MileHighGuy
I think there is a function on the fake console of the v1.3 patch that kills ai. I dont know what it is so you'll have to ask its creator.

Re: Kill all AI

Posted: Sun Nov 24, 2013 7:46 pm
by Lorul1
Mmmmmmmm :?
Okay we'll if any one knows what it is that'll be helpful, because of 2 reasons.

1. I don't know if the creator of the fake console is still active

2. I believe it against the rules to ask people questions like that through pm. :o unless of corse an admin lets me ask that question through pm for the good of ALL that want to know the kill all AI scrip :yes:

Re: Kill all AI

Posted: Sun Nov 24, 2013 9:49 pm
by Locutus
Use AllowAISpawn(false) to prevent the AI from spawning.
I can't think of a nice way to get rid of all bots now but you could go the hackish way by teleporting the player somewhere outside the playable part of the map, then activating a death or damage region that kills everything inside the playable part, deactivate it and then teleport the player back. Or simply kill the player along with the AI but force him to respawn at the position he died....

Re: Kill all AI

Posted: Sun Nov 24, 2013 10:06 pm
by Lorul1
:? ... :) .... :D not a half bad idea activating a death region

... Thanks for the help, well if any one finds out the thing for making all AI die by asking the creator of the fake console then post it here ( therefore I won't close this topic )

btw if your reading this and need to know how and would like to know how to activate a death region just click here :thumbs:

Re: Kill all AI

Posted: Sun Dec 01, 2013 7:35 pm
by [RDH]Zerted
I don't care if people PM or email me, but I don't guarantee a timely response.

AllowAISpawn( <team number>, <true or false>)

If you want to require.... sorry I've got to catch a bus....

Code: Select all

if uf_killUnits ~= nil then
    uf_killUnits( {1,2}, true )  --{1,2} are the teams and true means only kill AI (false means also kill humans
else
    print("WARNING: uf_killUnit() not found so likely v1.3 not installed.  ")
end
This is the code v1.3 uses to kill the units. Please don't copy this code into your program without changing the function names. You guys can call these functions if you want to use them.

Code: Select all

--
---- Description ----
-- Applies the given function to all the units of the given teams
--
---- Parameters ----
--cont      - the continuation function to call.  Should take 3 parameters: unit, property, value
--property  - value to be passed on to the given cont function
--value     - value to be passed on to the given cont function
--teams     - a table of numbers which represent team numbers 
--aiOrHuman - "ai" to only process AI bots, "human" to only process human players, nil to process both bots and humans
--
---- Returns ----
-- (nothing)
--
function uf_applyFunctionOnTeamUnits( cont, property, value, teams, aiOrHuman )
	if cont == nil then return end	--if have nothing to do, then do nothing

	--the teams whos units will have the given function applied to them
	local teams = teams or {1, 2}

	--for each team,
	local team
	for team = 1, table.getn(teams) do

		--get the team's size
	    local size = GetTeamSize( teams[team] )

	    --for each team member,
	    local m
	    for m = 0, size-1 do

	        --get a team member's unit
	        local player = GetTeamMember(teams[team], m)
	        local type = IsCharacterHuman(player)
			if (type and (aiOrHuman == "ai")) or ((not type) and (aiOrHuman == "human")) then
				--player is not the correct type
			else
				local unit = GetCharacterUnit(player)
				print( "uf_applyFunctionOnTeamUnits(): Team, Unit:", team, m ) 
	            cont(player, unit, property, value)
			end

		end
	end
end


--
---- Description ----
--  Kills the units on the given teams
--
---- Parameters ----
-- teams - a table of teams whose units should be killed
-- ai    - true to kill only AI units, false to kill only human units
--
---- Returns ----
-- (nothing)
--
function uf_killUnits( teams, ai )
	--check input
	if teams == nil then return end
	if ai == nil then return end

	--
	local miniFun = function( player, unit, property, ai, teams )
		if (player == nil) or (unit == nil) or (ai == nil) then return end	--check input

		--determine the player type (ai or human)
		--local isAi = true
		--if IsCharacterHuman(player) then
		--	isAi = false
		--end
		local isAi = not IsCharacterHuman(player)

		--if is the correct type, kill it
		if (isAi == ai) then
			KillObject( unit )
		end
	end

	uf_applyFunctionOnTeamUnits( miniFun, nil, ai, teams )
end