Spawn on death

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
User avatar
Alcoholic
General
Posts: 1470
Joined: Sat May 17, 2003 5:57 am
Location: California
Contact:

Spawn on death

Post by Alcoholic »

Is there anyway to spawn on item when an AI dies? i want to make it so that when the captain dies, he drops the battle plans that you use to continue the mission.
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

tiki

Post by tltrude »

Have you tried key I. If you give him a targetname, you can make him drop anything you like with the script.
Tom Trude,

Image
Parts
Sergeant
Posts: 72
Joined: Thu Apr 10, 2003 12:35 pm
Location: UK
Contact:

Post by Parts »

just create a thread waiting for the AI to die. As tltrude says you need to give the captain a targetname. The script below assumes you have given your AI a target name of captain

Code: Select all

main:

//All your normal script stuff

thread CaptainDeath

end

CaptainDeath:

   //Thread will wait until the death even happens
   $captain waittill death

   local.newobject = spawn .... etc etc

   //below line places the new object where the captain is
   local.newobject.origin = $captain.origin
end
[VS-UK]Capt.Parts[BnHQ]
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

good

Post by tltrude »

That looks good Parts, but what about giving the "battle plans " a targetname so it can be picked up?
Tom Trude,

Image
User avatar
Alcoholic
General
Posts: 1470
Joined: Sat May 17, 2003 5:57 am
Location: California
Contact:

Post by Alcoholic »

ok thats a great idea, but i have no knowledge about local classes the only one i use is level because local is really weird to me. ill try to do that, but whats this key I your talking about tltrude?
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

local is not extremely weird, it refers to the ScriptThread object the code is in. This means that when the thread ends, the object is removed and thus any local values are erased. level variables always keep their value. You will have to use local variables when your script expands.

If you use the spawn command you don't have to use a targetname (which is definately a work-around). Instead, you could make it a variable of another listener immediately.

e.g.:

level.battle_plans = spawn combat_info/plans/mybattleplans.tik
local.battle_plans = spawn combat_info/plans/mybattleplans.tik
$captain.battle_plans = spawn combat_info/plans/mybattleplans.tik (not recommended)
Image
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

video tutroial

Post by tltrude »

There is a really good tutorial on setting AI properties (key I) at this site.

http://www.carbongraphx.com/mohaa/vidtuts.html

Although Alcoholic is catching on fast, I think you guys may be two or three steps above his current scripting skill level.
Tom Trude,

Image
Parts
Sergeant
Posts: 72
Joined: Thu Apr 10, 2003 12:35 pm
Location: UK
Contact:

Post by Parts »

you can give spawned objects target names like this:

Code: Select all

spawn combat_info/plans/mybattleplans.tik "targetname" "BattlePlans"

$BattlePlans.origin = (20 20 0)
For example
[VS-UK]Capt.Parts[BnHQ]
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post by bdbodger »

If you want to pick up or should I say remove the item spawned you will have to make it a script model . I tried once in a map to place explosives to pick up . I could not get it to work until I made it a script model . So spawn a script model

local.droped= spawn script_model "model" "blabla.tik" .

You can ask jv or someone but I think it is possible to also spawn a trigger_use . Or make a trigger_use give it a targetname and hide it under the map or something then when the captain dies move it to the spot where he died . If the trigger has a setthread for when it is used you can maybe use the global items script to add the plans to the hud like you do with level1 papers etc . I see there is a german battleplans item in that script .

waitthread global/items.scr::add_item "battleplans"
Post Reply