OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: OFPfreak on 26 Jun 2005, 01:57:19
-
Once again this stupid nitro script again ;D!
I tried using loops, but they don't work! I want my nitro to end after 3 seconds! Here's what I got:
#accel
_inc = 1
_amountleft = 0
car1 setvelocity [(velocity car1 select 0) + _inc*sin getdir car1, (velocity car1 select 1) + _inc*cos getdir car1, velocity car1 select 2]
~0.25
_amountleft=_amountleft+1
? _amountleft > 20 : goto "exit"
? speed car1 < 300 && alive car1 : goto "accel"
car1 removeaction "nitrox1"
#exit
exit
Since that didn't work, I used the hard way:
_inc = 1
_amountleft = 0
car1 setvelocity [(velocity car1 select 0) + _inc*sin getdir car1, (velocity car1 select 1) + _inc*cos getdir car1, velocity car1 select 2]
~0.25
_inc = 1
_amountleft = 0
car1 setvelocity [(velocity car1 select 0) + _inc*sin getdir car1, (velocity car1 select 1) + _inc*cos getdir car1, velocity car1 select 2]
~0.25
_inc = 1
_amountleft = 0
car1 setvelocity [(velocity car1 select 0) + _inc*sin getdir car1, (velocity car1 select 1) + _inc*cos getdir car1, velocity car1 select 2]
~0.25
_inc = 1
_amountleft = 0
car1 setvelocity [(velocity car1 select 0) + _inc*sin getdir car1, (velocity car1 select 1) + _inc*cos getdir car1, velocity car1 select 2]
~0.25
_inc = 1
_amountleft = 0
car1 setvelocity [(velocity car1 select 0) + _inc*sin getdir car1, (velocity car1 select 1) + _inc*cos getdir car1, velocity car1 select 2]
~0.25
_inc = 1
_amountleft = 0
car1 setvelocity [(velocity car1 select 0) + _inc*sin getdir car1, (velocity car1 select 1) + _inc*cos getdir car1, velocity car1 select 2]
~0.25
_inc = 1
_amountleft = 0
car1 setvelocity [(velocity car1 select 0) + _inc*sin getdir car1, (velocity car1 select 1) + _inc*cos getdir car1, velocity car1 select 2]
~0.25
_inc = 1
_amountleft = 0
car1 setvelocity [(velocity car1 select 0) + _inc*sin getdir car1, (velocity car1 select 1) + _inc*cos getdir car1, velocity car1 select 2]
~0.25
_inc = 1
_amountleft = 0
car1 setvelocity [(velocity car1 select 0) + _inc*sin getdir car1, (velocity car1 select 1) + _inc*cos getdir car1, velocity car1 select 2]
~0.25
_inc = 1
_amountleft = 0
car1 setvelocity [(velocity car1 select 0) + _inc*sin getdir car1, (velocity car1 select 1) + _inc*cos getdir car1, velocity car1 select 2]
~0.25
_inc = 1
_amountleft = 0
car1 setvelocity [(velocity car1 select 0) + _inc*sin getdir car1, (velocity car1 select 1) + _inc*cos getdir car1, velocity car1 select 2]
~0.25
_inc = 1
_amountleft = 0
car1 setvelocity [(velocity car1 select 0) + _inc*sin getdir car1, (velocity car1 select 1) + _inc*cos getdir car1, velocity car1 select 2]
~0.25
car1 removeaction nitrox2
nitrox1=car1 addaction ["use nitro","1xnitro.sqs"]
exit
-
you set the initial values of the variables within the loop. each time it repeats, the values reset themselves. ::)
-
Well, you set the variable _amountleft to 0 inside the loop, which means it will never go higher than 1...
The loop first sets the _amountleft to 0, then later adds 1 in it and again when the loop restarts it sets the _amountleft to 0, and so on and so on...
This might not be the whole problem but sticks out first...
I would od the script like this:
_inc = 1
#accel
car1 setvelocity [(velocity car1 select 0) + _inc*sin getdir car1, (velocity car1 select 1) + _inc*cos getdir car1, velocity car1 select 2]
~0.25
? _time < 3 && alive car1 : goto "accel"
car1 removeaction "nitrox1"
_time is reserved OFP variable that returns the time since the script has started running, in seconds...
So with that it's easy to check if the scripts has run 3 secs...
-
lol stupid mistake of me.
ok thanks i'll use that stuff!