Jump to content
MFiveASP

Function call after Respawn

Recommended Posts

Hey. I use Serp to build TvT missions and I have a problem.
My function call in multiplayer doesn’t work, which is called respawn unit.

Init unit:
It works.
This gives the initial equipment to the unit. There are no problems with this, everything works.

[this,"opfor","opfor_squadleader"] call SerP_unitprocessor;

I try to call the same function, but after Respawn
 

this addEventHandler ["Respawn", { 
  params ["_unit", "_corpse"]; 
  [_unit, "opfor", "opfor_squadleader"] call SerP_unitprocessor; 
}];

 

It works, but not on the server.

I even tried doing this:

if (isServer) then {
  this addMPEventHandler ["MPRespawn", { 
    params ["_unit", "_corpse"]; 
    [_unit, "opfor", "opfor_squadleader"] call SerP_unitprocessor; 
  }];
};

 

But this does not work.
Could you help me solve this?

Share this post


Link to post
Share on other sites

sounds like locality issue since it doesn't work in MP

what's the code in SerP_unitprocessor?

Share this post


Link to post
Share on other sites
1 hour ago, gc8 said:

sounds like locality issue since it doesn't work in MP

what's the code in SerP_unitprocessor?

 

My description.ext

class CfgFunctions
{
    class mis
    {
        class Main
        {
            file="mis_funcs";
            class preinit
            {
                preInit=1;
                postInit=0;
            };
        };
    };
};

 

Function missionname/mis_funcs/fn_preinit.sqf

Serp_unitprocessor = compileFinal preprocessFileLineNumbers "Equipment\unitprocessor.sqf";

Equipment/unitprocessor.sqf

_unit = _this select 0;
_faction = _this select 1;
_loadout = _this select 2;

_item_processor = {
	removeAllItems _this;
	removeAllWeapons _this;
	removeAllItemsWithMagazines _this;
	removeAllAssignedItems _this;
	removeUniform _this;
	removeBackpack _this;
	removeGoggles _this;
	removeHeadgear _this;
	removeVest _this;
};

if (!isServer) exitWith {};

_unit call _item_processor;

_svn = format ["SerP_equipment_codes_%1_%2",_faction, _loadout];
if (isNil _svn) then
{
	missionNamespace setVariable [_svn, compile preprocessFileLineNumbers format ["Equipment\%1\%2.sqf", _faction, _loadout]];
};

[_unit] call (missionNamespace getVariable [_svn, {}]);

 

Only the issue of equipment after respawn does not work.

Share this post


Link to post
Share on other sites

try to replace the if (!isServer) exitWith {} by  if (local _unit) then { your code };

 

Share this post


Link to post
Share on other sites
19 minutes ago, pierremgi said:

try to replace the if (!isServer) exitWith {} by  if (local _unit) then { your code };

 

This does not work...

Share this post


Link to post
Share on other sites
_item_processor = {
	removeAllItems _this;
	removeAllWeapons _this;
	removeAllItemsWithMagazines _this;
	removeAllAssignedItems _this;
	removeUniform _this;
	removeBackpack _this;
	removeGoggles _this;
	removeHeadgear _this;
	removeVest _this;
};

Is everything getting removed?  Server is running a host of 'Argument Local' commands, so question is whether the unit is local to server.

 

_svn = format ["SerP_equipment_codes_%1_%2",_faction, _loadout];
if (isNil _svn) then
{
	missionNamespace setVariable [_svn, compile preprocessFileLineNumbers format ["Equipment\%1\%2.sqf", _faction, _loadout]];
};

[_unit] call (missionNamespace getVariable [_svn, {}]);

What's the code in your Equipment\_faction\_loadout script?

 

Also, confused why you're setting private variable "_svn" to missionNamespace and calling, when global SerP variable was what you were seeking.  Shouldn't you set and call the global SerP variable instead?

Share this post


Link to post
Share on other sites
Quote

Is everything getting removed?  Server is running a host of 'Argument Local' commands, so question is whether the unit is local to server.


Yes. Cleaning Inventory.
 

Quote

What's the code in your Equipment\_faction\_loadout script?

It's

comment "Добавляем Items, карту, компас, часы и рацию";
_unit linkItem "ItemMap";
_unit linkItem "ItemCompass";
_unit linkItem "ItemWatch";
_unit linkItem "ItemRadio";

comment "Добавляем униформу";
_unit forceAddUniform "RM_SWAT_Uniform_02";
_unit addGoggles "G_RM_SWAT_Balaclava";
_unit addHeadgear "RM_SWAT_Helmet_01";
_unit addVest "RM_SWAT_Vest_01";

comment "Добавляем предметы в униформу";
_unit addItemToUniform "ACE_epinephrine";
_unit addItemToUniform "ACE_EarPlugs";
_unit addItemToUniform "ACE_tourniquet";
for "_i" from 1 to 2 do {_unit addItemToUniform "ACE_morphine"; };
for "_i" from 1 to 2 do {_unit addItemToUniform "ACE_fieldDressing"; };
_unit addItemToUniform "ACE_elasticBandage";
_unit addItemToUniform "ACE_quikclot";
_unit addItemToUniform "ACE_packingBandage";

comment "Добавляем предметы в рюкзак";
for "_i" from 1 to 5 do {_unit addItemToVest "rhs_mag_30Rnd_556x45_M855A1_Stanag"; };
for "_i" from 1 to 3 do {_unit addItemToVest "rhsusf_mag_17Rnd_9x19_JHP"; };
for "_i" from 1 to 2 do {_unit addItemToVest "ACE_M84"; };
_unit addItemToVest "SmokeShell";
_unit addItemToVest "rhs_mag_m67";

comment "Добавляем основное оружие и приспособления к нему";
_unit addWeapon "rhs_weap_hk416d145";
_unit addPrimaryWeaponItem "optic_Aco";

comment "Добавляем второстепенное оружие и приспособления к нему";
_unit addWeapon "rhsusf_weap_glock17g4";
_unit addHandgunItem "rhsusf_acc_omega9k";

Ammunition Add Code. It works for the first time at the start of the game and the function works correctly.
But the function is not called after the death of the player and respawn.
There’s not even an inventory cleaning after Respawn

 

Quote

Also, confused why you're setting private variable "_svn" to missionNamespace and calling, when global SerP variable was what you were seeking.  Shouldn't you set and call the global SerP variable instead?

Sorry, but I didn’t write the code, so I can’t answer your question. I would be happy if I could figure this out. That is why I am here.

Share this post


Link to post
Share on other sites
this addEventHandler ["Respawn", { 
  params ["_unit", "_corpse"]; 
  [_unit, "opfor", "opfor_squadleader"] call SerP_unitprocessor; 
}];

Try remoteExecCall where _unit is local, instead of calling directly, see if it resolves.

Share this post


Link to post
Share on other sites

I recon the unit is still a null object.

Add:

private _timeOut = time + 5; 
waitUntil {!isNull _unit || time > _timeOut};

Before your loadout call.

Share this post


Link to post
Share on other sites
6 hours ago, opusfmspol said:

Also, confused why you're setting private variable "_svn" to missionNamespace and calling, when global SerP variable was what you were seeking.

As its not, its checking to see whether the( function ) missionNamespace variable "SerP_equipment_codes_faction_loadout" ( which the name is held in the local variable _svn ) has been created yet.

 

Quote

Shouldn't you set and call the global SerP variable instead?

Which is what it does.

//Create function NAME from _faction _loadout
_svn = format ["SerP_equipment_codes_%1_%2",_faction, _loadout];

//If the function has not yet been defined( missionNamespace variable named "SerP_equipment_codes_faction_loadout" is nil )
if (isNil _svn) then {
  //Compile the contents of file "Equipment\_faction\_loadout.sqf"
  //And store it in the global( missionNamespace ) variable "SerP_equipment_codes_faction_loadout"
  missionNamespace setVariable [_svn, compile preprocessFileLineNumbers format ["Equipment\%1\%2.sqf", _faction, _loadout]];
};

//Call the function "SerP_equipment_codes_faction_loadout"
[_unit] call (missionNamespace getVariable [_svn, {}]);

 

Same as others have suggested, it is a locality issue.

Use in units init...

if ( isServer ) then {
  this addMPEventHandler ["MPRespawn", {
      params ["_unit", "_corpse"];
      [_unit, "opfor", "opfor_squadleader"] call SerP_unitprocessor;
  }];
};
Quote

 


MPRespawn
Triggered when a unit, it is assigned to, respawns. This EH does not work as one would expect MP EH should work like. It is only triggered on one machine where the unit it was assigned to is local. The only difference between Respawn and MPRespawn is that MPRespawn can be assigned from anywhere
 

 

 

Then in Equipment/unitprocessor.sqf remove the line.

if (!isServer) exitWith {};

 

So on init server adds MP Respawn globally for that unit. When the unit respawns the event only gets called where the unit is local.

Your previous !isServer was stopping the equipment script, as the unit is not local to the server, but instead resides on the player( clients ) machine.

 

 

  • Thanks 2

Share this post


Link to post
Share on other sites

Larrow,  thanks! It looks like it works!

Share this post


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

its checking to see whether the( function ) missionNamespace variable "SerP_equipment_codes_faction_loadout" ( which the name is held in the local variable _svn ) has been created yet.

I see that now.  *headslap* > :smiley-punched: - oww

 

Thanks Larrow.  Defective brain cell registered "call compile format" instead of just "format".

Share this post


Link to post
Share on other sites
On 4/9/2020 at 2:19 AM, Larrow said:

As its not, its checking to see whether the( function ) missionNamespace variable "SerP_equipment_codes_faction_loadout" ( which the name is held in the local variable _svn ) has been created yet.

 

Which is what it does.


//Create function NAME from _faction _loadout
_svn = format ["SerP_equipment_codes_%1_%2",_faction, _loadout];

//If the function has not yet been defined( missionNamespace variable named "SerP_equipment_codes_faction_loadout" is nil )
if (isNil _svn) then {
  //Compile the contents of file "Equipment\_faction\_loadout.sqf"
  //And store it in the global( missionNamespace ) variable "SerP_equipment_codes_faction_loadout"
  missionNamespace setVariable [_svn, compile preprocessFileLineNumbers format ["Equipment\%1\%2.sqf", _faction, _loadout]];
};

//Call the function "SerP_equipment_codes_faction_loadout"
[_unit] call (missionNamespace getVariable [_svn, {}]);

 

Same as others have suggested, it is a locality issue.

Use in units init...


if ( isServer ) then {
  this addMPEventHandler ["MPRespawn", {
      params ["_unit", "_corpse"];
      [_unit, "opfor", "opfor_squadleader"] call SerP_unitprocessor;
  }];
};

 

Then in Equipment/unitprocessor.sqf remove the line.


if (!isServer) exitWith {};

 

So on init server adds MP Respawn globally for that unit. When the unit respawns the event only gets called where the unit is local.

Your previous !isServer was stopping the equipment script, as the unit is not local to the server, but instead resides on the player( clients ) machine.

 

 


You helped me make the call Serp unitprocessor work. But now I have another problem. The script issues equipment at the beginning of the game and after the player respawn. But it gives respawn not to one unit, but to everyone who has one script written. Example: There are three units with equipment "officer_squadleader" With respawn, it is activated on all three units, it does not matter if they are alive or not. Also, when you enter the game slot, the same thing happens.
How can I make one script work on several units, but for the script to give out equipment only to the unit that has just respawning or entered the game?

Share this post


Link to post
Share on other sites

 

Sorry for the second post, I do not know how to remove it.

Share this post


Link to post
Share on other sites
43 minutes ago, MFiveASP said:

With respawn, it is activated on all three units, it does not matter if they are alive or not. Also, when you enter the game slot, the same thing happens.
How can I make one script work on several units, but for the script to give out equipment only to the unit that has just respawning or entered the game?

Erm unless I'm having a derp moment, from what you have shown that cannot possibly happen.

Can you post a test mission? With all unneeded stuff removed.

I'll have a look in the morning on fresh eyes, getting later here need my bed.

Share this post


Link to post
Share on other sites
1 hour ago, Larrow said:

Erm unless I'm having a derp moment, from what you have shown that cannot possibly happen.

Can you post a test mission? With all unneeded stuff removed.

I'll have a look in the morning on fresh eyes, getting later here need my bed.

Yes!
https://dropmefiles.com/EdpDd

Share this post


Link to post
Share on other sites

Change your unit inits to...

if ( local this ) then {
	[ this, "blufor", "officer_squadleader" ] call SerP_unitprocessor;
};
if ( isServer ) then { 
	this addMPEventHandler[ "MPRespawn", {
		params [ "_unit", "_corpse" ];
		[ _unit, "blufor", "officer_squadleader" ] call SerP_unitprocessor;
	}];
};

I missed this in your first post and thought you were doing just the respawn part in the init and possibly had respawnOnStart turned on.

 

When clients load a mission all entities and their inits are run. In which case they would run the first function call, changing entities that are already being controlled by another machine. As above, you only want to change the entity that is local to the clients machine and only add the MPRespawn from the server.

Let me know how it goes.

Share this post


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

Change your unit inits to...


if ( local this ) then {
	[ this, "blufor", "officer_squadleader" ] call SerP_unitprocessor;
};
if ( isServer ) then { 
	this addMPEventHandler[ "MPRespawn", {
		params [ "_unit", "_corpse" ];
		[ _unit, "blufor", "officer_squadleader" ] call SerP_unitprocessor;
	}];
};

I missed this in your first post and thought you were doing just the respawn part in the init and possibly had respawnOnStart turned on.

 

When clients load a mission all entities and their inits are run. In which case they would run the first function call, changing entities that are already being controlled by another machine. As above, you only want to change the entity that is local to the clients machine and only add the MPRespawn from the server.

Let me know how it goes.


Thanks, it looks like it works. Tomorrow I will definitely inform you that we will have a game tomorrow and we will test it with a large number of players. But I have one more question, it’s not a lot on this topic.
 

How do I apply ModuleZoneRestriction to units that have been killed and respawn?

The module synchronizes units and it works on those that have not been killed.

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

×