Problem
#1

Hello everyone, so basically i have a problem with this faction system in sampdb (non sqlite):

pawn Код:
CMD:fcreate(playerid,params[])
{
    new query[115], DBResult: result, string[128];

    if(isnull(params)) return SendClientMessage(playerid, -1, "{3498db}* [USAGE]: {FFFFFF} /fcreate [faction name]");
    if(!strcmp(params,"INVALID",true)) return SendClientMessage(playerid, COLOR_LIGHTRED, "* Chosen faction name is invalid.");

    format(query,sizeof(query),"SELECT FactionName FROM Factions WHERE FactionName = '%q'",params);
    result = db_query(Database, query);

    if(db_num_rows(result))
    {
        db_free_result(result);
        return SendClientMessage(playerid, COLOR_LIGHTRED, "* This faction name already has been taken.");
    }
    db_free_result(result);

    ShowPlayerDialog(playerid,DIALOG_FACTION_COLOR,DIALOG_STYLE_LIST,"Faction Color",""BLUE"Blue\n"RED"RED\n"WHITE"White\n"PINK"Pink\n"CYAN"Cyan\n"ORANGE"Orange\n"GREEN"Green\n"YELLOW"Yellow","Select","Cancel");

    new Query[217];
    format( Query, sizeof(Query), "INSERT INTO Factions (FactionName,FactionColor) VALUES ('%q','%q')", FactionInfo[playerid][factionname],FactionInfo[playerid][factioncolor]);
    db_query(Database,Query);
    result = db_query(Database, "SELECT last_insert_rowid()");
    FactionInfo[playerid][factionid] = db_get_field_int(result);
    db_free_result(result);

    SendClientMessage(playerid, COLOR_YELLOW, "* You have sucessfully created a faction!");

    format(string,sizeof(string),""GREEN"%s "WHITE"has created a new faction named "GREEN"%s!"WHITE"",FactionInfo[playerid][username],FactionInfo[playerid][factionname]);
    SendClientMessageToAll(-1,string);
    return 1;
}
Seems to not work. Or to be more precise, works at 50%.

When i create a faction, its assigned ID is 1, but when i create another one it's again 1 (should be 2), and gets replaced the first faction i created.

Also sometimes doesn't even create anything.
Reply
#2

Код:
format(query,sizeof(query),"SELECT `FactionName` FROM `Factions` WHERE `FactionName` = '%q'",params);
format( Query, sizeof(Query), "INSERT INTO `Factions` (FactionName,FactionColor) VALUES ('%q','%q')",
Reply
#3

I don't understand what are you trying to say, sorry.
Reply
#4

Quote:
Originally Posted by SymonClash
Посмотреть сообщение
I don't understand what are you trying to say, sorry.
` is important
Reply
#5

Check if your database user, password, IP and database name are right.
Reply
#6

Quote:
Originally Posted by iHollyZinhO
Посмотреть сообщение
Check if your database user, password, IP and database name are right.
I think you have to re-read my first post. I'm not using MySQL for this faction system but the simple sampdb.

@Heress, thanks, i'll try later.
Reply
#7

Update: Getting a tagmismatch here:

pawn Код:
new Query[217];
format(Query, sizeof(Query), "INSERT INTO `Factions` (FactionName,FactionColor) VALUES ('%q','%q')", db_query(Database,Query);
Reply
#8

Код:
format(Query, sizeof(Query), "INSERT INTO `Factions` (`FactionName`,`FactionColor`) VALUES ('%q','%q')",FactionInfo[playerid][factionname],FactionInfo[playerid][factioncolor];
Reply
#9

Quote:

error 001: expected token: ",", but found ";"

Mh...
Reply
#10

Quote:
Originally Posted by SymonClash
Посмотреть сообщение
Mh...
sorry, missed ")" but this error is so easy and you can do it by yourself
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)