OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: dmakatra on 23 Jun 2004, 11:29:38
-
Hello. Long time no Q. No, you haven't get rid of me. :)
Anyway, this should be quite an easy one I belive. Just can't figure it out. :-\
_unit = _this select 0
_target = GL
_speed = 5
_2x = 0
_2y = 0
_dir=[_unit,_target] call DirToObj
#loop
_1x= getpos _unit select 0
_1y= getpos _unit select 1
_2x=_1x+(_speed * (sin(_dir)))
_2y=_1y+(_speed * (cos(_dir)))
_unit setpos [_2x, _2y, 0]
~ delayvariable
goto "loop"
Okdoki. This is a script that moves a unit to a onmapsingleclick pos where I've put a GL. It's not quite done yet as for example the unit don't know where to stop but I'm getting to that later. Anyway, the problem is that when the unit is assigned another position to go, I want this script to "break" and the target should instead move there. When I now click on another pos the unit will try to move to both positions, which will feck everything up. Do you understand? Puh, allways so hard to explain, much easier to post nonsense. ;D
Cheers to you all :cheers:
:beat: *Gets Shot* :beat:
-
The answer, as always, is a variable inside the loop. If it goes false the loop exits.
Maybe a new onmapclick sets the variable to false which makes the script go back to the beginning and start again?
I assume that the current problem is that a new onmapclick starts a second edition of the same script, so the poor unit is setpossed along both paths, jumping back and forth in a crazy and amusing manner.
-
Call me a noob if you wish, 'cause I am. I've weirdoed this mission up so much that I'm getting a headache just thinking of it. So why won't it work now? I'm so sick of this mission I wanna throw it in the garbage but I want to at least complete one mission before OFP 2. ;D
I have to use local booleans because of several reasons.
_unit = _this select 0
_target = GLclick
_Ismoving = false
_speed = 5
_2x = 0
_2y = 0
_dir = [_unit,_target] call DirToObj
#loop
_1x= getpos _unit select 0
_1y= getpos _unit select 1
_2x=_1x+(_speed * (sin(_dir)))
_2y=_1y+(_speed * (cos(_dir)))
_unit setpos [_2x, _2y, 0]
_ismoving = true
~ delayvariable
? ! _ismoving : exit
goto "loop"
I think I'm gonna put Official OFPEC Noob in my sign. ;D
:beat: *Gets Shot* :beat:
-
Lol I don't think you're a noob anymore Armsty.
_ismoving is a local variable so I can't see how it could be set to false. Also, your loop constantly sets it true. I'd do it more like this:-
move1=true
#loop
? !move1: exit
blah blah
goto loop
PS - What's going wrong?
PPS - Is this script for a lot of units or just one or two?
PPS - this is really a general question: if a script has been called for a unit, how can you stop the first version if the script is called again for the same unit. Maybe you could set up a file that keeps track of which units are undergoing the script .... boy this is right at the limits of my scripting .... sorry I'm not really answering the question.
-
PS 1) Can't remember now 'cause I've tried several types and they all go different. Gonna try it again.
PS 2) It's for several units that is why I need to set the boolean back to true all the time. :-\
PS 3) Yea but that can cause lag and I'm allready sending like 200 copies of this script, I don't want to cause any more lag. :-\
:beat: *Gets Shot* :beat:
-
I came up with an idea but it still keeps trying to go to both locations. I think I'm on the right track but there's gotta be something missing. :'(
_unit = _this select 0
_target = GL
_Ismoving = false
_i = 0
_speed = 5
_2x = 0
_2y = 0
_dir = [_unit,_target] call DirToObj
#loop
? _i >= 1 : goto "check"
_i = _i + 1
#cont
_1x= getpos _unit select 0
_1y= getpos _unit select 1
_2x=_1x+(_speed * (sin(_dir)))
_2y=_1y+(_speed * (cos(_dir)))
_unit setpos [_2x, _2y, 0]
_ismoving = true
~ delayvariable
? ! _ismoving : exit
goto "loop"
#check
? ! _ismoving : exit
goto "cont"
:beat: *Gets Shot* :beat:
-
what is this script supposed to move? people or inanimate objects?\
the most straightforward way to do it would be to have a global variable that can be flipped to true/false when the script is activated
otherwise, if you are dealing with an inanimate object, you could have the script do a check of whether the object is moving in a straight line, and then exit if it isnt.
another way i just thought of, which would probably be easier, would have the script check if the object is where it should be at the beginning (or end) of the loop (the important thing is that it's after the wait-time). this would only work if the object is inanimate though, and you would need to keep track of a script's age (so you delete the older one and not the younger one)
added stuff is surrounded by ******
_unit = _this select 0
_target = GL
_speed = 5
_2x = 0
_2y = 0
; *****
_ageofscript = 0
; *****
_dir=[_unit,_target] call DirToObj
#loop
_1x= getpos _unit select 0
_1y= getpos _unit select 1
_2x=_1x+(_speed * (sin(_dir)))
_2y=_1y+(_speed * (cos(_dir)))
_unit setpos [_2x, _2y, 0]
; *****
_unitpos = getpos _unit
; *****
~ delayvariable
; *****
?! (getpos _unit == _unitpos) and ? (_ageofscript > 1) : exit
_ageofscript = _ageofscript + 1
; *****
goto "loop"
-
Cheers pablo, but I'm afraid it isn't working.
?! (getpos _unit == _unitpos) and ? (_ageofscript > 1) : exit
The above lines dislikes arrays, and _unitpos is an array. I could stick a GL there but that would cause even more lag and I can't afford that.
?! (getpos _unit = _unitpos) and ? (_ageofscript > 1) : exit
Doesn't work either, gives the error message Unknown Operator at the equals mark. Thank you for your idea pablo, I'm almost there. If anyone know whats wrong I want to have their babies. :D
:beat: *Gets Shot* :beat:
-
my script was presented more as something to build off of than a final solution, but the problem you have seems easy enough to fix:
?! (getpos _unit = _unitpos) and ? (_ageofscript > 1) : exit
the reason this doesnt work is because "a = b" means "set a equal to b", not "is a = b?"; ie its a command, not a question. if you want to know if a is equal to b, you use double equal signs (==)
?! (getpos _unit == _unitpos) and ? (_ageofscript > 1) : exit
if it doesnt like arrays then just break the array into its three parts:
!(getpos _unit select 0 == _unitpos select 0) or !(getpos _unit select 1 == _unitpos select 1) or !(getpos _unit select 2 == _unitpos select 2) and (_ageofscript > 1) : exit
this just breaks the array into its three elements (x,y,z)
-
Cheers!
The script still spat it out because it was an array, I solved it with creating a third set of coordinates of _unit and messuring array part with array part (x with x, y with y) . Thanks macguba and .pablo.!
:beat: *Gets Solved* :beat: