Jump to content
schmoking

vehicle respawn with addaction on dedicated server

Recommended Posts

hi...  i been away from arma a long time, got back into it with apex and started editing my old mission again. its an armory type deathmatch thing called Gunship_Airport_Stratis.

i have a dedicated server running for it now.

the whole thing is a horrible hackjob of oudated code a bunch of triggers and all sorts of errors,

but it works and its alot of fun to play... :)

exept for one single plane i need to respawn with an addaction added to it.. :(

it works in the editor, but not on the server.. in searching for answers i just came across an old post i forgotten from 2014 asking the same stupid questions and not figuring it out.. :(

the advice i got then was try using BIS_fnc_MP.. but when i read about it my head starts spinning, i have no scripting experience so im clueless. the old sqs files used to make a little sense but this stuff i dont get. anyone who can help me make this work?  this is what i got

 

ini.sqf

[] call compile preProcessFile "vehInitFunctions.sqf"

 

vehInitFunctions.sqf

TAG_FNC_TankInit = {

// -- Example code. You can work with the vehicle anyway you like here!! -- //
_veh = _this select 0;

_veh setFuel 0.1;nuke = _veh addaction [("" + "DropNuclearBomb" + ""),"scripts\NukeInit.sqs"];



};

TAG_FNC_HunterInit = {

// -- Example code. You can work with the vehicle anyway you like here!! -- //
_veh = _this select 0;

createVehicleCrew _veh; _veh setFuel 0.1;_veh addweapon "HMG_127"; _veh addmagazine "500Rnd_127x99_mag_Tracer_Red";_veh addweapon "gatling_25mm"; _veh addmagazine "300Rnd_25mm_shells";


};

TAG_FNC_HunterHMGInit = {

_veh = _this select 0;

};

TAG_FNC_HunterGMGInit = {

_veh = _this select 0;
createVehicleCrew _veh;_veh setFuel 0.3;_veh addweapon "rockets_230mm_GAT"; _veh addmagazine "12Rnd_230mm_rockets";

};

TAG_FNC_slammerInit = {

_veh = _this select 0;


};

TAG_FNC_marshallInit = {

_veh = _this select 0;


};


 

vehRespawn.sqf

/* ---------------------------------------------------------------------------------------------------

File: vehRespawn.sqf
Author: Iceman77

Description:
Respawn destroyed and abandoned vehicles

Parameter(s):
_this select 0: vehicle
_this select 1: abandoned delay in minute(s) - Required
_this select 2: destroyed delay in minute(s) - Required
_this select 3: Function to call for the newly spawned vehicle (for custom armaments etc) - Optional

How to use - Vehicle Init Line:
_nul = [this, 2, 1, {[_this] call TAG_FNC_TankInit}] execVM "vehRespawn.sqf"; << 2 minute abandoned delay, 1 minute destroyed delay, call the function that disables the TI
_nul = [this, 2, 1, {}] execVM "vehrespawn.sqf"; << 2 minute abandoned delay, 1 minute destroyed delay, NO function called for the newly respawned vehicle (standard way)

---------------------------------------------------------------------------------------------------- */


private "_veh";

_veh = _this select 0;
_abandonDelay = (_this select 1) * 60;
_deadDelay = (_this select 2) * 60;
_vehInit = _this select 3;
_dir = getDir _veh;
_pos = getPos _veh;
_vehtype = typeOf _veh;
_vehName = vehicleVarName _veh;

if (isServer) then {
While {True} Do {
sleep 1;
if ((alive _veh) && {canMove _veh} && {{alive _x} count crew _veh == 0}) then {
_abandoned = true;

for "_i" from 0 to _abandonDelay do {
if (({alive _x} count (crew _veh) > 0) || (!alive _veh) || (!canMove _veh)) exitWith {_abandoned = false;};
sleep 1;
};

if ((_abandoned) && {_veh distance _pos > 10}) then {
deleteVehicle _veh;
sleep 1;
_veh = createVehicle [_vehtype, _pos, [], 0, "CAN_COLLIDE"];
_veh setDir _dir;
_veh setPos [_pos select 0, _pos select 1,0];
missionNamespace setVariable [_vehName, _veh];
publicVariable _vehName;
_veh call _vehInit;
};
};

if ((!alive _veh) || (!canMove _veh)) then {
_dead = true;

for "_i" from 0 to _deadDelay do {
if (({alive _x} count (crew _veh) > 0) || (canMove _veh)) exitWith {_dead = false;};
sleep 1;
};

if (_dead) then {
deleteVehicle _veh;
sleep 1;
_veh = createVehicle [_vehtype, _pos, [], 0, "CAN_COLLIDE"];
_veh setDir _dir;
_veh setPos [_pos select 0, _pos select 1,0];
missionNamespace setVariable [_vehName, _veh];
publicVariable _vehName;
_veh call _vehInit;
};
};
};
};

 

 

edit* this is the line with the addaction tha wont work on a dedicated server from vehInitFunctions.sqf

thet set fuel works even on dedicated but not the addaction

_veh setFuel 0.1;nuke = _veh addaction [("" + "DropNuclearBomb" + ""),"scripts\NukeInit.sqs"];

Share this post


Link to post
Share on other sites

Addaction  command is local and if you execute it on server it will be invisible for players.

 

There are many method how to run addaction in MP environment.

 

I am preferring  usage of function which adds addaction

fnc_addactionMP = {
    params ["_object", "_screenMsg", "_scriptToCall", "_arguments", "_priority", "_showWindow", "_hideOnUse", "_shortcut", "_condition"];

    if(isNull _object) exitWith {};
    _object addaction [_screenMsg,_scriptToCall,_arguments,_priority,_showWindow,_hideOnUse,_shortcut,_condition];
};

This function needs to be global.

 

and for example you can add addaction globally like this:

        [[_object,"<t color='#ff9900'>Take satelite phone</t>",{
                    private ["_grabber","_obj"];
                    _obj = _this select 0;
                    _grabber = _this select 1;
                    _grabber playMove "AinvPknlMstpSnonWnonDnon_medic_1";
                    sleep 5;
                    deleteVehicle _obj;
                    },nil,6,true,true,"","(_target distance _this) < 5"],"fnc_addactionMP",true,true] spawn BIS_fnc_MP;

There also other methods using remoteExec on scheduled  or remoteExecCall on unscheduled env like this:

[_unit,"<t color='#949494'>Unstuck me</t>","scripts\unstack_ai.sqf",[],6,false,true,"","(_target distance _this) < 5"] remoteExecCall ["fnc_addactionMP", 0, true];

In both ways the passed object  needs to be global.

Share this post


Link to post
Share on other sites

 ok  so what im trying to do is having a plane with a nuclear bomb on respawn on the runway every 5 minutes if its destroyed or abandoned

this is the old line:

_veh setFuel 0.1;nuke = _veh addaction [("" + "DropNuclearBomb" + ""),"scripts\NukeInit.sqs"];

 

this is what i tried and replace it with: 

_veh setFuel 0.1;nuke = [_veh,"<t color='#949494'>DropNuclearBomb</t>","scripts\NukeInit.sqs",[],6,false,true,"","(_target distance _this) < 5"] remoteExecCall ["fnc_addactionMP", 0, true];

_veh setFuel 0.1; [_veh,"<t color='#949494'>DropNuclearBomb</t>","scripts\NukeInit.sqs",[],6,false,true,"","(_target distance _this) < 5"] remoteExecCall ["fnc_addactionMP", 0, true];

 

im sorry i dont really understand where to use this code.. that last example looked the most familiar to the old line

Share this post


Link to post
Share on other sites

First of all you need add the function fnc_addactionMP.

 

For example you can add it direct on top init.sqf or

read THIS and add it in correct way.

 

 

Then you can remoteExec it

[_veh,"<t color='#949494'>DropNuclearBomb</t>","scripts\NukeInit.sqs",[],6,false,true,"","(_target distance _this) < 5"] remoteExec ["fnc_addactionMP", 0, true];

Share this post


Link to post
Share on other sites

thank you for trying to help me here... i tried reading the link but this stuff is way over my head.

and im sure if i got it working i would break something else like i usually do fixing things in this mission., spending hours testing again and again...

seems everytime i got some time to play the game all i do is try fix something in this mission, im surprised i got this far but i give up now.

 

i made another post in the find or offer editing section.. im willing to pay for someones time to fix this for me.

so if your interested have a look

 

https://forums.bistudio.com/topic/193254-looking-for-scripter-to-fixclean-up-my-mission-will-pay/

Share this post


Link to post
Share on other sites

We don't earn money here, give the link to your mission and we will fix it for you.

Share this post


Link to post
Share on other sites

that would be awesome if you could take a look at it   :)

 

here is a link to my mission. 

 

http://www.mediafire.com/download/jlnswtzbdqcrtz1/GUNSHIP_Airport.Stratis.rar

 

if you load this in the eden editor you will spawn next to the plane i cant get working.

also there is two things i noticed today thats not working and i think theire related.

in the ini.sqf i recently added:

 

player enableStamina FALSE;
player addEventHandler ['Respawn',{player enableStamina FALSE;}];
[] execVM "briefing.sqf";
 
this removes the stamina system and adds a briefing i made to explain the mission
and both works when i start a fresh server, but it doesnt when i rejoin the server.
 
thanks for helping me with this i really apreciate it  :)

Share this post


Link to post
Share on other sites

Well i have done a quick look and that will be something to do.

Some scripts/ functions are created for single player scenario and need to be corrected.

You knew there are some code which should be executed server side  only due to global commands and otherwise.

Share this post


Link to post
Share on other sites

are you talking about other scripts than the respawn scripts now?  if so...  the only way i could figure it out was to use triggers. i have a trigger for each player slot, the nuke and the napalm have two triggers each, the addaction to eject from helicopters use triggers.

but it all actually work on the server.  i mean i do get some errors in the editor debug, but it all still works.  i know i probably shouldnt do it that way, but i have a very limited understanding of this :) the only thing that dont actually work is the addaction to the respawning plane... if i could use triggers for that to i would. or maybe i can, i just dont know how. the plane spawns without a name and there could be other planes of the same type spawned elswhere.   

its all very confusing to me... but if i could get that respawn working i would be happy with it. no need for more than that  :)

Share this post


Link to post
Share on other sites

if you say so but hosting errors can lead to unaccepted behavior and you cant even know why.

 

anyway if you so happy with i will fix the init.sqf and that plane respawn only.

Share this post


Link to post
Share on other sites

i didnt mean it like you shouldnt touch anything else then the respawn... i just wouldnt expect you to spend a lot of time on it.

im just happy youre helping me out here, you can do whatever you want with it.

Share this post


Link to post
Share on other sites

Here are  your mission.

 

Changes:

 

used bis vehicle respawn module with init code:

if (isServer) then {

      params [["_newVeh", objNull], ["_oldVeh", objNull]];
	  
	  switch (typeOf _newVeh) do {
	  
		case "I_Plane_Fighter_03_CAS_F": {
	  
			  _newVeh setFuel 0.1;
			  [_newVeh, ["<t color='#e53700'>DropNuclearBomb</t>", {  _this exec "scripts\NukeInit.sqs";  }]] remoteExec ["addAction", 0, _newVeh];
		};
		
		case "B_UAV_02_CAS_F": {
	  
			[_newVeh] call TAG_FNC_HunterInit;

		};
		
		case "B_UGV_01_rcws_F": {
	  
			[_newVeh] call TAG_FNC_HunterGMGInit;

		};
		
		default {};
		
	  };
};

fixed:

init.sqf

addaction DropNuclearBomb

some errors in few scripts

 

Anyway this mission is very bad scripted according to MP environment.

This can be make a much much better, drop the whole sqs scripts and rewrite it in MP scenario goals.

Enjoy & Nuke them ALL :D

Share this post


Link to post
Share on other sites

thank you so much for this. the respawn works great.  

 

hehe..  if you think this mission is bad then you should have seen the one i made for arma 2, that thing couldnt run for more than 30-40 minutes then it was unplayable.

im afraid rewriting this is way out of my reach, you have no idea how much i struggled to make this work.   :)

 

there is one more thing tho... 

the briefing and the player stamina.. they still only work when i restart the server, if i leave and rejoin the briefing wont show up and stamina is in effect again.

 

so what i wonder is, im using a trigger to run a script everytime player respawns to give weapons and vehicle menu to player.

could i use the   player enableStamina FALSE;  code here so that it runs on every respawn, or is this a bad idea? and could i do the same with the briefing?

 

again thank you for the help!

Share this post


Link to post
Share on other sites

I got it working now, both briefing and stamina   :)

 

when i look at my server stats, it looks like the server uses about 10% less RAM now after you looked at the scripts.

this is awesome!

Share this post


Link to post
Share on other sites

Great for you.

 

I have already got that in different way.

TAG_FNC_setVehicleName = {

	params ["_veh", "_name"];
	
		missionNamespace setVariable [_name, _veh, true];
		[_veh, _name] remoteExecCall ["setVehicleVarName", 0, _name];
	
};

TAG_FNC_handleActions = {

params ["_veh"];

	_veh addEventHandler ["GetIn",{
	
		params ["_veh", "_seat", "_player"];
			
			if (_seat isEqualTo "driver") then {
			
				_veh addAction ["<t color='#f80106'>EMERGENCY EJECT</t>", {
				
					[] spawn {
						
						moveout player;
						sleep 1;
						player action ["openParachute"];
					};
				
				},nil,6,true,true,"","(damage _target) != 0",10,false];

				_veh addAction ["<t color='#e53700'>RELEASE NUKE</t>", {
				
					_this exec "scripts\NukeInit.sqs";
				
				},nil,5,false,true,"","((getPos _target) select 2) > 100",10,false];
				
			};
	}];
};

TAG_FNC_NukebomberInit = {

	params ["_veh"];

		_veh setFuel 0.1;       
		[_veh, "nukebomber"] call  TAG_FNC_setVehicleName;
		_veh remoteExec ["TAG_FNC_handleActions", -2, _veh];
		
};

Now there are no nuke action until the plane are at least at 100m high, and emergency exit are bump on the screen only if the plane get some damage

Tried to decrease script count either

Used initPlayerLocal.sqf:

if (hasInterface) then {

	waitUntil {!isnull player && alive player};


    player enableStamina false;
    player addEventHandler ["Respawn",{
	
		params ["_player", "_courpse"];
	
			_player enableStamina false;
			_player execVM "rearm.sqf";
			
			[_courpse] spawn {
			
				params ["_deadbody", "_droppedGear"];
				_droppedGear = nearestObjects [_deadbody, ["WeaponHolder", "WeaponHolderSimulated", "GroundWeaponHolder"], 10];
				sleep 10;
				{deleteVehicle _x} forEach _droppedGear + _deadbody;
			
			};
	}];
	
	nukebomber call TAG_FNC_handleActions;
	
	[] execVM "briefing.sqf";
	[] execVM "taw_vd\init.sqf";
	player exec "rearm.sqf";

And init.sqf

[] call compile preprocessFileLineNumbers "vehInitFunctions.sqf";

if (isServer) then {

	[3,0,false] execVM "cly_removedead.sqf";

	[] spawn {

		while {true} do {
			sleep (60*5);
			skiptime -(1/(60 / 5));
		};

	};

};

Share this post


Link to post
Share on other sites

ok.. so i been trying to understand this.

 

the first script doesnt look like its for the respawn module. so i tried making that vehInitFunctions.sqf and use vehRespawn.sqf to respawn with this line int the planes init:

_nul = [this, 1, 1, {[_this] call TAG_FNC_NukebomberInit}] execVM "vehRespawn.sqf"; this setFuel 0.1; nuke = this addaction [("<t color='#e53700'>" + "DropNuclearBomb" + "</t>"),"scripts\NukeInit.sqs"];

i called TAG_FNC_NukebomberInit because it seems to call the other functions?  this didnt work... 

 

 

and...  the  initPlayerLocal.sqf

am i understanding this right that this script will start the rearm script on playerrespawn without the need for all the triggers i have for each player? and also clean up dead bodies and gear?

and how does run? i thought that all scripts that start with init and are not in a folder run themselves? but this dont, so im not sure where i have that from. :blink:

Share this post


Link to post
Share on other sites

Oh yea i forgot to give you vehicle respawn module code and other

 

if (isServer) then {
              
	params [["_newVeh", objNull], ["_oldVeh", objNull]];
	
	switch (typeOf _newVeh) do {
	
		case "I_Plane_Fighter_03_CAS_F": {
		
			[_newVeh] call TAG_FNC_NukebomberInit;
		
		};
		
		case "B_UAV_02_CAS_F": {
		
			[_newVeh] call TAG_FNC_HunterInit;
		};
		
		case "B_UGV_01_rcws_F": {
		
			[_newVeh] call TAG_FNC_HunterGMGInit;
		
		}; 
		
		default {};  
	
	};   
};


//rewritten rearm.sqf

private "_unit";

_unit = _this;

removeBackpack _unit;
_unit addrating 100000;
_unit addBackpack "B_Parachute";
_unit addAction [("<t color='#00f700'>" + "VehicleMenu" + "</t>"), "createveh.sqf",nil,0,false,false,"","player ==_target"];
_unit addAction [("<t color='#00f700'>" + "WeaponsMenu" + "</t>"), "Weaponmenu.sqf",nil,0,false,false,"","player ==_target"];


// rewritten createveh.sqf

private ["_vmenu", "_unit", "_upos"];

_vmenu = _this select 0;
_unit = _this select 1;
_upos = getPos _unit;

_unit addAction [("<t color='#FF9900'>" + "Air" + "</t>"),"enter.sqs",[],0,false,false,"","player ==_target"];
_unit addAction [("<t color='#FF9900'>" + "Armored Vehicle" + "</t>"),"armored.sqs",[],0,false,false,"","player ==_target"];
_unit addAction [("<t color='#FF9900'>" + "Vehicle" + "</t>"),"plane.sqs",[],0,false,false,"","player ==_target"];
_unit addAction [("<t color='#FF9900'>" + "Boat" + "</t>"),"Boat.sqs",[],0,false,false,"","player ==_target"];
(_this select 0) removeAction (_this select 2);


//rewritten Weaponmenu.sqf

private ["_vmenu", "_unit", "_upos"];

_vmenu = _this select 0;
_unit = _this Select 1;
_upos = getPos _unit;

_unit addAction [("<t color='#ff0000'>" + "Armed UAV" + "</t>"),"auav.sqs",[],0,false,false,"","player ==_target"];
_unit addAction [("<t color='#ff0000'>" + "Static Weapon" + "</t>"),"mortar.sqs",[],0,false,false,"","player ==_target"];
_unit addAction["<t color='#ff0000'>Virtual Ammobox</t>", "VAS\open.sqf",[],0,false,false,"","player ==_target"];

(_this select 0) removeAction (_this select 2);


//vehInitFunctions.sqf

TAG_FNC_setVehicleName = {

	params ["_veh", "_name"];
	
		missionNamespace setVariable [_name, _veh, true];
		[_veh, _name] remoteExecCall ["setVehicleVarName", 0, _name];
	
};

TAG_FNC_handleActions = {

params ["_veh"];

	_veh addEventHandler ["GetIn",{
	
		params ["_veh", "_seat", "_player"];
			
			if (_seat isEqualTo "driver") then {
			
				_veh addAction ["<t color='#f80106'>EMERGENCY EJECT</t>", {
				
					[] spawn {
						
						moveout player;
						sleep 1;
						player action ["openParachute"];
					};
				
				},nil,6,true,true,"","(damage _target) != 0",10,false];

				_veh addAction ["<t color='#e53700'>RELEASE NUKE</t>", {
				
					_this exec "scripts\NukeInit.sqs";
				
				},nil,5,false,true,"","((getPos _target) select 2) > 100",10,false];
				
			};
	}];
};

TAG_FNC_NukebomberInit = {

	params ["_veh"];

		_veh setFuel 0.1;       
		[_veh, "nukebomber"] call  TAG_FNC_setVehicleName;
		_veh remoteExec ["TAG_FNC_handleActions", 0, _veh];
		
};

TAG_FNC_TankInit = {

// -- Example code. You can work with the vehicle anyway you like here!! -- //
_veh = _this select 0;

};

TAG_FNC_HunterInit = {

// -- Example code. You can work with the vehicle anyway you like here!! -- //
_veh = _this select 0;

createVehicleCrew _veh;
_veh setFuel 0.3;
_veh addweapon "HMG_127";
_veh addmagazine "500Rnd_127x99_mag_Tracer_Red";
_veh addweapon "gatling_25mm";
_veh addmagazine "300Rnd_25mm_shells";


};

TAG_FNC_HunterHMGInit = {

_veh = _this select 0;

};

TAG_FNC_HunterGMGInit = {

_veh = _this select 0;
createVehicleCrew _veh;
_veh setFuel 0.3;
_veh addweapon "rockets_230mm_GAT";
_veh addmagazine "12Rnd_230mm_rockets";

};

TAG_FNC_slammerInit = {

_veh = _this select 0;


};

TAG_FNC_marshallInit = {

_veh = _this select 0;


};

Share this post


Link to post
Share on other sites

allright... the respawn is now working.

but im still abit confused on the initPlayerLocal.sqf

i did a search and found this:   initPlayerLocal.sqf:  Executed locally when player joins mission (includes both mission start and JIP). 

so from my simple understanding i thouhgt this would run itself... but it dont. or is this something that would only work on a server and not in editor?

 

i tried writing    this exec "initPlayerLocal.sqf";   in the player init field. that worked but it gave me double vehicle and weapon menu. and dont remove them when i use it.

so.. did i do this all wrong?  or is this just a matter of me organising the menu again, figuring out what action deletes another. ..? 

not sure why this gave me a double menu... does this somehow run the script twice?

Share this post


Link to post
Share on other sites

initPlayerLocal.sqf are executed automatically if placed in mission root.

Contained code are run locally for every connected PC.

The double action is because you are server and you have interface at the same time while in  mission editor preview and the remoteExec are set to 0 (everywhere included server )

Run this on server, connect and its will be normal. You can also change the number to - 2 but then you will get no action in SP.

Share this post


Link to post
Share on other sites

so initPlayerLocal.sqf is suposed to run on the server without having to execute it anywhere?  this doesnt happen, i get no scroll menu... nothing in the sript runs   same as editor.

then i tried with  this exec "initPlayerLocal.sqf";   in the player init, (this im not suposed to do right?) now it runs but the menu is messed up...  same as in editor.

 

im very confused right now... i been at it for a while. im gonna take a break then come back and see if messed up some files. i got mission files everywhere now...  :banghead:

Share this post


Link to post
Share on other sites

ok.. so i made some progress, but im still confused.  

 

soo.. in a desperate atempt to figure this out, i dont know why but  i removed this line from the top of this script:            if (hasInterface) then {

initPlayerLocal.sqf

if (hasInterface) then {

waitUntil {!isnull player && alive player};


player enableStamina false;
player addEventHandler ["Respawn",{

params ["_player", "_courpse"];

_player enableStamina false;
_player execVM "rearm.sqf";

[_courpse] spawn {

params ["_deadbody", "_droppedGear"];
_droppedGear = nearestObjects [_deadbody, ["WeaponHolder", "WeaponHolderSimulated", "GroundWeaponHolder"], 10];
sleep 10;
{deleteVehicle _x} forEach _droppedGear + _deadbody;

};
}];

nukebomber call TAG_FNC_handleActions;

[] execVM "briefing.sqf";
[] execVM "taw_vd\init.sqf";
player exec "rearm.sqf";

 

and to my big surprise now it works both in server and etitor.

im really confused as to why this happend?  so i search and find this:

Killzone Kid
if (isDedicated) then {
//run on dedicated server only
};

if (isServer) then {
//run on dedicated server or player host
};

if (hasInterface) then {
//run on all player clients incl. player host
};

if (!isDedicated) then {
//run on all player clients incl. player host and headless clients
};

if (!isServer) then {
//run on all player clients incl. headless clients but not player host
};

if (!hasInterface) then {
//run on headless clients and dedicated server
};

if (!hasInterface && !isDedicated) then {
//run on headless clients only
};

 

can i use this instead?     if (!isDedicated) then {

or can i just leave it out?

 

*EDIT

i tried all of these that had player client, and its the same. so i guess its not needed?

 

------------------------------------------------

 

 

ok.. i think i got this working as good as i can now.

thanks for the help.

 

my mission

http://www.mediafire.com/download/aix63edciw62caw/GUNSHIP_Airport.Stratis.rar

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

×