Jump to content
Sign in to follow this  
McArcher

Player's position in Multiplayer game

Recommended Posts

I'm totally lost with scripting =)

Now the problem is....

I have a script, which is run in init.sqf for Dedicated server,

this script generates random positions for two base starts (RU and US) on the ground (i finally wrote the function :D), creates 2 MHQs, some vehicles near them (jeep and truck) and moves infantry near MHQs (15 RU and 15 US), they are all playable. Tested on one PC without "isDedicated"-check. Then I added isDedicated-condition, and this script is now run by a server.

I use "publicVariable" to make created vehicles and markers visible to all client-PCs. But there's the problem... When I start the game, I spawn at the position, that was made in Editor, instead of new script-changed-one!!! I know that change of coordinations for players works, because all my AIs have disappeared from Editor's position, and are now standing near MHQ, created somewhere on map (marker of base is visible to me).

I tried to add some code for non-server (client) in init.sqs, after server's code, it can teleport me to MHQ at start, that's great, but... when I want to teleport me to RU_player_1 or RU_player_5 for example, it doesnt move me, though I know that that unit was standing there near MHQ before I ran "setPos getPos RU_player_5"...

Question:

Why I can teleport to MHQ and cannot teleport to position of RU_player_* ?

Array RU_players = [RU_player_1, RU_player_2, RU_player_3, RU_player_4, RU_player_5, RU_player_6, RU_player_7, RU_player_8, RU_player_9, RU_player_10, RU_player_11, RU_player_12, RU_player_13, RU_player_14, RU_player_15]; is declared public with publicVariable after server-script finishes all the changes!

I tried to do

if ((side player) == east) then
{
player globalChat ("I am on EAST side."); //dbg
_i = 0;
{
	if (player == _x) then
	{
		player globalChat ("i am the " + str i + "th RU unit."); //dbg
		player setPos getPos _x;
		if (TRUE) exitWith{};
		_i = _i + 1;
	};
} forEach RU_players;
};
if ((side player) == west) then
{
{
	if (player == _x) then
	{
		player setPos getPos _x;
		if (TRUE) exitWith{};
	};
} forEach US_players;
};

, but it seems that player isnt any element of that array! It says just I'm on the east side an thats all!

How can I teleport to RU_player_* 's position?

What am I doing wrong?

---------- Post added at 08:02 PM ---------- Previous post was at 07:54 PM ----------

here's my init.sqf:

// mca_jip.sqf
// version 1.0
// JIP for MCTI
// client script
/////////////////////////////////////////////////////////////////////////////
private ["_i"];

waitUntil {time > 1};
player globalChat ("Starting JIP procedure..."); //dbg

player globalChat ("Deciding my number..."); //dbg
// updating position
if ((side player) == east) then
{
player globalChat ("I am on EAST side."); //dbg
_i = 1;
{
	if (player == _x) then
	{
		player globalChat ("i am the " + str _i + "th RU unit."); //dbg
		player setPos [(getPos _x select 0), (getPos _x select 1) + 5];
	}
	else
	{
		player globalChat ("i am not the " + str _i + "th RU unit."); //dbg
	};
	_i = _i + 1;
} forEach RU_players;
};

it says that I'm the 3rd when I select 3-rd east team slot, but it doesn't teleport me!

---------- Post added at 08:47 PM ---------- Previous post was at 08:02 PM ----------

I have an Idea...

maybe If I know my Player's number, must manually (by script) locate him according to MHQ's position and his number (like server-side script did in init.sqf) ? But it is strange, why MHQ's coordinates change , and my coordinates don't change via server's script.

---------- Post added at 09:21 PM ---------- Previous post was at 08:47 PM ----------

it worked :)

now i respawn near MHQ's latest position in game =)

// mca_jip.sqf
// version 1.0
// JIP for MCTI
// client script
/////////////////////////////////////////////////////////////////////////////
private ["_i", "_respawn_pos"];
waitUntil {time > 1};
// updating position
if ((side player) == east) then
{
_i = 0;
{
	if (player == _x) then
	{
		player globalChat ("I am RU_Player_" + str _i ); //dbg///////////////////////
		_respawn_pos = getPos RU_MHQ;
		player setPos [(_respawn_pos select 0) + (_i - 7)*5, (_respawn_pos select 1) + 20];
	};
	_i = _i + 1;
} forEach RU_players;
};
if ((side player) == west) then
{
_i = 0;
{
	if (player == _x) then
	{
		player globalChat ("I am US_Player_" + str _i ); //dbg///////////////////////
		_respawn_pos = getPos US_MHQ;
		player setPos [(_respawn_pos select 0) + (_i - 7)*5, (_respawn_pos select 1) + 20];
	};
	_i = _i + 1;
} forEach US_players;
};

BUT.... the way Arma2 works is VERY strange for me :(

Edited by McArcher

Share this post


Link to post
Share on other sites
AI leaders are always local to the server, if placed in the mission editor
, that's why all playable units changed their position. But, why did my playable unit didn't change it's position? It was also set in editor and script that was executed by server changed it's coordinates. I don't understand...

Maybe with that

The player's unit is always local to its client

this means that server cannot control coordinates of playable unit if it is controlled by a human? only client's script can change it's position?

then, if I somehow (how?) make an array that will store copies of playable units positons (coordinates) in server's script, I will be able to teleport my player using client's script that will read data from that special array given from server? how can i do this? (and how to refresh them? if they were all visible to sever,i wouldnt ask such stupid questions)....

how can a client's script learn coordinates of all playable units (those, whos place you can take when select slot in game lobby)? please show me.

I don't understand the idea of OFP/Arma's engine...:( it seems that it is like stone age... especially its script syntax...(it doesn't even understand operators like "x=y=5" !!! let alone more complicated things :()

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  

×