12.11.2018, 21:55
Can someone tell me why this command doesn't work in the way it should? Basically, if i create a faction, it's ID is 1, but if i create another one, it's ID is again 1 and replaces the first faction. Also sometimes doesn't write anything in the table. P.S It's in sampdb, not MySQL:
pawn Код:
CMD:fcreate(playerid,params[])
{
if (Player[playerid][AccountLevel] < 5) return 0;
if(IsPlayerInFaction(playerid)) return SCM(playerid, COLOR_LIGHTRED, "* You're already in a faction. Type /fleave to quit.");
new query[115], DBResult: result, string[128];
if(isnull(params)) return SCM(playerid, -1, "{3498db}* [USAGE]: {FFFFFF} /fcreate [faction name]");
if(!strcmp(params,"INVALID",true)) return SCM(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 SCM(playerid, COLOR_LIGHTRED, "* This faction name already has been taken.");
}
db_free_result(result);
/*FactionInfo[playerid][factionmember] = 1;
format(FactionInfo[playerid][factionname], 32, params);
FactionInfo[playerid][factionleader] = 1;*/
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);
/*format( Query,sizeof(Query), "INSERT INTO Members (FactionID,UserName,FactionLeader) VALUES (%d,'%q',1)",FactionInfo[playerid][factionid],FactionInfo[playerid][username]);
db_query(Database,Query);*/
SCM(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]);
SCMTA(-1,string);
return 1;
}