Getting their favorite weapon
#1

Well, I'm trying to create a function that gets their favorite weapon and tbh, i'm stuck;

My player variables are like so:

pawn Code:
enum            E_accVars {
    Passcode,           Cash,                   RegisteredIP[ 16 ],
    Kills,              Deaths,                 Status,
    Model,              KillsWithWeapon [ 42 ], DeathsByWeapon [ 42 ] //KillsWithWeapon & DeathsByWeapon are the variables used in this.
}
How said variables are set:

pawn Code:
public OnPlayerDeath(playerid, killerid, reason)
{
       
    GivePlayerMoney( playerid, 10 ),        GivePlayerMoney( killerid, -100 );
    //Give them $100 if they succeed in killing someone, and take $10 if they die. This should help create an economy.

    if( reason >= 0 && reason < 43 ) {
        accInfo [ killerid ] [ KillsWithWeapon ] [ reason ] += 1;
        accInfo [ playerid ] [ DeathsByWeapon ] [ reason ] += 1;
    }

    player_Spawned [ playerid ] = false;
    return 1;
}
What I've got so far is:

pawn Code:
stock GetFavoriteWeapon( playerid )
{
    new
        favWepID = 0;
       
    for( new w; w < 42; w ++ )
    {
        if( accInfo [ playerid ] [ KillsWithWeapon ] [ w ] != 0 )
        {
            //This is a viable candidate for their favorite weapon - they've used it before.
            if( accInfo [ playerid ] [ KillsWithWeapon ] [ w ] > favWepID )
            {
                favWepID = w;
            }
        }
    }
    return favWepID;
}
Could someone assist me further?
Reply
#2

In OnPlayerDeath you should check if the killerid is valid

pawn Code:
public OnPlayerDeath(playerid, killerid, reason)
{
    if( killerid != INVALID_PLAYER_ID )
    {
        if( reason < 43 )
        {
            accInfo [ killerid ] [ KillsWithWeapon ] [ reason ] += 1;
        }
        GivePlayerMoney( killerid, 100 );
    }
    player_Spawned [ playerid ] = false;

    if( reason <  43 )
    {
        accInfo [ playerid ] [ DeathsByWeapon ] [ reason ] += 1;
    }
    GivePlayerMoney( playerid, -10 );

    return 1;
}
Just some little changes and it was done

pawn Code:
stock GetFavoriteWeapon( playerid )
{
    new
        weapon,
        favWeapon,
        kills = accInfo [ playerid ] [ KillsWithWeapon ] [ 0 ]
    ;
    while( ++weapon  < 43 )
    {
        if( kills < accInfo [ playerid ] [ KillsWithWeapon ] [ weapon ] )
        {
            kills = accInfo [ playerid ] [ KillsWithWeapon ] [ ( favWeapon = weapon ) ];
        }
    }
    return favWeapon;
}
Reply
#3

Quote:
Originally Posted by Nero_3D
View Post
In OnPlayerDeath you should check if the killerid is valid

pawn Code:
public OnPlayerDeath(playerid, killerid, reason)
{
    if( killerid != INVALID_PLAYER_ID )
    {
        if( reason < sizeof accInfo[][] )
        {
            accInfo [ killerid ] [ KillsWithWeapon ] [ reason ] += 1;
        }
        GivePlayerMoney( killerid, 100 );
    }
    player_Spawned [ playerid ] = false;

    if( reason <  sizeof accInfo[][] )
    {
        accInfo [ playerid ] [ DeathsByWeapon ] [ reason ] += 1;
    }
    GivePlayerMoney( playerid, -10 );

    return 1;
}
Just some little changes and it was done

pawn Code:
stock GetFavoriteWeapon( playerid )
{
    new
        kills,
        weapon,
        favWeapon
    ;
    while( ++weapon  < sizeof accInfo[][] )
    {
        if( kills < accInfo [ playerid ] [ KillsWithWeapon ] [ weapon ] )
        {
            kills = accInfo [ playerid ] [ KillsWithWeapon ] [ ( favWeapon = weapon ) ];
        }
    }
    return favWeapon;
}
Thank you very much.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)