GetPlayerWeaponData
#1

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

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 
0<= 12i++)
{
    
GetPlayerWeaponData(playeridiweapons[i][0], weapons[i][1]);

weapons[i][0]” holds their weapon ID and “weapons[i][1]” holds the ammo.

PHP код:
new
    
weapon_idammow_string[128]
;
for(new 
i13i++) // 0-12; 
{
    
GetPlayerWeaponData(playeridiweapon_idammo);
    
    
format(w_stringsizeof w_string"Weapon ID: %i, Ammo: %i"weapon_idammo);
    
SendClientMessage(playerid, -1w_string);

You understandin?
Reply
#3

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 
0<= 12i++)
{
    
GetPlayerWeaponData(playeridiweapons[i][0], weapons[i][1]);

weapons[i][0]” holds their weapon ID and “weapons[i][1]” holds the ammo.

PHP код:
new
    
weapon_idammow_string[128]
;
for(new 
i13i++) // 0-12; 
{
    
GetPlayerWeaponData(playeridiweapon_idammo);
    
    
format(w_stringsizeof w_string"Weapon ID: %i, Ammo: %i"weapon_idammo);
    
SendClientMessage(playerid, -1w_string);

You understandin?
Kinda'. Say, how do you do that with dialogs?
Reply
#4

PHP код:
stock list_weapons(playerid)
{
    new 
wep_list[256], wep_holder[128];
    new 
weapon_idweapon_ammo
    
    for(new 
i13i++){
        
        
GetPlayerWeaponData(playeridiweapon_idweapon_ammo);
        
        if(
weapon_id != 0)
        {
            
format(wep_holdersizeof wep_holder"Wep ID: %i - Ammo: %i\n"weapon_idweapon_ammo); 
            
strcat(wep_listwep_holder); 
        }
    }
    
ShowPlayerDialog(playerid0DIALOG_STYLE_LIST"Caption"wep_list"<<"">>"); 
    return 
1;

Is a way.
Reply
#5

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(playerid2weapon[0], ammo[0]);
    
GetPlayerWeaponData(playerid3weapon[1], ammo[1]);
    
GetPlayerWeaponData(playerid4weapon[2], ammo[2]);
    
GetPlayerWeaponData(playerid5weapon[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], weapon0sizeof(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(playerid55DIALOG_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.
Reply
#6

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
Reply
#7

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.
Reply
#8

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.
Reply
#9

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], weapon0sizeof(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(playerid55DIALOG_STYLE_MSGBOX"Weapon Info"string"Okay"""); //showing the dialogue with that string 
//==////
was that more simple? what do you not understand exactly??
Reply
#10

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


Forum Jump:


Users browsing this thread: 1 Guest(s)