Unknown Command -
Joshayersm - 13.10.2014
So, whenever I use this command on the server, I get an error for unknown command. Maybe it's just because I'm not noticing something, but I honestly feel like nothing is wrong with this command.
Код:
CMD:createfaction(playerid, params[])
{
new factionname[32], query[128];
if(sscanf(params, "s[32]", factionname)) return SendClientMessage(playerid, cred, "USAGE: /createfaction [factionname]");
fInfo[Total_Factions_Created][ID] = Total_Factions_Created;
fInfo[Total_Factions_Created][Name] = factionname;
format(query, sizeof(query), "INSERT INTO `factiondata` (id, name) VALUES('%i', '%s')", Total_Factions_Created, fInfo[Total_Factions_Created][Name]);
mysql_query(query);
Total_Factions_Created++;
return 1;
}
Re: Unknown Command -
YanLanger - 13.10.2014
Do you get any errors?
Re: Unknown Command -
Joshayersm - 13.10.2014
Quote:
Originally Posted by YanLanger
Do you get any errors?
|
Nah, it compiles fine.
Re: Unknown Command -
YanLanger - 13.10.2014
What does the command suppose to do ?
Re: Unknown Command -
Joshayersm - 13.10.2014
Quote:
Originally Posted by YanLanger
What does the command suppose to do ?
|
Create a faction and then save it to the database.
Re: Unknown Command -
AnnaSB - 13.10.2014
pawn Код:
fInfo[Total_Factions_Created][Name] = factionname;
turn this line into:
pawn Код:
format(fInfo[Total_Factions_Created][Name], 32, factionname);
You cannot directly set an string to an string var in C/C++/PAWN, you should use COPY functions like strcat or format for them, they deal with array characters, not with the string at once.
Hope I helped ^^
Re: Unknown Command -
Joshayersm - 13.10.2014
Quote:
Originally Posted by AnnaSB
pawn Код:
fInfo[Total_Factions_Created][Name] = factionname;
turn this line into:
pawn Код:
format(fInfo[Total_Factions_Created][Name], 32, factionname);
You cannot directly set an string to an string var in C/C++/PAWN, you should use COPY functions like strcat or format for them, they deal with array characters, not with the string at once.
Hope I helped ^^
|
Thanks, however in game it's still saying "Unknown Command".
Re: Unknown Command -
Joshayersm - 13.10.2014
Okay so this is my new command. Maybe this will give more insight into what I'm trying to do. I'm trying to check all of the Faction's names to see if they are equal to the faction name the user has entered, if they match then I want it to send an error stating that there is already a faction named that. If they don't I want it to continue on. However I'm doing things very wrong I'm sure, and this command currently doesn't work. I'm just trying to create a scaffold sort of thing.
Код:
CMD:createfaction(playerid, params[])
{
new factionname[32], string[128], query[128];
if(pInfo[playerid][pAdmin] < HEAD_ADMIN) return ErrorMessage(playerid);
if(sscanf(params, "s[32]", factionname)) return SendClientMessage(playerid, cred, "USAGE: /createfaction [factionname]");
for(new i = 0; i <= Total_Factions_Created; i++)
{
if(!strcmp(factionname, fInfo[i][Name], true))
{
SendClientMessage(playerid, cred, "That faction has already been created!");
}
else
{
fInfo[i][ID] = i;
fInfo[i][Name] = factionname;
format(query, sizeof(query), "INSERT INTO `factiondata` (id, name) VALUES('%d', '%s')",
fInfo[i][ID],
fInfo[i][Name]);
mysql_query(query);
format(string, sizeof(string), "You just created a faction called, %s.", fInfo[i][Name]);
SendClientMessage(playerid, cwhite, string);
}
}
return 1;
}
Re: Unknown Command -
AnnaSB - 13.10.2014
Can you post declaration part for fInfo?
Seems it's messing with bounds...
Also I suggest you to use
mysql_format instead of format for query strings.
Re: Unknown Command -
Joshayersm - 13.10.2014
Quote:
Originally Posted by AnnaSB
Can you post declaration part for fInfo?
Seems it's messing with bounds...
Also I suggest you to use mysql_format instead of format for query strings.
|
Is this what you're talking about?
new fInfo[MAX_FACTIONS][FactionInfo], Total_Factions_Created;
And I will try to use that, I've been using format for mysql queries all throughout my script so I don't think it's that. Unless you were just saying for efficiency.