Jump to content
IGD Big Steve

Need help with script for MP server (Resolved)

Recommended Posts

I am making a Team vs Team multiplayer mission to help my team practice PvP. This mission is hosted dedicated on my server. Players can choose from multiple sectors to capture. I am trying to give the team who captured the sector points for doing so. I have tried using the "Expression" field of the sector, with working results when testing in singleplayer and multiplayer from within the editor, but never works when hosted on my server. I have tried using the Expression field to do even just hint a message, for which it seems like it will not work if the server is dedicated. I currently am using an event handler to give money to players for killing each other, which works similar to the one below, with no issues.

 

This is the latest version of my script:

Spoiler

{[ _x, "ownerChanged", {
        params[ "_sector", "_owner", "_ownerOld" ];

        if ( _owner isEqualTo (side player)) then {
        pointsPlayer = pointsPlayer + 1000;
        hint format ["You got 1000 points for capturing a cartel, you have %1 points",  pointsPlayer];    
        };
    }] call BIS_fnc_addScriptedEventHandler;} forEach ( true call BIS_fnc_moduleSector );

 

I have tried using this script, or variations of it in the expression field:

Spoiler

[_this select 0, _this select 1 , _this select 2] execvm"scripts\captureMoney.sqf";

 

I tried scripts similar to this, with area being defined in the init.sqf file  (this is the captureMoney.sqf file):

Spoiler

if ((area getvariable "owner") isEqualTo (side player)) then 
{
pointsPlayer = pointsPlayer + 1000; 
hint format ["You got 1000 points for capturing a cartel, you have %1 points",  pointsPlayer];
};

 

I need help with a script to give money to all players, when a sector owner changes, and the player is part of that side. These scripts, and the ones I wrote for my server are the extent of my SQF knowledge so any help would be awesome.

Share this post


Link to post
Share on other sites

This is a locality issue. The biggest sign is it not working on a dedicated server but working locally. What is the difference you ask?

Player is not assigned on a dedicated server, but is assigned locally.

You must have a variable instead of the player command, and assign it a unit object instead.

 if ( _owner isEqualTo (side player)) then { pointsPlayer = pointsPlayer + 1000; ....

Needs to be

_unit = blueTeamGuy1 or (code to find specific player unit);

 if ( _owner isEqualTo (side _unit)) then { pointsPlayer = pointsPlayer + 1000; ....

 

Share this post


Link to post
Share on other sites

So I would need to run this command for each unit inside the server? I have a 16 player cap and for Blufor I have BL_1 as the variable name for the first unit inside the editor. Would this work or some form?

 

 

 

_unit1 = BL_1;

_unit2 = BL_2;

...

 if ( _owner isEqualTo (side _unit1)) then {
        pointsPlayer = pointsPlayer ....

 

...

 if ( _owner isEqualTo (side _unit2)) then {
        pointsPlayer = pointsPlayer ....

 

 

or something like for (_x in allplayers) do.

 

this is the script that works for my kills in my init.sqf:

 

addMissionEventHandler ["EntityKilled", {
params ["_killed","_killer","_instigator"];
if ((name player isEqualTo name _instigator) && (name _killer != name _killed) && (side _killed != side _killer)) then {hint format ["+500 Points for killing %1", name _killed];
pointsPlayer = pointsPlayer +500;};
}];

 

EDIT:

Tried this combination of expression and script with success on singleplayer. I though running the script for allplayers would work.

https://gyazo.com/0f1d21b4aed835fdde159c3856667afb

Share this post


Link to post
Share on other sites

You would be better off creating a function that gets called by your event handler. The best way to do it is using getPlayerUID. Here is an example of how I might do this.  Written on a laptop, unsure if this works or has errors.

fn_playerKilled = {

	params ["_killed","_killer","_instigator"];

    //Exit if not players involved
    if !((isPlayer _killed) OR (isPlayer _killer)) exitwith {};
	
	//Exit if on same side
	if (side _killed == side _killer) exitiwith {};
	
	//You cannot give individual players points here as this is now serverside, you must make a variable per player
	_playerVariable = format ["%1_points", getPlayerUID _killer];
	
	//retrieve current points
	private _points = missionNamespace getvariable "_playerVariable";
	
	//Throw error if points are set before game start.
	if (isNil _points) exitwith {"Problem, no points set"};

	_updatePoints = _points + 500;
	
	//Set points
	missionNamespace setvariable ["playerVariable",_points];

};

//Eventhandler
addMissionEventHandler ["EntityKilled", {_this call fn_playerKilled}];

//Set everyones points to 0 on mission start
{

	private _playerVariable = format ["%1_points", getPlayerUID _x];

	missionNamespace setVariable [_playerVariable, 0];

} foreach allPlayers;

 

  • Like 1

Share this post


Link to post
Share on other sites
On 2/13/2019 at 12:42 AM, IGD Big Steve said:

I am trying to give the team who captured the sector points for doing so.

On 2/13/2019 at 12:42 AM, IGD Big Steve said:

I need help with a script to give money to all players, when a sector owner changes, and the player is part of that side.

 

First sentence can be read as only the people present at the sector when captured? So I have provided two options...

  • A player who is present at the sector when captured
  • A player who belongs to the side that captured the sector, no matter their location
//initServer.sqf

//Sector Expression only happens on the server

_h = [] spawn {
	//Wait unitl the mission has started so all sectors have been initialised
	waitUntil{ time > 0 };

	//*****
	//For all players of capturing side
	//*****
	{
		[ _x, "ownerChanged", {
			params[ "_sector", "_owner", "_ownerOld" ];

			//Sectors fire at mission start.
			//If no default owner is set then the expression will fire against sideUnknown
			//Otherwise the expression will fire against the default owner
			if !( _owner isEqualTo sideUnknown || _owner isEqualTo _ownerOld ) then {
				//Call client function to add points, on all clients that have a player of the capturing side
				[] remoteExec[ "TAG_fnc_addCapturePoints", _owner ];
			};
		}] call BIS_fnc_addScriptedEventHandler;
	} forEach ( true call BIS_fnc_moduleSector );


	//*****
	//For all players of capturing side who are present at sector when captured
	//*****
	{
		[ _x, "ownerChanged", {
			params[ "_sector", "_owner", "_ownerOld" ];

			//Sectors fire at mission start.
			//If no default owner is set then the expression will fire against sideUnknown
			//Otherwise the expression will fire against the default owner
			if !( _owner isEqualTo sideUnknown || _owner isEqualTo _ownerOld ) then {

				//Get sectors capture trigger areas
				_sectorAreas = _sector getVariable[ "areas", [] ];

				//Find all players of _owner side that are in the sectors areas
				_playersInSector = allPlayers select {
					_x params[ "_player" ];
					side _player isEqualTo _owner && { { _player inArea _x }count _sectorAreas > 0 }
				};

				//If we have some players
				if !( _playersInSector isEqualTo [] ) then {
					//Call clients function to add points, on all clients of _playersInSector
					[] remoteExec[ "TAG_fnc_addCapturePoints", _playersInSector ];
				};
			};
		}] call BIS_fnc_addScriptedEventHandler;
	} forEach ( true call BIS_fnc_moduleSector );
		
	//*****
	//For all players or AI with player leader of capturing side who are present at sector when captured
	//*****
	{
		[ _x, "ownerChanged", {
			params[ "_sector", "_owner", "_ownerOld" ];

			//Sectors fire at mission start.
			//If no default owner is set then the expression will fire against sideUnknown
			//Otherwise the expression will fire against the default owner
			if !( _owner isEqualTo sideUnknown || _owner isEqualTo _ownerOld ) then {

				//Get sectors capture trigger areas
				_sectorAreas = _sector getVariable[ "areas", [] ];

				//Include players and AI lead by a player
				_capturedBy = allUnits select{
					_x params[ "_unit" ];
					( isPlayer _unit || { isPlayer leader group _unit } ) && { side _unit isEqualTo _owner && { { _unit inArea _x }count _sectorAreas } }
				} apply{ [ leader group _x, _x ] select isPlayer _x };
				
				//Make sure player is only listed once
				_capturedBy = _capturedBy arrayIntersect _capturedBy;
				
				//If we have some players
				if !( _capturedBy isEqualTo [] ) then {
					//Call clients function to add points, on all clients of _playersInSector
					[] remoteExec[ "TAG_fnc_addCapturePoints", _capturedBy ];
				};
			};
		}] call BIS_fnc_addScriptedEventHandler;
	} forEach ( true call BIS_fnc_moduleSector );
};
//initPlayerLocal.sqf

pointsPlayer = 0;

TAG_fnc_addCapturePoints = {
	pointsPlayer = pointsPlayer + 1000;
	hint format ["You got 1000 points for capturing a cartel, you have %1 points",  pointsPlayer];
};

UNTESTED

  • Like 3

Share this post


Link to post
Share on other sites
9 hours ago, Larrow said:

First sentence can be read as only the people present at the sector when captured? So I have provided two options...

  • A player who is present at the sector when captured
  • A player who belongs to the side that captured the sector, no matter their location

UNTESTED

 

Thanks of your feedback. I am pretty confident I can get this block to work. I realize my error in explaining now, yes I want it to give them points regardless of their location. I will test both scripts and tell you the results.

 

EDIT: Tried this script with no success on the server, I tried running it from the expression field in a script also. I think the script gives 4000 points upon the capture of only 1 sector (4 sectors total * 1000 points) when run from the editor. I feel like the server isn't calling the function or isn't reading the initServer/event handler. Would using RemoteExecCall or making the added event handler a variable work? You could possibly use the getplayerUID command.

Share this post


Link to post
Share on other sites
10 hours ago, MKD3 said:

You would be better off creating a function that gets called by your event handler. The best way to do it is using getPlayerUID. Here is an example of how I might do this.  Written on a laptop, unsure if this works or has errors.

 

 

The script I use is much more clunky than yours but it gets the job done. Mine just makes some simple checks. I am trying to repurpose your script combined with the help from Larrow to work with the sector execution. I'm still trying to figure out how everything comes together.

addMissionEventHandler ["EntityKilled", {

params ["_killed","_killer","_instigator"];

if ((name player isEqualTo name _instigator) && (name _killer != name _killed) && (side _killed != side _killer)) then {
hint format ["+500 Points for killing %1", name _killed];
pointsPlayer = pointsPlayer +500;
};
}];

 

Share this post


Link to post
Share on other sites
13 hours ago, IGD Big Steve said:

Tried this script with no success

Works fine for me? :shrug:

TEST_MISSION tested both SP, MP (hosted and dedicated)

Share this post


Link to post
Share on other sites
10 hours ago, Larrow said:

Works fine for me? :shrug:

TEST_MISSION tested both SP, MP (hosted and dedicated)

 

You're right. I hosted your mission and I receive money for capturing the small objectives. Despite this, if I leave the objective and come back, it gives me money when I enter the sector while it is not captured. I can also not see the capture progress on sectors A and B, not sure why, I looked at your mission in the editor and it looks spotless, although the ones in my mission work fine so I'm not worried. Is the script not working for me because I have an init.Sqf and an initServer.Sqf? I will try just pasting your files into my mission to see what happens.

 

EDIT: The script works on my server, I had originally cut off the portion of your script that you commented, not sure why it didn't work. I will be testing it further and probably adding to it. I will let you know the results but thanks for all your help and not yelling at me for not knowing different scopes haha.

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

×