XP when kill
#1

I wonder how do you add xp when kill someone.Like,I am human and I kill zombie.How do I recieve the xp.I know how to set it like score.But,I want it like each kill you recieve randomy xp.For example,1st kill I get like 40 xp 2nd I get 14 and 3rd I will get like 20 see how it recieve differently.
Please help me I really need help with this.If you help me I will be so happy.
Reply
#2

You already got a kill variable, dont you? I will call it gPlayerKills.
pawn Код:
// OnPlayerDeath
    if(killerid != INVALID_PLAYER_ID) {
        new
            expGain,
            kills = ++gPlayerKills[killerid]
        ;
        if(kills == 1) { // for the first kill
            expGain += 10; // 10 - 20 exp
        }
        if((kills % 5) == 0) { // for every fifth kill he gets bonus exp
            expGain += kills; // 5 kills = 5 - 10 exp | 10 kills = 10 - 20 exp | 15 kills = 15 - 30 exp
        }
        if(reason < 16) {
            expGain += 10; // melee kill = 10 - 20 exp
        } else {
            expGain += 5; // range kill = 5 - 10 exp
        }
        expGain += random(expGain); // random that he could get the double exp
    }
That were my toughts, add what you want
Reply
#3

How do I put it in.This what I have for onplayerdeath.I remove my check player have weapon crap ban them.I remove that so now its just blank like this.

public OnPlayerDeath(playerid, killerid, reason)
{
return 1;
}


So,how do I add the stuff you put to mines.Can you put it how I add it on here together?
Reply
#4

Just in the middle...
pawn Код:
stock
    gPlayerKills[MAX_PLAYERS]
;
pawn Код:
public OnPlayerDeath(playerid, killerid, reason) {
    if(killerid != INVALID_PLAYER_ID) {
        new
            expGain,
            kills = ++gPlayerKills[killerid]
        ;
        if(kills == 1) { // for the first kill
            expGain += 10; // 10 - 20 exp
        }
        if((kills % 5) == 0) { // for every fifth kill he gets bonus exp
            expGain += kills; // 5 kills = 5 - 10 exp | 10 kills = 10 - 20 exp | 15 kills = 15 - 30 exp
        }
        if(reason < 16) {
            expGain += 10; // melee kill = 10 - 20 exp
        } else {
            expGain += 5; // range kill = 5 - 10 exp
        }
        expGain += random(expGain); // random that he could get the double exp

        // use here the function to give the player his exp
    }
    return true;
}
Reply
#5

I keep getting errors for kills = ++gPlayerKills[killerid] I will post type of errors later.
Reply
#6

Check is player connected preventing Crash.
Reply
#7

pawn Код:
new xp[MAX_PLAYERS];

public OnPlayerDeath(playerid,killerid,reason)
{
     xp[killerid] += 10;
     return 1;
}
Reply
#8

PHP код:
new xp[MAX_PLAYERS];

public 
OnPlayerDeath(playerid,killerid,reason)
{
    
// OnPlayerConnect check's is player connected,
    // preventing Crash when use "-1"
    // Exemple: xp[-1] ++;  crash.
    
if(IsPlayerConnected(killerid)){
        
xp[killerid] ++;
    }
    return 
1;

Reply
#9

Thanks Kitten and Garfield.A Kitten for your's how can I make the script have different xp randomly for each kill like you did in your server?
Reply
#10

pawn Код:
new xp[MAX_PLAYERS];

public OnPlayerDeath(playerid,killerid,reason)
{
     switch(random(2))
     {
          case 0: xp[killerid] += 10;
          case 1: xp[killerid] += 20;
     }
     return 1;
}
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)