OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: iso_A on 15 Jun 2008, 20:06:20

Title: Some problems with setvelocity
Post by: iso_A on 15 Jun 2008, 20:06:20
'ello!


I'm having a bit trouble with setvelocity command on manned vehicles

Example:
BMP moves from waypoint A to waypoint B and then executes a script, which makes it to move forward (or at least that's what I want it to do), but instead of going forward, the driver turns the vehicle and it starts to drive in circle. I tried dostop bmp1 and bmp1 disableAI "move" with no luck. Deleting the driver could be one thing to do, but it's not quite the same. Imagine a jeep driving without driver, not good.

[bmp1, 4] exec "setvel.sqs" on a trigger or scripted waypoint. Tried also in initilization field of a manned vehicle with no waypoints just to be sure the waypoints don't mess it, but same thing happened. Driver messed everything up.

Here's the script setvel.sqs
Code: [Select]
_unit              = _this select 0
_speed           = _this select 1
;;_trigger        = _this select 2      can I specify the variable that stops the script also in [brackets] when I exec the script? I tried this way, but it didn't work.
movestop1      = false

;dostop _unit                    Tried these two lines here with no luck.
;_unit disableAI "move"

#loop1
_velocity = [sin (getdir _unit) * _speed, cos (getdir _unit) * _speed , 0]
_unit setvelocity _velocity
~0.1
?(movestop1):goto "loppu"          ;; Tried ?(_trigger):goto "loppu" but it didn't work. Maybe I did it wrong.
goto "loop1"

#loppu
exit

So, the vehicle should drive forward and when it has moved for a while, a trigger sets movestop1 to true and the vehicle stops moving. It worked fine with empty vehicles. But when there's a driver inside, he messes it completely.



Another related question:
Can I specify a variable so I could use the script for different vehicles at same time. Like this:
[jeep1, 4, stopmove1] exec "setvel.sqs"
and then have a trigger to set stopmove1 to true when i want the jeep to stop.
And another vehicle to have [jeep2, 4, stopmove2] exec "setvel.sqs" etc. Instead of every script stopping when I set movestop1 to true.
Or maybe some kind of workaround to detect when the vehicle is in certain place or something. Or a completely different and better script to do the same, I'm not really good in these yet.


Hmm. This post came out quite long and messy, I hope you understand what I mean. Thanks in advance for any help!
Title: Re: Some problems with setvelocity
Post by: Gcfungus on 16 Jun 2008, 00:01:48
I can't help with your first problem, as the set velocity and similar commands just went right over my head - I never understood them.

For your second question, it is fairly easily possible to make a script applicable to different objects. You would use the:
Code: [Select]
[jeep1,4,stopmove1]and use something like this in the code:
Code: [Select]
_vehicle = _this select 0
_speed = _this select 1
_trigger = _this select 2
That would give you the three variables in the script.

The only potential problem with this is naming the triggers. I remember trying this, and it not working (I'm not sure though). A possible work around is setting a variable to true, then make any triggers conditions as the variable being true.

Hope this helps  :D,
-=GC=-Fungus1999
Title: Re: Some problems with setvelocity
Post by: Garcia on 16 Jun 2008, 00:04:50
1 - It's because the BMP have a waypoint. As you say, the BMP drives from point A to point B with a waypoint. At point B, the BMP is then gets a velocity forward. However, the BMP still have the waypoint, so it wants to stay at the waypoint, point B. Therefor the driver tries to drive to point B.

2 - You can't execute a script with a variable, and then use that variable later in the script as you say.

Example:

Code: [Select]
[variable1] exec "script.sqs"
Then, in script.sqs, you have something, then a check

Code: [Select]
_localVariable = _this select 0

...

? variable1 : do stuff

This won't work. _localVariable will get the value that variable1 had when the script was executed. When variable1 then changes, _localVariable still have the value that variable1 had when the script was executed.


Anyways, I'm not good with waypoints. My suggestion is to not use setVelocity, use either move, doMove, commandMove or a new waypoint.