GetWeaponData help
#1

Hi guys I wanted to make a command that would show how much ammo the player would have in all his guns like
after I typed /weaps 1 for example it will show me how much ammo player 1 has in all his weapons.
Can someone help me?
Reply
#2

pawn Код:
CMD:weaps(playerid, params[])
{
    if (!IsPlayerAdmin(playerid)) return 1;

    new
        id;

    if (sscanf(params, "r", id)) return SendClientMessage(playerid, -1, "Usage: /weaps <ID/Part Of Name>");
    if (id == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "Invalid player");

    new
        weaponid,
        ammo,
        sz_T[32];
       
    GetPlayerName(id, sz_T, MAX_PLAYER_NAME);
    format( sz_T, sizeof (sz_T), "%s's weapons:", sz_T);
    SendClientMessage(playerid, -1, sz_T);

    for (new i; i != 13; ++i)
    {
        GetPlayerWeaponData(id, i, weaponid, ammo);
        format(sz_T, sizeof (sz_T), "weaponid: %d & ammo: %d", weaponid, ammo);
        SendClientMessage(playerid, -1, sz_T);
    }
    return 1;
}
Reply
#3

It doesnt work it compiles fine but I dont get anything
Reply
#4

Quote:
Originally Posted by Hybris
Посмотреть сообщение
It doesnt work it compiles fine but I dont get anything
You need to be logged in as RCON admin so you'll be able to use the command. In case you're not logged in as a RCON admin, then it will simple do nothing.

You can change it to your admin levels or remove the admin access completely.
Reply
#5

pawn Код:
//under OnPlayerCommand
dcmd(weaps,5,cmdtext);

//dcmd command
dcmd_weaps(playerid,params[])
{
    if(IsPlayerAdmin(playerid))
    {
        new pID, weaposL[320];
        if(sscanf(params, "u",pID))return SendClientMessage(playerid,0xFF0000FF,"Usage: /checkwep [ID]");
        if(!IsPlayerConnected(pID))return SendClientMessage(playerid,0xFF0000FF,"Player ID/Name not found!");
        if(pID == INVALID_PLAYER_ID)return SendClientMessage(playerid,0xFF0000FF,"This PlayerId is invalid!");
        new weapons[13][2],weaponsName[13][32];
        for (new i = 0; i < 13; i++)
        {
            GetPlayerWeaponData(pID, i, weapons[i][0], weapons[i][1]);
            switch(weapons[i][0])
            {
                case 0:weaponsName[i]="Unarmed";
                case 1:weaponsName[i]="Brass Knuckles";
                case 2:weaponsName[i]="Golf Club";
                case 3:weaponsName[i]="Nightstick";
                case 4:weaponsName[i]="Knife";
                case 5:weaponsName[i]="Baseball Bat";
                case 6:weaponsName[i]="Shovel";
                case 7:weaponsName[i]="Pool Cue";
                case 8:weaponsName[i]="Katana";
                case 9:weaponsName[i]="Chainsaw";
                case 10:weaponsName[i]="Dildo 1";
                case 11:weaponsName[i]="Dildo 2";
                case 12:weaponsName[i]="Vibrator 1";
                case 13:weaponsName[i]="Vibrator 2";
                case 14:weaponsName[i]="Flowers";
                case 15:weaponsName[i]="Cane";
                case 16:weaponsName[i]="Grenade";
                case 17:weaponsName[i]="Tear Gas";
                case 18:weaponsName[i]="Molotov Cocktail";
                case 22:weaponsName[i]="9mm Pistol";
                case 23:weaponsName[i]="9mm Pistol silenced";
                case 24:weaponsName[i]="Desert Eagle";
                case 25:weaponsName[i]="Shotgun";
                case 26:weaponsName[i]="SawnOff Shotgun";
                case 27:weaponsName[i]="Combat Shotgun";
                case 28:weaponsName[i]="Micro SMG";
                case 29:weaponsName[i]="MP5";
                case 30:weaponsName[i]="Ak47";
                case 31:weaponsName[i]="M4";
                case 32:weaponsName[i]="Tec9";
                case 33:weaponsName[i]="Country Rifle";
                case 34:weaponsName[i]="Sniper Rifle";
                case 35:weaponsName[i]="RPG";
                case 36:weaponsName[i]="Heat Seeker Rocket";
                case 37:weaponsName[i]="Flamethrower";
                case 38:weaponsName[i]="Minigun";
                case 39:weaponsName[i]="Satchel Charge";
                case 40:weaponsName[i]="Detonator";
                case 41:weaponsName[i]="Sprycan";
                case 42:weaponsName[i]="Fire Extinguisher";
                case 43:weaponsName[i]="Camera";
                case 44:weaponsName[i]="Night Vision Goggles";
                case 45:weaponsName[i]="Thermal Goggles";
                case 46:weaponsName[i]="Parachute";
                default:weaponsName[i]="NONE";
            }
            format(weaposL, sizeof weaposL, "%s Weapon: %s | Ammo: %d\r\n", weaposL, weaponsName[i], weapons[i][1]);
        }
        ShowPlayerDialog(playerid, 1, DIALOG_STYLE_MSGBOX,"{EE0000}Weaponlist", weaposL, "Ok", "");
        new name[24],string[128];
        GetPlayerName(pID,name,24);
        format(string,sizeof(string),"{00FF7F}%s's current weapon data is displayed below...",name);
        SendClientMessage(playerid,0xFF0000FF,string);
    }else return SendClientMessage(playerid, 0xFF0000FF, "You are not an admin!");
    return 1;
}
Reply
#6

Quote:
Originally Posted by BlackWolf120
Посмотреть сообщение
pawn Код:
..
Your code looks long and looks dirty, it isn't the best way to do that, Konstatinos would work properly if the Hybris understand what he means, anyways, here's the code.

pawn Код:
CMD:weaps(playerid, params[])
{
    new
        PlayerWeapons[13], PlayerAmmo[13],
        WeaponName[30], string[100],
        targetid, i = 1
    ;

    if( sscanf ( params, "u", targetid ) )
        return SendClientMessage(playerid, -1, "Syntax: /weaps [Player Name/ID]");

    while(i <= 12)
    {
        GetPlayerWeaponData( id, i, PlayerWeapons[ i ], PlayerAmmo[ i ] );
        if( PlayerWeapons[ i ] != 0 )
        {
            GetWeaponName( PlayerWeapons[i], WeaponName, sizeof( WeaponName ) );
            format( string, sizeof( string ) , "Weapon ID: [%d] Weapon Name: [%s] - Ammo: [%d]", PlayerWeapons[ i ], WeaponName, PlayerAmmo[ i ] );
            SendClientMessage( playerid, -1, string );
        }
        i++;
    }
    return true;
}
Reply
#7

@pds2k12: i know there are more effective ways to do it but i dont think codes posted here just should be copied
into the script by the thread starter!
I dont know about you but me as a newbie in scripting would have problems to fully follow certain codes.
It always helped me to see different codes doing same or simillar stuff so i could understand and later combine everything to try out things on my own.
Unfortunately it has become pretty common to serve everything on a silver plate and invite newbies to just C&P codes instead of asking questions and being able to fully understand it.

I didnt want the thread starter to simply copy my code into his script, i just wanted to show how it also works, as
my foreposter already posted a full code and i think you can easily see how the loop/GetPlayerWeaponData function works on my example.
I at least always appreciated more examples of certain systems/functions to think about it and see certain differences.


regards, wolf.
Reply
#8

Quote:
Originally Posted by BlackWolf120
Посмотреть сообщение
@pds2k12: i know there are more effective ways to do it but i dont think codes posted here just should be copied
into the script by the thread starter!
I dont know about you but me as a newbie in scripting would have problems to fully follow certain codes.
It always helped me to see different codes doing same or simillar stuff so i could understand and later combine everything to try out things on my own.
Unfortunately it has become pretty common to serve everything on a silver plate and invite newbies to just C&P codes instead of asking questions and being able to fully understand it.

I didnt want the thread starter to simply copy my code into his script, i just wanted to show how it also works, as
my foreposter already posted a full code and i think you can easily see how the loop/GetPlayerWeaponData function works on my example.
I at least always appreciated more examples of certain systems/functions to think about it and see certain differences.


regards, wolf.
I understand you, I apologize if I insulted you in some ways, I am just saying your code is obsolete people maybe used it, but when they learn and know better about it, they will start realizing this code it pretty old and stuff, once again I apologize if I insulted you in some ways, but the code looks messy and not intended very well. +3 Reputations.

- Regards
pds2k12
Reply
#9

Thank you for helping me out I will rep you
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)