Jump to content
Sign in to follow this  
Exxor

How would i make a XP system?

Recommended Posts

So im trying to make a xp system where if the player kills another player then they gain some xp, or if they capture a objective they would gain some xp.

Im new to arma scripting and im just trying to figure this out i tried using the eventHandler MPKilled but it does not seem to work :/. Please tell me what i am doing wrong because i have no idea on what to do, so that it can tell if the player has killed another player.

 

 

initPlayerLocal.sqf

player addMPEventHandler ["MPKilled", _this execVM"fn_PlayerXP.sqf"];

fn_PlayerXP.sqf

CONQ_FNC_ADDXP =
{
    if (player == _this select 1)
      {
        Conq_Plyr_xp = Conq_Plyr_xp + 100;
        hint "You have killed a dued";
        hint format ["You have killed a dued! %1", Conq_Plyr_xp];
      };
};

Share this post


Link to post
Share on other sites

Your "fn_PlayerXP.sqf" only loads a function into a variable (CONQ_FNC_ADDXP), it doesn't actually execute that function.

 

 

Here, this may give you some idea of how functions work:

https://community.bistudio.com/wiki/Function

 

And this is the best way to work with them:

https://community.bistudio.com/wiki/Functions_Library_(Arma_3)

  • Like 1

Share this post


Link to post
Share on other sites

 

So im trying to make a xp system where if the player kills another player then they gain some xp, or if they capture a objective they would gain some xp.

Im new to arma scripting and im just trying to figure this out i tried using the eventHandler MPKilled but it does not seem to work :/. Please tell me what i am doing wrong because i have no idea on what to do, so that it can tell if the player has killed another player.

 

You can use the entitykilled mission eventhandler, so you don't have to apply this to every unit/vehicle, it will work with spawned units on the fly as well.

Also don't use global variables for that, since it's always one unit killing another unit simply store the XP value on the unit itself.

 

Something like this:

addMissionEventHandler ["EntityKilled",{

    params ["_killedUnit","_killer","_triggerMan"];

    _getXP = [] call MyXpTable;
    _getXP params ["_man","_car","_tank","_aircraft"];
    _xp = 0;
    if (typeof _killedUnit isKindOf "CAManBase") then {_xp = _man};
    if (typeof _killedUnit isKindOf "Car") then {_xp = _car};
    if (typeof _killedUnit isKindOf "Tank") then {_xp = _tank};
    if (typeof _killedUnit isKindOf "Air") then {_xp = _aircraft};
    _killerXP = _killer getvariable ["MyXpSystem",0];
    _killer setvariable ["MyXpSystem",_killerXP + _xp];

    systemchat format ["Rewarding %1 points to %2, killer of %3",_xp,name _killer,name _killedUnit];
    systemchat format ["%1 now has %2 XP",name _killer,_killerXP + _xp];




}];

MyXpTable = {

    _man = 5;    
    _car = 10;
    _tank = 50;
    _aircraft = 150;
    [_man,_car,_tank,_aircraft]

};

You can adjust points in the xptable function, on the fly, mid mission.

It's rather simple and quickly typed out, but it's working.

It's also possible to add a fraction of a units earned xp to the killer, so killing a unit that killed lots of units grants more xp.

You can add more values by adding more types to the xptable and additional checks to the eventhandler, pretty basic.

 

Feel free to ask if you have further questions.

 

Cheers

Share this post


Link to post
Share on other sites

@ grumpy old man I don't understand what params does and why I wouldn't use a global var to store the xp of a player?

Share this post


Link to post
Share on other sites

You can use the entitykilled mission eventhandler, so you don't have to apply this to every unit/vehicle, it will work with spawned units on the fly as well.

Also don't use global variables for that, since it's always one unit killing another unit simply store the XP value on the unit itself.

 

Something like this:

addMissionEventHandler ["EntityKilled",{

    params ["_killedUnit","_killer","_triggerMan"];

    _getXP = [] call MyXpTable;
    _getXP params ["_man","_car","_tank","_aircraft"];
    _xp = 0;
    if (typeof _killedUnit isKindOf "CAManBase") then {_xp = _man};
    if (typeof _killedUnit isKindOf "Car") then {_xp = _car};
    if (typeof _killedUnit isKindOf "Tank") then {_xp = _tank};
    if (typeof _killedUnit isKindOf "Air") then {_xp = _aircraft};
    _killerXP = _killer getvariable ["MyXpSystem",0];
    _killer setvariable ["MyXpSystem",_killerXP + _xp];

    systemchat format ["Rewarding %1 points to %2, killer of %3",_xp,name _killer,name _killedUnit];
    systemchat format ["%1 now has %2 XP",name _killer,_killerXP + _xp];




}];

MyXpTable = {

    _man = 5;    
    _car = 10;
    _tank = 50;
    _aircraft = 150;
    [_man,_car,_tank,_aircraft]

};
You can adjust points in the xptable function, on the fly, mid mission.

It's rather simple and quickly typed out, but it's working.

It's also possible to add a fraction of a units earned xp to the killer, so killing a unit that killed lots of units grants more xp.

You can add more values by adding more types to the xptable and additional checks to the eventhandler, pretty basic.

 

Feel free to ask if you have further questions.

 

Cheers

I don't understand why I wouldn't use a global variable, Aswell as how you call the function or increase the amount of xp. Thanks in advanced

Share this post


Link to post
Share on other sites

Here you go about params, quite a delicious command.

Use the snippet in the init.sqf

To increase the xp values for certain targets simply define the MyXpTable function again.

Increasing the xp gain for killing aircraft would be something like this:

MyXpTable = {

    _man = 5;    
    _car = 10;
    _tank = 50;
    _aircraft = 300;
    [_man,_car,_tank,_aircraft]

};

global variables could get messy if you tend to expand the functionality of the xp system (broadcasting them to other players machines if they want to check another players xp etc.), in this case they're not necessary in the first place.

 

Cheers

Share this post


Link to post
Share on other sites

Here you go about params, quite a delicious command.

Use the snippet in the init.sqf

To increase the xp values for certain targets simply define the MyXpTable function again.

Increasing the xp gain for killing aircraft would be something like this:

MyXpTable = {

    _man = 5;    
    _car = 10;
    _tank = 50;
    _aircraft = 300;
    [_man,_car,_tank,_aircraft]

};

global variables could get messy if you tend to expand the functionality of the xp system (broadcasting them to other players machines if they want to check another players xp etc.), in this case they're not necessary in the first place.

 

Cheers

So i have read the params desc on bohemias wiki, and from my understanding it just holds an array of strings? or would it be an array of variables? so therefor when you declare the line   

  _getXP params ["_man","_car","_tank","_aircraft"];

it makes a array of variables, which when one of the variables is used later in the script it calls the xp table fnc ex:

if (typeof _killedUnit isKindOf "CAManBase") then {_xp = _man};

is this correct? sorry just trying to understand this

 

also 

what is the point of the array at the bottom of this FNC

MyXpTable = {

    _man = 5;    
    _car = 10;
    _tank = 50;
    _aircraft = 150;
    [_man,_car,_tank,_aircraft]

};

Also where can i find the type of things i am allowed to put inside of the isKindOf command ex: isKindOf "Tank" <--- where do i find stuff to put inside of the string

 

Sorry Another question ): Could you explain what bohemia means with the command typeOf description it is not very discriptive. It states "Returns the class name of a given object." <---- Wth does that mean XD.

Share this post


Link to post
Share on other sites

For starters I'd say go through the stickied thread and take a look at these things:

Kylania

Mr. Murray

Helped me out big time.

 

If you further want to confuse yourself take a look at KK's blog, excellent if you're a bit more advanced.

 

Now to your questions:

MyXpTable = {

_man = 5;
_car = 10;
_tank = 50;
_aircraft = 150;
[_man,_car,_tank,_aircraft]

};

The point of the array at the bottom means this array will be the output of the function MyXpTable.

MyXpTable = {

_man = 5;
_car = 10;
_tank = 50;
_aircraft = 150;
[_man,_car,_tank,_aircraft]

};
_getTable = [] call MyXpTable;
hint str _getTable; // will display "[5,10,50,150]"

Params is dynamic and holds info depending on how it is set up.

The examples on the wiki should tell you everything about it.

Clarified my usage of it below:

addMissionEventHandler ["EntityKilled",{

    params ["_killedUnit","_killer","_triggerMan"]; //this declares the input of the eventhandler

    _getXP = [] call MyXpTable; //here we call the XpTable, so we always have the current xp values for each class, this line makes it possible to change xp earnings mid mission
    _getXP params ["_man","_car","_tank","_aircraft"]; //the _getXP variable now holds the array of values we defined in the MyXpTable function on the bottom
    _xp = 0; //set _xp to 0 if an unknown or unwanted class is killed
    if (typeof _killedUnit isKindOf "CAManBase") then {_xp = _man};
    if (typeof _killedUnit isKindOf "Car") then {_xp = _car};
    if (typeof _killedUnit isKindOf "Tank") then {_xp = _tank};
    if (typeof _killedUnit isKindOf "Air") then {_xp = _aircraft};
    _killerXP = _killer getvariable ["MyXpSystem",0];
    _killer setvariable ["MyXpSystem",_killerXP + _xp];

    systemchat format ["Rewarding %1 points to %2, killer of %3",_xp,name _killer,name _killedUnit];
    systemchat format ["%1 now has %2 XP",name _killer,_killerXP + _xp];

}];

isKindOf goes through the configHirarchy and checks if the class is a child in the hirarchy.

Easiest way to access it would be to check the config viewer which shows the hirarchy of each class in the lower center of the screen.

Could show something like this:

(configFile >> "CfgVehicles" >> "Car" >> "MyCarClass")

Regarding the typecheck question:

if (typeof _killedUnit isKindOf "CAManBase") then {_xp = _man};

_killedUnit refers to the object, which is the wrong datatype for the iskindof check.

IsKindOf requires a string datatype, in this case the classname of the object.

typeOf object returns its classname.

Objects have unique identifiers in game, something like B: Alpha 1-3 876345.

The classname would be something like "B_rifleman_F".

 

Cheers

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  

×