Jump to content
Ambross

Change player roles/classes and traits on respawn

Recommended Posts

Hi I've been working on setting up respawn loadouts for a mission I am making and while I have figured out how to set up the gear that the player will respawn with but i cant figure out how to change the role (or class I'm not sure of the right term but basically how the player will show up on the map and other players HUD) and the player traits (medic, engineer, etc.) after the player respawns. From what I have learned so far I think that it might not be potable to change the role if I want to use a custom loadout but I at least should be able to change traits. Below are links to a pastebin of my initserver.sqf, onplayerRespawn.sqf and description.ext if needed although I'm pretty sure the problem is in the onplayerRespawn.sqf.

 

initserver.sqf

https://pastebin.com/Xv08VPYT

 

onplayerRespawn.sqf

https://pastebin.com/Rkr7ynSU

 

description.ext

https://pastebin.com/NcAUdaTX

 

Any help with this would be appreciated and I'd be happy to answer any questions you might have.

Thanks 

Share this post


Link to post
Share on other sites

Try changing player to _unit inside onplayerRespawn.sqf

Also you need to pass _unit and _corpse parameters from the event handler.

Share this post


Link to post
Share on other sites
4 hours ago, Ambross said:

how to change the role (or class I'm not sure of the right term but basically how the player will show up on the map and other players HUD)

Changing class I don't think will be that easy (responsible for units map marker and on HUD hover description). Only way I can think of trying is to create your own respawnTemplate , where you specify a new function for the templates onPlayerRespawn that creates a new unit of the class you want, swap the player in via selectPlayer and then calls BI's original function for menuInventory onPlayerRespawn that will handle the selected respawnInventory. Only trouble here is as the unit is a fresh new unit many things will be missing and will need to be tracked and handled by your script...

  • name
  • face
  • voice
  • any object variables
  • any persistent events

etc.

If all your code is your own then this could be doable, but if you are using any other scripts or mods then this could be a hard task to accomplish.

 

4 hours ago, Ambross said:

_playersWeapons = weapons player;
_playerRole = roleDescription player;
_playerBackpackItems = backpackItems player;
_itemsplayer = items player;
 
if ("H_MilCap_mcamo" in _itemsplayer) then {_playerRole = "AirborneSquadLeader";};
if ("H_Booniehat_mcamo" in _itemsplayer) then {_playerRole = "AirborneRepairSpecialist";};
if ("launch_B_Titan_F" in _playersWeapons) then {_playerRole = "AirborneAARifleman";};
if ("arifle_MXM_F" in _playersWeapons) then {_playerRole = "AirborneMarksman";};
if ("DemoCharge_Remote_Mag" in _playerBackpackItems) then {_playerRole = "AirborneExplosiveSpecialist";};
if ("Medikit" in _playerBackpackItems) then {_playerRole = "Medic";};
if ("launch_MRAWS_sand_F" in _playersWeapons) then {_playerRole = "LAT2";};
if ("arifle_MX_SW_F" in _playersWeapons) then {_playerRole = "AR";};
if ("arifle_MX_GL_F" in _playersWeapons) then {_playerRole = "GL";};

 

This can be replaced with...

_respawnCombo = uiNamespace getVariable (["BIS_RscRespawnControlsMap_ctrlComboLoadout", "BIS_RscRespawnControlsSpectate_ctrlComboLoadout"] select (uiNamespace getVariable ["BIS_RscRespawnControlsSpectate_shown", false]));
_respawnTemplateDisplayName = _respawnCombo lbText (lbCurSel _respawnCombo);

original post

Where _respawnTemplateDisplayName would be the displayName from each CfgRespawnInventory i.e "Airborne Squad Leader", "Airborne Repair Specialist" etc

Again this could also be handle by a new respawnTemplate of which its onPlayerRespawn points to your own function, that calls BI's original template function to apply selected loadout, and then does as shown in your onPlayerRespawn.sqf to apply traits.

 

As @MechSlayer says try using the variables as passed into the event script (onPlayerRespawn.sqf) instead of player, see params passed for the event script here.

Another possible reason your having trouble with traits may just be a timing issue between when the respawnTemplates onPlayerRespawn is called (that changes the units loadout) and your onPlayerRespawn.sqf is called (that relies on the units loadout having been changed)?

Share this post


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

Also you need to pass _unit and _corpse parameters from the event handler.

I'm not sure what exactly that means.

 

9 hours ago, Larrow said:

Changing class I don't think will be that easy (responsible for units map marker and on HUD hover description). Only way I can think of trying is to create your own respawnTemplate , where you specify a new function for the templates onPlayerRespawn that creates a new unit of the class you want, swap the player in via selectPlayer and then calls BI's original function for menuInventory onPlayerRespawn that will handle the selected respawnInventory. Only trouble here is as the unit is a fresh new unit many things will be missing and will need to be tracked and handled by your script...

ya doing that would make me have to go back and basically redo all the tasks for my entire campaign and id rather not do that so I'm fine if they all show up as riflemen titled "paratrooper" or something (like BI did in Apex where everyone was just labeled solder).

 

 

9 hours ago, Larrow said:

Another possible reason your having trouble with traits may just be a timing issue between when the respawnTemplates onPlayerRespawn is called (that changes the units loadout) and your onPlayerRespawn.sqf is called (that relies on the units loadout having been changed)?

I tested this by seeing if the traits are held by a unit are not changed until the next respawn (so basically i went in with a rifleman, forced respawn, chose a medic, forced respawn, chose rifleman and then checked if I could use a medic bag). that didnt seem to be the problem if I am understanding it right. 

 

So now I just want to just change player traits on respawn but cant seem to get that to work either. 

Thanks

Share this post


Link to post
Share on other sites

Alright got the problem fixed just figured I would post this for posterity and to help anyone else out that had this problem. The easiest way to change classes on respawn is to just forget about roles and change the players traits. Just make all your player units rifleman or paratroopers or something that fits the mission (this isn't necessary for this to work but should help ease the confusion on the players). Then create a text document title it onplayerRespawn.sqf and paste this in it (https://pastebin.com/T2mG87Kc). On respawn this script checks the players backpack for either a toolkit or a medkit and if one is present will assign them the explosive specialist and engineer traits or the medic traits depending one which one they have. A similar thing can be done with the uav hacker trait but the script would have to be modified to check the players assigned items for a uav terminal of that players faction (check here https://community.bistudio.com/wiki/assignedItems for more info on how assigned items work). 

 

Thanks

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

×