Command help
#1

I have a faction system which each faction has 9 ranks, each one with their proper title.

rank 1: Trial
rank 2: Testing
rank 3: Underboss

etc.

Since i don't wanna create 9 commands to edit each rank, i did in this way:

pawn Код:
CMD:fazione(playerid, params[])
{
    if (Player[playerid][AccountLevel] < 5) return 0;

    new factionname[30], newrankname[30], rank, query[200];

    if(sscanf(params, "s[30]ds[30]", factionname, rank, newrankname)) return SCM(playerid, COLOR_LIGHTRED, "* [USAGE]: /fazione [faction name] [rank to edit] [new rank name]");

    format(query, sizeof(query), "UPDATE `Factions` SET `Name` = '%s', Rank1 = '%s'", factionname, newrankname);
    mysql_tquery(g_SQL, query);
    return 1;
}
I know the above query is totally wrong, but i can't go forward. Basically an admin should do /fazione faction name - rank to edit (1-9) - new rank name

So imagine i have a LSPD faction and i want to edit rank 2, i wanna set rank 2 title to: Test

How i can do it with params? I can't manage to get it working.
Reply
#2

sscanf utilisation must be: "intenger string" because a string can be anything.
PHP код:
sscanf(params"s[30]ds[30]"factionnameranknewrankname)) 
become
PHP код:
sscanf(params"ds[30]s[30]"rankfactionnamenewrankname)) 
PHP код:
    format(querysizeof(query), "UPDATE `Factions` SET `Name` = '%s', Rank1 = '%s'"factionnamenewrankname);
    
mysql_tquery(g_SQLquery); 
Assuming you are using the latest MySQL version, you have to use '%e' specifier to escape string and avoid SQL injections. To use this special specifier, you need to use the function mysql_format.
Your query become better
PHP код:
    mysql_format(querysizeof(query), "UPDATE `Factions` SET `Name` = '%e', Rank1 = '%e'"factionnamenewrankname);
    
mysql_tquery(g_SQLquery); 
You are missing a WHERE clause in your query. I advice you to lear a bit SQL language before using it: https://www.w3schools.com/sql/sql_update.asp
Reply
#3

Ok but the "Rank1" should not be static, since the admin has to choose WHICH rank to edit (Rank1, Rank2 etc).

How?
Reply
#4

Maybe this can help you.

PHP код:
CMD:editfrank(playeridparams[])
{
    new 
string[128], rname[32], query[400], fidrid;
    if(
sscanf(params"dds[32]"fidridrname)) return SCM(playeridCOLOR_WHITE"USAGE: /editrank [faction id] [rank id] [rank name]\nTIPS: Rank ID = 1 - 10");
    switch(
rid)
    {
        case 
1:
        {
            
format(Factions[fid][Rank1], 32"%s"rname);
            
format(stringsizeof(string), "You have set faction id %d rank 1 name to %s"fidFactions[fid][Rank1]);
            
mysql_format(g_SQLquerysizeof(query), "UPDATE `Factions` SET Rank1 = '%s' WHERE ID = %d"Factions[fid][Rank1], fid);
            
mysql_tquery(g_SQLquery);
        }
        case 
2:
        {
            
format(Factions[fid][Rank2], 32"%s"rname);
            
format(stringsizeof(string), "You have set faction id %d rank 2 name to %s"fidFactions[fid][Rank2]);
            
mysql_format(g_SQLquerysizeof(query), "UPDATE `Factions` SET Rank2 = '%s' WHERE ID = %d"Factions[fid][Rank2], fid);
            
mysql_tquery(g_SQLquery);
        }
        case 
3:
        {
            
format(Factions[fid][Rank3], 32"%s"rname);
            
format(stringsizeof(string), "You have set faction id %d rank 3 name to %s"fidFactions[fid][Rank3]);
            
mysql_format(g_SQLquerysizeof(query), "UPDATE `Factions` SET Rank3 = '%s' WHERE ID = %d"Factions[fid][Rank3], fid);
            
mysql_tquery(g_SQLquery);
        }
        case 
4:
        {
            
format(Factions[fid][Rank4], 32"%s"rname);
            
format(stringsizeof(string), "You have set faction id %d rank 4 name to %s"fidFactions[fid][Rank4]);
            
mysql_format(g_SQLquerysizeof(query), "UPDATE `Factions` SET Rank4 = '%s' WHERE ID = %d"Factions[fid][Rank4], fid);
            
mysql_tquery(g_SQLquery);
        }
        case 
5:
        {
            
format(Factions[fid][Rank5], 32"%s"rname);
            
format(stringsizeof(string), "You have set faction id %d rank 5 name to %s"fidFactions[fid][Rank5]);
            
mysql_format(g_SQLquerysizeof(query), "UPDATE `Factions` SET Rank5 = '%s' WHERE ID = %d"Factions[fid][Rank5], fid);
            
mysql_tquery(g_SQLquery);
        }
        case 
6:
        {
            
format(Factions[fid][Rank6], 32"%s"rname);
            
format(stringsizeof(string), "You have set faction id %d rank 6 name to %s"fidFactions[fid][Rank6]);
            
mysql_format(g_SQLquerysizeof(query), "UPDATE `Factions` SET Rank6 = '%s' WHERE ID = %d"Factions[fid][Rank6], fid);
            
mysql_tquery(g_SQLquery);
        }
        case 
7:
        {
            
format(Factions[fid][Rank7], 32"%s"rname);
            
format(stringsizeof(string), "You have set faction id %d rank 7 name to %s"fidFactions[fid][Rank7]);
            
mysql_format(g_SQLquerysizeof(query), "UPDATE `Factions` SET Rank7 = '%s' WHERE ID = %d"Factions[fid][Rank7], fid);
            
mysql_tquery(g_SQLquery);
        }
        case 
8:
        {
            
format(Factions[fid][Rank8], 32"%s"rname);
            
format(stringsizeof(string), "You have set faction id %d rank 8 name to %s"fidFactions[fid][Rank8]);
            
mysql_format(g_SQLquerysizeof(query), "UPDATE `Factions` SET Rank8 = '%s' WHERE ID = %d"Factions[fid][Rank8], fid);
            
mysql_tquery(g_SQLquery);
        }
        case 
9:
        {
            
format(Factions[fid][Rank9], 32"%s"rname);
            
format(stringsizeof(string), "You have set faction id %d rank 9 name to %s"fidFactions[fid][Rank9]);
            
mysql_format(g_SQLquerysizeof(query), "UPDATE `Factions` SET Rank9 = '%s' WHERE ID = %d"Factions[fid][Rank9], fid);
            
mysql_tquery(g_SQLquery);
        }
        case 
10:
        {
            
format(Factions[fid][Rank10], 32"%s"rname);
            
format(stringsizeof(string), "You have set faction id %d rank 10 name to %s"fidFactions[fid][Rank10]);
            
mysql_format(g_SQLquerysizeof(query), "UPDATE `Factions` SET Rank10 = '%s' WHERE ID = %d"Factions[fid][Rank10], fid);
            
mysql_tquery(g_SQLquery);
        }
    }
    return 
1;

I hope you can understand
Reply
#5

Quote:
Originally Posted by KinderClans
Посмотреть сообщение
Ok but the "Rank1" should not be static, since the admin has to choose WHICH rank to edit (Rank1, Rank2 etc).

How?
Use "format" function to format the rank id like: "Rank%i" with the rank id but you should normalize (iirc that's the correct word) your table. I mean, you should have not Rank1, Rank2, Rank3, ... but something like that:
- SQLID
- Rank id
- Faction id
- Rank's name
In your gamemode, create a 3D (and also a 4D implicit one because of the rank's name) array: ArrayName[factionid][rankid][enum]
Example:

It's a bit more tricky but it allows you to do many ranks as you want.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)