Jump to content
Sign in to follow this  
snkman

Randomselect Script in ArmA?

Recommended Posts

Hi Guy's,

well in OFP i always used a Script ( RandomSelect 1.1 by Daddldiddl ) which allowes me to get a dynamic Starting point.

Now i tryed the Script with ArmA and i always get a error message...

Maybee someone of you know's how to get the Script work in ArmA...

move.sqs

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">? !(local Suche):exit

~3

_movepos=[gl_1,gl_2] call RandomSelect

_unit1 = _this select 0

_unit1 setpos getpos _movepos

~2

({_x setpos getpos _movepos} forEach units _unit1)

exit

randomselect.sqf

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">//RandomSelect 1.1 by Daddldiddl

private ["_list","_ntotal","_random","_result","_ziel"];

_list=_this;

_ntotal=count _list;

_random=random(_ntotal);

_result=_random - ((_random) mod (1));

if (_result==_ntotal) then {_result=_result-1};

_ziel=_list select _result;

_ziel

rands.sqs

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">;================

;preload function

;================

RandomSelect = preprocessFile "randomselect.sqf"

?!(local Server):EXIT

exit

As i tested the Script i always get a error message about this part of the Script:

move.sqs

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">? !(local Suche):exit

~3

_movepos=[gl_1,gl_2] call RandomSelect

It would really nice if someone can help me cuz i really inlove.gif this Script.

Share this post


Link to post
Share on other sites

Thanks to the new command floor, you should only need this.

randomselect.sqf:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_This Select (Floor (random (Count _This)))

But thats assuming your array will never be empty, but seen as there was no check in the original. It should be ok for you.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">;================

;preload function

;================

RandomSelect = preprocessFile "randomselect.sqf"

?!(local Server):EXIT

exit

BTW the above should be:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">RandomSelect = Compile preprocessFile "randomselect.sqf"

You can put that line straight into your init.sqs. I don't really understand this bit:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">?!(local Server):EXIT

exit

As it will exit regardless of object Server being local or not. I can only assume you have other code there, that you haven't posted? But either way, I think you need to use If Then, instead of ?. If your calling your scripts with execVM e.t.c

Share this post


Link to post
Share on other sites

Very cool it works very well!!! smile_o.gif

Thank you very much UNN for your time. thumbs-up.gif

Share this post


Link to post
Share on other sites

Sorry i have just another question:

I like to have some East troups shown on the map with Markers.

I always used:

markers.sqs

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">#loop

~1

if (count units ge1 > 0) then {{ge1m} setmarkerpos getpos leader ge1;} else {{ge1m} setmarkertype {empty}}

goto "loop"

I wrote in the init of the Leader of the Group "ge1=group this;"

and "[] exec "markers.sqs"" in the init.sqs of the mission.

and i created a Marker with the name: ge1m

now the marker is following the groupe on the Map where ever they go... But now in ArmA it looks like it doesnt work... Damn did BIS replace all old code with new one?

Share this post


Link to post
Share on other sites
Quote[/b] ]I like to have some East troups shown on the map with Markers.

I wrote three different examples of looping a marker to a groups leader here (half way down the page):

Loops

Perhaps one of those will be helpful. They all do the same thing, its really down to which one you find the most appealing, to look at smile_o.gif

BTW the problem with your original code, is the {} brackets. With Arma you have to be explicit when it comes to denoting strings\text and code:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">#loop

~1

if (count units ge1 > 0) then {"ge1m" setmarkerpos getpos leader ge1} else {"ge1m" setmarkertype "empty"}

goto "loop"

Share this post


Link to post
Share on other sites

WOW UNN i'm really impressed!!! notworthy.gif

Your script's are so much better than the one i used. Really very good. thumbs-up.gif

Once again Thank you very much UNN for your greate help. smile_o.gif

Share this post


Link to post
Share on other sites

No worries, glad I could help out. It's still not the perfect marker script, it won't account for breaking your original squad into multiple teams i.e Red, Green e.t.c

If you run into any problems with it, give us a shout and I will see if I can improve on it.

Share this post


Link to post
Share on other sites

Hi UNN well i just have another quastion about your Marker Script: Well in the Editor it works very well but in MP i cant see the Markers?

Do you know how to fix it?

Share this post


Link to post
Share on other sites

There is a more detail discussion here about markers in MP. But from what I understand from Karrilions comment:

Quote[/b] ]ATM, createMarker and setMarkerText are GLOBAL commands, whereas all other setMarker commands are LOCAL.  This will obviously change with ArmA 1.04 since they just added a ton of Local marker commands.

You could try this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_Group=_This Select 0;

_Name=_This Select 1;

If (Local Server) Then

{

_Marker=CreateMarker [_Name,GetPos (Leader _Group)];

Call Compile Format ["%1DONE=%2",_Marker,True];

PublicVariable (_Marker+"DONE");

};

_Marker=_Name;

WaitUntil {Call Compile Format ["%1DONE",_Marker]};

_Marker SetMarkerType "Dot";

_Marker SetMarkerSize [1,1];

WaitUntil

      {

      _Leader=Leader _Group;

      WaitUntil

              {

              If (Alive _Leader) Then

                      {

                      _Marker SetMarkerPos (GetPos _Leader);

                      Sleep 1;

                      };

     

              !(Alive _Leader)

              };

      ((Count (Units _Group))==0)

      };

DeleteMarker _Marker;

Ok i'm sticking my neck out a bit now. Perhaps someone more familiar with Markers or able to test this in MP, can offer a better solution? I'm assuming the value returned by CreateMarker will be the same as the original name you provided, if succesfull.

Share this post


Link to post
Share on other sites

WOW nice it works!!! smile_o.gif Thank you UNN.

Share this post


Link to post
Share on other sites

Well look's like RandomSelect did not work 100% like it should... crazy_o.gif

It happends very often, that i get teleported by the Script but the rest of my Team stay just where it was... They dont follow me.

Maybee someone know's the Problem:

Init of the Leader:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[this] exec "move.sqs"

move.sqs

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">? !(local Suche):exit

~3

_movepos=[gl_1,gl_2,gl_3,gl_4,gl_5,gl_6,gl_7,gl_8,gl_9,gl_10] call RandomSelect

_unit1 = _this select 0

_unit1 setpos getpos _movepos

~2

({_x setpos getpos _movepos} forEach units _unit1)

exit

randomselect.sqf:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_This Select (Floor (random (Count _This)))

rands.sqs:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">RandomSelect = Compile preprocessFile "randomselect.sqf"

init.sqs of the Mission:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[] exec "rands.sqs"

AllPlayers = list playersearch

On the map i have a Logic with the Name Suche

Hmm.... I really don't know why it doesn't work sometimes and sometimes it works very well?

B.t.w. I use PRiME's Revive in this mission too. Can this be the Problem?

Well just 1 more question:

ArmA is using "JIP" i have a Lokal Dedicated Server but no one is joining... sad_o.gif so maybee someone can answere me.

What will happend with the RandomSelect Script if im in the Mission and a new player join my mission?

Will randomselect teleport him to me? Or will he just stay at the starting point? How does it works?

Share this post


Link to post
Share on other sites
Well look's like RandomSelect did not work 100% like it should...  crazy_o.gif

It happends very often, that i get teleported by the Script but the rest of my Team stay just where it was... They dont follow me.

Maybee someone know's the Problem:

Init of the Leader:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[this] exec "move.sqs"

move.sqs

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">? !(local Suche):exit

~3

_movepos=[gl_1,gl_2,gl_3,gl_4,gl_5,gl_6,gl_7,gl_8,gl_9,gl_10] call RandomSelect

_unit1 = _this select 0

_unit1 setpos getpos _movepos

~2

({_x setpos getpos _movepos} forEach units _unit1)

exit

randomselect.sqf:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_This Select (Floor (random (Count _This)))

rands.sqs:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">RandomSelect = Compile preprocessFile "randomselect.sqf"

init.sqs of the Mission:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[] exec "rands.sqs"

AllPlayers = list playersearch

On the map i have a Logic with the Name Suche

Hmm.... I really don't know why it doesn't work sometimes and sometimes it works very well?

B.t.w. I use PRiME's Revive in this mission too. Can this be the Problem?

Well just 1 more question:

ArmA is using "JIP" i have a Lokal Dedicated Server but no one is joining...  sad_o.gif  so maybee someone can answere me.

What will happend with the RandomSelect Script if im in the Mission and a new player join my mission?

Will randomselect teleport him to me? Or will he just stay at the starting point? How does it works?

I actually have no idea, but I will try anyway wink_o.gif

It appeers that your move.sqs only moves the leader:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_unit1 = _this select 0

_unit1 setpos getpos _movepos[/QUOTE]

Since you called your move.sqs with

[this] exec "move.sqs" 

In the init field of the leader,

The _unit variable will always only be the leader, no?

Is it possible to use:

_unit1= _this select [0,1,2,3,4,5,6,7,8,9,10]

??

Share this post


Link to post
Share on other sites

It does sound like every now and again, your not getting the full list of units from your group. During startup there is a slight delay before the groups and associated units are defined, perhaps sometimes it takes a little longer.

You could see if this helps any:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">? !(local Suche):exit

~3

_movepos=[gl_1,gl_2,gl_3,gl_4,gl_5,gl_6,gl_7,gl_8,gl_9,gl_10] call RandomSelect

_unit1 = _this select 0

_unit1 setpos getpos _movepos

~2

WaitUntil {Count (units _unit1)>1}

{_x setpos (getpos _movepos)} forEach (units _unit1)

exit

If you know exactly how many units are in the group, you can change the condition to wait until it counts the correct number. If not, greater than 1 might be enough of a delay?

I have a vauge recolection of hitting a similar problem, so it may also be worth trying this line instead:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">{_x setpos (getpos _movepos)} forEach (Units (Group _unit1))

If you still can't get to the bottom of it, add some debug hints. To return the number of units in the group:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">? !(local Suche):exit

~3

_movepos=[gl_1,gl_2,gl_3,gl_4,gl_5,gl_6,gl_7,gl_8,gl_9,gl_10] call RandomSelect

_unit1 = _this select 0

Hint Format ["Group %1 has %2 units",Group _unit1,Count (Units (Group _unit1))]

_unit1 setpos getpos _movepos

~2

WaitUntil {Count (units _unit1)>1}

{_x setpos (getpos _movepos)} forEach (units _unit1)

exit

At least that way you can check to see if thats the true cause of your problem, or something else. Trying to position an entire squad onto the same XY location could be causing you problems. You should really take into account their position relative to the squad leader to. But my point is, it could turn out to be the setpos command.

Share this post


Link to post
Share on other sites

Really nice Guy's! smile_o.gif Thank's a lot for your help.

I will try everything and report what's happend.

So long... wink_o.gif THX

Okay here are my results:

@Espectro

if i use your way i get an Error at the beginning of the mission, when the script is readed...

@UNN

well all your script's work just fine in the Editor but at the Dedi it's the same like bevore... confused_o.gif

The script:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">? !(local Suche):exit

~3

_movepos=[gl_1,gl_2,gl_3,gl_4,gl_5,gl_6,gl_7,gl_8,gl_9,gl_10] call RandomSelect

_unit1 = _this select 0

Hint Format ["Group %1 has %2 units",Group _unit1,Count (Units (Group _unit1))]

_unit1 setpos getpos _movepos

~2

WaitUntil {Count (units _unit1)>1}

{_x setpos (getpos _movepos)} forEach (units _unit1)

exit

Is very cool but the Message how many Soldiers are in my Team apperes in the Editor only too.

On a Dedi i get no Message...

Okay here's something strange i found out! smile_o.gif

Well if i play my mission on a Dedi ( Me and 4 - 5 KI Soldiers ) for the first 10 - 20 sec. of the Mission, when i wait to get teleportet i can't shoot the KI Soldiers.

Than after the 10 - 20 sec. and maybee 1 - 2 sec. bevor we get teleportet i can Shoot the KI Soldiers from my Team and i noticed:

Maybee it's just coincidence but if i shoot just 1 Soldier of my team in the 1 - 2 sec. bevore we get teleportet it alway's works. rofl.gif

Can that be? I really don't understand this? crazy_o.gif

How can a Script work one time and another time it doesn't work? It's a Script? How can this be?

Maybe it has somethink to do with the Beta Dedicated Server i really have no clue. smile_o.gif

Well i will use it like it's now. I have to restart the mission maybe 5 - 6 times but anyway it work's. biggrin_o.gif

So many thank's for all your greate help and time spend to me!

Many Greetings SNK wink_o.gif

Share this post


Link to post
Share on other sites

Hi Guy's,

well so far the Script works good. smile_o.gif

About "JIP" is there a way to get Players which come's into the Game later to teleport to the Leader?

I tested it but later joining Players keep staying on the start position...

I have 12 Playable Soldiers Named: p1,p2,p3,p4,...p12

I thought maybe it's possible to let them teleport as soon as they are in use to the Leader ( p1 ) or to the Point, where the leader was teleportet to...?

Share this post


Link to post
Share on other sites
Quote[/b] ]Is very cool but the Message how many Soldiers are in my Team apperes in the Editor only too.

On a Dedi i get no Message...

If it's an AI team then you would have to broadcast the results over the network:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">GROUP01=Count Units (Group _Unit1)

PublicVariable "GROUP01"

Then on your client run a script:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">GROUP01=-1

If (IsNull Player) Then {goto "Exit"}

@(GROUP01!=-1)

Hint Format ["Group01 has %1 units",GROUP01]

Exit

But I'm afaid I can't offer much help when it comes to MP.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×