Forum Jump :

Author Message


Posts: 3
Rank:


Level: Member

Country: ca
Location: Southern Ontario
Occupation: Your average angry mob goer
Age: 22
In-game name: Kaas298

 
#1 Posted at 2016-02-15 07:42        
     
_wep = [];
_mag = [];



player addeventhandler ["Take",{

_wep = weapons (_this select 0);
hint format ["%1",_wep];
}];

player addeventhandler["Respawn",{

//checks players equipment
_mag = magazines (_this select 1);


//adds all the weapons and equipment we found earlier
removeallweapons (_this select 0);
removeallitems (_this select 0);
removebackpack (_this select 0);
{(_this select 0) addmagazine _x}foreach _mag;
{(_this select 0) addweapon _x}foreach _wep;
hint format ["%1",_wep];
}];


So the point of the script to record a players equipment before death, then give it to them when they respawn. I want this because I allow free arsenal to my players. I've got the script to count magazines and give them to the newly spawned player but Weapons are a different ball game.

when run the script will collect the classname for the weapons the player has, this is what I want; But when the player respawns it returns "any" instead of the classname.

I thought this was because of scope, but I was unable to get it to work.

Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. - Martin Golding

Author Message


Posts: 1189
Rank:


Level: Member

Country: tr
Location:
Occupation: Computer Science student
Age: 21
In-game name: Wak

 
#2 Posted at 2016-02-15 07:58        
     
You might want to use these functions:
  • BIS_fnc_saveInventory
  • BIS_fnc_loadInventory

  • A good way to do this is save the player's loadout when he's leaving the respawn area, then load it back on repsawn. A script like this should do it:
    player addEventHandler ["Respawn", {
    	[_this select 0, [missionNamespace, "last_loadout"]] call BIS_fnc_loadInventory;
    }];
    while {true} do {
    	waitUntil {sleep 1; player distance (markerPos "respawn_west") > 250};
    	[player, [missionNamespace, "last_loadout"]] call BIS_fnc_saveInventory;
    	waitUntil {sleep 1; player distance (markerPos "respawn_west") < 250};
    };
    

    Sometimes I like to think as I started the whole "earplugs" thing.

    W0lle: The only advice I can give you is: Do not try to understand BI. You will not succeed and it only makes your brain go boom. I would even go so far and say that not even they understand their own actions :-D.

    #define getDamage getDammage

    Advertisement


    Author Message


    Posts: 3
    Rank:


    Level: Member

    Country: ca
    Location: Southern Ontario
    Occupation: Your average angry mob goer
    Age: 22
    In-game name: Kaas298

     
    #3 Posted at 2016-02-15 18:17        
         
    Works great! thanks for the quick response.

    I guess I'm off to study the functions library.

    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. - Martin Golding

    Author Message


    Posts: 1189
    Rank:


    Level: Member

    Country: tr
    Location:
    Occupation: Computer Science student
    Age: 21
    In-game name: Wak

     
    #4 Posted at 2016-02-15 19:21        
         
    If that's where you're headed, be aware that the list in the wiki is outdated. I'd suggest you use the in-game Function Viewer, accessed from the Debug Console. This way you can always view all available functions, since they'll be fetched straight from your current game version.

    Sometimes I like to think as I started the whole "earplugs" thing.

    W0lle: The only advice I can give you is: Do not try to understand BI. You will not succeed and it only makes your brain go boom. I would even go so far and say that not even they understand their own actions :-D.

    #define getDamage getDammage

    Author Message


    Posts: 3
    Rank:


    Level: Member

    Country: ca
    Location: Southern Ontario
    Occupation: Your average angry mob goer
    Age: 22
    In-game name: Kaas298

     
    #5 Posted at 2016-02-21 07:53        
         
    Neato! thanks.

    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. - Martin Golding