22.10.2018, 08:16
I have a problem with the command to create faction. I removed team skins and added the possibility to set faction skins directly with the /fcreatecommand. But faction doesn't create, i get the ownership message and everything but in database faction doesn't create. Here is whole command:
In mysql log i get "invalid passing parameter" referred to "INSERT INTO factions" query, maybe added one useless parameter?
pawn Код:
CMD:fcreate(playerid, params[]) {
if (!IsPlayerAdmin(playerid))
return SendClientMessage(playerid, COLOR_TOMATO, "Error: Only admin level 5 and above can access to this command.");
new factionName[MAX_FACTION_NAME], factionTag[MAX_FACTION_TAG_NAME], ownerid, skin;
if (sscanf(params, "s["#MAX_FACTION_NAME"]s["#MAX_FACTION_TAG_NAME"]rd", factionName, factionTag, ownerid, skin)) {
SendClientMessage(playerid, COLOR_LIGHT_AQUA, "Usage: /fcreate [name] [tag] [owner] [faction skin]");
SendClientMessage(playerid, COLOR_LIGHT_AQUA, "Usage: To add spaces in [name], you can use '_' and it will be auto detected as a white space!");
return 1;
}
if(skin < 0 || skin > 311) return SendClientMessage(playerid, -1, "* Invalid skin ID (1-311)");
foreach_factions(i) {
if (!strcmp(factionData[i][FACTION_NAME], factionName, true)) {
return SendClientMessage(playerid, COLOR_TOMATO, "Error: The faction name already exist, try another one.");
}
if (!strcmp(factionData[i][FACTION_TAG], factionTag, true)) {
return SendClientMessage(playerid, COLOR_TOMATO, "Error: The faction tag already exist, try another one.");
}
}
if (!IsPlayerConnected(ownerid))
return SendClientMessage(playerid, COLOR_TOMATO, "Error: The owner player isn't connected.");
if (playerFactionID[ownerid] != -1)
return SendClientMessage(playerid, COLOR_TOMATO, "Error: The owner player is in a faction.");
new index = -1;
for (new i = 0; i < MAX_FACTIONS; i++) {
if (factionData[i][FACTION_NAME][0] == EOS) {
index = i;
break;
}
}
if (index == -1)
return SendClientMessage(playerid, COLOR_TOMATO, "Error: Looks like the server factions creation limit has been reached, please contact server developer about this.");
for (new i = 0; factionName[i] != EOS; i++) {
if (factionName[i] == '_') {
factionName[i] = ' ';
}
}
new pos = strfind(factionTag, "[");
if (pos != -1)
strdel(factionTag, pos, pos + 1);
pos = strfind(factionTag, "]");
if (pos != -1)
strdel(factionTag, pos, pos + 1);
format(factionData[index][FACTION_TAG], MAX_FACTION_TAG_NAME, factionTag);
format(factionData[index][FACTION_NAME], MAX_FACTION_NAME, factionName);
factionData[index][FACTION_SKIN] = skin;
GetPlayerName(ownerid, factionData[index][FACTION_OWNER], MAX_PLAYER_NAME);
factionData[index][FACTION_WAR_WINS] = 0;
factionData[index][FACTION_WAR_TOTAL] = 0;
factionData[index][FACTION_SPAWN_POS][0] = 0.0;
factionData[index][FACTION_SPAWN_POS][1] = 0.0;
factionData[index][FACTION_SPAWN_POS][2] = 0.0;
factionData[index][FACTION_SPAWN_POS][3] = 0.0;
factionData[index][FACTION_SPAWN_INTERIORID] = 0;
factionData[index][FACTION_SPAWN_WORLDID] = 0;
factionData[index][FACTION_VAULT_MONEY] = 0;
for (new i = 0; i < MAX_FACTION_WEAPONS; i++) {
factionData[index][FACTION_VAULT_WEAPONS][i] = -1;
factionData[index][FACTION_VAULT_WEPS_TIMESTAMP][i] = -1;
}
factionData[index][FACTION_TOTAL_EXP] = 0;
factionData[index][FACTION_3D_TEXT_LABEL] = Text3D:INVALID_STREAMER_ID;
factionData[index][FACTION_PICKUPID] = INVALID_STREAMER_ID;
playerFactionID[ownerid] = index;
playerFactionRank[ownerid] = FACTION_RANK_OWNER;
new vault_weapons[32];
for (new i = 0; i < MAX_FACTION_WEAPONS; i++) {
format(vault_weapons, sizeof(vault_weapons), "%s-1", vault_weapons);
if (i != (MAX_FACTION_WEAPONS - 1)) {
strcat(vault_weapons, " ");
}
}
new query[512];
mysql_format(database, query, sizeof(query),
"INSERT INTO factions (\
tag, name, skin, exp, team, factionwar_wins, factionwar_total, \
spawn_x, spawn_y, spawn_z, spawn_angle, spawn_interiorid, spawn_worldid, \
vault_money, vault_weapons, vault_weapons_timestamp\
) VALUES (\
'%e', '%e', %d, 0, %i, 0, 0, \
0.0, 0.0, 0.0, 0.0, 0, 0, \
0, '%s'\
)",
factionTag, factionName, skin,
vault_weapons, vault_weapons
);
mysql_format(database, query, sizeof(query),
"INSERT INTO faction_members (\
faction_name, name, rank\
) VALUES (\
'%e', '%e', %i\
)",
factionName, factionData[index][FACTION_OWNER], FACTION_RANK_OWNER
);
mysql_tquery(database, query);
for (new i = 0; i < MAX_FACTION_RANKS; i++) {
format(factionRankNames[index][i], MAX_FACTION_RANK_NAME, DEFAULT_FACTION_RANKS[i]);
mysql_format(database, query, sizeof(query),
"INSERT INTO faction_ranks (\
faction_name, name, level\
) VALUES (\
'%e', '%e', %i\
)",
factionName, DEFAULT_FACTION_RANKS[i], i
);
mysql_tquery(database, query);
}
mysql_format(database, query, sizeof(query),
"SELECT id FROM factions WHERE faction_name = '%e'",
factionName
);
new Cache:cache = mysql_query(database, query);
cache_get_value_int(0, "id", factionData[index][FACTION_SQLID]);
cache_delete(cache);
UpdateFactionsRank();
new string[164];
format(string, sizeof(string), "[%s] %s", factionData[index][FACTION_TAG], factionRankNames[index][MAX_FACTION_RANKS - 1]);
playerFaction3DTextLabel[ownerid] = CreateDynamic3DTextLabel(string, -1, 0.0, 0.0, 0.0, 25.0, ownerid, .testlos = 1);
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
SendClientMessage(ownerid, COLOR_GREEN, "_________________________________________");
SendClientMessage(ownerid, COLOR_GREEN, "");
SendClientMessage(ownerid, COLOR_GREEN, " FACTION OWNERSHIP");
format(string, sizeof(string), "Admin "COL_DEFAULT"%s"COL_GREEN", have assgined you as owner of new faction: "COL_DEFAULT"%s", name, factionData[index][FACTION_NAME]);
SendClientMessage(ownerid, COLOR_GREEN, string);
SendClientMessage(ownerid, COLOR_GREEN, "Here are some tips to get a head start with your faction:");
SendClientMessage(ownerid, COLOR_GREEN, "To start recruiting players to your faction, use "COL_DEFAULT"/finvite");
SendClientMessage(ownerid, COLOR_GREEN, "For list of faction commands that you have access to all of them, type "COL_DEFAULT"/fhelp");
SendClientMessage(ownerid, COLOR_GREEN, "_________________________________________");
format(string, sizeof(string), "Admin: You have suceessfully assigned a new faction, "COL_DEFAULT"%s "COL_BLUE"to player "COL_DEFAULT"%s", factionData[index][FACTION_NAME], factionData[index][FACTION_OWNER]);
SendClientMessage(playerid, COLOR_BLUE, string);
PlayerPlaySound(playerid, 1057, 0.0, 0.0, 0.0);
PlayerPlaySound(ownerid, 1057, 0.0, 0.0, 0.0);
format(string, sizeof(string), "(%s)", factionData[index][FACTION_TAG]);
TextDrawSetString(factionAnnouncementTD[1], string);
format(string, sizeof(string), "~w~Faction ~r~~h~%s ~w~is now recruiting new memebers. To request an invite, contact ~r~~h~%s ~w~(id: ~r~%i~w~)", factionData[index][FACTION_NAME], factionData[index][FACTION_OWNER], ownerid);
TextDrawSetString(factionAnnouncementTD[2], string);
foreach (new i : Player) {
if (GetPlayerState(i) != PLAYER_STATE_WASTED || GetPlayerState(i) != PLAYER_STATE_SPECTATING) {
for (new x = 0; x < sizeof(factionAnnouncementTD); x++) {
TextDrawShowForPlayer(i, factionAnnouncementTD[x]);
}
}
}
factionAnnouncementTimer = SetTimer("OnAnnouncementExpire", (30 * 1000), false);
format(string, sizeof(string), "[%s] %s", factionData[index][FACTION_TAG], factionRankNames[index][FACTION_RANK_OWNER]);
playerFaction3DTextLabel[playerid] = CreateDynamic3DTextLabel(string, -1, 0.0, 0.0, 0.0, 25.0, playerid, .testlos = 1);
format(string, sizeof(string), "~g~~h~~h~(%s) ~g~~h~%s ~w~(Rank: (%i)%s)", factionData[index][FACTION_TAG], factionData[index][FACTION_NAME], FACTION_RANK_OWNER + 1, factionRankNames[index][FACTION_RANK_OWNER]);
PlayerTextDrawSetString(playerid, factionNamePTD[playerid], string);
PlayerTextDrawShow(playerid, factionNamePTD[playerid]);
return 1;
}