Jump to content

Recommended Posts

I got this to work (at least partially):

in the init:

if (isServer) then {
    addMissionEventHandler["PlayerConnected",{_this execVM "playerInit.sqf"}];
};

in playerInit.sqf:

thisPlayer = objNull;
playerId = (_this select 4);
for "_x" from 0 to (count allPlayers) -1 step 1 do {
    
    if (owner _x == playerId) then {
        thisplayer = (allPlayers select _x);
    };
};
thisPlayer = _this
publicVariable "thisplayer";
publicVariable "playerId";

the Id is correctly transfered

the problem is thisPlayer returns nothing

the if never returns true

so either the player is not in the list allPlayers at the time or i have no clue

 

I tested everything seperately and everything works so Ihave nu f*king idea why it doesn't work

 

Please help

thanks in advance

Share this post


Link to post
Share on other sites

Im not sure what your trying to do as thisPlayer and playerID will get over written for each connecting player and they will always reference the last connecting player ( In general if it worked ).

If you just want to grab each player as he joins can you not use initPlayerServer.sqf ?


//initPlayerServer.sqf

params[ "_player", "_didJIP" ];


//Do whatever

  • Like 1

Share this post


Link to post
Share on other sites
48 minutes ago, Tom507 said:

thisPlayer = _this


missing ; will result in compile error

 

49 minutes ago, Tom507 said:

the Id is correctly transfered

 

therefore ^^^^^ cannot possibly be true

  • Like 1

Share this post


Link to post
Share on other sites

thank you for your fast answers !!!

@ larrow : Im just using global variables for testing purposes its not final code but I will definetly look into initPlayerServer.sqf

I didn't know that that is something Special.

 

@KK : I just now found out about the .rpt files so I will propably get at least the syntax right :dummy: in the future.

btw is there any other method to get the syntax errors of called scripts on the server in real time like in the editor?

Why can the condition of the if not be true ?

is the owner (id) not the same as 3 (for the first connected Player)?

 

Share this post


Link to post
Share on other sites
16 minutes ago, Tom507 said:

Why can the condition of the if not be true

Script will abort on compile error

you can also use -showScriptErrors to get on screen notifications, but it wont help if error happens on dedicated server

Share this post


Link to post
Share on other sites

I think I got everything right now but it still doesn't work:

init.sqf

if (isServer) then {
    addMissionEventHandler["PlayerConnected",{_this execVM "GW_3_1_Main.sqf"}];
};

GW_3_1_Main.sqf :

I noticed that I had befor: owner _x  fixed it still no luck

thisPlayer = objNull;
playerId = (_this select 4);
// I also tried somethings with isNull but i have no object since I have not yet selected the Player
// and this with isNil doesn't work either
// waitUntil {!isNil (str playerId)};
for "_x" from 0 to (count allPlayers) -1 step 1 do {
    
    if ((owner (allPlayers select _x)) == playerId) then {
        thisplayer = (allPlayers select _x);
    };
};
publicVariable "thisplayer";
publicVariable "playerId";

the problem is still that thisPlayer returns: null object (as initialized) while playerId works fine

I'm afraid I need your help once more since I don't see anything wrong with this.

thanks in advance!

Share this post


Link to post
Share on other sites

@larrow:

OK WTF I just tried your solution Larrow and it works just like that!!! ( initPlayerServer.sqf )

I'm  amazed thanks soooooo much now i can get on with the fun stuff, this held me back for a week or so from making my script multiplayer compatible.

 

I have to say I'm verry thankfull that you pro's took it upon you to answer me. I already saw alot of stuff from both of you larrow and KK.

btw. can I somehow mark this as solved?

Share this post


Link to post
Share on other sites
2 hours ago, Tom507 said:

the problem is still that thisPlayer returns: null object (as initialized) while playerId works fine

 

This is because player is not yet initialised, so you loop though all players, find no player matching, and then publicVariable NULL player. Ideally you need to wait and keep checking to see if player is initialised, but this will be expensive. Larrow's solution is better.

  • Like 1

Share this post


Link to post
Share on other sites

still two questions

can I put my main script in the initPlayerServer.sqf with heavy stuff like checkVisibility or should i write my own list of Players and go through it seperatly?

and secondly just out of interest how exactly would I do this

6 hours ago, killzone_kid said:

checking to see if player is initialised

?

maybe something like Player == Player that I read a couple of times or !isNull Player (woulndn't work tho since i don't yet have the object Player)?

 

will it be the right Player Object from the moment the initPlayerServer.sqf runns? important for this:

_DetectionTrigger setTriggerStatements [
    "this",
    format ["
            
    %1 setVariable ['_DetTrgThisList_%1',  thisList]
            
    ", _player ]
    , ""
];

 

Edited by Tom507
make it readable

Share this post


Link to post
Share on other sites

@killzone_kid I'm afraid I have to take some of your Time again

I got everything to work so far exept one thing wich is the check if the Player is alive

 

iterestingly the Player object changes in the middle of my script from:

R Alpha 1-1:1 (Tom507) REMOTE

to:

286a0080# 48: vr_protagonist_f.p3d REMOTE

(thats propably the moment the player takes controll of the Unit) thought it might be important

 

I have a simple

if (alive _player) then {
	// my main script
	
	} else {
		// it allways runns into the else I dont understand why
		sleep 2;
		if (alive _player) then {
			_player setCaptive true; // this is supposed to make the Player captive every time he respawns
			
		};
	};

the question is why does my alive check not work?

to qoute your own Blog KK

http://killzonekid.com/arma-scripting-tutorials-locality/

AG: Command accepts global arguments. If the argument is a vehicle, I do not have to find the PC that owns it, I can just reference it from anywhere.

if thats the case (witch it is with alive) I don't understand it

this is my whole script in case you wan't a look:

Spoiler

(this is actually the version for having it in one sqf since im using only local vars for the trigger for example (I also failed to attach a variable to the player so that i could use it in both scripts, but that was propably because the code never ran due to the problem above))

initPlayerServer.sqf


// init
	diag_log "initPlayerServer.sqf Loaded";
	params[ "_player", "_didJIP" ];
	waituntil {alive _player};
	// add Event Handler to all Players witch puts every unit that fired a shot to the List HostilePlayers
	_player addEventHandler['FiredMan',{ 
		_player execVM  "GW_EventH_Fired.sqf";
	}];
	diag_log "initPlayerServer.sqf Status: EH FiredMan Initialized";
	// add opfor detection trigger on players current pos
	_DetectionTrigger = createTrigger ["EmptyDetector", getPos _player];
	_DetectionTrigger setTriggerArea [1000, 1000, -1, false];
	_DetectionTrigger setTriggerActivation ["EAST", "PRESENT", true];

	// Trigger sets Variable _DetTrgThisList (attached to apropriate Player) to the List of Objects currently fulfilling the Trigger conditions (in this case all Enemys in radius)
	_DetectionTrigger setTriggerStatements [
		"this",
			/*format ["
			diag_log ('DetTrg Status: Activated  List: ' + str thisList);
			(%1) setVariable ['_DetTrgThisList',  thisList];
				
			", _player ]// you may still have to waituntil the Player is alive*/
			"diag_log ('DetTrg Status: Activated  List: ' + str thisList +'  '+ str time);"
		, "diag_log 'DetTrg Status: deactivated '"
	];
	diag_log "initPlayerServer.sqf Status: DetectionTrigger Initialized";
	sleep 1.5;
	
	_player execVM  "GW_Main.sqf";

GW_Main.sqf:


// MAIN
While {true} do {
	
	
	/*// DEBUG //////////////////////////////////////////////////////*/diag_log ("Player: "+str _player + " LoopCount: " + str _counter); sleep 2;/*## DEBUG ##*/
	
	// Trigger folowing Player
	if (alive _player) then {
		/*## DEBUG ##////////////////////////////////////////////////*/diag_log ("Player: "+str _player + " LoopCount: " + str _counter + " Player alive  " + str time); sleep 2;/*## DEBUG ##*/
		if (!isNUll _DetectionTrigger) then{
			_DetectionTrigger setPos (getpos _player);
			/*## DEBUG ##////////////////////////////////////////////*/diag_log ("Player: "+str _player + " LoopCount: " + str _counter + " folowing Trigger  " + str time); sleep 2;/*## DEBUG ##*/
			
			_knowsAboutList = [];
			_ListInTrigger = (list _DetectionTrigger);
			
			for "_listInTrgCount" from 0 to (count _ListInTrigger) -1 step 1 do {
				// executed for every enemy in every trigger of every player
				_listInTrgObject = _ListInTrigger select _listInTrgCount;
				// writes bool list _knowsAboutList with value if each enemy in trigger knowsAbout Player
				_knowsAboutList = _knowsAboutList + [((_listInTrgObject knowsAbout _player) >= knowsAboutValue)];
				
				if (true in _knowsAboutList) then {
					// LOS check
					if (([_player,"FIRE"]checkVisibility[eyepos _listInTrgObject,eyepos _player]) > AiSight) then {
					/*## DEBUG ##////////////////////////////////////*/PlayerInSight = true;/*## DEBUG ##*/
					_TimeLastSight = Time;
					} /*## DEBUG ##//////////////////////////////////*/else {PlayerInSight = false;/*## DEBUG ##*/ };
				};
			};
		/*## DEBUG ##*/GW_Main_RU = ("Player: "+str _player + " LoopCount: " + str _counter + " LOS Eval");/*## DEBUG ##*/
		};
		
		if (_player in HostilePlayers) then {
			/*## DEBUG ##////////////////////////////////////////////*/diag_log ("Player: "+str _player + " LoopCount: " + str _counter + " Player in HostilePlayers  " + str time);/*## DEBUG ##*/
			
			_TimeLastShot = _player getVariable "_TimeLastShot";
			
			_LastShotEval = time >= (_TimeLastShot + SearchTime);
			_LastSightEval = time >= (_TimeLastSight + SearchTime);
			if (!((isNil "_LastShotEval") or (isNil "_LastSightEval"))) then {
			
				if (_LastShotEval and _LastSightEval) then {
					// This code is executed once a Players SearchTime is over
					
					hint (str (name _player)+ "is not being searched anymore");
					_player setCaptive true;
					
					// removing Player from Searched List
					HostilePlayers = HostilePlayers - [_player];
					/*## DEBUG ##////////////////////////////////////*/diag_log ("Player: "+str _player + " LoopCount: " + str _counter + " removal from HostilePlayers  " + str time);/*## DEBUG ##*/
				};
			};
		};
		
		
	} else {
		/*## DEBUG ##////////////////////////////////////////////////*/diag_log ("Player: "+str _player + " LoopCount: " + str _counter + " Player not alive  " + str time);/*## DEBUG ##*/
		if (_player in HostilePlayers) then{
			HostilePlayers = HostilePlayers -[_player];
		};
		sleep 2;
		if (alive _player) then {
			_player setCaptive true;
			/*## DEBUG ##////////////////////////////////////////////////*/diag_log ("Player: " + str _player + " is now Captive");/*## DEBUG ##*/
		};
	};
	
// DEBUG
	thisplayer = _player;
	publicVariable "thisplayer";
	publicVariable "HostilePlayers";
	publicVariable "GW_Main_RU";
sleep 0.5;
_counter = _counter + 1;
};

 

btw I also tryed putting it all in the initPlayerServer.sqf  but since it never got to the the main part of the code it made no difference whatsoever

I noticed the Note under the alive command I have only the respaw activated but that shouldn't be an issue so far anyway since I never died while testing:

 

Thanks for any answer in advance!!!!

 

plus: I found out now that, the value of thisPlayer (witch is the global variable i'm asigning _player to) switches from bis_02_47( witch is the correct value I think)

to: (some number, different every time): vr_protagonist_f.p3d REMOTE every view seconds

 

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

×