SA-MP Forums Archive
This is giving me the same weapon 12 times. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: This is giving me the same weapon 12 times. (/showthread.php?tid=505040)



This is giving me the same weapon 12 times. - Dokins - 06.04.2014

pawn Код:
for(new w = 0; w < 13; w++)
                {
                        new id = PlayerWeapons[playerid][w];
                        printf("WeaponID: %d", id);
                        if(WepAmmo[id] > 0)
                        {
                            GivePlayerWeapon(playerid,WepModel[id],WepAmmo[id]);
                            printf("Weapon: %d, Ammo: %d", WepModel[id], WepAmmo[id]);
                        }

                }

The PlayerWeapons[playerid][w] is the WeaponSQLID.

It's already loaded into this variable.

PlayerWeapons[playerid][13] is the amount.

I want it to give the weapon and ammo once, but it gives 12 times.


Re: This is giving me the same weapon 12 times. - MyLife - 06.04.2014

Can you show the code that storing data in PlayerWeapons ?


Re: This is giving me the same weapon 12 times. - Dokins - 06.04.2014

pawn Код:
for(new w=0; w < 13; w++)
                {
                    new string[12];
                    format(string, sizeof(string), "Weapon%d", w);
                    mysql_get_field(string, QueryString);
                    PlayerWeapons[playerid][w] = strval(QueryString);
                }



Re: This is giving me the same weapon 12 times. - MyLife - 06.04.2014

Quote:
Originally Posted by Dokins
Посмотреть сообщение
pawn Код:
for(new w=0; w < 13; w++)
                {
                    new string[12];
                    format(string, sizeof(string), "Weapon%d", w);
                    mysql_get_field(string, QueryString);
                    PlayerWeapons[playerid][w] = strval(QueryString);
                }
Are you sure it load correctly ?

Try to show output of " printf("WeaponID: %d", id); "


Re: This is giving me the same weapon 12 times. - Dokins - 06.04.2014

I'm 100% sure.


Re: This is giving me the same weapon 12 times. - MyLife - 06.04.2014

Wanna see output "
pawn Код:
printf("Weapon: %d, Ammo: %d", WepModel[id], WepAmmo[id]);
//and
printf("WeaponID: %d", id);
Can you show me ?


Re: This is giving me the same weapon 12 times. - Dokins - 06.04.2014

pawn Код:
[18:49:43] Weapon: 22, Ammo: 250
[18:49:43] WeaponID: 0
[18:49:43] Weapon: 22, Ammo: 250
[18:49:43] WeaponID: 1
[18:49:43] WeaponID: 0
[18:49:43] Weapon: 22, Ammo: 250
[18:49:43] WeaponID: 0
[18:49:43] Weapon: 22, Ammo: 250
[18:49:43] WeaponID: 0
[18:49:43] Weapon: 22, Ammo: 250
[18:49:43] WeaponID: 0
[18:49:43] Weapon: 22, Ammo: 250
[18:49:43] WeaponID: 0
[18:49:43] Weapon: 22, Ammo: 250
[18:49:43] WeaponID: 0
[18:49:43] Weapon: 22, Ammo: 250
[18:49:43] WeaponID: 0
[18:49:43] Weapon: 22, Ammo: 250
[18:49:43] WeaponID: 0
[18:49:44] Weapon: 22, Ammo: 250
[18:49:44] WeaponID: 0
[18:49:44] Weapon: 22, Ammo: 250
[18:49:44] WeaponID: 0
[18:49:44] Weapon: 22, Ammo: 250
The weapon ID should be 1.


Re: This is giving me the same weapon 12 times. - Mattakil - 06.04.2014

The loop is set to give the gun less than 13 times, which gives it 12 times. Don't use the loop.


Re: This is giving me the same weapon 12 times. - MyLife - 06.04.2014

I don't understand about your variables value.

PlayerWeapons is not a weapon id ? Is it a boolean ( 1 Or 0 ) ?

WepModel and WepAmmo is script defined value ? Not load from mysql ?

I suggest to use PlayerWeapons and PlayerAmmos for store value.

Example
pawn Код:
for(new w=0; w < 13; w++)
                {
                    new string[12];
                    format(string, sizeof(string), "Weapon%d", w);
                    mysql_get_field(string, QueryString);
                    PlayerWeapons[playerid][w] = strval(QueryString); //this should be weapon id
                    format(string, sizeof(string), "Ammo%d", w);
                    mysql_get_field(string, QueryString);
                    PlayerAmmo[playerid][w] = strval(QueryString);
                }

// And give weapon to  player.

for(new w = 0; w < 13; w++)
                {

                        if(PlayerAmmo[playerid][w] > 0)
                        {
                            GivePlayerWeapon(playerid,PlayerWeapons[playerid][w],PlayerAmmo[playerid][w]);

                        }// this would work.



Re: This is giving me the same weapon 12 times. - Dokins - 06.04.2014

They are loaded from MySQL.