Can someone explain this, Just using comments?
#1

I would like to understand what this is actually doing....I want to know how RemovePlayerWeapon works, I will code my own if someone could explain the pseudocode.


pawn Код:
RemovePlayerWeapon(playerid, weaponid)
{
    new plyWeapons[13];
    for(new s = 0; s < 12; s++)
    {
        new wep, ammo;
        GetPlayerWeaponData(playerid, s, wep, ammo);

        if(wep != weaponid)
        {
            GetPlayerWeaponData(playerid, s, plyWeapons[s], ammo);
        }
        else
        {
            PlayerInfo[playerid][pGuns][s] = 0;
            PlayerInfo[playerid][pAGuns][s] = 0;
        }
    }

    ResetPlayerWeapons(playerid);
    for(new s = 0; s < 12; s++)
    {
        GivePlayerValidWeapon(playerid, plyWeapons[s], 60000);
    }
    return 1;
}
Reply
#2

Well for starters, GivePlayerValidWeapon is not a native SAMP function. It's obviously part of an anticheat.

pawn Код:
stock RemovePlayerWeapon(playerid, weaponid) //declares the following code as a stock function.
{
    new plyWeapons[13]; //declares a variable with array size 13 (this will store the player's current weapons)
    for(new s = 0; s < 12; s++) //loops s from 0 to 11
    {
        new wep, ammo; //declares two empty variables
        GetPlayerWeaponData(playerid, s, wep, ammo); //get's whatever weapons is at slot 's' for playerid and returns "wep" as weaponid and "ammo" as ammoid

        if(wep != weaponid) //checks whether the detected gun is NOT the one specified in the function call
        {
            GetPlayerWeaponData(playerid, s, plyWeapons[s], ammo); // if not? return the information to plyWeapons at the index of 's' in the array. Also returns the ammo to 'ammo'
        }
        else //if wep DOES equal the weaponid specified on function call
        {
            PlayerInfo[playerid][pGuns][s] = 0; //enum'd array storing the player's information > the gun @ slot 's' is set to 0
            PlayerInfo[playerid][pAGuns][s] = 0; //same as above, just set's a custom variable for storing the ammo to 0. this will later be saved in a db/file for later use
        }
    }

    ResetPlayerWeapons(playerid); //at this point all of the player's weapons are removed.
    for(new s = 0; s < 12; s++) // once again loop through 's' until it equals 11
    {
        GivePlayerValidWeapon(playerid, plyWeapons[s], 60000); //give the player back the weaponid stored in plyWeapons[]
    }
    return 1;
}
So to explain simply:

The code detects what guns the player has, saves them to an array if they DO NOT equal the gun to be removed.
Then it removes ALL of the player's guns.
Apon completion, it gives the player all of the guns stored in that array (so naturally minus the one you wanted to remove)
Reply
#3

Thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)