Jump to content
nebulazerz

Passing Player Through Params Using remoteExec Serverside

Recommended Posts

I am trying to create a function that will let me add a remoteExec to the script of any object or vehicle that I want my players to be able to teleport to through a screen near where they spawn. I am getting an error that tells me _unit is undefined.

 

EDIT: Nevermind, after thinking about this for a minute. I realise how silly of a question this is. Its always going to be the player so I dont need to pass the parameter... overthinking it once again haha sorry.

 

EDIT2: seems my real issue now is that its telling me undefined variable in expression _truck. The hold action is showing up on the object BluTeleScreen so i know that variable is passing through, but not the truck.

 

In vehicle script after vehicle creation

[BluSpawnTruck, BluTeleScreen] remoteExec ["neb_fnc_core_teleToTruck"];

the function is in my coreFunctions

neb_fnc_core_teleToTruck = {
		params ["_truck","_home"];
		Blu_MobileFOB_Action = [
	/* 0 object */				_home,
	/* 1 action title */			"Teleport To Mobile FOB",
	/* 2 idle icon */				"images\blinkicon.paa",
	/* 3 progress icon */			"images\blinkicon.paa",
	/* 4 condition to show */		"true",
	/* 5 condition for action */		"true",
	/* 6 code executed on start */		{},
	/* 7 code executed per tick */		{},
	/* 8 code executed on completion */	{player setPos (getPos _truck)},
	/* 9 code executed on interruption */	{},
	/* 10 arguments */			[],
	/* 11 action duration */		1,
	/* 12 priority */			0,
	/* 13 remove on completion */		false,
	/* 14 show unconscious */		false
	] call bis_fnc_holdActionAdd;
};

Share this post


Link to post
Share on other sites

Try to check if _truck is passed trough the remoteExec. by simply adding a hint/diag_log (str _truck) before the holdAction.

 

if that doesn't put anything out double check if you set up the trucks name correct.

Share this post


Link to post
Share on other sites

As with any action you need to use the arguments(10) to pass local variables into the actions code blocks(6,7,8,9)

//arguments(10)

_truck
//code block

{
	_truck = param[ 3 ];
	player setPos getPos _truck;
},
Or if you need to pass multiple arguments

//arguments(10)

[ _arg1, _arg2 ]
//code block

{
	param[ 3 ] params[ "_arg1", "_arg2" ];
	//Do something
},
  • Like 1

Share this post


Link to post
Share on other sites

Thanks Larrow, i'll try that.

 

EDIT: Once again, you have the answer for me when im stuck. :D Works like a charm, now just to tweak it to be more functional instead of putting you in the middle of the truck, haha.

 

Heres the working hold action. I tried the top method first but it was telling me that it was an array instead of an object so I tried the method under and it worked.

//Tele to Truck
neb_fnc_core_teleToTruck = {
		params ["_home","_truck"];
		
		hint format ["%1", _truck];
		Blu_MobileFOB_Action = [
	/* 0 object */				_home,
	/* 1 action title */			"Teleport To Mobile FOB",
	/* 2 idle icon */				"images\blinkicon.paa",
	/* 3 progress icon */			"images\blinkicon.paa",
	/* 4 condition to show */		"true",
	/* 5 condition for action */		"true",
	/* 6 code executed on start */		{},
	/* 7 code executed per tick */		{},
	/* 8 code executed on completion */	{
										param[ 3 ] params ["_home","_truck"];
										player setPos getPos _truck;
										},
	/* 9 code executed on interruption */	{},
	/* 10 arguments */			[_home,_truck],
	/* 11 action duration */		1,
	/* 12 priority */			0,
	/* 13 remove on completion */		false,
	/* 14 show unconscious */		false
	] call bis_fnc_holdActionAdd;
};

Share this post


Link to post
Share on other sites

I have a new problem, When the truck gets destroyed and respawns, the setPos is putting me at [0,0,0] instead of at the newly spawned truck. Is this because the action is still ascociated with the old truck even though they have the same variable name? I tried removing the action but the second action always duplicates even when I try to remove it.

 

 

Here is where the vehicle is being created.

//BLU SPAWN TRUCK
neb_fnc_core_bluSpawnTruck = {
	createMarker ["BluTruckSpawn",[3116.23,13584.7]];
		"BluTruckSpawn" setMarkerType "Empty";
		"BluTruckSpawn" setMarkerSize [2, 2];

	while {true} do {
					
					_direction = 120;
					_position = getMarkerPos "BluTruckSpawn";
					_mrk = "BluTruckSpawn";
					_veh = createVehicle ["B_T_Truck_01_box_F", _position, [], 0, "NONE"];
					_veh setVariable ["BIS_enableRandomization", false];
					_veh setDir _direction;
					clearWeaponCargoGlobal _veh;
					clearMagazineCargoGlobal _veh;
					clearItemCargoGlobal _veh;
					_veh setVehicleVarName "BluSpawnTruck";
					BluSpawnTruck = _veh;
					if (isNil "BluTruckAction") then {
					BluTruckAction = 0;
					BluTruckActionFree = 0;
					[BluSpawnTruck] call neb_fnc_addBounty;
					[BluTeleScreen, BluSpawnTruck, BluTruckAction] remoteExec ["neb_fnc_core_teleToTruck"];
					[BluTeleScreen, BluSpawnTruck, BluTruckActionFree] remoteExec ["neb_fnc_core_teleToTruckFree"];
					};
					
					//Create trigger for shop
					_trigger = createTrigger[ "EmptyDetector", getMarkerPos _mrk, true ];
					//Set trigger size on all clients and JIP
					[ _trigger, [ 5, 5, 0, false, 5 ] ] remoteExec [ "setTriggerArea", 0, true ];
					//Attach it to the vehicle
					_trigger attachTo [ BluSpawnTruck, [0,0,0] ];

					//Call shopInit on server and all clients and JIP
					_JIP = [ _trigger, "Blu Mobile FOB", "ALL", true, true ] remoteExec [ "NEB_fnc_shopInit", [ 0, 2 ], true ];
					
					
					waitUntil {!alive BluSpawnTruck};
					sleep .5;
					BluSpawnTruck = nil;
					sleep 10;
		};
	
};

Here is what the holdaction function currently looks like

neb_fnc_core_teleToTruck = {
		params ["_home","_truck", "_action"];
		
		_action = [
	/* 0 object */				_home,
	/* 1 action title */			"Teleport To Mobile FOB ($500)",
	/* 2 idle icon */				"images\blinkicon.paa",
	/* 3 progress icon */			"images\blinkicon.paa",
	/* 4 condition to show */		"true",
	/* 5 condition for action */		"true",
	/* 6 code executed on start */		{},
	/* 7 code executed per tick */		{},
	/* 8 code executed on completion */	{
										param[ 3 ] params ["_home","_truck", "_action"];
										[500] call neb_fnc_core_pay;
										player setPos [getPos _truck select 0, (getPos _truck select 1) +5, (getPos _truck select 2)];
										},
	/* 9 code executed on interruption */	{},
	/* 10 arguments */			[_home,_truck,_action],
	/* 11 action duration */		1,
	/* 12 priority */			0,
	/* 13 remove on completion */		false,
	/* 14 show unconscious */		false
	] call bis_fnc_holdActionAdd;
};

EDIT:

 

Doing this worked, though I wish it would let me assign action ID to names instead of numbers, It would be a lot easier to delete them without any issues that way.

waitUntil {!alive BluSpawnTruck};
					sleep .5;
					[BluTeleScreen,0] call bis_fnc_holdActionRemove;
					[BluTeleScreen,1] call bis_fnc_holdActionRemove;
					BluSpawnTruck = nil;
					sleep 10;

EDIT2: Hmm after more testing, seems that it starts to duplicate after the second time the vehicle is destroyed.

 

EDIT3: seems the only way to get decent results after the vehicle respawns is to removeAllActions from the screen.

Share this post


Link to post
Share on other sites

Dont remove the actions just pass the vehicles varName string instead of the reference.

You will need to change your spawn loop so your not re-adding the actions and shop every respawn.

//BLU SPAWN TRUCK
neb_fnc_core_bluSpawnTruck = {
    private[ "_veh", "_trigger" ];
    
    createMarker [ "BluTruckSpawn", [3116.23,13584.7] ];
    "BluTruckSpawn" setMarkerType "Empty";
    "BluTruckSpawn" setMarkerSize [ 2, 2 ];

    while {true} do {

            _direction = 120;
            _position = getMarkerPos "BluTruckSpawn";
            _mrk = "BluTruckSpawn";
            
            _veh = createVehicle [ "B_T_Truck_01_box_F", _position, [], 0, "NONE" ];
            _veh setVariable [ "BIS_enableRandomization", false ];
            _veh setDir _direction;
            
            clearWeaponCargoGlobal _veh;
            clearMagazineCargoGlobal _veh;
            clearItemCargoGlobal _veh;
            
            _veh setVehicleVarName "BluSpawnTruck";            
            missionNamespace setVariable [ "BluSpawnTruck", _veh, true ];
            
            [ _veh ] call neb_fnc_addBounty;
            
            //if the trigger does not exist we must be creating the truck for the first time
            //So create trigger and init actions and shop with JIP
            if ( isNil "_trigger" ) then {
                //Change remoteExecs to pass varName as STRING ..with unique JIP queue name so they can be removed if needed
                [ BluTeleScreen, "BluSpawnTruck" ] remoteExec [ "neb_fnc_core_teleToTruck", 0, "BluTruckJIP" ];
                [ BluTeleScreen, "BluSpawnTruck" ] remoteExec [ "neb_fnc_core_teleToTruckFree", 0, "BluTruckFreeJIP" ];
            
                //Create trigger for shop
                _trigger = createTrigger[ "EmptyDetector", getMarkerPos _mrk, true ];
                //Set trigger size on all clients and JIP
                [ _trigger, [ 5, 5, 0, false, 5 ] ] remoteExec [ "setTriggerArea", 0, true ];
                
                //Call shopInit on server and all clients and JIP
                [ _trigger, "Blu Mobile FOB", "ALL", true, true ] remoteExec [ "NEB_fnc_shopInit", [ 0, 2 ], true ];
            };
            
            //Attach it to the vehicle
            _trigger attachTo [ _veh, [0,0,0] ];

            waitUntil { !alive _veh };
            detach _trigger;
            sleep 10;
        };

};
//Tele to Truck

neb_fnc_core_teleToTruck = {
	params [ "_home", "_truckVarName" ];
		
	_action = [
	/* 0 object */				_home,
	/* 1 action title */			"Teleport To Mobile FOB ($500)",
	/* 2 idle icon */			"images\blinkicon.paa",
	/* 3 progress icon */			"images\blinkicon.paa",
	/* 4 condition show */		        format[ "
                                                    call {
                                                        private _truck = missionNamespace getVariable [ '%1', objNull ];
                                                        !isNull _truck && { alive _truck }
                                                    };
                                                ", _truckVarName ],
	/* 5 condition progress */              "
                                                    _arguments params [ '_truckVarName' ];
                                                    _truck = missionNamespace getVariable [ _truckVarName, objNull ];
                                                    !isNull _truck && { alive _truck }
                                                ",
	/* 6 code executed on start */		{},
	/* 7 code executed per tick */		{},
	/* 8 code executed on completion */	{
							param[ 3 ] params [ "_truckVarName" ];
							_truck = missionNamespace getVariable [ _truckVarName, objNull ];
							if ( !isNull _truck && { alive _truck } ) then {
								[ 500 ] call neb_fnc_core_pay;
								player setPos ( _truck getPos [ 5, random 360 ] );
							};
						},
	/* 9 code executed on interruption */	{},
	/* 10 arguments */			[ _truckVarName ],
	/* 11 action duration */		1,
	/* 12 priority */			0,
	/* 13 remove on completion */		false,
	/* 14 show unconscious */		false
	] call BIS_fnc_holdActionAdd;
};

Plus added some code examples for 4 and 5 to hide the action if the truck is not available.

Not thoroughly tested, other than the holdAction to make sure it was working properly.

  • Like 1

Share this post


Link to post
Share on other sites

Awesome, It all works from just my machine now. I cant test it JIP yet because I am having some issues still with players not getting setPos and hideObject false, but i trust that it works JIP and ill be testing it later today hopefully when i find a fix to the other JIP issues I am having. 

 

Is this a good way to check for the action instead of removing and adding it? Seems to work on my end but not sure if there are any multiplayer issues with this.

if (isNil "BluActionSpawnTruckCheck") then {
[ BluTeleScreen, "BluSpawnTruck" ] remoteExec ["neb_fnc_core_teleToTruck", 0, "BluTruckJIP" ];
BluActionSpawnTruckCheck = true;
};

Share this post


Link to post
Share on other sites
Is this a good way to check for the action instead of removing and adding it?

I had already taken care of that part for you...

 

//if the trigger does not exist we must be creating the truck for the first time
//So create trigger and init actions and shop with JIP

 

If the trigger does exist then it is respawning the vehicle and skips that part as the actions have already been called and setup for JIP on the first initial run through.

  • Like 1

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

×