Worst code snippets you encountered
#1

Quite often I'm hired to "fix lag", or some "minor" stuff. I'm not perfect too, but well, the things I've seen... Well, it might seem minor for players, but when you have to dissect the code, you can see the beast inside.

Number 1: Whole Raven's RP

pawn Код:
enum pInfo
{
    //(...)
    pAchievement0,
    pAchievement1,
    pAchievement2,
    pAchievement3,
    pAchievement4,
    pAchievement5,
    pAchievement6,
    pAchievement7,
    pAchievement8,
    pAchievement9,
    pAchievement10,
    pAchievement11,
    pAchievement12,
    pAchievement13,
    pAchievement14,
    pAchievement15,
    pAchievement16,
    pAchievement17,
    pAchievement18,
    pAchievement19,
    pAchievement20,
    pShiftName,
    pWeapon,
    pWeapon2,
    pWeapon3,
    pWeapon4,
    pWeapon5,
    pWeapon6,
    pWeapon7,
    pWeapon8,
    pWeapon9,
    pWeapon10,
    pWeapon11,
    pWeapon12,
    pAmmo,
    pAmmo2,
    pAmmo3,
    pAmmo4,
    pAmmo5,
    pAmmo6,
    pAmmo7,
    pAmmo8,
    pAmmo9,
    pAmmo10,
    pAmmo11,
    pAmmo12,
    //(...)
}
Arrays? What's that?

pawn Код:
new RandomFemaleSkins[][] =
{
    {9},{10},{11},{38},{39},{40},{54},{55},{56},{63},{64},{75},{76},{77},
    {85},{87},{88},{90},{93},{131},{130},{138},{139},{141},{145},{148},{149},
    {152},{157},{169},{172},{178},{190},{192},{193},{194},{199},{198},{201},
    {207},{211},{215},{219},{225},{226},{233},{237},{244},{246},{251},{257},
    {263}
};
Oh, I remember now!

Between poor design decisions and stuff, that's a little sad that it's one of the most popular GM's. But I'm not a player, so maybe features outweight other things. Maybe.

2. Some other things
pawn Код:
new DBResult:result = db_query(ServerDB, "SELECT * FROM `PermCars`");
id = db_num_rows(result) + 1;
format(string, sizeof(string), "SELECT * FROM `PermCars` WHERE `PermCarID` = '%d'", id);
dbResult[0] = db_query(ServerDB, string);
if (db_num_rows(dbResult[0]) != 0)
{
    //  That ID exists... let's keep finding one that doesn't exist then.
    while (!found && attempts++ != 50)
    {
        id++;
        format(string, sizeof(string), "SELECT * FROM `PermCars` WHERE `PermCarID` = '%d'", id);
        dbResult[1] = db_query(ServerDB, string);
        if (db_num_rows(dbResult[1]) != 0)
        {
            db_free_result(dbResult[1]);
            continue;
        }
        else
        {
            db_free_result(dbResult[1]);
            found = true;
            break;
        }
    }
}
else found = true;
db_free_result(result);
I wondered why sqlitei autofree storage was overflowing. Well, when someone is firing >2k queries, it might choke everything a little.

Share your traumatic experiences.

#e: Ha, the #2 isn't as bad as I thought, it "only" tries for 50 times.
Reply
#2

I haven't got any examples but the main issue has got to be poor indentation, it's just impossible to read/understand.

EDIT:
Found this:
pawn Код:
if( !strcmp( cmdtext, "/lol", true ) )
{
  if( !strcmp( cmdtext[ 5 ], "rofl", true ) )
     {
   SendClientMessage( playerid, -1, "Your parameter after the /lol command is 'rofl'." );
        }
return 1;
}
Reply
#3

I could find stuff like that in pretty much every gamemode that's released here. If I'd get a dollar for each inefficiency I'd be a rich motherfucker.
Reply
#4

Quote:
Originally Posted by Vince
Посмотреть сообщение
I could find stuff like that in pretty much every gamemode that's released here. If I'd get a dollar for each inefficiency I'd be a rich motherfucker.
I'd be a multi millionaire, muhaha.
Reply
#5

What's the point of this thread anyway? I think it should be moved to

Quote:

SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Discussion

Reply
#6

Public shaming, that's the point!
Reply
#7

Am not that awsome at scripting but can you at least tell me why this is bad below i want more info so i stay away from things like it

Код:
enum pInfo
{
    //(...)
    pAchievement0,
    pAchievement1,
    pAchievement2,
    pAchievement3,
    pAchievement4,
    pAchievement5,
    pAchievement6,
    pAchievement7,
    pAchievement8,
    pAchievement9,
    pAchievement10,
    pAchievement11,
    pAchievement12,
    pAchievement13,
    pAchievement14,
    pAchievement15,
    pAchievement16,
    pAchievement17,
    pAchievement18,
    pAchievement19,
    pAchievement20,
    pShiftName,
    pWeapon,
    pWeapon2,
    pWeapon3,
    pWeapon4,
    pWeapon5,
    pWeapon6,
    pWeapon7,
    pWeapon8,
    pWeapon9,
    pWeapon10,
    pWeapon11,
    pWeapon12,
    pAmmo,
    pAmmo2,
    pAmmo3,
    pAmmo4,
    pAmmo5,
    pAmmo6,
    pAmmo7,
    pAmmo8,
    pAmmo9,
    pAmmo10,
    pAmmo11,
    pAmmo12,
    //(...)
}
Reply
#8

Quote:
Originally Posted by AlonzoTorres
Посмотреть сообщение
What's the point of this thread anyway? I think it should be moved to
I don't! That section is for GOOD topics (shame it has fallen on hard times lately).
Reply
#9

Quote:
Originally Posted by ColeMiner
Посмотреть сообщение
I don't! That section is for GOOD topics (shame it has fallen on hard times lately).
This thread wasn't meant to be good, I just wanted to cheer myself that I could be in worse situation, and cheer others that their code isn't so terrible!

@Cypress: I don't sell my knowledge, only my time and skills, however I'm terrible at explaining things (english being my third language doesn't help at all).

Also:

pawn Код:
for(new vehicleid = 1; vehicleid < MAX_VEHICLES; vehicleid++)
{
    new query[128], DBResult:result, field[128], var[32];
    format(query, sizeof(query), "SELECT * FROM `OtherCars` WHERE `veh_id` = '%d'", vehicleid);
    result = db_query(ServerDB, query);
    if (db_num_rows(result) != 0)
    {
        //some stuff
    }
}
I simply don't understand, the guy had to know what WHERE means, how come he didn't know that without it he can get all results at once?
Reply
#10

Quote:
Originally Posted by Misiur
Посмотреть сообщение
I simply don't understand, the guy had to know what WHERE means, how come he didn't know that without it he can get all results at once?
You'd be surprised at the amount of people that actually do it like this. Treating SQL like some dirty filesystem. The principle of multiple rows in a result doesn't seep through.

On a completely different note, I regularly come across posts from ones who think every "undefined symbol" error can be solved with #define or new.
pawn Код:
#defined playerid
new playerid;
new params; // zcmd ....

new customFunction;
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)