basic scripting / trigger problem

Post your scripting questions / solutions here

Moderator: Moderators

User avatar
wacko
Field Marshal
Posts: 2085
Joined: Fri Jul 05, 2002 8:42 pm
Location: Germany

Post by wacko »

I made it this way:

Code: Select all

main:
	level waittill spawn
	thread bridge_prep
end

bridge_sway_on:
	$bridge_on nottriggerable
	$bridge1 rotateXupto 10
	$bridge1 waitmove
	$bridge1 rotateXdownto 0
	$bridge1 waitmove
	$bridge1 rotateXdownto 350
	$bridge1 waitmove
	$bridge1 rotateXupto 0
	$bridge1 waitmove
	$bridge_on triggerable
end

bridge_prep:
	$bridge1 time 2
end
I don't need a stop thread anymore, because the bridge will always end this thread in the center.
But, of course, this looks rather strange as nihilo said. Now, when I tried to expand the script to 3 or even more bridge pieces with a to the center increasing rotation angle, it becomes a little difficult. I tried something like

Code: Select all

bridge_sway_on:
	$bridge_on nottriggerable
	thread swing1 // to the left
	thread swing2 // to the center
	thread swing3 // to the right
	thread swing4 // to the center again
	$bridge_on triggerable
end
swing1:
	$bridge1 rotateXupto 3 //outer parts
	$bridge2 rotateXupto 6 
	$bridge3 rotateXupto 9 // center part
end
swing2:
	$bridge1 rotateXdownto 0
	$bridge2 rotateXdownto 0
	$bridge3 rotateXdownto 0
end
swing3:		
	$bridge1 rotateXdownto 357
	$bridge2 rotateXdownto 354
	$bridge3 rotateXdownto 351
end
swing4:		
	$bridge1 rotateXupto 0
	$bridge2 rotateXupto 0
	$bridge3 rotateXupto 0
end
with waitmoves at some positions but it didn't work until now. I will go on trying, but, maybe, someone knows without trying, where to set some wait commands? In the moment, with the script above, as far as I can remember, the bridge isn't moving at all. The aim is to make bridge1, 2 and 3 move at the same time to the next position and then to the one after that and so on...
nuggets
General
Posts: 1006
Joined: Fri Feb 28, 2003 2:57 am
Location: U-england-K (england in the UK) :P
Contact:

Post by nuggets »

//well this 1 got me thinking and i like to help where possible sooo...
//here's my solution :D

//make the trigger "bridge_on" extend to reach both "trigger_A" triggers
//delete the two "trigger_A" triggers

//...side...bridge1...bridge2...bridge3...side...// is this how the bridge works?

bridge_prep:
$bridge1 time 2
$bridge2 time 2
$bridge3 time 2
end

bridge_sway_on:
level.wackos_swayer = randomint (2) // will create a number 0, or 1
if (level.wackos_swayer == 0) // if left is chosen (0)
{
(level.sway_start = randomint (3) + 1 // will create a number 1, 2, or 3
}
else
{
(level.sway_start = randomint (3) + 6 // will create a number 6, 7, or 8
}
thread swaying // starts the motion
end

swaying:
if (parm.other istouching $bridge_on) // if any1 is touching the trigger
// which will be true when activated
// if ($player istouching $bridge_on) // use this if testing in single player
$bridge_on nottriggerable // stops other players interfering
{
switch level.sway_start // choose the outcome of the integer
{
case 1: // option 1
$bridge1 rotateXupto 8
$bridge1 move
// move the 1st part 8 degrees as u know
$bridge2 rotateXupto 12
$bridge2 move
// move the 2nd part 12 degrees
$bridge3 rotateXupto 8
$bridge3 waitmove
// move the 3rd part the same as the 1st
level.sway_start = randomint (4) + 5 // creates the next random position
// only ends once bridge2 has finished
thread swaying // starts the sway again
break // ends the switch command
case 2: // option 2
$bridge1 rotateXupto 4
$bridge1 move
$bridge2 rotateXupto 6
$bridge2 move
$bridge3 rotateXupto 4
$bridge3 waitmove
level.sway_start = randomint (4) + 5
thread swaying
break
case 3: // option 3
$bridge1 rotateXupto 2
$bridge1 move
$bridge2 rotateXupto 3
$bridge2 move
$bridge3 rotateXupto 2
$bridge3 waitmove
level.sway_start = randomint (4) + 5
thread swaying
break
case 4: // option 4
$bridge1 rotateXupto 0
$bridge1 move
$bridge2 rotateXupto 0
$bridge2 move
$bridge3 rotateXupto 0
$bridge3 waitmove
level.sway_start = randomint (4) + 5
thread swaying
break
case 5: // option 5
$bridge1 rotateXdownto 0
$bridge1 move
$bridge2 rotateXdownto 0
$bridge2 move
$bridge3 rotateXdownto 0
$bridge3 waitmove
level.sway_start = randomint (4) + 1
thread swaying
break
case 6: // option 6
$bridge1 rotateXdownto 358
$bridge1 move
$bridge2 rotateXdownto 357
$bridge2 move
$bridge3 rotateXdownto 358
$bridge3 waitmove
level.sway_start = randomint (4) + 1
thread swaying
break
case 7: // option 7
$bridge1 rotateXdownto 356
$bridge1 move
$bridge2 rotateXdownto 354
$bridge2 move
$bridge3 rotateXdownto 356
$bridge3 waitmove
level.sway_start = randomint (4) + 1
thread swaying
break
case 8: // option 8
$bridge1 rotateXdownto 352
$bridge1 move
$bridge2 rotateXdownto 348
$bridge2 move
$bridge3 rotateXdownto 352
$bridge3 waitmove
level.sway_start = randomint (4) + 1
thread swaying
break
}
}
else
{ // stop swaying
if level.sway_start >> 4) // bridge's last move was right
{
$bridge1 rotateXupto 0
$bridge1 move
$bridge2 rotateXupto 0
$bridge2 move
$bridge3 rotateXupto 0
$bridge3 waitmove
}
else
{ //bridge's last move was left
$bridge1 rotateXdownto 0
$bridge1 move
$bridge2 rotateXdownto 0
$bridge2 move
$bridge3 rotateXdownto 0
$bridge3 waitmove
}
$bridge_on triggerable
}
end
Last edited by nuggets on Thu May 08, 2003 5:13 pm, edited 2 times in total.
hope this helps, prob not cos it's all foreign 2 me :-/
User avatar
wacko
Field Marshal
Posts: 2085
Joined: Fri Jul 05, 2002 8:42 pm
Location: Germany

Post by wacko »

hi, nuggets! i already was missing you!

your code looks interesting! as far as i can see, it does something different to what my bridge had ought :? to do, but of course i will try it (to see what it does) and hopefully find out, why your script works (and mine doesn't). My bridge was rather
side...bridge1...bridge2...bridge3...bridge2...bridge1...side
but this surely won't make much difference in whether it works but rather in how :wink:

Questions about your script:
why would i have to use '$player istouching' in SP? Is the parm.other or the setthread of the bridge_on trigger not working in SP (and MP)?
you use in swaying the command 'thread swaying'. Why not 'goto swaying'? For me it's fine, of course, but where's the difference?

ty :!:
nuggets
General
Posts: 1006
Joined: Fri Feb 28, 2003 2:57 am
Location: U-england-K (england in the UK) :P
Contact:

Post by nuggets »

what's the bridge supposed 2 do?

are there 3 parts 2 the bridge?
hope this helps, prob not cos it's all foreign 2 me :-/
User avatar
wacko
Field Marshal
Posts: 2085
Joined: Fri Jul 05, 2002 8:42 pm
Location: Germany

Post by wacko »

nuggets wrote:what's the bridge supposed 2 do?
2 answers possible:
A: it should look realistic :wink:
B: it should make me get a little bit more of this scripting topic.

(A) may be more important to others (didn't someone ask in the beginning how to do it?! :wink: )
(B) is, why I bother you all all the time.

For (A) most ppl here will love you for scripting a perfect swaying bridge, but for reason (B), I would prefer that s/o would try to make my code below running, so I would see why it didn't work.
and then, nuggets wrote:are there 3 parts 2 the bridge?
After I managed to make 1 piece o' bridge sway, I thought, next step is 3 pieces. Because the bridge could be symetric over the middle, this made 5 pieces like ...AAAABBBBCCCCBBBBAAAA... I would probably make more of them later if 3 script_objects aren't enough to look realistic, but in the moment, this seems to be more than enough.
These 3 (or more) pieces all have a different rotation origin, because the outer ones should have it almost on bridge level (with low rotation angle) and going further to the bridge's center, these origins could be higher and higher (with also increasing rotation angle).
Then, the bridge ought to (that's what I imagine) sway rather realistic from side to side!?

Here's again my current

Code: Select all

main:
	level waittill spawn
	thread bridge_prep
end

sway_on:
	$bridge_on nottriggerable
	waitthread swing1 // to the left
	waitthread swing2 // to the center
	waitthread swing3 // to the right
	waitthread swing4 // to the center again
	$bridge_on triggerable
end

swing1:
	$bridge1 rotateXupto 3 //outer parts
	$bridge2 rotateXupto 6 
	$bridge3 rotateXupto 9 // center part
	$bridge3 waitmove
end

swing2:
	$bridge1 rotateXdownto 0
	$bridge2 rotateXdownto 0
	$bridge3 rotateXdownto 0
	$bridge3 waitmove
end

swing3:		
	$bridge1 rotateXdownto 357
	$bridge2 rotateXdownto 354
	$bridge3 rotateXdownto 351
	$bridge3 waitmove
end

swing4:		
	$bridge1 rotateXupto 0
	$bridge2 rotateXupto 0
	$bridge3 rotateXupto 0
	$bridge3 waitmove
end

bridge_prep:
	$bridge1 time 2
	$bridge2 time 2
	$bridge3 time 2
end
In the moment, with above script, only bridge3 is moving, bridge1 and bridge2 don't. I can make them move as well by adding a waitmove after their (e.g.) rotateXupto command, but then the 3 pieces of the bridge don't move simultanously but one after the other :cry: Then, when I remove all waitmove commands, nothing is moving! You probably will say, "yes, that's obvious!", but well, it isn't for me :oops:
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

waitthread

Post by tltrude »

if you use waitthread, it waits untill that thread is done before going to the next line. It would make them all move at the same time if you change all but the last one to just "thread".
Tom Trude,

Image
nuggets
General
Posts: 1006
Joined: Fri Feb 28, 2003 2:57 am
Location: U-england-K (england in the UK) :P
Contact:

Post by nuggets »

u will need to use waitthread

otherwise thread4 will be last 1 it will read, therefore endind the bridge at rotateXupto 0

so...

main:
level waittill spawn
thread bridge_prep
end

sway_on:
$bridge_on nottriggerable
waitthread swing1 // to the left
waitthread swing2 // to the center
waitthread swing3 // to the right
waitthread swing4 // to the center again
$bridge_on triggerable
end
swing1:
$bridge1 rotateXupto 3 //outer parts
$bridge1 move
$bridge2 rotateXupto 6
$bridge2 move //repeat for all
$bridge3 rotateXupto 9 // center part
$bridge3 waitmove
end
swing2:
$bridge1 rotateXdownto 0
$bridge2 rotateXdownto 0
$bridge3 rotateXdownto 0
$bridge3 waitmove
end
swing3:
$bridge1 rotateXdownto 357
$bridge2 rotateXdownto 354
$bridge3 rotateXdownto 351
$bridge3 waitmove
end
swing4:
$bridge1 rotateXupto 0
$bridge2 rotateXupto 0
$bridge3 rotateXupto 0
$bridge3 waitmove
end

bridge_prep:
$bridge1 time 2
$bridge2 time 2
$bridge3 time 2
end
hope this helps, prob not cos it's all foreign 2 me :-/
User avatar
wacko
Field Marshal
Posts: 2085
Joined: Fri Jul 05, 2002 8:42 pm
Location: Germany

Post by wacko »

yessss! :D
Thanks, nuggets and all those who helped!

As I thought, it's dead easy! I will make that bridge as perfect as it is possible for me and then post a link to a bridge.pk3!


tltrude, I have put those waitthread in the script because the script shall wait for all pieces to have reached their next position. It would look rather strange if parts of the bridge swing to the left while others swing to the right. I even think, I had it running with just one waitthread (maybe there was s/th else different, too) and, as I said, it looked odd!

One question left :oops: : This rotateXupto command, or moveto or similar ones, why and when do they need the following move command to be executed, and sometimes not?
Is there a recommended source about such topics, so I won't have to bother you all the time?! (This was the 2nd question :oops: :oops: )
nuggets
General
Posts: 1006
Joined: Fri Feb 28, 2003 2:57 am
Location: U-england-K (england in the UK) :P
Contact:

Post by nuggets »

but we love you bothering us :D

personally though, i don't, i think ur a pain in the ass :lol: (joking)

don't really know where u can get a list of all the functions, variables, etc...

i just tend to go through the .scr's in the maps folder and see what's going on in there

it may look bloody impossible at 1st, but a bit of thought and persistance, and possibly a prayer or 2 u'll get the hang of it :D

when you tell something to move it's after it's had all it's pre-determined paths/angles set eg.

$bridge time 2
$bridge moveUp 10
$bridge moveLeft 20
$bridge rotateXup 5
$bridge move

will do all of these at once,

$bridge time 2
$bridge moveUp 10
$bridge move
$bridge moveLeft 20
$bridge move
$bridge rotateXup 5
$bridge move

will only rotate the bridge as it's the bridge's last command

$bridge time 2
$bridge moveUp 10
$bridge waitmove
$bridge moveLeft 20
$bridge waitmove
$bridge rotateXup 5
$bridge waitmove

will move up 10 then left 20 then rotate it

depending on where u put the move commands will have a big effect on what's actually happening :D

although!!! some1 (i think bdbodger) said that sometimes u don't need that command, something to do with a fan i think :?:
hope this helps, prob not cos it's all foreign 2 me :-/
User avatar
wacko
Field Marshal
Posts: 2085
Joined: Fri Jul 05, 2002 8:42 pm
Location: Germany

Post by wacko »

thanks a lot :D

the bridge is swaying now, but still looks rather strange, even made with 9 script_objects which makes 17 bridge pieces...
i will have to try to reduce the movement speed at the turning points and the difference of the rotation angle and/or origin height between the objects is hard to find out: will probably start this map for many many times...
But this is okay for me, now having atleast a script that is predictable :wink:
User avatar
wacko
Field Marshal
Posts: 2085
Joined: Fri Jul 05, 2002 8:42 pm
Location: Germany

Post by wacko »

well, well, well, not really satisfying, but best I could do...
here's map, scr and bsp in a pk3.
For a better result, I would have to invent a acceleration command, because in my opinion, the worst thing is that the bridge doesn't slow down when going to the side and accelerate coming back to the middle :cry: To cut the motion in lots of little threads with different speeds would cause a very, very long script.
Any suggestions? Some lions? :wink:
Is it possible to name script_objects s/th like piece(1), piece(2)... and have
while (level.i < level.anything)
{
$piece(level.i) thread something
level.i ++
}
??
Post Reply