Home   Help Search Login Register  

Author Topic: Move all units + waypoints inside trigger to a different location?  (Read 2822 times)

0 Members and 1 Guest are viewing this topic.

Offline Clayborne

  • Members
  • *
Hello

I'd like to know if it is possible to randomize an objective's location by transporting all of the units, waypoints and objects inside a trigger area to a different location, depending on a certain condition being met.

So if I have a group that has a patrol path around a radio tower or something, and on startup a random number is chosen, if the number is <1 then everything in the trigger is setpos'd to a different location, but the units still have their waypoints and still patrol the same way around the objective.

Is that doable? If not, I guess the alternative is to randomize the location of just the tower, place several identical groups with the same patrol paths at the possible locations for the tower, then delete the unused groups after startup.

The second way would be fine, but the first way would be faster. Anyone know if it's possible?

Offline RKurtzDmitriyev

  • Former Staff
  • ****
Maybe you could do just with relative positions.

Example: you have two soldiers, loon1 and loon2, and a gamelogic called "patrolcenter." You're going to teleport them to a new location _newloc . Unit loon1 is 10 metres west of patrolcenter, loon2 is 10 metres north. Then:

Code: [Select]

loon1 setpos [(_newloc select 0) - 10, (_newloc select 1)]
loon2 setpos [(_newloc select 0), (_newloc select 1) + 10]


Use setWPPos to set waypoint positions in the same manner.

Of course, this presupposes that you know where the positions of the units are. But unless the player is going to be in view of the teleportation, I don't see why you can't just stick the units in relative locations close to one of their waypoints.

If you need the relative locations to be exact, maybe try:

Code: [Select]
_loon1locx = (getpos loon1 select 0) - (_newloc select 0)
_loon1locy = (getpos loon1 select 1) - (_newloc select 1)

loon1 setpos [(_newloc select 0) + _loon1locx, (_newloc select 1) + _loon1locy]

Or maybe you don't know which units are going to be in the trigger zone. If that's the case, I think I have an inkling of what might help, but I'm not going to bother writing it all out unless it's what you actually need. ;)

Hope the above scripts work.
The OFP Editing Center wishes to remind you that the faithful COMREF will never threaten to stab you and, in fact, cannot speak.
However, in the event that it does speak, you are encouraged to heed its advice. ;)

Offline Clayborne

  • Members
  • *
The patrol groups will stay the same. Maybe some of their number will have random appearance % but the group leaders will be the same, so that idea should probably work ok.

But I'm new to random multiplayer events so I'm having a problem with setting the location of the objective. To test I put down a flag pole (flag1) between two triggers (FlagA and FlagB). The variable obj2a will be another objective, I just haven't dealt with it yet in the script. Here is what I've got;

Code: [Select]
wait_server = false

?!(local Server): goto "wait_client"


obj1a = random 2
obj2a = random 2



"publicVariable {_x}" forEach [obj1a,obj2a]

~1

wait_server = true

~0.1

publicVariable "wait_server"

#wait_client
@wait_server



?(obj1a <= 1): goto "obj1rand0"

~1

?(obj1a >= 1): goto "obj1rand1"


#obj1rand0
flag1 setpos getpos flagA


#obj1rand1
flag1 setpos getpos flagB


exit

 The flag has been teleported to flagB 100% of the time. I also tried :

Code: [Select]
obj1a = obj1a - obj1a % 1
goto format ["obj1rand%1", obj1a]


#obj1rand0
flag1 setpos getpos flagA


#obj1rand1
flag1 setpos getpos flagB

Thanks for your suggestions so far.
« Last Edit: 16 Jan 2010, 00:28:37 by Clayborne »

Offline RKurtzDmitriyev

  • Former Staff
  • ****
Thanks for your suggestions so far.

You're welcome. BTW I made an error in the second code above, it should be

Code: [Select]
_loon1locx = (getpos loon1 select 0) - (getpos radiotower select 0)
_loon1locy = (getpos loon1 select 1) - (getpos radiotower select 1)

loon1 setpos [(_newloc select 0) + _loon1locx, (_newloc select 1) + _loon1locy]

Where radiotower is the name of the object that the loons were patrolling around originally. The first two lines get the relative distance to radiotower, the third line puts loon1 at that same relative position to _newloc.

As for your randomness problem, I don't know what's going wrong, it looks like everything should work. Check for dumb errors, like the one above. ;) For example, make sure flagA has been defined correctly, etc.

EDIT: LOL, I know what the problem is. Everything is fine until you get here:

Code: [Select]
#obj1rand0
flag1 setpos getpos flagA


#obj1rand1
flag1 setpos getpos flagB


exit

The engine will continue reading even after the setpos getpos flagA, and so it will always set it to flagB immediately afterward! So either way, it ends up at flagB. :P

What you need is an exit before #obj1rand1 :

Code: [Select]
#obj1rand0
flag1 setpos getpos flagA

exit

#obj1rand1
flag1 setpos getpos flagB


exit

Tested in the mission editor, it should work now. :cool2:
« Last Edit: 16 Jan 2010, 15:36:48 by RKurtzDmitriyev »
The OFP Editing Center wishes to remind you that the faithful COMREF will never threaten to stab you and, in fact, cannot speak.
However, in the event that it does speak, you are encouraged to heed its advice. ;)

Offline Clayborne

  • Members
  • *
For some reason the random thing isn't working properly in MP.

The idea is that the two main objectives each have two possible locations. One of the objective locations was the same for me and the server, but the other objective didn't work (we got different marker locations, but the objective wasn't in either of them). Unfortunately we didn't have time to test it again to see if the same objective worked a second time. Here is the relevant section from the init.sqs.

Code: [Select]
wait_server = false

?!(local Server): goto "wait_client"


obj1a = random 2
obj2a = random 2



"publicVariable {_x}" forEach [obj1a,obj2a]

~1

wait_server = true

~0.1

publicVariable "wait_server"

#wait_client
@wait_server


~1


?(obj1a <= 1): goto "obj1rand0"


?(obj1a >= 1): goto "obj1rand1"



#obj1rand0
obj1_1 = true                  [objective 1, location1]
deletevehicle radar1b        [deleting the duplicate objective]    
deletevehicle power1b
goto "next"


#obj1rand1
obj1_2 = true
deletevehicle radar1a
deletevehicle power1a

#next

~1

?(obj2a <= 1): goto "obj2rand0"



?(obj2a >= 1): goto "obj2rand1"



#obj2rand0
obj2_1 = true
deletevehicle comm1b
deletevehicle crate1b
deletevehicle truck1b
deletevehicle radio1b
goto "next2"


#obj2rand1
obj2_2 = true
deletevehicle comm1
deletevehicle crate1
deletevehicle truck1
deletevehicle radio1

#next2

Should I execute this in a seperate script? I read that sometimes not having proper intervals between lines can mean information being lost for clients; could this be the case here?

Offline RKurtzDmitriyev

  • Former Staff
  • ****
Well, you're getting to the point where you probably know more than I do, but I'm curious to know:

(1) Does the script work in singleplayer? If it doesn't work in the mission editor preview, it's probably not going to work in MP. :)

(2) Which objective failed to appear at either location?
The OFP Editing Center wishes to remind you that the faithful COMREF will never threaten to stab you and, in fact, cannot speak.
However, in the event that it does speak, you are encouraged to heed its advice. ;)

Offline Clayborne

  • Members
  • *
Yes, everything works fine in SP.

The objective that failed to appear was objective 1. But again, I'm not sure if the other objective was just a fluke because we didn't test it again. I think we just happened to have the same outcome for that one.


Offline RKurtzDmitriyev

  • Former Staff
  • ****
I'm afraid I'm out of ideas. :(

Maybe try dePBOing others' multiplayer missions that have random events? I know of at least one working mission that uses lots of random locations. That's Pilot Down. I've attached the WGL version, because I can't find the original. (I had to remove the music to make the file fit under the size limit). It requires WGL5 and Occasus Island.

[CiA]Post also made a very interesting mission called Kwoal Genocide, for Tonal Island. I'm not sure if it's using random positions, but it definitely has random events.

Hope these help. :)

EDIT: Removing files, don't seem to be necessary any more.
« Last Edit: 20 Feb 2010, 04:06:32 by RKurtzDmitriyev »
The OFP Editing Center wishes to remind you that the faithful COMREF will never threaten to stab you and, in fact, cannot speak.
However, in the event that it does speak, you are encouraged to heed its advice. ;)

Offline Clayborne

  • Members
  • *
Thanks for those. The WGL one is particularly helpful because everything is annotated.

I don't get why the script I have isn't working, but whatever. I have moved the random stuff from the init.sqs to its own script. If that doesn't work, I'll just have the random number part for obj1a and obj2a seperate from the rest of the script and with ?(! local Server): exit so that part is definitely only run by the server.

I won't be able to test it for a while but thanks for your time!