GetWeaponName acting up?
#1

pawn Code:
new str1[800],str2[64];
new prim[12],secon[12],melee[12],spec[12],armor[12];

GetWeaponName(FactionInfo[factionid][fClass1Primary],prim,sizeof(prim));
GetWeaponName(FactionInfo[factionid][fClass1Secondary],secon,sizeof(secon));
GetWeaponName(FactionInfo[factionid][fClass1Melee],melee,sizeof(melee));
GetWeaponName(FactionInfo[factionid][fClass1Special],spec,sizeof(spec));
switch(FactionInfo[factionid][fClass1Armor]) {
    case 25: format(armor,sizeof(armor),"Stab vest");
    case 50: format(armor,sizeof(armor),"Half body armor");
    case 100: format(armor,sizeof(armor),"Full body armor");
}

format(str1,sizeof(str1),"Rename class\nRank restriction (Current: %s)\nChange primary (Current: %s)\nChange secondary (Current: %s)\nChange melee (Current: %s)\nChange special (Current: %s)\nChange armor (Current: %s)",GetFactionRankName(factionid,FactionInfo[factionid][fClass1Rank]),prim,secon,melee,spec,armor);
format(str2,sizeof(str2),"Class %i - %s",classid,FactionInfo[factionid][fClass1Name]);

ShowPlayerDialog(playerid,DIALOG_FCLASSEDIT,DIALOG_STYLE_LIST,str2,str1,"Select","Back");
Can anyone spot anything wrong with this bit of code? Specifically the name fetching and formatting; the "(Current: %s)" in the primary weapon slot and sometimes the secondary refuse to display anything. They print "(null)" in the console, but the ID is set correctly, because I receive the correct weapon when I equip the class.

I'm aware of the few weapon IDs that GetWeaponName is incompatible with, but I'm not using those.

Edit: fixed this for the time being with a custom weapon name function:
pawn Code:
stock GetGunName(gunid)
{
    new res[24];
    switch(gunid) {
        case 0: format(res,sizeof(res),"Fist");
        case 1: format(res,sizeof(res),"Brass Knuckles");
        case 2: format(res,sizeof(res),"Golf Club");
        case 3: format(res,sizeof(res),"Nightstick");
        case 4: format(res,sizeof(res),"Knife");
        case 5: format(res,sizeof(res),"Baseball Bat");
        case 6: format(res,sizeof(res),"Shovel");
        case 7: format(res,sizeof(res),"Pool Cue");
        case 8: format(res,sizeof(res),"Katana");
        case 9: format(res,sizeof(res),"Chainsaw");
        case 10: format(res,sizeof(res),"Double-ended Dildo");
        case 11: format(res,sizeof(res),"Dildo");
        case 12: format(res,sizeof(res),"Vibrator");
        case 13: format(res,sizeof(res),"Silver Vibrator");
        case 14: format(res,sizeof(res),"Flowers");
        case 15: format(res,sizeof(res),"Cane");
        case 16: format(res,sizeof(res),"Grenade");
        case 17: format(res,sizeof(res),"Tear Gas");
        case 18: format(res,sizeof(res),"Molotov Cocktail");
        case 22: format(res,sizeof(res),"9mm Pistol");
        case 23: format(res,sizeof(res),"Silenced 9mm Pistol");
        case 24: format(res,sizeof(res),"Desert Eagle");
        case 25: format(res,sizeof(res),"Pump Shotgun");
        case 26: format(res,sizeof(res),"Sawnoff Shotgun");
        case 27: format(res,sizeof(res),"Combat Shotgun");
        case 28: format(res,sizeof(res),"Uzi");
        case 29: format(res,sizeof(res),"MP5");
        case 30: format(res,sizeof(res),"AK-47");
        case 31: format(res,sizeof(res),"M4");
        case 32: format(res,sizeof(res),"Tec-9");
        case 33: format(res,sizeof(res),"Country Rifle");
        case 34: format(res,sizeof(res),"Sniper Rifle");
        case 35: format(res,sizeof(res),"RPG");
        case 36: format(res,sizeof(res),"Heat Seeker");
        case 37: format(res,sizeof(res),"Flamethrower");
        case 38: format(res,sizeof(res),"Minigun");
        case 39: format(res,sizeof(res),"Satchel Charge");
        case 40: format(res,sizeof(res),"Detonator");
        case 41: format(res,sizeof(res),"Pepper Spray");
        case 42: format(res,sizeof(res),"Fire Extinguisher");
        case 43: format(res,sizeof(res),"Camera");
        case 44: format(res,sizeof(res),"Night Vision Goggles");
        case 45: format(res,sizeof(res),"Thermal Goggles");
        case 46: format(res,sizeof(res),"Parachute");
        default: format(res,sizeof(res),"Unknown");
    }
    return res;
}
Reply
#2

Lol, that GetGunName is so unoptimized. You do 40+ conditions to get only one weapon name :/

I wrote this for u

pawn Code:
new GunName[47][20] =
{
    "Fist","Brass Knuckles","Golf Club","Nightstick","Knife","Basebal Bat","Shovel","Pool Cue","Katana","Chainsaw","Double-ended Dildo","Dildo","Vibrator",
    "Silver Vibrator","Flowers","Cane","Grenade","Tear Gas","Molotv Cocktail","?","?","?","9mm","Silenced 9mm","Desert Eagle","Shotgun","Sawnoff-Shotgun",
    "Combat Shotgun","Micro-SMG","MP5","Ak-47","M4","Tec9","Country Rifle","Sniper Rifle","RPG","HS-RPG","Flame-Thrower","Minigun","Satchel Charge","Detonator",
    "Spray Can","Fire Extinguisher","Camera","Night Goggles","Thermal Goggles","Parachute"
};

// Example of use:

CMD:mygun(playerid)
{
    new text[48];
    format(text,sizeof text,"You've got a nice: {FFFFFF}%s",GunName[GetPlayerWeapon(playerid)]);
    SendClientMessage(playerid,0xFFDD22FF,text);
    return 1;
}
And you don't need to format a string, if you will not use placeholders.

You cant just do:
pawn Code:
new var[30] = "Var Test";
// or

new var[35];
switch(playerid)
{
    case 0: var = "First Player!";
    case 1: var = "Second Player!";
    default: var = "You're not first neither second :/";
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)