OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Ding on 06 Mar 2005, 20:07:45

Title: Teleportation of objects/units?
Post by: Ding on 06 Mar 2005, 20:07:45
i am wondering how teleportation is done, im pretty sure it can be done but i do not know what editor command is used to teleport an object, can anyone tell me what commands i would need to put in a script or the editor, for me to say move a chair from point A to point B.

thankyou ding.
Title: Re:Teleportation of objects/units?
Post by: THobson on 06 Mar 2005, 21:09:19
Have a look at the setPos command in the comref
setPos needs a position so to move a unit you  would put
unitname setPos [x,y,z]
You should also look at getPos.

I don't really think this should be under Advanced scripting.

Title: Re:Teleportation of objects/units?
Post by: Ding on 06 Mar 2005, 21:59:44
ahh setpos thanks :D i thjought it was mutc more complicated than that thanks.
Title: Re:Teleportation of objects/units?
Post by: bedges on 07 Mar 2005, 11:42:32
hokay mister THobson, i throw down the gauntlet at thine feetsies ;)

how does one teleport an entire squad, of an undetermined number of loons, in formation?

mmm?

heheh. it's a problem (http://www.ofpec.com/yabbse/index.php?board=6;action=display;threadid=22422) i've been playing with over the last couple of days, i ran into a brick wall, and settled for a random sin/cos placement around the setpos coordinate.

if you have a tidier solution however, i would be all eyes/ears :)

regards
b
Title: Re:Teleportation of objects/units?
Post by: ACF on 07 Mar 2005, 12:21:17
Untried, but the principle is sound (probably...):

EDIT - Now tried and tested - my unforgivable error rectified by bedges!

Code: [Select]
; [GROUP,MARKER/OBJECT/POS] Exec "teleport.sqs"

_group = _this Select 0
_units = Units _group

_finish = something _this Select 1
; derive your target position however
_finishx = _finish Select 0
_finishy = _finish Select 1

_start = GetPos (_units Select 0)
_startx = _start Select 0
_starty = _start Select 1
_gpx = []
_gpy = []

{_gpx = _gpx + [((GetPos _x) Select 0) - _startx]} ForEach _units
{_gpy = _gpy + [((GetPos _x) Select 1) - _starty]} ForEach _units

_imax = Count _units
_i = 0

#loop
(_units Select _i) SetPos [_finishx + (_gpx Select _i),_finishy + (_gpy Select _i),0]
_i = _i + 1
?(_i >= _imax): exit
Goto "loop"
exit

; in theory, this sets up two arrays of x and y offsets from a 'datum' unit in the group.
; All units are then setpossed to the new position plus the relevant offsets.
; There is an assumption that ForEach works from element 0 up,
; and that adding elements to an array puts them at the high end, not the low.
; i.e. [0,1,2,3,4] + [z] = [0,1,2,3,4,z] and not [z,0,1,2,3,4] or worse!

Assuming they move as intended, how long they will stand there dumbly adjusting to their new surroundings I don't know.

If you want a group to be teleported while moving (like they're coming out of a building), start them moving towards their real destination and use a simpler script to teleport them to the same point (e.g. the door) with a delay between each - as they appear, they move away and clear the space for the next one.
Title: Re:Teleportation of objects/units?
Post by: bedges on 07 Mar 2005, 12:30:31
that is inspired.... arrays. of course. can you see the wee lightbulb switched on above me?

thanks most kindly :)

EDIT - the script as it stands doesn't work. the _i variable needs to be declared outside the #loop, otherwise it just keeps on going round and round and round.....

otherwise it works a treat. i think this should perhaps be added to the knowledgebase... [shadow=blue,left,300]big up[/shadow] to ACF ;)
Title: Re:Teleportation of objects/units?
Post by: THobson on 07 Mar 2005, 12:42:06
I have just looked in quickly so I have not had time to look in details ACF's script.  I presume it calculates an x,y offset for each loon on the group from some reference point - say the leader, and then uses the same offsets to find their final location.

My puzzle is why you would want to do this.  When I have teleported groups in the past I have been trying to simulate them, leavinga building, so they are all teleported to the same place, but with a time delay.
Title: Re:Teleportation of objects/units?
Post by: Roni on 09 Mar 2005, 12:02:53
My puzzle is why you would want to do this.  When I have teleported groups in the past I have been trying to simulate them, leavinga building, so they are all teleported to the same place, but with a time delay.

I'll tell you why !

I've got a mission (mentioned millions of times before  :P ) in which the players all play black ops inserted on to an island at a random position.  There are three bases on the island that they can get to to rest, heal wounds, pick up ammo etc.  At the moment these bases positions are all fixed.

Being the tinkerer (sp?) that I am  :joystick: I've decided to make some of the hunting and patrolling bad guys playable.  Problem - I designed the mission, so i know where all the bases are.  Solution1 - take BMP and crew to each base and wipe them out (each base is loaded with semtex so no problem there !)

Solution2 is what I'm working on (and which looks to be solved for me !) - a method of lifting the entire base and putting it in a random spot at the start of the mission.  BTW - the "base" consists of a fireplace, some ammo bozes, a barrel of water, some tents and some concealing foliage.

What I want to do is create a sneaky, well hidden base, then move it exactly as is somewhere on the map.  The players will be able to find it thanks to a custom RDF script (radio call to return exact bearing and rough distance to base), but the bad guys will have to depend upon luck and lots of patrolling.

And yes, some day I'll finish the dang thing and post it !   :P



roni

Title: Re:Teleportation of objects/units?
Post by: Flauta on 11 Mar 2005, 00:17:15
well actualy, I am serching for a Script wich meets toes propietys....

what I need is a random Wolle-squad teleportation (set by markers or Heliports) when a tigger is hit....

any ideas about that?
Title: Re:Teleportation of objects/units?
Post by: ACF on 11 Mar 2005, 01:34:32
Now we know it works, use the corrected script above. Set your trigger up and in 'On Activation' have either:

[mywollesquad,GetPos myinvisibleH] Exec "teleport.sqs"

or:

[mywollesquad,GetMarkerPos "mymarker"] Exec "teleport.sqs"

depending on what you're using to mark the destination.
Title: Re:Teleportation of objects/units?
Post by: Flauta on 11 Mar 2005, 03:45:23
..but how to randomize positions... maybe randomizing the position of the hiliport from diferent heliports... but  how to do that..?
Title: Re:Teleportation of objects/units?
Post by: THobson on 11 Mar 2005, 08:59:32
If you want a random position centred on a location try the following:

_x and _y are the coordinates of the place you want the random locations to be centred around  (get them by using getPos)

_distance = random 50 (or whatever)
_theta = random 360  (leave this at 360)

_xRandom = _x + _distance * sin (_theta)
_yRandom = _y + _distance * cos(_theta)

That will select random locations in a circle.  If you want them in a rectangle:

_xRange = 50 (or whatever)
_yRange = 50 (or whatever)

_xRandom = _x - _xRange + 2 * random _xRange
_yRandom = _y - _yRange + 2 * random _yRange
Title: Re:Teleportation of objects/units?
Post by: Infierie Blou on 11 Mar 2005, 22:22:21
I'd use a small vehicle (man moveincargo car)...
then get out hey presto done.