Bug #5059

Change Class MP Issue

Added by ArMaTeC over 5 years ago. Updated over 3 years ago.

Status:Assigned Start date:10/09/2009
Priority:Low Due date:03/01/2011
Assignee:Dwarden % Done:

0%

Category:Scripting: Problem
Target version:-
Affected ArmA II version:1.58 BETA First affected build:
Reproduced by another DH user:No First affected ArmA II version:
I am using some Mods:No Single / Multi Player?:
I am using:OA only BIForumURL:
Reproducible for you:Yes NGUrl:
Related to content of DLC: WIKIurl:

Description

Hello all i have 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.
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.

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;
    };

    sleep 0.5;

    //Reinit unit

    titleCut["", "BLACK in",0.5];
};

mptesting.rar (6.1 kB) ArMaTeC, 10/11/2009 08:08


Related issues

related to ARMA2 Community Issue Tracker - Bug #10582: selectPlayer does not transfer identity to the new unit. Rejected 05/10/2010
related to ARMA2 Community Issue Tracker - Feature #13265: Add a simple and robust way to change the player model dy... Assigned 08/25/2010
related to ARMA2 Community Issue Tracker - Bug #4461: setPlayable: Does not appear to work Assigned 09/11/2009 03/01/2011

History

Updated by kju over 5 years ago

  • Assignee deleted (Dwarden)
  • Target version deleted (1.04.59026)
  • Affected ArmA II version changed from Please select... to 1.04.59026

Updated by Fireball over 5 years ago

  • Status changed from New to Rejected

Please use the BI forums for that unless you know it's a game bug and then add a repro mission, stating current behaviour, expected behaviour and repro steps.

Updated by Dwarden over 5 years ago

  • Status changed from Rejected to Assigned
  • Assignee set to Dwarden

Updated by Dwarden over 5 years ago

  • Status changed from Assigned to Feedback
  • Priority changed from Normal to Low

make the repro simpler and clearer but don't feel ignored ...

Updated by ArMaTeC over 5 years ago

updated the repo to have a test mission and have attached file here

Updated by Fireball over 5 years ago

  • Due date set to 11/09/2009
  • Status changed from Feedback to Assigned

Thank you!

Updated by Fireball over 5 years ago

  • Target version deleted (1.04.59026)

Updated by Fireball over 5 years ago

  • Due date changed from 11/09/2009 to 12/09/2009

Updated by Fireball over 5 years ago

  • Due date changed from 12/09/2009 to 01/09/2010

Updated by kju about 5 years ago

  • Due date changed from 01/09/2010 to 03/02/2010
  • Category changed from Multiplayer to Scripting: Problem

Updated by kju almost 5 years ago

  • Due date changed from 03/02/2010 to 07/28/2010
  • Affected ArmA II version changed from 1.04.59026 to 1.52.71816
  • Audio card set to Please specify!
  • Size of OS swap file set to Please specify!

Updated by kju over 4 years ago

  • Due date changed from 07/28/2010 to 03/01/2011
  • Operating system deleted (Win7 32 bit)
  • Affected ArmA II version changed from 1.52.71816 to 1.58 BETA
  • CPU deleted (E7300)
  • I am using some Mods set to No
  • I am using set to OA only
  • Reproducible for you set to Yes

Also available in: Atom PDF