Weapons problem
#1

Hello. I have a question related to the weapons and their ammo. I am using my command /agiveweapon to give myself a weapon. Lets say I have given myself an AK-47 with 5 ammo. I shoot five times and the weapon disappears. When I log out and log back in, the weapon is back with 5 ammo. I tried adding ResetPlayerWeapons to OnPlayerDisconnect, but didnt help. Any ideas?
Reply
#2

Well, are you saving weapons with ammo inside any callback?
Reply
#3

Here. This is the stock I am using for spawning the weapons.
pawn Код:
stock GiveAdminSpawnedWeapon(playerid, weaponid, ammo)
{
    GunsBeingRemoved[playerid] = 1;
    PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
    if(weaponid == 0 || weaponid == 1)
    { // Slot 0
        GunsBeingRemoved[playerid] = 1;
        PlayerInfo[playerid][pGun00] = weaponid;
        PlayerInfo[playerid][pAmmo00] = ammo;
        GunsBeingRemoved[playerid] = 1;
    }
    else if(weaponid == 2 || weaponid == 3 || weaponid == 4 || weaponid == 5 || weaponid == 6 || weaponid == 7 || weaponid == 8 || weaponid == 9)
    { // Slot 1
        GunsBeingRemoved[playerid] = 1;
        PlayerInfo[playerid][pGun01] = weaponid;
        PlayerInfo[playerid][pAmmo01] = ammo;
        GunsBeingRemoved[playerid] = 1;
    }
    else if(weaponid == 22 || weaponid == 23 || weaponid == 24)
    { // Slot 2
        GunsBeingRemoved[playerid] = 1;
        PlayerInfo[playerid][pGun02] = weaponid;
        PlayerInfo[playerid][pAmmo02] = ammo;
        GunsBeingRemoved[playerid] = 1;
    }
    else if(weaponid == 25 || weaponid == 26 || weaponid == 27)
    { // Slot 3
        GunsBeingRemoved[playerid] = 1;
        PlayerInfo[playerid][pGun03] = weaponid;
        PlayerInfo[playerid][pAmmo03] = ammo;
        GunsBeingRemoved[playerid] = 1;
    }
    else if(weaponid == 28 || weaponid == 29 || weaponid == 32)
    { // Slot 4
        GunsBeingRemoved[playerid] = 1;
        PlayerInfo[playerid][pGun04] = weaponid;
        PlayerInfo[playerid][pAmmo04] = ammo;
        GunsBeingRemoved[playerid] = 1;
    }
    else if(weaponid == 30 || weaponid == 31)
    { // Slot 5
        GunsBeingRemoved[playerid] = 1;
        PlayerInfo[playerid][pGun05] = weaponid;
        PlayerInfo[playerid][pAmmo05] = ammo;
        GunsBeingRemoved[playerid] = 1;
    }
    else if(weaponid == 33 || weaponid == 34)
    { // Slot 6
        GunsBeingRemoved[playerid] = 1;
        PlayerInfo[playerid][pGun06] = weaponid;
        PlayerInfo[playerid][pAmmo06] = ammo;
        GunsBeingRemoved[playerid] = 1;
    }
    else if(weaponid == 35 || weaponid == 36 || weaponid == 37 || weaponid == 38)
    { // Slot 7
        GunsBeingRemoved[playerid] = 1;
        PlayerInfo[playerid][pGun07] = weaponid;
        PlayerInfo[playerid][pAmmo07] = ammo;
        GunsBeingRemoved[playerid] = 1;
    }
    else if(weaponid == 16 || weaponid == 17 || weaponid == 18 || weaponid == 39)
    { // Slot 8
        GunsBeingRemoved[playerid] = 1;
        PlayerInfo[playerid][pGun08] = weaponid;
        PlayerInfo[playerid][pAmmo08] = ammo;
        GunsBeingRemoved[playerid] = 1;
    }
    else if(weaponid == 41 || weaponid == 42 || weaponid == 43)
    { // Slot 9
        GunsBeingRemoved[playerid] = 1;
        PlayerInfo[playerid][pGun09] = weaponid;
        PlayerInfo[playerid][pAmmo09] = ammo;
        GunsBeingRemoved[playerid] = 1;
    }
    else if(weaponid == 10 || weaponid == 11 || weaponid == 12 || weaponid == 13 || weaponid == 14 || weaponid == 15)
    { // Slot 10
        GunsBeingRemoved[playerid] = 1;
        PlayerInfo[playerid][pGun10] = weaponid;
        PlayerInfo[playerid][pAmmo10] = ammo;
        GunsBeingRemoved[playerid] = 1;
    }
    else if(weaponid == 44 || weaponid == 45 || weaponid == 46)
    { // Slot 11
        GunsBeingRemoved[playerid] = 1;
        PlayerInfo[playerid][pGun11] = weaponid;
        PlayerInfo[playerid][pAmmo11] = ammo;
        GunsBeingRemoved[playerid] = 1;
    }
    GivePlayerWeapon(playerid, weaponid, ammo);
    return 1;
}
The command itself.
pawn Код:
CMD:agiveweapon(playerid, params[])
{
    if(PlayerInfo[playerid][AdminLevel] >= 3)
    {
        new targetid, gunid, ammo, string[128];
        if(sscanf(params, "uii", targetid, gunid, ammo)) return SendClientMessage(playerid, GREY, "USAGE: /agiveweapon [playerid] [weaponid] [ammo]");
        if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, GREY, NotConnected);
        if(gunid < 0 || gunid == 19 || gunid == 20 || gunid == 21) return SendClientMessage(playerid, GREY, "Invalid Weapon id.");
        GiveAdminSpawnedWeapon(targetid, gunid, ammo);
        format(string, sizeof(string), " You have given %s a %s with %d ammo.", TInfo(targetid), GInfo(gunid), ammo);
        SendClientMessage(playerid, LIBLUE, string);
        format(string, sizeof(string), " Administrator %s has given you a %s with %d ammo.", TInfo(targetid), GInfo(gunid), ammo);
        SendClientMessage(targetid, LIBLUE, string);
    }
    return 1;
}
I dont think I have anything to update the ammo. Here is the way I save weapons and their ammo.
pawn Код:
INI_WriteInt(File,"Gun00",PlayerInfo[playerid][pGun00]);
    INI_WriteInt(File,"Gun01",PlayerInfo[playerid][pGun01]);
    INI_WriteInt(File,"Gun02",PlayerInfo[playerid][pGun02]);
    INI_WriteInt(File,"Gun03",PlayerInfo[playerid][pGun03]);
    INI_WriteInt(File,"Gun04",PlayerInfo[playerid][pGun04]);
    INI_WriteInt(File,"Gun05",PlayerInfo[playerid][pGun05]);
    INI_WriteInt(File,"Gun06",PlayerInfo[playerid][pGun06]);
    INI_WriteInt(File,"Gun07",PlayerInfo[playerid][pGun07]);
    INI_WriteInt(File,"Gun08",PlayerInfo[playerid][pGun08]);
    INI_WriteInt(File,"Gun09",PlayerInfo[playerid][pGun09]);
    INI_WriteInt(File,"Gun10",PlayerInfo[playerid][pGun10]);
    INI_WriteInt(File,"Gun11",PlayerInfo[playerid][pGun11]);
    INI_WriteInt(File,"Ammo00",PlayerInfo[playerid][pAmmo00]);
    INI_WriteInt(File,"Ammo01",PlayerInfo[playerid][pAmmo01]);
    INI_WriteInt(File,"Ammo02",PlayerInfo[playerid][pAmmo02]);
    INI_WriteInt(File,"Ammo03",PlayerInfo[playerid][pAmmo03]);
    INI_WriteInt(File,"Ammo04",PlayerInfo[playerid][pAmmo04]);
    INI_WriteInt(File,"Ammo05",PlayerInfo[playerid][pAmmo05]);
    INI_WriteInt(File,"Ammo06",PlayerInfo[playerid][pAmmo06]);
    INI_WriteInt(File,"Ammo07",PlayerInfo[playerid][pAmmo07]);
    INI_WriteInt(File,"Ammo08",PlayerInfo[playerid][pAmmo08]);
    INI_WriteInt(File,"Ammo09",PlayerInfo[playerid][pAmmo09]);
    INI_WriteInt(File,"Ammo10",PlayerInfo[playerid][pAmmo10]);
    INI_WriteInt(File,"Ammo11",PlayerInfo[playerid][pAmmo11]);
Reply
#4

Why the need of loading the info into \ variables?

Load the info in local variables, give the weapons (GivePlayerWeapon). Then when the user disconnects, save the weapons with the ammo (GetPlayerWeaponData).
Reply
#5

If someone is able to help me with this one, feel free to do it.
Reply
#6

Loading the weapons correctly?
If so, how we can help you?
Reply
#7

I explained the problem above, its running out of ammo and when I relog, the ammo is back.
Reply
#8

As easy as it sounds:

Код:
SavePlayerWeaponData(playerid) // save the data on disconnect
{
	new 
		weaponid,
		ammo,
		string[10]
	;

	for (new i = 0; i != 13; i++)
	{
		GetPlayerWeaponData(playerid, i, weaponid, ammo);

		if(!weaponid)
			continue;

		format(string, sizeof (string), "Gun%02i", i);
		INI_WriteInt(File, string, weaponid);

		format(string, sizeof (string), "Ammo%02i", i)
	    INI_WriteInt(File, string, ammo);
	}
}

// Load the data on first spawn

	new 
		weaponid,
		ammo,
		string[10]
	;

	for (new i = 0; i != 13; i++)
	{
		format(string, sizeof (string), "Gun%02i", i);
		INI_Int(string, weaponid);
		format(string, sizeof (string), "Ammo%02i", i)
	    INI_Int(string, ammo);

	    GivePlayerWeapon(playerid, weaponid, ammo);
	}
}
Reply
#9

You must delete this value of the variable if the weapon is empty.
Put this into OnPlayerWeaponShot:
PHP код:
new Waffe[7],Ammo[8];
for(new 
i;i<12;i++)
{
    if(
10 && > -1)
    {
        
format(Waffe,sizeof Waffe,"pGun0%i",i);
        
format(Ammo,sizeof Ammo,"pAmmo0%i",i);
    }
    else if(
>= 10)
    {
        
format(Waffe,sizeof Waffe,"pGun%i",i);
        
format(Ammo,sizeof Ammo,"pAmmo%i",i);
    }
    if(
PlayerInfo[playerid][Waffe] == weaponid)
    {
        if(
PlayerInfo[playerid][Ammo] > 0)
        {
            
PlayerInfo[playerid][Ammo] --;
        }
        if(
PlayerInfo[playerid][Ammo] == 0)
        {
            
PlayerInfo[playerid][Ammo] = 0;
            
PlayerInfo[playerid][Waffe] = 0;
        }
    }

Maybe it is not the best solution but it work.
Reply
#10

Quote:
Originally Posted by Ralfie
Посмотреть сообщение
As easy as it sounds:

Код:
SavePlayerWeaponData(playerid) // save the data on disconnect
{
	new 
		weaponid,
		ammo,
		string[10]
	;

	for (new i = 0; i != 13; i++)
	{
		GetPlayerWeaponData(playerid, i, weaponid, ammo);

		if(!weaponid)
			continue;

		format(string, sizeof (string), "Gun%02i", i);
		INI_WriteInt(File, string, weaponid);

		format(string, sizeof (string), "Ammo%02i", i)
	    INI_WriteInt(File, string, ammo);
	}
}

// Load the data on first spawn

	new 
		weaponid,
		ammo,
		string[10]
	;

	for (new i = 0; i != 13; i++)
	{
		format(string, sizeof (string), "Gun%02i", i);
		INI_Int(string, weaponid);
		format(string, sizeof (string), "Ammo%02i", i)
	    INI_Int(string, ammo);

	    GivePlayerWeapon(playerid, weaponid, ammo);
	}
}
So, I created the stock. Added it OnPlayerDisconnect as it follows:
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    if(PlayerInfo[playerid][Registered])
    {
        if(Spawned[playerid])
        {
            SaveUser(playerid);
        }
    }
    new string[128];
    switch(reason)
    {
        case 0: format(string,sizeof string,"%s left the server. (Lost Connection)", RemoveUnderScore(playerid));
        case 1: format(string,sizeof string,"%s left the server.", RemoveUnderScore(playerid));
        case 2: format(string,sizeof string,"%s left the server. (Kicked/Banned)", RemoveUnderScore(playerid));
    }
    CloseMessage(playerid, GREY, string);
    SendAdminMessage(GREY, string);
    SavePlayerWeaponData(playerid);
    ResetPlayerWeapons(playerid);
    return 1;
}
It gave me the following errors:
pawn Код:
(1038) : error 017: undefined symbol "File"
(1041) : error 001: expected token: ";", but found "-identifier-"
(1041) : error 017: undefined symbol "File"
The lines 1038, 1041
pawn Код:
format(string, sizeof (string), "Gun%02i", i);
        INI_WriteInt(File, string, weaponid); // 1038

        format(string, sizeof (string), "Ammo%02i", i)
        INI_WriteInt(File, string, ammo); // 1041
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)