Some error inside cycle.
#1

Hey there,
i have something like this(ignore the language, im from Slovakia ):
pawn Код:
new gWeaponNames[][] = {
    {"Pest",0},
    {"Boxer",1},
    {"Golf",2},
    {"Obusok",3},
    {"Noz",4},
    {"Baseball",5},
    {"Lopata",6},
    {"Tago",7},
    {"Katana",8},
    {"Motorovka",9},
    {"Dildo",10},
    {"SmallVibrator",11},
    {"LargeVibrator",12},
    {"SilverVibrator",13},
    {"Kvety",14},
    {"Palica",15},
    {"Granat",16},
    {"Dymovnica",17},
    {"Molotov",18},
    {"Pistol",22},
    {"TlmenaPistol",23},
    {"Deagle",24},
    {"Brokovnica",25},
    {"Upilka",26},
    {"Spas12",27},
    {"MicroSMG",28},
    {"MP5",29},
    {"AK-47",30},
    {"M4",31},
    {"Tec9",32},
    {"Puska",33},
    {"Sniperka",34},
    {"Raketomet",35},
    {"Plamenomet",37},
    {"Minigun",38},
    {"C4",39},
    {"Detonator",40},
    {"Spray",41},
    {"Hasicak",42},
    {"Fotak",43},
    {"NocneVidenie",44},
    {"TermalneVidenie",45},
    {"Padak",46}
};
for(new i=0;i<sizeof(gWeaponNames);i++)
{
   if(strcmp(Weapon,gWeaponNames[i][0],true)==0)
   {
    model=gWeaponNames[i][1];
    break;
    }
}
return 1;
And, when i set "Weapon" to eg. "Deagle", it sets "model" to "101"... Does someone have any idea, how to slove it?
Thanks so much
Reply
#2

try to switch to this
pawn Код:
new
      gWeaponNames[ 38 ] [ ]
instead of

pawn Код:
new gWeaponNames[][]
Reply
#3

Nothing happens
Reply
#4

maybe switching
pawn Код:
for(new i = 0; i < sizeof (gWeaponNames); i++)
to
pawn Код:
for(new i = 0; i < gWeaponNames; i++)
Reply
#5

i dont think so, i think array must be indexed :\
Reply
#6

Enum fixed it.
But there is another problem. This is my command:

pawn Код:
dcmd_giveweapon(playerid,params[])
    {
        new
            ID,
            Weapon[50],
            Ammo,
            model=666
        ;
        sscanf(params,"us[50]I(100000)",ID,Weapon,Ammo)
        printf("ID: %d | Weapon: %s | Ammo: %d",ID,Weapon,Ammo);
        new i=0;
        while(i<=sizeof(gWeaponNames))
        {
            if(strcmp(Weapon,gWeaponNames[i][z_nazov],true)==0)
            {
                model=i;
                break;
            }else i++;
        }
        model=gWeaponNames[model][z_id];
        if(model==666)
        {
            new zbran=strval(Weapon);
            if((zbran>=0 && zbran <= 47) && (zbran!=19 && zbran!= 20 && zbran!= 21))
            {
                model=zbran;
            }
        }
        if(model==666) return SCM(playerid,red,"Bad gun ID or name!");
        printf("ID: %d | Model: %d | Ammo: %d",ID,model,Ammo);
        GivePlayerWeapon(ID,model,Ammo);
        return 1;
    }
i removed some returns like "Bad player ID", "No params" etc, i don't want to translate it now

So, this works perfectly. But, when i type eg. "deaglec" (some error in name), it doesnt return "Bad gun ID or name!", but "Server: Unknown command". Some ideas?
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)