OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Swatdog on 22 Dec 2005, 00:16:07
-
Hey all, I'm making a convoy mission much like Desert Ambush on Malden, but with many many enhancements. Anyway, I'm trying to make a time calculator, by finding the current speed of the convoy, and then dividing that by how many meters away the convoy is from the player. I know how to do it, but the speed command isn't working for me.
I have:
_convoyspeed = speed conlead
conlead is the leader of the convoy's group. I tried that and it returns the value as '0', so I tried:
_convoyspeed = speed brdm
brdm is the lead vehicle's name. The BRDM is an empty vehicle with conlead assigned as the driver. Would that make a difference?
Anyway, help would be MUCHLY appreciated.
Thanks
-
From the description I am not sure why it isn't working but have you tried:
_convoyspeed = speed vehicle conlead
-
Don't use strings that occur in the game (such as BRDM) for vehicle names, it can lead to .... undocumented outcomes. Call it "BRDM1" or something.
Don't use a named unit when you can avoid it: he might have been killed. Much better to use
leader grp1
which will work as long as somebody in the group is still alive.
-
Ok, thanks guys. I'll try your suggestions.
-
Ok, I got it to work. Thanks guys. But I still have a problem with another part of my script, but I dont feel like creating a new topic just to discuss it so I'll post it here.
Here is the code I have to calculate the time it'll take for the lead vehicle in the convoy to reach the player's group:
#loop
;Get the speed of the lead vehicle
_convoyspeed = speed vehicle brdm1
;Get the distance to group's leader
_convoydist = leader convoy distance leader marines
;Establish estimated time
_convoytime = (_convoydist) / (_convoyspeed)
; Show speed (debug)
hint format["Current speed:\n%1\nDistance:\n%2\n------\nEstimated time:\n%3",_convoyspeed, _convoydist,_convoytime]
~2
goto "loop"
I go and load up the mission and I get this error:
'_convoytime = (_convoydist) / (_convoyspeed)|#|': Error Zero division
At first I figured that maybe _convoyspeed isn't defined before it reaches that part of the script to display it causing it to divide something that isn't defined. BUT it works once the convoy starts going and gets some speed and then it displays the estimated time.
Is there a way to avoid this error being shown? I don't mind having an error in the script because it obviously works, but I just don't want it to be seen.
-
Simply change the last line:
_convoytime = (_convoydist) / (_convoyspeed)to this:
? _convoyspeed > 0 : _convoytime = (_convoydist) / (_convoyspeed)Or you can do this:
? _convoyspeed == 0 : _convoyspeed = .000001
_convoytime = (_convoydist) / (_convoyspeed)
-
I just noticed another problem. The speed command gives speen in k/h, but the distance is in meters. So your time will not be correct. You have to convert the speed to m/s. So:
_convoyspeed = _convoyspeed * 1000 / 3600
? _convoyspeed == 0 : convoyspeed = .0001
_convoytime = (_convoydist) / (_convoyspeed)
-
Check the bugged command thread. I recently submitted an entry relating to speed and velocity. The long of the short of it, is that neither commands work properly on a unit in a vehicle, instead returning the last recorded speed/velocity of the unit before entering the vehicle.