Forum Jump :

Author Message


Posts: 48
Rank:


Level: Member

Country: de
Location: K-Town
Occupation: Medic
Age: 38
In-game name: Officer D

 
#1 Posted at 2016-02-23 08:43        
     
Hope there is a quick fix for this. My arma code understanding is limited so probably just a noobish mistake. I have a random spawn script wich sets players to marker locations. I need a check if a player is already there and then call the script again until the player is alone.

This needs to work on a dedicated server.

RandomSpawn.sqf
SpawnMarker = ["spawn1","spawn2","spawn3","spawn4","spawn5","spawn6","spawn7","spawn8","spawn9","spawn10","spawn11","spawn12","spawn13","spawn14","spawn15","spawn16","spawn17","spawn18","spawn19","spawn20","spawn21","spawn22","spawn23","spawn24","spawn25","spawn26","spawn27","spawn28","spawn29","spawn30","spawn31","spawn32","spawn33","spawn34","spawn35","spawn36","spawn37","spawn38","spawn39","spawn40","spawn41","spawn42","spawn43","spawn44","spawn45","spawn46","spawn47","spawn48","spawn49","spawn50"] call BIS_fnc_selectRandom;
startPos = getMarkerPos SpawnMarker;

publicVariable "startPos";

if {(playableUnits distance) < 100 AND isPlayer} then {
	player setPos startPos;
	sleep 0.1;
	player setPos [getPos this select 0, getPos this select 1, 2];
}
else
{
	sleep 0.1;
	[player] execVM "scripts\RandomSpawn.sqf";
};

This post was edited by Officer D (2016-02-23 08:54, ago)


Author Message


Posts: 1589
Rank:


Level: Member

Country: pf
Location: Tahiti
Occupation: too many Arma
Age: 61
In-game name: Kobayashi Maru

 
#2 Posted at 2016-02-23 09:47        
     
If (!isDedicated) exitWith {};
_spawnMarkers = ["spawn1","spawn2","spawn3","spawn4","spawn5","spawn6","spawn7","spawn8","spawn9","spawn10","spawn11","spawn12","spawn13","spawn14","spawn15","spawn16","spawn17","spawn18","spawn19","spawn20","spawn21","spawn22","spawn23","spawn24","spawn25","spawn26","spawn27","spawn28","spawn29","spawn30","spawn31","spawn32","spawn33","spawn34","spawn35","spawn36","spawn37","spawn38","spawn39","spawn40","spawn41","spawn42","spawn43","spawn44","spawn45","spawn46","spawn47","spawn48","spawn49","spawn50"];
{
  _playerMarker = selectRandom _spawnMarkers;
  _x setPosAtl getMarkerPos _playerMarker;
  _spawnMarkers = _spawnMarkers - [_playerMarker] } foreach playableUnits;

selectRandom is a new command for arma 3 v 1.56
For Arma 2 OA replace:
_playerMarker = selectRandom _spawnMarkers;
by
_playerMarker = _spawnMarkers call BIS_fnc_selectRandom;

PLEASE CONTACT ME ON BI FORUMS FOR ANY SCRIPT / MOD QUESTION. TKS

Advertisement


Author Message


Posts: 48
Rank:


Level: Member

Country: de
Location: K-Town
Occupation: Medic
Age: 38
In-game name: Officer D

 
#3 Posted at 2016-02-23 09:51        
     
Will it work for Arma 2 OA aswell? I can't imagine that unless there has been an Arma 2 update.


Author Message


Posts: 1589
Rank:


Level: Member

Country: pf
Location: Tahiti
Occupation: too many Arma
Age: 61
In-game name: Kobayashi Maru

 
#4 Posted at 2016-02-23 09:53        
     
seen. And updated my previous post.

PLEASE CONTACT ME ON BI FORUMS FOR ANY SCRIPT / MOD QUESTION. TKS

Author Message


Posts: 48
Rank:


Level: Member

Country: de
Location: K-Town
Occupation: Medic
Age: 38
In-game name: Officer D

 
#5 Posted at 2016-02-23 09:57        
     
Right! Thank you for your help.

This script will check if a player is already near the marker and then choose a different one? I don't see how but I'll just accept that this is how it's done then.


Author Message


Posts: 1589
Rank:


Level: Member

Country: pf
Location: Tahiti
Occupation: too many Arma
Age: 61
In-game name: Kobayashi Maru

 
#6 Posted at 2016-02-23 10:09        
     
No, first playable unit choose a slot at random, then available markers are all the other ones and second unit "choose" at random within the new collection, ... there is no need to check if there is already some playable unit because the slot is no more available.

And, of course, checked from Eden MP preview.

PLEASE CONTACT ME ON BI FORUMS FOR ANY SCRIPT / MOD QUESTION. TKS

Author Message


Posts: 48
Rank:


Level: Member

Country: de
Location: K-Town
Occupation: Medic
Age: 38
In-game name: Officer D

 
#7 Posted at 2016-02-23 10:19        
     
The thing is I'm using respawn eventhandler:

player addEventHandler
[
	"respawn",
	{
		(_this select 0) execVM "scripts\RandomSpawn.sqf";
	}
];

Wouldn't that mean that all slots are available again after respawning? I had a working random spawn script. The problem was that player kept on getting spawned next to eachother.

Edit : I need this script to have a check if a playble unit is near it and choose a different marker if that is the case.
startMarker = ["spawn1","spawn2","spawn3","spawn4","spawn5","spawn6","spawn7","spawn8","spawn9","spawn10","spawn11","spawn12","spawn13","spawn14","spawn15","spawn16","spawn17","spawn18","spawn19","spawn20","spawn21","spawn22","spawn23","spawn24","spawn25","spawn26","spawn27","spawn28","spawn29","spawn30","spawn31","spawn32","spawn33","spawn34","spawn35","spawn36","spawn37","spawn38","spawn39","spawn40","spawn41","spawn42","spawn43","spawn44","spawn45","spawn46","spawn47","spawn48","spawn49","spawn50"] call BIS_fnc_selectRandom;
startPos = getMarkerPos startMarker;

publicVariable "startPos";

player setPos startPos;

sleep 2;

player setPos [getPos this select 0, getPos this select 1, 2];

This post was edited by Officer D (2016-02-23 14:14, ago)


Author Message


Posts: 1189
Rank:


Level: Member

Country: tr
Location:
Occupation: Computer Science student
Age: 23
In-game name: Wak

 
#8 Posted at 2016-02-23 16:17        
     
This should be all you need:
_startPos = getMarkerPos (["spawn1","spawn2","spawn3","spawn4","spawn5","spawn6","spawn7","spawn8","spawn9","spawn10","spawn11","spawn12","spawn13","spawn14","spawn15","spawn16","spawn17","spawn18","spawn19","spawn20","spawn21","spawn22","spawn23","spawn24","spawn25","spawn26","spawn27","spawn28","spawn29","spawn30","spawn31","spawn32","spawn33","spawn34","spawn35","spawn36","spawn37","spawn38","spawn39","spawn40","spawn41","spawn42","spawn43","spawn44","spawn45","spawn46","spawn47","spawn48","spawn49","spawn50"] call BIS_fnc_selectRandom);
_safe = true;
{if (_startPos distance _x < 100) exitWith {_safe = false}} forEach playableUnits;

if (_safe) then {player setPos _startPos} else {[] execVM "scripts\RandomSpawn.sqf"};

This post was edited by 654wak654 (2016-02-23 18:30, ago)

Sometimes I like to think as I started the whole "earplugs" thing.

W0lle: The only advice I can give you is: Do not try to understand BI. You will not succeed and it only makes your brain go boom. I would even go so far and say that not even they understand their own actions :-D.

#define getDamage getDammage

Author Message


Posts: 48
Rank:


Level: Member

Country: de
Location: K-Town
Occupation: Medic
Age: 38
In-game name: Officer D

 
#9 Posted at 2016-02-23 17:06        
     
Thanks! That looks promising. However the forEach playableUnits could be a problem for the respawn eventhandler. Wouldnt this mean, when someone respawns everybody currently playing will also get a new location?


Author Message


Posts: 1189
Rank:


Level: Member

Country: tr
Location:
Occupation: Computer Science student
Age: 23
In-game name: Wak

 
#10 Posted at 2016-02-23 17:14        
     
I think you misunderstood what forEach is. It's just a type of loop, same with while or for. It doesn't do any global execution by itself.

Sometimes I like to think as I started the whole "earplugs" thing.

W0lle: The only advice I can give you is: Do not try to understand BI. You will not succeed and it only makes your brain go boom. I would even go so far and say that not even they understand their own actions :-D.

#define getDamage getDammage

Author Message


Posts: 48
Rank:


Level: Member

Country: de
Location: K-Town
Occupation: Medic
Age: 38
In-game name: Officer D

 
#11 Posted at 2016-02-23 17:19        
     
Right! Thanks, I'll have to test it on the dedicated server. The script Pierre MGI posted also has the forEach playableunits in it and on respawn, everybody on the map got teleported.


Author Message


Posts: 1189
Rank:


Level: Member

Country: tr
Location:
Occupation: Computer Science student
Age: 23
In-game name: Wak

 
#12 Posted at 2016-02-23 17:24        
     
It might be because you're adding the EH to all units, for all units. Change your current Respawn EH to this:

player addEventHandler ["Respawn", {if (local (_this select 0)) then {[] execVM "scripts\RandomSpawn.sqf"}}];

Sometimes I like to think as I started the whole "earplugs" thing.

W0lle: The only advice I can give you is: Do not try to understand BI. You will not succeed and it only makes your brain go boom. I would even go so far and say that not even they understand their own actions :-D.

#define getDamage getDammage

Author Message


Posts: 48
Rank:


Level: Member

Country: de
Location: K-Town
Occupation: Medic
Age: 38
In-game name: Officer D

 
#13 Posted at 2016-02-23 17:43        
     
hmm, the random spawn script doesn't seem to work. Players start where they were placed.


Author Message


Posts: 1189
Rank:


Level: Member

Country: tr
Location:
Occupation: Computer Science student
Age: 23
In-game name: Wak

 
#14 Posted at 2016-02-23 18:30        
     
My bad, had a small error in the script. I edited my original post with the fixed code.

Sometimes I like to think as I started the whole "earplugs" thing.

W0lle: The only advice I can give you is: Do not try to understand BI. You will not succeed and it only makes your brain go boom. I would even go so far and say that not even they understand their own actions :-D.

#define getDamage getDammage

Author Message


Posts: 1589
Rank:


Level: Member

Country: pf
Location: Tahiti
Occupation: too many Arma
Age: 61
In-game name: Kobayashi Maru

 
#15 Posted at 2016-02-23 20:10        
     
I thought you were on a start mission problem and a playable units is not already a player. So, the script i wrote is on server side and runs at start only.
When a player respawn, the respawn mode can be last position, base, group...
First of all you must be on respawn = 2; ("instant" = old position).

There is no reason to re-run this server side script, but your problem still remains if you don't want to spawn near a player. Sorry, I missed that.

Wak gave you a solution and the forEach playable units is just here to toggle a variable for the presence or not of a potential player (even not yet in game but AI on a playable slot).

Wak, the little weakness (not error) I think occurs when the number of players are very close to the number of spots. Your script can run many times as you randomize all spots, again and again. In game, you can cope with the fact, players are away and not necessary on a spot. But for a mission start with all playable units on their respective spot, you can run a lot of time the script before finding the true spot.

Alternate script, checking once for each spawn markers:

If (!isserver) exitWith {};
// my former script here if you don't respawnOnStart

player addEventHandler  ["respawn", {
  _spawnMarkers = ["spawn1","spawn2","spawn3","spawn4","spawn5","spawn6","spawn7","spawn8","spawn9","spawn10","spawn11","spawn12","spawn13","spawn14","spawn15","spawn16","spawn17","spawn18","spawn19","spawn20","spawn21","spawn22","spawn23","spawn24","spawn25","spawn26","spawn27","spawn28","spawn29","spawn30","spawn31","spawn32","spawn33","spawn34","spawn35","spawn36","spawn37","spawn38","spawn39","spawn40","spawn41","spawn42","spawn43","spawn44","spawn45","spawn46","spawn47","spawn48","spawn49","spawn50"];
  _occupied = [];
  for "_i" from 0 to count _spawnMarkers -1 do {
    _playerMarker = _spawnMarkers select _i;
    {if (getMarkerPos _playerMarker distance _x < 100) then {
      _occupied set [count _occupied, _playerMarker]} } foreach playableUnits - [player];
    };
    _spawnMarkers = _spawnMarkers - _occupied;
    _playerMarker = _spawnMarkers call BIS_fnc_selectRandom;
    (_this select 0) setposATL getMarkerPos _playerMarker;
 }];

This post was edited by Pierre MGI (2016-02-23 21:37, ago)

PLEASE CONTACT ME ON BI FORUMS FOR ANY SCRIPT / MOD QUESTION. TKS





Tags: Random, Script, Spawn