SA-MP Forums Archive
GetPlayerWeaponData - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: GetPlayerWeaponData (/showthread.php?tid=646379)



GetPlayerWeaponData - NealPeteros - 16.12.2017

I'm kinda confused with GetPlayerWeaponData. Could someone send an example, listing every weapon and ammo the player has using this function?


Re: GetPlayerWeaponData - Kane - 16.12.2017

It's pretty straight forward.

“slots” is the slot ID the weapon is held in. There are 13 slots, 0 to 12. You loop through these slots and get their weapons and ammo for those slots.
Two examples are:

PHP код:
// Common use: get all weapons and store info in an array containing 13 slots
// The first value is the weapon ID, and second is the ammo
 
new weapons[13][2];
 
for (new 
i = 0; i <= 12; i++)
{
    
GetPlayerWeaponData(playerid, i, weapons[i][0], weapons[i][1]);
} 
“weapons[i][0]” holds their weapon ID and “weapons[i][1]” holds the ammo.

PHP код:
new
    
weapon_id, ammo, w_string[128]
;
for(new 
i; i < 13; i++) // 0-12; 
{
    
GetPlayerWeaponData(playerid, i, weapon_id, ammo);
    
    
format(w_string, sizeof w_string, "Weapon ID: %i, Ammo: %i", weapon_id, ammo);
    
SendClientMessage(playerid, -1, w_string);
} 
You understandin?


Re: GetPlayerWeaponData - NealPeteros - 16.12.2017

Quote:
Originally Posted by Arthur Kane
Посмотреть сообщение
It's pretty straight forward.

“slots” is the slot ID the weapon is held in. There are 13 slots, 0 to 12. You loop through these slots and get their weapons and ammo for those slots.
Two examples are:

PHP код:
// Common use: get all weapons and store info in an array containing 13 slots
// The first value is the weapon ID, and second is the ammo
 
new weapons[13][2];
 
for (new 
i = 0; i <= 12; i++)
{
    
GetPlayerWeaponData(playerid, i, weapons[i][0], weapons[i][1]);
} 
“weapons[i][0]” holds their weapon ID and “weapons[i][1]” holds the ammo.

PHP код:
new
    
weapon_id, ammo, w_string[128]
;
for(new 
i; i < 13; i++) // 0-12; 
{
    
GetPlayerWeaponData(playerid, i, weapon_id, ammo);
    
    
format(w_string, sizeof w_string, "Weapon ID: %i, Ammo: %i", weapon_id, ammo);
    
SendClientMessage(playerid, -1, w_string);
} 
You understandin?
Kinda'. Say, how do you do that with dialogs?


Re: GetPlayerWeaponData - Kane - 16.12.2017

PHP код:
stock list_weapons(playerid)
{
    new 
wep_list[256], wep_holder[128];
    new 
weapon_id, weapon_ammo; 
    
    for(new 
i; i < 13; i++){
        
        
GetPlayerWeaponData(playerid, i, weapon_id, weapon_ammo);
        
        if(
weapon_id != 0)
        {
            
format(wep_holder, sizeof wep_holder, "Wep ID: %i - Ammo: %i\n", weapon_id, weapon_ammo); 
            
strcat(wep_list, wep_holder); 
        }
    }
    
ShowPlayerDialog(playerid, 0, DIALOG_STYLE_LIST, "Caption", wep_list, "<<", ">>"); 
    return 
1;
} 
Is a way.


Re: GetPlayerWeaponData - RogueDrifter - 16.12.2017

Visit samp wiki For weapon slots
look at the Slots section to know which slot that is for the weapon, as for GetPlayerWeaponData
here's the paramters (playerid, slot, &weapons, &ammo) so playerid, slot which u can get from the link i sent above and the weapon to be saved and the ammo, say i wanna save a player's weapons when he disconnects, so i'll do this:
PHP код:
public OnPlayerDisconnect(playerid,reason)
{
    new 
weapon[4],ammo[4];
    
GetPlayerWeaponData(playerid, 2, weapon[0], ammo[0]);
    
GetPlayerWeaponData(playerid, 3, weapon[1], ammo[1]);
    
GetPlayerWeaponData(playerid, 4, weapon[2], ammo[2]);
    
GetPlayerWeaponData(playerid, 5, weapon[3], ammo[3]);
    
//after that you save that weapon[0-->3] and same for ammo into the file for ex if i use DINI i will do this
    
dini_IntSet(file,"FirstWeapon",weapon[0]);
    
dini_IntSet(file,"FirstAmmo",ammo[0]);
    
//and so on for the rest of the ammo spots we saved
    
return 1;
} 
for the 2nd question to do that with a dialogue simply format a string and set it as the dialogue like:
PHP код:
new name[24],string[128],weapon0[15],weapon1[15];
GetPlayerName(playerid,name,sizeof(name));
GetWeaponName(weapon[0], weapon0, sizeof(weapon0));
GetWeaponName(weapon[1], weapon1,sizeof(weapon1));
format(string,sizeof(string),"%s has the weapon %s with %d ammmo and a %s with %d ammo",name,weapon0,ammo[0],weapon1,ammo[1]);
ShowPlayerDialog(playerid, 55, DIALOG_STYLE_MSGBOX, "Weapon Info", string, "Okay", ""); 
EDIT: this is merely an example to show you how it could work like, not an actual script to be used.


Re: GetPlayerWeaponData - NealPeteros - 16.12.2017

EDIT: btw is it possible to show the selected weapon's name after responding to the dialog?


2nd EDIT: had to delete that previous message to avoid doublepost


Re: GetPlayerWeaponData - RogueDrifter - 16.12.2017

Quote:
Originally Posted by NealPeteros
Посмотреть сообщение
EDIT: btw is it possible to show the selected weapon's name after responding to the dialog?


2nd EDIT: had to delete that previous message to avoid doublepost
did u read my example? GetWeaponName...?? OnDialogueResponse to that dialogue id format a string JUST like the one i formatted in my example and do showplayerdialogue with that string, like my example.


Re: GetPlayerWeaponData - NealPeteros - 16.12.2017

Quote:
Originally Posted by RogueDrifter
Посмотреть сообщение
did u read my example? GetWeaponName...?? OnDialogueResponse to that dialogue id format a string JUST like the one i formatted in my example and do showplayerdialogue with that string, like my example.
I'm sorry, but um...huh? Can you probably say it in words I can understand, please? Kinda spent 10 minutes figuring out what you meant.


Re: GetPlayerWeaponData - RogueDrifter - 16.12.2017

Quote:
Originally Posted by NealPeteros
Посмотреть сообщение
I'm sorry, but um...huh? Can you probably say it in words I can understand, please? Kinda spent 10 minutes figuring out what you meant.
PHP код:
new name[24],//player name varibale

string[128],//string for the dialogue

weapon0[15],//string for first weapon name

weapon1[15]; //string for second weapon name

GetPlayerName(playerid,name,sizeof(name));//saving the player name in (name)

GetWeaponName(weapon[0], weapon0, sizeof(weapon0));//saving first weapon name in (weapon0)

GetWeaponName(weapon[1], weapon1,sizeof(weapon1));//saving second weapon in (weapon1)

format(string,sizeof(string),"%s has the weapon %s with %d ammmo and a %s with %d ammo",name,weapon0,ammo[0],weapon1,ammo[1]);//formatting the string with the values we got

ShowPlayerDialog(playerid, 55, DIALOG_STYLE_MSGBOX, "Weapon Info", string, "Okay", ""); //showing the dialogue with that string 
//==////
was that more simple? what do you not understand exactly??


Re: GetPlayerWeaponData - Kane - 16.12.2017

Quote:
Originally Posted by RogueDrifter
Посмотреть сообщение
...
Stop.