Spawn an object

Post your scripting questions / solutions here

Moderator: Moderators

Mistab33n
Lance Corporal
Posts: 15
Joined: Wed Jun 11, 2003 2:45 pm

Spawn an object

Post by Mistab33n »

ok this is what i need to do:
i have a trigger brush in my map, and when i USE the trigger there should spawn a model on a specific place somewhere.
does someone knows how to do do this plz, i looked in all tuts but coulnd find it.

greetz mistabeen
Slyk
Lieutenant Colonel
Posts: 361
Joined: Sun Jul 14, 2002 12:42 am
Location: Elizabethtown, PA

Post by Slyk »

OK, I'll try to explain this using some of one of my scripts....which is more complicated than you need but maybe it will help....

First: This is set up with a 'switch/lever' that when triggered will spawn an explosion at one of three random loctions.

What you need to do:
1. create a 'script/origin' where you want to spawn the object. Name it with the key: $targetname and value: name

- now you need to input the model info for the object you want to spawn. For me it was a key: model value: emitters/mortar_concrete.tik

2. next set up your switch. You need to create the actual switch, right click and make it a 'script/object' and give it a '$targetname' and 'name' also. Mine below is a name of 'atswitch'.

3. next add another little brush at the bottom of your switch. Texture it with the 'origin' texture. Then right click and make it a 'script/object'. Now give it the 'targetname' and 'name'. Mine is named 'atswitch_origin'.

4. create a trigger drawing a brush the size you need covering the switch. Next right click and make it a 'trigger/use'. It will auto change to the texture for you. Name it. Mine is 'atswitch_trigger'.

- ALSO with the trigger... you need the lines: Key: setthread Value: threadname Mine is Key: setthread Value: atfire (this tells the trigger what script to run to spawn your object, etc.)

5. After your 'Level Waittill Spawn' header you need to add:
level.at2switch_up (replace with your switch name) = 1
yours should look like this: level.yourswitchname_up =1

and then this line changing the names:
$atshell1_spawn1 bind $atshell1
(name of script/origin) bind (name of object that is spawned) this ties the object to the spawn location.


NOW FOR THE SCRIPT::::::::::: BE VERY CAREFUL WITH WHAT YOU CHANGE.

FIRST OFF: change my text of "atswitch_" to the name of yours in all places. If mine says "$atswitch_trigger" yours should be "$yourswitch_trigger" or "$yourswitch_origin" etc. It's best to use a standard name for ALL the components, much easier that way.

I left in the sounds, although the reload one isn't working right.

Last part of the script sets up 'where' the object spawns. In that section "atshell1" is the name of the spawned object so change that to match your objects name in all places. The other section gives you up to three random spots to spawn the object. IF you are using only 1 spot, delete that text or ignore it...it won't hurt anything.
In my example I'm spawning a mortar explosion that gives a radius of damage. Pretty cool, actually. MORE QUESTIONS??? POST, JV will be along soon enough to amend this for sure.

OH... if you want this to spawn the object only once, you need to do more with the script by adding the line: "$yourswitch_trigger remove" near the end of the script just before "end". That will prohibit more than one use. Other stuff can be done too, but this is quick and dirty.

//--------------------------------------------------------------
// Move the switch handle - AT Gun 1
//--------------------------------------------------------------
atfire:
$atswitch_trigger nottriggerable
$atswitch bind $atswitch_origin
if( level.atswitch_up == 1 )
{
$atswitch_origin speed 1.0
$atswitch_origin rotatezdownto 180
$atswitch_origin waitmove
$atswitch_origin playsound switchbox

level.atswitch_up = 2
}

$atswitch_origin playsound tank_snd_fire1
//wait 1.0
$atswitch_origin playsound king_snd_reload

thread at50fire

wait 3.5

$atswitch bind $atswitch_origin
if( level.atswitch_up == 2 )
{
$atswitch_origin speed 1.0
$atswitch_origin rotatezupto 0
$atswitch_origin waitmove
$atswitch_origin playsound switchbox
level.atswitch_up = 1

$atswitch_trigger triggerable
}
end


//--------------------------------------------------------------
// Fire the Gun - AT Gun 1 SPAWNS A RANDOM TARGETED SHELL
//--------------------------------------------------------------

at50fire:
wait .25
local.location = ((randomint (2)) + 1)
local.location = $("atshell1_spawn" + local.location)
$atshell1.origin = local.location.origin

$atshell1 anim start
$atshell1 damage 300
radiusdamage $atshell1 512 384

wait .25

end
Mistab33n
Lance Corporal
Posts: 15
Joined: Wed Jun 11, 2003 2:45 pm

Post by Mistab33n »

can you add me on msn plz :oops:
its to complicated, i understand s***t of it :(
i am trying but its to complicated for me

plz add me on msn mistab33n@hotmail.com i need this for something the modernmods could use :)
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post by bdbodger »

for something a little less compicated try this

make a script_origin give it a $targetname of lets say spawn_origin

give your trigger_use a key: setthread Value: spawn_thing

in your script

spawn_thing:
local.temp = spawn models/kingtank.tik "targetname" "tank1"
local.temp.origin = $spawn_thing.origin
end
Slyk
Lieutenant Colonel
Posts: 361
Joined: Sun Jul 14, 2002 12:42 am
Location: Elizabethtown, PA

Post by Slyk »

Sorry, told you it might be a lot. If you want to move a switch and have it make a sound, you need a version like mine. I didn't explain it all to well though. Best bet to work with it is copy it out and make a test script and then go through and change the targetnames to yours OR better yet create a test map matching my targetnames and then slowly change everything to your own names. That would help you understand it. IF I can get some free time, I'll send you a small map file if you want.
Mistab33n
Lance Corporal
Posts: 15
Joined: Wed Jun 11, 2003 2:45 pm

Post by Mistab33n »

bdbodger wrote:for something a little less compicated try this

make a script_origin give it a $targetname of lets say spawn_origin

give your trigger_use a key: setthread Value: spawn_thing

in your script

spawn_thing:
local.temp = spawn models/kingtank.tik "targetname" "tank1"
local.temp.origin = $spawn_thing.origin
end
thx, allot shorter, but only 1problem :( its a healthcanteen, and once its spawns it keeps returning when i use it :s that shoulnd be hapening
i'l take a look in the scripts of ai when they die they leave a canteen
thx for help

greetz
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post by bdbodger »

spawn_thing:
self remove or
self nottriggerable

local.temp = spawn items/item_100_healthbox.tik "targetname" "healthcanteen "
local.temp.origin = $spawn_thing.origin
end

this will remove the trigger but I don't know about the health reappearing . You could try to wait some time then if you gave it a targetname try

wait 10
$healthcanteen delete
Mistab33n
Lance Corporal
Posts: 15
Joined: Wed Jun 11, 2003 2:45 pm

Post by Mistab33n »

thx, for now its allready working but it has just a few probs i need to fix,
the object doesnt spawn at the place where the originbrush is (realy needs to be fixed)
when the map starts there is allready a canteen standing there, it shouldnt (not that important, bad luck if it wont work :p)
the script doesnt loop, there should be loop in the script with a 5sec waitingtime before the script starts again (we dont want people to start jamming the usekey that makes it spawn like 20canteens at a time)

that should be fixed yet :) i have to say thx for the help, your name is allready in the script included, the name wil also be on the loadingscreen and in the readme

i got also a script in mind that should limit the canteens but for that it needs some nifty scripting, if you are intrested in helping just add me on msn messenger mistab33n@hotmail.com
Slyk
Lieutenant Colonel
Posts: 361
Joined: Sun Jul 14, 2002 12:42 am
Location: Elizabethtown, PA

Post by Slyk »

Sounds like you need a 'script/origin' entity at the location to spawn, not an 'origin' brush. The script/origin entity will spawn the canteen each time at the right location--but shouldn't spawn it at the map startup. As for the waiting time, just add "wait 5.0" before the "end" line in the script.
Mistab33n
Lance Corporal
Posts: 15
Joined: Wed Jun 11, 2003 2:45 pm

Post by Mistab33n »

Slyk wrote:Sounds like you need a 'script/origin' entity at the location to spawn, not an 'origin' brush. The script/origin entity will spawn the canteen each time at the right location--but shouldn't spawn it at the map startup. As for the waiting time, just add "wait 5.0" before the "end" line in the script.
there is a script/origin at the the place where it should spawn :s but maybe i gave it the wrong name

Code: Select all

level waittill spawn

spawn_hp: 
self remove
self nottriggerable 
local.temp = spawn items/item_25_healthbox.tik "targetname" "healthcanteen" 
local.temp.origin = $spawn_hp.origin 
wait 5 
$healthcanteen delete
wait 5
end
this is waht i got

and at the spawn/origin i got key: $targetname value: spawn_origin
Slyk
Lieutenant Colonel
Posts: 361
Joined: Sun Jul 14, 2002 12:42 am
Location: Elizabethtown, PA

Post by Slyk »

Ok, I'm no expert on scripts, but this is what I see as issues:

1. How is the health canteen being triggered? I know you have a physical trigger brush somewhere...that's fine. What it seems you need is to move the whole thread OUT of where it is and put it AFTER all the 'main' stuff. You should have the 'main' script info, prespawn, spawn, roundstart, then END then go on and have the script i.e.

main:

prespawn
text here
spawn
text here
roundstart
text here

end

spawn_hp:
your script text.



WHAT I really think is wrong, and I might be off base, but... I think you need to:

1. create a script/object and name it: (goes anywhere in the map)
key: $targetname value: hp

2. input the data for the type of object it is:
key: model value: items/item_25_healthbox.tik

3. create a script/origin and name it: (goes at the point of spawn)
key: $targetname value: hp_origin

4. in your script in the 'prespawn' area add this line:
$hp bind $hp_origin

5. be sure that your trigger brush has these:
key: setthread value: spawn_hp

6. change your script. as it reads now, it seems like you are deleting the health canteen after 5 seconds if it isn't picked up. again, how is the player 'frobbing'/'using' a switch etc. to spawn the item???? Also, with the trigger, depending on how it is set up, you probably will want to use the "nontriggerable"/"triggerable" commands on it through a script to move/activate the switch.

SCRIPT: (I think I'd try a short version like this)

spawn_hp:
hp.origin = $spawn_hp.origin
wait 5
end


****Like I said, I'm not an expert, but modding the version I posted earlier I think you can get it to work as long as you set up the entities first and be sure they are correct. But seriously, how are the players to 'spawn' the thing??? That will have to be scripted to if there is any movement like a switch etc. Just curious. Hope that suggestion works...if JV comes along, he'll straighten all of us out. :D
Mistab33n
Lance Corporal
Posts: 15
Joined: Wed Jun 11, 2003 2:45 pm

Post by Mistab33n »

dont want to sound evil ore something, but the ways you tell this ALWAYS confuses me :? :)
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post by bdbodger »

The script_origin should have a $targetname of spawn_hp to match your script . It is it's origin that you use to place your health , You place the health at the same spot as it is at .

local.temp.origin = $spawn_hp.origin

self is the trigger that triggered the thread . You don't need self remove and self nottriggerable it should be one or the other both will work but if you use nottriggerable you could make it triggerable later remove just removes it so you won't be able to reuse it because it will be gone . You don't need the final wait just end it .
Mistab33n
Lance Corporal
Posts: 15
Joined: Wed Jun 11, 2003 2:45 pm

Post by Mistab33n »

ok so far i got this:
when the map starts, there is allready 1canteen that disapears after 5seconds
afther those 5seconds i got 5seconds time to use the trigger ore it ends, in those 5seconds i can spawn as much canteens i want
so i need to have like take a canteen, then 5sec not able to take one and after that able to regrab one
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

Not sure if this is what you're looking for, but you can disable respawning of any item with the set_respawn command:

$myjuicycanteen set_respawn 0
Last edited by jv_map on Fri Jun 13, 2003 7:43 pm, edited 1 time in total.
Image
Post Reply