This is giving me the same weapon 12 times.
#1

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.
Reply
#2

Can you show the code that storing data in PlayerWeapons ?
Reply
#3

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);
                }
Reply
#4

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); "
Reply
#5

I'm 100% sure.
Reply
#6

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

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.
Reply
#8

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

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.
Reply
#10

They are loaded from MySQL.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)