Jump to content
Sign in to follow this  
armatech

Changing Class in MP Issue

Recommended Posts

Hello all i have asked around all the best coders i know without any luck about a small issue with a script I'm creating and I'm hoping that someone has experience with addSwitchableUnit that can help me solve this issue(**bug**).

My issue is that for some reason after switching units my old unit remains and i loose the ability to respawn from the new unit.

To use the code run this command (local)

if(local player)then
{
["Citizen4",player] call DCV_ChangeClass;
};

So to sum up the issue is:

1. No default Respawn after switching to a new unit

2. The old Unit is still respawning

Any help welcomed.

DCV_ChangeClass = 
{
//["Citizen4",player] call DCV_ChangeClass;
private ["_NewType", "_infoarray", "_currentunit", "_OrginalDir", "_OrginalPosition", "_OrginalView", "_newUnit", "_dummyUnit", "_dummyGroup", "_fSelectWeapon","_player"];
_NewType = _this select 0;
_player = _this select 1;
_Currentunit = _player;
_OrginalDir  = getdir _player;
_OrginalPosition  = getpos _player;
_OrginalView = cameraView;
//Create an array of the current players information
_infoarray = 
[
//Get Current weapons
weapons _currentunit,

//Get Current Ammo
magazines _currentunit, 

//Get Current Rank
rank _currentunit, 

//Get Current Score
score _currentunit,

//Get Current Group
group _currentunit,

//Get Current location
getPos _currentunit, 

//Check if group leader is player
(leader _currentunit) == _currentunit, 

//Get original name
vehicleVarName _currentunit
];

//Function to select players current weapon and bring it up ready for use
_fSelectWeapon = 
{
private ["_unit", "_weap", "_cfg", "_muz", "_array"];
_unit = _this select 0;
_weap = _this select 1;
_cfg = (configFile >> "CfgWeapons" >> _weap >> "muzzles");
if (isArray _cfg) then 
{
_array = getArray _cfg;
_muz = _array select 0;
if (_muz == "this") then 
{
_muz = _weap; 
};
}else{
_muz = _weap;
};
if (player hasWeapon _weap) then 
{ 
_unit selectWeapon _muz;
};
};

//Create Dummy Group used to create the new unit
_dummyGroup = createGroup (side _currentunit);
_dummyUnit = (_infoarray select 4) createUnit [_NewType, [1000,10,0], [], 0, "NONE"];

//Change player group to the dummy group
[_currentunit] join _dummyGroup;

//Create the New unit to be spawned info
_newUnit = _dummyGroup  createUnit [_NewType, [(getpos _player select 0)+200,(getpos player select 1)+200,0], [], 0, "NONE"];

//Make the new unit switchable
addSwitchableUnit _newUnit;

//Display some output to the user while we switch them
titleCut ["Changing Outfit","black faded", 2];

//DEBUG
_player sidechat format ["Name before: %1",name _player];
sleep 1;

//Clean out old eventhandelers from old unit
_currentunit removeAllEventHandlers "killed";
_currentunit removeAllEventHandlers "Fired";
_currentunit removeAllEventHandlers "hit";
_currentunit removeAllEventHandlers "getin";
_currentunit removeAllEventHandlers "getout";

//Set Old units name to old(original name)
_currentunit setVehicleInit format["this setVehicleVarName 'old%1'; old%1 = this", _infoarray select 7];

//Set New units name to original name
_newUnit setVehicleInit format["this setVehicleVarName '%1'; %1 = this;", _infoarray select 7];

//Process both units init commands
processInitCommands;

//Debug Output
player sidechat format ["Name after: %1",name _player];
sleep 0.5;

//Transfer player to new unit
selectNoPlayer;
setPlayable _newUnit;
selectPlayer _newUnit;

[_newUnit] joinsilent startgroup;
startgroup selectLeader _newUnit;
//Remove Temp Group
deleteVehicle _dummyUnit;
deletegroup _dummyGroup;

//Remove Player switch on new and old units
removeSwitchableUnit _newUnit;
removeSwitchableUnit _currentunit;
sleep 1;

//Remove old unit
[_currentunit]spawn
{
private ["_currentunit"];
_currentunit = _this select 0;
while{(not(isnull _currentunit))}do
{
_currentunit setdammage 1;
sleep 0.01;
deleteVehicle _currentunit;
};
};

//Set Unit location back to original
player setdir _OrginalDir;
player setpos _OrginalPosition;
if (cameraOn == player) then
{
player switchCamera _OrginalView;
};


//RE-Add Current Loadout
removeAllWeapons player;
removeAllItems player;
//Ammo
if(count(_infoarray select 1) > 0)then
{
{
player addMagazine _x;
}foreach (_infoarray select 1);
};
//Weapons
_notallowed = [];
if(count(_infoarray select 0) > 0)then
{
{
if(_x in _notallowed)then
{
}else{
player addWeapon _x;
};
}foreach (_infoarray select 0);
reload player;
}; 
if ((primaryWeapon player) != "") then 
{ 
[player, primaryWeapon player] call _fSelectWeapon;
};
//Reinit unit
titleCut["", "BLACK in",0.5];
};

Share this post


Link to post
Share on other sites

i didnt think it was possible to unit switch in MP, without actually going to the slot screen.

Share this post


Link to post
Share on other sites

ive seen it done in a diffent mission but there code was all over the place try it out and you will see that it works except for the 2 issues i posted.

Share this post


Link to post
Share on other sites

yes, this works, but there are more issues than just the two.

e.g. ArmA keeps thinking you (the player) are still in control of the original unit even after the switch. This causes a whole lot of errors (like both you and the AI being in control of the same unit after respawn... !).

After all, as stated in the biki, this is a single player feature. So I guess we will have to live with it.

It's only weird that team switch works just fine when setting repawn to 5...

Cheers,

D.

Share this post


Link to post
Share on other sites

well, you could try to script a workaround using respawn = 5, which (as you will know for sure) enables team switch in multiplayer.

Good luck

&

Cheers,

D.

Share this post


Link to post
Share on other sites

anyone? would be sooo great if this could work.

and I don't get it why it shouldn't, there has to be some way.

Share this post


Link to post
Share on other sites

im still working on it i have it working fundamentally but having issues with other scripts clashing

Share this post


Link to post
Share on other sites

Don't give up, it works great

See here :

http://dev-heaven.net/wiki/whis-maas

My whole project revolves partially around this functionnality

Give it a try, check the files for testing, check the code in the repository, it may not be ultra_clean, but, well, it works...

Case in point : you have to handle the respawning system from a new created unit where the player is switched into all by yourself. This is not that hard, EventHandlers help a great deal.

EDIT :

To explain a bit :

The original slot the player choses is only acting as a kind of container. Player connects, is spawned as usual by the game into this personna, and is immediatly presented a GUI asking which class he wants.

After that, the player will never be controlling his initial unit anymore.

After chosing a class, a new unit is created, in a group local to player's computer, selectPlayer is used to switch the player to this new unit, the new unit information is registered in the old unit variable space using setVariable (in fact, I use the original player's unit as a "playerNameSpace" storing informations about player's status) for potential need for reference (when any other script needs to know "in which unit is this player?").

Sickboy did write a whole algorithm for the selectPlayer thing which works great.

the new unit has attached eventHandlers detecting death condition. When the new unit is dead, the engine won't do anything by itself, player will just be lying on the ground, unable to do anything, and reduced to using group chat channel (he won't be in any group apart from the "dead people group")

So the EH needs to redraw the class-chosing GUI, and redo the unit spawning process all again, in the same fashion.

The "group chat" thing is rather annoying in-game, it forced me to stop using "killed" EH, but instead "handleDamage" EH to intercept death, make the player act like he's dead (dead anim forced) and do everything like he was dead (but he's not, so he can still chat in his side, group, all channels available to him)

EDIT 2 : Once the mission is in finished-enough state, I think I should extract the respawn system, at least, to make some kind of Class Based Respawn system module for anyone to use. I'm slow, few available time, so it may take a while, though

Edited by whisper

Share this post


Link to post
Share on other sites

I haven't arrived at this need myself yet but will eventually, I was hoping something like you've described would be possible, good to hear that it is.

Share this post


Link to post
Share on other sites

we do also but its the integration in to city life that's the issue at the mo it works on all other missions just has a few kinks with our revive system. if you have an example of pogomans work on this matter feel free to post it so the community can benefit from it and maybe city life we are planning to make ours standalone once we get it globally working with all mods.

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
Sign in to follow this  

×