16.12.2015, 16:04
Two workarounds available:
1. No sync (to be used only when needed):
2. Delay:
1. No sync (to be used only when needed):
pawn Код:
// ** INCLUDES
#include <a_samp>
#include <zcmd>
// ** VARIABLES
// *** PER-PLAYER VARIABLES
// **** GLOBAL
new pWeaponData[MAX_PLAYERS][2][13];
// ** MAIN
main()
{
print("Loaded \"get_player_weapon_data_no_sync.amx\".");
}
// ** CALLBACKS
public OnGameModeInit()
{
return 1;
}
public OnGameModeExit()
{
return 1;
}
// ** COMMANDS
CMD:weapondata1(playerid, params[])
{
new string[144], weapon_id[13], weapon_ammo[13];
GivePlayerWeapon_NoSync(playerid, 26, 500);
for(new i = 0; i < 13; i ++)
{
GetPlayerWeaponData_NoSync(playerid, i, weapon_id[i], weapon_ammo[i]);
format(string, sizeof(string), "Slot: %d - Weapon ID: %d - Ammo: %d", i, weapon_id[i], weapon_ammo[i]);
SendClientMessage(playerid, -1, string);
}
return 1;
}
CMD:weapondata2(playerid, params[])
{
new string[144], weapon_id[13], weapon_ammo[13];
GivePlayerWeapon_NoSync(playerid, 27, 500);
for(new i = 0; i < 13; i ++)
{
GetPlayerWeaponData_NoSync(playerid, i, weapon_id[i], weapon_ammo[i]);
format(string, sizeof(string), "Slot: %d - Weapon ID: %d - Ammo: %d", i, weapon_id[i], weapon_ammo[i]);
SendClientMessage(playerid, -1, string);
}
return 1;
}
// ** FUNCTIONS
stock GivePlayerWeapon_NoSync(playerid, weapon_id, weapon_ammo)
{
new weapon_data[2], slot = GetWeaponSlot(weapon_id);
GetPlayerWeaponData(playerid, slot, weapon_data[0], weapon_data[1]);
if(weapon_data[1] >= 1)
{
pWeaponData[playerid][1][slot] = weapon_data[1] + weapon_ammo;
}
else
{
pWeaponData[playerid][0][slot] = weapon_id;
pWeaponData[playerid][1][slot] = weapon_ammo;
}
return GivePlayerWeapon(playerid, weapon_id, weapon_ammo);
}
stock GetPlayerWeaponData_NoSync(playerid, slot, &weapon_id, &weapon_ammo)
{
weapon_id = pWeaponData[playerid][0][slot];
weapon_ammo = pWeaponData[playerid][1][slot];
return 1;
}
stock GetWeaponSlot(weaponid)
{
new slot;
switch(weaponid)
{
case 0, 1: slot = 0;
case 2, 3, 4, 5, 6, 7, 8, 9: slot = 1;
case 22, 23, 24: slot = 2;
case 25, 26, 27: slot = 3;
case 28, 29, 32: slot = 4;
case 30, 31: slot = 5;
case 33, 34: slot = 6;
case 35, 36, 37, 38: slot = 7;
case 16, 17, 18, 39: slot = 8;
case 41, 42, 43: slot = 9;
case 10, 11, 12, 13, 14, 15: slot = 10;
case 44, 45, 46: slot = 11;
case 40: slot = 12;
}
return slot;
}
pawn Код:
// ** INCLUDES
#include <a_samp>
#include <zcmd>
// ** VARIABLES
// *** PER-PLAYER VARIABLES
// **** TIMERS
new tmPrintPlayerWeaponData[MAX_PLAYERS];
// ** MAIN
main()
{
print("Loaded \"get_player_weapon_data_delay.amx\".");
}
// ** CALLBACKS
public OnGameModeInit()
{
return 1;
}
public OnGameModeExit()
{
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
KillTimer(tmPrintPlayerWeaponData[playerid]);
return 1;
}
// ** COMMANDS:
CMD:weapondata(playerid, params[])
{
GivePlayerWeapon(playerid, 24, 300);
GivePlayerWeapon(playerid, 25, 300);
GivePlayerWeapon(playerid, 31, 300);
tmPrintPlayerWeaponData[playerid] = SetTimerEx("PrintPlayerWeaponData", 500, false, "i", playerid);
return 1;
}
// ** FUNCTIONS
forward PrintPlayerWeaponData(playerid);
public PrintPlayerWeaponData(playerid)
{
new string[144], weapon_id[13], weapon_ammo[13];
for(new i = 0; i < 13; i ++)
{
GetPlayerWeaponData(playerid, i, weapon_id[i], weapon_ammo[i]);
format(string, sizeof(string), "Slot: %d - Weapon ID: %d - Ammo: %d", i, weapon_id[i], weapon_ammo[i]);
SendClientMessage(playerid, -1, string);
}
return 1;
}