16.12.2017, 07:50
I'm kinda confused with GetPlayerWeaponData. Could someone send an example, listing every weapon and ammo the player has using this function?
// 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]);
}
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);
}
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 код:
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;
}
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;
}
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", "");
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.
|
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