Page 1 of 1

lift script problem

Posted: Thu Oct 04, 2007 11:43 pm
by Tazz
ok i have 2 problems with this script here.......i got this script from TMT i think and i been playing with it trying to get everything right......now for the probs......i spawn a cratelid2.tik for my lift floor and have it triggered by a electrical_pulse_switch.tik.....1st prob is everything spawns correctly except for my cratelid2.tik.....it doesnt show up until i hit the trigger to activate the lift...then it appears and u have to get on it then.....how can i make it show all the time?.......2nd prob is the trigger works great but when my lift returns to the bottom it doesnt wait to be triggered again it just waits 5 secs then goes back up automatically and continues for the rest of the map without anyone triggering it......i've been looking and reading but cant seem to get it working right any and all help would be greatly appreciated...thx in advance



Tazz


heres the script now

Code: Select all

level waittill spawn

	spawn models/miscobj/electrical_switch_pulse.tik "origin" "-1129 -1040 -200" "targetname" "ele_switch" "classname" "animate"
$ele_switch.angles = ( 0 90 0 )
$ele_switch anim idle
$ele_switch notsolid
spawn trigger_use "origin" "-1129 -1040 -200" "targetname" "ele_trig"
$ele_trig setsize ( -5 -5 -5 ) ( 5 5 5 )
$ele_trig setthread bring_it_on 
end


// switch anims...

// idle switch_off.skc
// off     switch_off.skc
// on      switch_on.skc
// turn switch_turnon.skc

bring_it_on:
$ele_switch anim turn
$ele_trig nottriggerable
$ele_switch playsound elevator_start
$ele_switch anim off

local.lift1 = spawn script_model
local.lift1 model "static/cratelid2.tik"
local.lift1.origin = ( -1130 -1070 -245 )

while (1)
{
wait 5
local.lift1 speed 150
local.lift1 moveUp 960
local.lift1 loopsound elevator_run
local.lift1 waitmove
local.lift1 stoploopsound
wait 5
local.lift1 moveDown 960
local.lift1 loopsound elevator_run
local.lift1 waitmove
local.lift1 stoploopsound
} 
end

Posted: Fri Oct 05, 2007 6:58 am
by bdbodger
What you have said make perfect sence thats what you wrote for it to do .

1. you spawned the cratelid in the thread called by the setthread statement so of course it won't spawn until the trigger is triggered

2. the only thing between the moveup statements and the movedown statements is a 5 second wait

3. You turned off the trigger but no where have you turned it back on

4. Movement is in a endless while loop

*************
ToDo
*************

1. spawn cratelid in the main thread not in the thread started by setthread
2. create a level variable to keep track of where the lift is top or bottom defined with a default value in the main thread IE. level.elepos = 0 ( bottom)
3. add a switch statement or if statement in the thread based on the level variable so if it is at the top move it to the bottom and set level variable to new position ( maybe a switch at the top with setthread set to same thread too )
4. turn trigger(s) back on at end of thread
5. use $targetname wittill animdone after anim statements to pause script untill the animation is done ( substitute $targetname with actual targetname of entity )
6. remove while loop so that thread runs when trigger is triggered then waits to be triggered again after trigger is turned back on . ( You don't need a while loop when using setthread . Setthread automatically starts the thread when the trigger is triggered )

************
suggestion
************

1. don't use setthread call the thread from the main thread and put statements into a while loop first line of which is $mytriggername waittill trigger so thread does not run continually and only runs after trigger is triggered . If you do that no need to turn on and off the trigger but then you will need to make two threads if you have a top switch and another variable to keep track of if the elevator is moveing and not move it with the top or botton trigger/switch if it is moving already only move it if it is stopped ( set moving variable when it starts and stops ).

Posted: Fri Oct 05, 2007 1:49 pm
by Tazz
ok i moved the spawn of the cratelid at prespawn but then it doesnt go up...then u said this

Code: Select all

. create a level variable to keep track of where the lift is top or bottom defined with a default value in the main thread IE. level.elepos = 0 ( bottom) 
3. add a switch statement or if statement in the thread based on the level variable so if it is at the top move it to the bottom and set level variable to new position ( maybe a switch at the top with setthread set to same thread too ) 
and i have no idea what ur talking about....still trying to get all this

although i have been playing with the script and have it to where i can move the crate np but it doesnt run anymore....u said make if statement but i dont have leves i just have the floor i guess would be level 1 then it goes up 915 units then returns down 915 to the bottom...i think i understand taking the while out and that should not make it loop?...

Posted: Fri Oct 05, 2007 4:18 pm
by bdbodger
like this
main:

level waittill spawn

level.elepos = 0 // bottom

spawn models/miscobj/electrical_switch_pulse.tik "origin" "-1129 -1040 -200" "targetname" "ele_switch" "classname" "animate"
$ele_switch.angles = ( 0 90 0 )
$ele_switch anim idle
$ele_switch notsolid

spawn script_model model "static/cratelid2.tik" origin ( -1130 -1070 -245 ) targetname "lift"
$lift speed 150

spawn trigger_use "origin" "-1129 -1040 -200" "targetname" "ele_trig"
$ele_trig setsize ( -5 -5 -5 ) ( 5 5 5 )
$ele_trig setthread bring_it_on

end

bring_it_on:

$ele_trig nottriggerable

$ele_switch anim turn
$ele_switch waittill animdone

$ele_switch playsound elevator_start

$ele_switch anim off
$ele_switch waittill animdone

if(level.elepos == 0)
{

wait 3
$lift moveUp 960
$lift loopsound elevator_run
$lift waitmove
$lift stoploopsound
level.elepos = 1 // top

}
else
{

wait 3
$lift movedown 960
$lift loopsound elevator_run
$lift waitmove
$lift stoploopsound
level.elepos = 0 // bottom

}

$ele_trig triggerable

end

Posted: Fri Oct 05, 2007 6:33 pm
by Tazz
wow i understood that :D .....everything worked perfect except the return i had to take out the else then it dropped after the wait...thx alot man for the help its getting there....now though lol....i need 2 of these can i just copy it basically over and just add 1 to the names or is there a simpler way?....well i know there is just dont know how to simplify the scripts YET =)

Posted: Fri Oct 05, 2007 7:26 pm
by bdbodger
Well the else ment that you would have to use the trigger again to bring the elevator back down just like a real elevator :)

Yes there is a simpler way . Have the trigger target the switch and have the switch target the cratelid . Why do you ask ? So you can write a thread that both elevators can use , one that does not use literal targetnames but instead is more generic and can be use by several entities . In fact get use to doing scirpts this way it will save you having to rewrite the same lines over and over again . When a thread runs because of a setthread statement "self" in the thread refers to the trigger that started the thread .

Example
main:

level waittill spawn

spawn trigger_use "origin" "-1129 -1040 -200" "targetname" "ele_trig"
$ele_trig setsize ( -5 -5 -5 ) ( 5 5 5 )
$ele_trig setthread bring_it_on

spawn models/miscobj/electrical_switch_pulse.tik "origin" "-1129 -1040 -200" "targetname" "ele_switch" "classname" "animate"
$ele_switch.angles = ( 0 90 0 )
$ele_switch anim idle
$ele_switch notsolid

spawn script_model model "static/cratelid2.tik" origin ( -1130 -1070 -245 ) targetname "lift"
$lift speed 150
$lift.pos = 0 // bottom

$ele_trig target $ele_switch
$ele_switch target $lift


spawn trigger_use "origin" "-1129 -1040 -200" "targetname" "ele_trig2"
$ele_trig2 setsize ( -5 -5 -5 ) ( 5 5 5 )
$ele_trig2 setthread bring_it_on

spawn models/miscobj/electrical_switch_pulse.tik "origin" "-111 -222 -333" "targetname" "ele_switch2" "classname" "animate"
$ele_switch2.angles = ( 0 90 0 )
$ele_switch2 anim idle
$ele_switch2 notsolid

spawn script_model model "static/cratelid2.tik" origin ( -1130 -1070 -245 ) targetname "lift2"
$lift2 speed 150
$lift2.pos = 0 // bottom

$ele_trig2 target $ele_switch2
$ele_switch2 target $lift2


end

bring_it_on:

self nottriggerable

local.switch = $(self.target)
local.lift = $(local.switch.target)


local.switch anim turn
local.switch waittill animdone

local.switch playsound elevator_start

local.switch anim off
local.switch waittill animdone

if(local.lift.pos == 0)
{

wait 3
local.lift moveUp 960
local.lift loopsound elevator_run
local.lift waitmove
local.lift stoploopsound
local.lift.pos = 1 // top

}
else
{

wait 3
local.lift movedown 960
local.lift loopsound elevator_run
local.lift waitmove
local.lift stoploopsound
local.lift.pos = 0 // bottom

}

self triggerable

end

Posted: Fri Oct 05, 2007 9:00 pm
by Tazz
alright thx alot man yes that was alot easier also thats what i needed was the lift to auto return i probably didnt tell u thats y i took the else out...there is no trigger to bring it back down....its all running perfect now i really appreciate it...now on to the rest of the mods lol...i promise ill be back lol