Textdraw and String issues.. GIVE REP
#1

Hello, on my serevr i am making a "You killed PLAYERNAMe with a GUNNAME" feature and its bugging a bit..

Here ismy code for it:

pawn Код:
new gunname[20], playername[15], string2[75];
   
    switch(reason){
        case 0,1,2,3:{
            format(gunname, sizeof(gunname), "Fist");
        }
        case 4:{
            format(gunname, sizeof(gunname), "Knife");
        }
        case 5,6,7,8,14,15:{
            format(gunname, sizeof(gunname), "Baseball Bat");
        }
        case 9:{
            format(gunname, sizeof(gunname), "Chainsaw");
        }
        case 10,11,12,13:{
            format(gunname, sizeof(gunname), "Dildo");
        }
        case 16,17,18:{
            format(gunname, sizeof(gunname), "Grenade");
        }
        case 22,23:{
            format(gunname, sizeof(gunname), "9mm Pistol");
        }
        case 24:{
            format(gunname, sizeof(gunname), "Deagle");
        }
        case 25:{
            format(gunname, sizeof(gunname), "Shotgun");
        }
        case 26:{
            format(gunname, sizeof(gunname), "Sawn Off Shotgun");
        }
        case 27:{
            format(gunname, sizeof(gunname), "Combat Shotgun");
        }
        case 28:{
            format(gunname, sizeof(gunname), "Uzi");
        }
        case 29:{
            format(gunname, sizeof(gunname), "Mp5");
        }
        case 30:{
            format(gunname, sizeof(gunname), "Ak47");
        }
        case 31:{
            format(gunname, sizeof(gunname), "M4");
        }
        case 32:{
            format(gunname, sizeof(gunname), "Tec-9");
        }
        case 33:{
            format(gunname, sizeof(gunname), "Rifle");
        }
        case 34:{
            format(gunname, sizeof(gunname), "Sniper");
        }
        case 35,36:{
            format(gunname, sizeof(gunname), "Rocket Launcher");
        }
        case 37:{
            format(gunname, sizeof(gunname), "Flamethrower");
        }
        case 38:{
            format(gunname, sizeof(gunname), "Minigun");
        }
        default:{
            format(gunname, sizeof(gunname), "Unknown");
        }
    }
    GetPlayerName(playerid, playername, sizeof(playername));

    format(string2, sizeof(string2), "You Killed %s with a %s.", playername, gunname);

    TextDrawSetString(KilledTD[0], string2);
   
    TextDrawShowForPlayer(killerid, KilledTD[0]);
    TextDrawShowForPlayer(killerid, KilledTD[1]);
    SetTimerEx("KilledTDTimer", 5000, false, "i", killerid);

...

forward KilledTDTimer(playerid);
public KilledTDTimer(playerid){
    TextDrawHideForPlayer(playerid, KilledTD[0]);
    TextDrawHideForPlayer(playerid, KilledTD[1]);
    return 1;
}
The thing is, I was tested it with my brother... I logged into the serevr on my laptop and he logged in on his computer... and when i killed him it worked perfectly everytime but when he killed me it DIDNT show the gunname...

We have no idea why this is happening...

thanks for any help!

NOTE: I know that i need to make the textdraw for MAX_PLAYERS.. we arnt worrying about that yet...
Reply
#2

https://sampwiki.blast.hk/wiki/GetWeaponName ?

Also you can assign literal strings to arrays directly. No need to format.
pawn Код:
gunname = "Fist";
Works perfectly fine.

Furthermore, playernames can be up to 24 characters long, so it might as well be an overflow issue.
Reply
#3

Thanks, Rep given... fixed the problem and learnt a few more things about strings
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)