Kill all AI

In this forum you will find and post information regarding the modding of Star Wars Battlefront 2. DO NOT POST MOD IDEAS/REQUESTS.

Moderator: Moderators

Post Reply
User avatar
Lorul1
Rebel Colonel
Rebel Colonel
Posts: 562
Joined: Wed Apr 24, 2013 10:34 pm
Projects :: Assault on Theed
Games I'm Playing :: Battlegrounds
xbox live or psn: No gamertag set
Location: Your House

Kill all AI

Post 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?
JimmyAngler
High General
High General
Posts: 837
Joined: Mon Nov 04, 2013 10:37 am
Projects :: Battlefront Halation
Games I'm Playing :: SWBF 1-2-2015
xbox live or psn: none
Location: Area 51

Re: Kill all AI

Post 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:
User avatar
Lorul1
Rebel Colonel
Rebel Colonel
Posts: 562
Joined: Wed Apr 24, 2013 10:34 pm
Projects :: Assault on Theed
Games I'm Playing :: Battlegrounds
xbox live or psn: No gamertag set
Location: Your House

Re: Kill all AI

Post 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")
MileHighGuy
Jedi
Jedi
Posts: 1194
Joined: Fri Dec 19, 2008 7:58 pm

Re: Kill all AI

Post 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.
User avatar
Lorul1
Rebel Colonel
Rebel Colonel
Posts: 562
Joined: Wed Apr 24, 2013 10:34 pm
Projects :: Assault on Theed
Games I'm Playing :: Battlegrounds
xbox live or psn: No gamertag set
Location: Your House

Re: Kill all AI

Post 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:
User avatar
Locutus
1st Lieutenant
1st Lieutenant
Posts: 420
Joined: Fri Jun 04, 2010 10:08 am
Projects :: Stargate Battlefront Pegasus
Location: Germany
Contact:

Re: Kill all AI

Post 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....
User avatar
Lorul1
Rebel Colonel
Rebel Colonel
Posts: 562
Joined: Wed Apr 24, 2013 10:34 pm
Projects :: Assault on Theed
Games I'm Playing :: Battlegrounds
xbox live or psn: No gamertag set
Location: Your House

Re: Kill all AI

Post 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:
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: Kill all AI

Post 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

Post Reply