Save ammo and then set it
#1

Hello!

I need some help. How do I save the ammo when they change the weapon and then set it back when they change back to the previous weapon? And save the ammo of ALL the weapons then set it back when they change the weapon.
Example: I have an AK47, I change to MP5 and it saves my AK47 ammo. When I change back to AK47, it sets my ammo to the previous. And I mean the rounds REMAINING to shoot out, not the whole equipment.
I tried some stuff with OnPlayerUpdate - failed.
Reply
#2

new weapons[13],ammo[13];

for(new i = 0;i<13;i++){
GetPlayerWeaponData(playerid,i,weapons[i],ammo[i]);}

You must Get first Weapon Data, then you can Use Variables to Save, easy

Reply
#3

But I think when I'll set the player's ammo back, it will set the amount of the whole "equipment", not just the remaining rounds.
Reply
#4

Quote:
Originally Posted by SpiderPork
But I think when I'll set the player's ammo back, it will set the amount of the whole "equipment", not just the remaining rounds.
Код:
new weapons[13],ammo[13];
for(new i = 0;i<13;i++){
GetPlayerWeaponData(playerid,i,weapons[i],ammo[i]);}
Not really, check the slots of the weapon and then the weapon is < weapons[SLOT] >
Check the weapon slots at the weapon list on the wiki.
Reply
#5

I don't understand this at all. I never ever worked with GetPlayerWeaponData.
Could anyone make just an example of how to save and set it back?
Reply
#6

how to make a loadweapondata when player joins the server
Reply
#7

Quote:
Originally Posted by Derksen123
how to make a loadweapondata when player joins the server
Well provided you're already using a save script and you have the weapon values saved, you'll want to use SetPlayerAmmo and GivePlayerWeapon.
Reply
#8

pawn Код:
new bullets[MAX_PLAYERS][12];
new weapons[MAX_PLAYERS][12];
GetPlayerWeaponData(playerid,1,weapons[playerid][0],bullets[playerid][0]);
GetPlayerWeaponData(playerid,2,weapons[playerid][1],bullets[playerid][1]);
GetPlayerWeaponData(playerid,3,weapons[playerid][2],bullets[playerid][2]);
GetPlayerWeaponData(playerid,4,weapons[playerid][3],bullets[playerid][3]);
GetPlayerWeaponData(playerid,5,weapons[playerid][4],bullets[playerid][4]);
GetPlayerWeaponData(playerid,6,weapons[playerid][5],bullets[playerid][5]);
GetPlayerWeaponData(playerid,7,weapons[playerid][6],bullets[playerid][6]);
GetPlayerWeaponData(playerid,8,weapons[playerid][7],bullets[playerid][7]);
GetPlayerWeaponData(playerid,9,weapons[playerid][8],bullets[playerid][8]);
GetPlayerWeaponData(playerid,10,weapons[playerid][9],bullets[playerid][9]);
GetPlayerWeaponData(playerid,11,weapons[playerid][10],bullets[playerid][10]);
GetPlayerWeaponData(playerid,12,weapons[playerid][11],bullets[playerid][11]);

//Gets the player's weapons for each slot and the ammo of it.
//You would need to also define the playerid for the weapons+bullets if you wanted to give the player these weapons at a later time
then to give the saved weapons:
pawn Код:
if(weapons[playerid][0]!=0)GivePlayerWeapon(playerid,weapons[playerid][0],bullets[playerid][0]);
if(weapons[playerid][1]!=0)GivePlayerWeapon(playerid,weapons[playerid][1],bullets[playerid][1]);
if(weapons[playerid][2]!=0)GivePlayerWeapon(playerid,weapons[playerid][2],bullets[playerid][2]);
if(weapons[playerid][3]!=0)GivePlayerWeapon(playerid,weapons[playerid][3],bullets[playerid][3]);
if(weapons[playerid][4]!=0)GivePlayerWeapon(playerid,weapons[playerid][4],bullets[playerid][4]);
if(weapons[playerid][5]!=0)GivePlayerWeapon(playerid,weapons[playerid][5],bullets[playerid][5]);
if(weapons[playerid][6]!=0)GivePlayerWeapon(playerid,weapons[playerid][6],bullets[playerid][6]);
if(weapons[playerid][7]!=0)GivePlayerWeapon(playerid,weapons[playerid][7],bullets[playerid][7]);
if(weapons[playerid][8]!=0)GivePlayerWeapon(playerid,weapons[playerid][8],bullets[playerid][8]);
if(weapons[playerid][9]!=0)GivePlayerWeapon(playerid,weapons[playerid][9],bullets[playerid][9]);
if(weapons[playerid][10]!=0)GivePlayerWeapon(playerid,weapons[playerid][10],bullets[playerid][10]);
if(weapons[playerid][11]!=0)GivePlayerWeapon(playerid,weapons[playerid][11],bullets[playerid][11]);
Reply
#9

http://forum.sa-mp.com/index.php?topic=76543.0
http://forum.sa-mp.com/index.php?topic=104807.0

After 2 seconds of searching -.-
Reply
#10

You don't understand me. Anyways:

1.) Why bump an old topic.
2.) I already found out that there is no function to set the ammount of ammo in the MAGAZINE.
3.) I don't want it to save on player's disconnect, I want it to save when a player changes the weapon and set it back when they change back.
4.) Lock this topic.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)