SA-MP Forums Archive
sscanf inside strcmp - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: sscanf inside strcmp (/showthread.php?tid=291522)



sscanf inside strcmp - Cowboy - 20.10.2011

Hello all,

I tried to make a sscanf parameter after the strcmp check but it didn't work

pawn Код:
COMMAND:gang(playerid, params[])
{
    new string[128], gName[128], Query[200], gID[5], DBResult:Result, pName[MAX_PLAYER_NAME];
    if(sscanf(params, "s[128]", params)) return SendClientMessage(playerid, Yellow, "Usage: /gang <create>");
    GetPlayerName(playerid, pName, sizeof(pName));
    if (!strcmp("create", params, true))
    {
        if(PlayerInfo[playerid][Gang] != 0) return SendClientMessage(playerid, Red, "..");
        if(sscanf(params, "s[128]", gName)) return SendClientMessage(playerid, Yellow, "Usage: /gang <create> <gangname>");
        if(CheckGangByName(gName)) return SendClientMessage(playerid, Yellow, "..");
        format(Query, sizeof(Query), "INSERT INTO `GANGS` (`ID`, `NAME`, `OWNER`) VALUES (NULL, '%s', '%s');", gName, pName);
        db_query(Database, Query);
        format(Query, sizeof(Query), "SELECT * FROM `USERS` WHERE `NAME` = '%s'", pName);
        Result = db_query(Database, Query);
        db_get_field_assoc(Result, "ID", gID, 5);
        PlayerInfo[playerid][Gang] = strval(gID);
        format(Query, sizeof(Query), "UPDATE `USERS` SET `GANG` = '%d' WHERE `NAME` = '%s'", PlayerInfo[playerid][Gang], pName);
        db_query(Database, Query);
        format(string, sizeof(string), "... Name: %s. ID: %d", gName, PlayerInfo[playerid][Gang]);
        SendClientMessage(playerid, Green, string);
    }
    return 1;
}
If I type /gang create, the gang name will be "create".. How to do it?


Re: sscanf inside strcmp - System64 - 20.10.2011

lolz what you talking about?
You want command gang and then you type /gang create what... ?


Re: sscanf inside strcmp - vassilis - 20.10.2011

Does it Compile it or it has errors?


Re: sscanf inside strcmp - Cowboy - 20.10.2011

@System64If you type /gang create, then the gangname parameter has towork, but it doesn't.. so it would be like this /gang <create> <gangname>.

@vassilis Yes, it compiles fine


Re: sscanf inside strcmp - =WoR=Varth - 20.10.2011

You don't need to use sscanf
pawn Код:
CMD:gang(playerid, params[])
{
   if(!strcmp(params,"create"))



Re: sscanf inside strcmp - Cowboy - 20.10.2011

After a player has typed /gang create.. how would he able to write the gang name aswell ? Don't I need sscanf then?


Re: sscanf inside strcmp - =WoR=Varth - 20.10.2011

In that case:
pawn Код:
CMD:gang(playerid, params[])
{
    new gangname[128];
    if(!sscanf(params,"'create's",gangname))
    {
        //createganghere



Re: sscanf inside strcmp - System64 - 20.10.2011

I think that in ZCMD and other procesors you can't use command than strcmp than somethig else...
Should look like this:
pawn Код:
COMMAND:gang create(playerid, params[])
{
    new string[128], gName[128], Query[200], gID[5], DBResult:Result, pName[MAX_PLAYER_NAME];
    if(sscanf(params, "s[128]", gName)) return SendClientMessage(playerid, Yellow, "Usage: /gang create <name>");
    GetPlayerName(playerid, pName, sizeof(pName));
    if(PlayerInfo[playerid][Gang] != 0) return SendClientMessage(playerid, Red, "..");
    if(CheckGangByName(gName)) return SendClientMessage(playerid, Yellow, "..");
    format(Query, sizeof(Query), "INSERT INTO `GANGS` (`ID`, `NAME`, `OWNER`) VALUES (NULL, '%s', '%s');", gName, pName);
    db_query(Database, Query);
    format(Query, sizeof(Query), "SELECT * FROM `USERS` WHERE `NAME` = '%s'", pName);
    Result = db_query(Database, Query);
    db_get_field_assoc(Result, "ID", gID, 5);
    PlayerInfo[playerid][Gang] = strval(gID);
    format(Query, sizeof(Query), "UPDATE `USERS` SET `GANG` = '%d' WHERE `NAME` = '%s'", PlayerInfo[playerid][Gang], pName);
    db_query(Database, Query);
    format(string, sizeof(string), "... Name: %s. ID: %d", gName, PlayerInfo[playerid][Gang]);
    SendClientMessage(playerid, Green, string);
    return 1;
}



Re: sscanf inside strcmp - Cowboy - 20.10.2011

I'll try Varth.

@System64: I need some other things under "/gang <create/invite" etc, and I've heard it's possible. I tried to do some searching but I didn't find anything


Re: sscanf inside strcmp - System64 - 20.10.2011

lol
just create more commands, /gang create, /gang invite...