Home   Help Search Login Register  

Author Topic: Moving briefing markers to the random locations of objects  (Read 2292 times)

0 Members and 1 Guest are viewing this topic.

Offline RKurtzDmitriyev

  • Former Staff
  • ****
This isn't possible, is it?

I'm trying to do all of the following at once:

(1) Have several groups of playable units distributed randomly at predefined locations. ("Who goes where" is random, but the possible locations are pre-specified). These will be the players in the mission.

(2) Assign specific markers showing where each group was placed.

(3) All players must be able to see these markers during briefing.

(4) All of this must be done in briefing, before the mission starts.

I can't seem to get them all to work. (1) is no problem by itself, I've got that part working. Number (2) can be done with setmarkerpos, but the computer must know where to stick the markers. Which brings us to (3) : setmarkerpos is local, so changing a marker's position on one computer has no bearing on where it is on another computer.

That's no problem if all clients run the same script with setmarkerpos, like as follows:

Code: [Select]
;logic1, logic2...etc are game logics
"marker1" setmarkerpos getpos logic1
"marker2" setmarkerpos getpos logic2
"marker3" setmarkerpos getpos logic3
"marker4" setmarkerpos getpos logic4
exit

BUT it doesn't seem to work when (4) the position that the markers are going to is being changed in briefing, before the game starts. So, for example, the following will

not work, according to my tests in a pseudo-MP environment (running 2 instances of OFP on my computer):

Code: [Select]
;moving the logics
logic1 setpos getpos logic5
logic2 setpos getpos logic6
logic3 setpos getpos logic7
logic4 setpos getpos logic8

;setting the markers to their positions
"marker1" setmarkerpos getpos logic1
"marker2" setmarkerpos getpos logic2
"marker3" setmarkerpos getpos logic3
"marker4" setmarkerpos getpos logic4
exit

During briefing, it seems that the logics are only moved on the server's computer. The clients won't move the logics until after the game has started, and they'll set the markers where the logics were before moved.

And no, I don't think it's just a problem with game logics as soldiers don't seem to work, either.

Does anyone know of a way to get what I'm after, above? I think I'll just have to either drop the random placement at the beginning, or not have markers at the beginning. I'm not excited about either possibility. :(

My script, designed for the mission I'm making, is attached below, for anyone who wants to get a clearer picture of where I'm trying to go. It would be run straight from init.sqs .

P.S.: While researching for this post I realised that I might be triggering FADE on my computer by running two instances of OFP at once, so I won't do that anymore (see thread). But frankly I don't think that's the problem, it seems more likely to be a locality issue as BIS isn't likely to deter warezers by screwing up convoluted marker scripts. :P

EDIT: Wrong attachment!  >:(
« Last Edit: 25 Mar 2010, 19:04:36 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 dr. seltsam

  • Members
  • *
Re: Moving briefing markers to the random locations of objects
« Reply #1 on: 25 Mar 2010, 21:59:00 »
If i got you right, you need an information that is random and is accessible for the server and the clients during the briefing screen...

First i thought about using a publicvariable... but i fear the effect of an publicvariable is not reaching the clients before mission start... but then... i had an idea...

Check the demo mission, and tell me your thoughts...
:cool2:


Offline RKurtzDmitriyev

  • Former Staff
  • ****
Re: Moving briefing markers to the random locations of objects
« Reply #2 on: 26 Mar 2010, 00:04:14 »
Thanks for the reply.

Quote
you need an information that is random and is accessible for the server and the clients during the briefing screen...

That's basically it, yeah.

Quote
First i thought about using a publicvariable... but i fear the effect of a publicvariable is not reaching the clients before mission start...

And that's the problem. It seems that server and clients will automatically execute all code begun in init.sqs up to and until the point that a time delay is needed. And in order to wait for publicvariable to be transmitted to clients, I need a time delay. :banghead:

Quote
Check the demo mission, and tell me your thoughts...

Interesting idea. If you made that just for me, then thanks. :-[

Of course I can't use probability of presence as in that missionette, because these units will be players. But I may be able to use a little-known feature in OFP: if you group units to markers (which can be invisible), they'll appear randomly either at their location in the editor or at one of the markers. That's how you always appear at a random one of several possible locations in the BIS mission Steal the Car.

Problem now is that I don't want more than one group of players at a given location, but that will tend to happen if I try this strategy. It's like I'm trying to distribute four stones randomly into four holes, and I don't want more than one stone in each hole. I can tell each stone to pick a random hole, but then it's quite likely that two of them will decide to drop in the same hole.

Maybe I can find some way to work around that, though...stay tuned (or feel free to barge in with any insights :D).

EDIT: So I think I've gotten this to work now. I have gamelogics grouped to markers, causing them to appear randomly either at their editor location or at one of the markers. The positions are synchronized between server and client before the briefing screen comes up, though. These random locations then form a kind of "random seed" which each computer is told to act on in the same way, using code like the following:

Code: [Select]
;use the distance formula take the distance between the gamelogic "randomlogic" and markers random0
;random1, random2, random3, to find out where the logic was positioned. Then, assign a value to variable
;"randommarker" which will be used for other stuff.

? sqrt ((((getpos randomlogic) select 0)-((getmarkerpos "random0") select 0))^2 + (((getpos randomlogic) select 1)-((getmarkerpos "random0") select 1))^2) < 10 : randommarker = 0
? sqrt ((((getpos randomlogic) select 0)-((getmarkerpos "random1") select 0))^2 + (((getpos randomlogic) select 1)-((getmarkerpos "random1") select 1))^2) < 10 : randommarker = 1
? sqrt ((((getpos randomlogic) select 0)-((getmarkerpos "random2") select 0))^2 + (((getpos randomlogic) select 1)-((getmarkerpos "random2") select 1))^2) < 10 : randommarker = 2
? sqrt ((((getpos randomlogic) select 0)-((getmarkerpos "random3") select 0))^2 + (((getpos randomlogic) select 1)-((getmarkerpos "random3") select 1))^2) < 10 : randommarker = 3

;array of possible starting positions for players
_markerarray = ["nwpos", "swpos", "nepos", "sepos"]

;marker influenced randomly by the code above
_marker = _markerarray select randommarker

;prevents more than one squad from being sent to the same location
_markerarray = _markerarray - [_marker]

;designate position and move unit & marker to it
_newpos = getmarkerpos _marker
"mainloons1marker" setmarkerpos _newpos
leader mainloons1 setpos _newpos

It's a hack, but I haven't figured out any other way to get random information synchronized between all players while still in briefing. :cool2:

Your demo mission gave me the inspiration, thanks for sending it. :good:
« Last Edit: 26 Mar 2010, 23:14:18 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 dr. seltsam

  • Members
  • *
Re: Moving briefing markers to the random locations of objects
« Reply #3 on: 27 Mar 2010, 13:18:40 »
I developed my idea a bit further...

I made a function that will pick an element from an array depending on the probability of presence of some preplaced soldiers in the map. If you have 4 soldiers with a probability of presence of 50%, this function can result into 2^4 = 16 different selection results. If you have an array with less than 16 elements, it does not matter, the function will pick the element that was the nearest in the last calculation step. Example: The last calculation was 3,625 --> leads to --> array select 4

If your input array has one element --> it always calculates between 0 and 0, and the output is --> array select 0

Selector.sqf
Code: [Select]
// Selector

private [{_s_ar},{_u_ar},{_sl},{_sh},{_a},{_i}];

_s_ar=_this select 0;
_u_ar=_this select 1;

_sl=0;
_sh=(count _s_ar)-1;

_a=0;
_i=0;
while {_i < (count _u_ar)} do
{
_a=(_sl+_sh)/2;
if (format ["%1",_u_ar select _i] == "scalar bool array string 0xfcffffef") then
{
_sh=_a;
}
else
{
_sl=_a;
};
_i=_i+1;
};
_a=(_sl+_sh)/2;
_a=_a+0.5;
_a=_a-_a mod 1;

_s_ar select _a

This funtion can select what you want... markers, objects, numbers, positions, arrays, text strings... really what you want...

Quote
Problem now is that I don't want more than one group of players at a given location, but that will tend to happen if I try this strategy. It's like I'm trying to distribute four stones randomly into four holes, and I don't want more than one stone in each hole. I can tell each stone to pick a random hole, but then it's quite likely that two of them will decide to drop in the same hole.

Then i do the same as you... I remove the "holes" from the possible selections after every step. For some reason i got some strange distribution patterns with my script. I use shuffled soldier patterns for the function input now, and the strange pattern does not occur that often...

Briefing.sqs
Code: [Select]
; *****************************************************
; ** Briefing
; *****************************************************

_fSelector=preprocessFile "Selector.sqf"

_m_ar   = ["ma","mb","mc","md"]
_c_ar_1 = [c1,c2,c3,c4]
_c_ar_2 = [c2,c3,c4,c1]
_c_ar_3 = [c3,c4,c1,c2]
_c_ar_4 = [c4,c1,c2,c3]
_y=50

_m=[_m_ar,_c_ar_1] call _fSelector
_p=getMarkerPos _m
"m1" setMarkerPos [_p select 0,(_p select 1)-_y]
_m_ar=_m_ar-[_m]

_m=[_m_ar,_c_ar_2] call _fSelector
_p=getMarkerPos _m
"m2" setMarkerPos [_p select 0,(_p select 1)-_y]
_m_ar=_m_ar-[_m]

_m=[_m_ar,_c_ar_3] call _fSelector
_p=getMarkerPos _m
"m3" setMarkerPos [_p select 0,(_p select 1)-_y]
_m_ar=_m_ar-[_m]

_m=[_m_ar,_c_ar_4] call _fSelector
_p=getMarkerPos _m
"m4" setMarkerPos [_p select 0,(_p select 1)-_y]

exit

I really like the idea of a randomized mission start, that shows the situation in the briefing (markers, text, etc.) aswell...  :good:

Tell me where to play your mission when it's online.
:)
« Last Edit: 27 Mar 2010, 14:25:41 by dr. seltsam »

Offline RKurtzDmitriyev

  • Former Staff
  • ****
Re: Moving briefing markers to the random locations of objects
« Reply #4 on: 27 Mar 2010, 13:47:38 »
Wow, thanks for writing the function, I'll see if it fits into my mission build.

Quote
I really like the idea of a randomized mission start, that shows the situation in the briefing (markers, text, etc.) aswell...

Tell me where to play your mission when it's online.

Thank you. It'll probably be on CiA server if the mission gets off the ground.
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 dr. seltsam

  • Members
  • *
Re: Moving briefing markers to the random locations of objects
« Reply #5 on: 27 Mar 2010, 14:24:21 »
Can you provide an example mission for your last script version? I want to test it..

Offline RKurtzDmitriyev

  • Former Staff
  • ****
Re: Moving briefing markers to the random locations of objects
« Reply #6 on: 27 Mar 2010, 21:47:43 »
Sure, here you go.

The critical script is markerstart.sqs . Not only does it set the markers to random locations, it also puts group leaders as well as their squads in the same relative positions they were assigned in the editor.
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. ;)