SA-MP Forums Archive
Command With Playerid and Reason - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Command With Playerid and Reason (/showthread.php?tid=64086)



Command With Playerid and Reason - sidhu123 - 01.02.2009

Hey hey!... [SAP]Sidhu here.. I'm making a new GM and I'm stuck on one of the commands I want to make. I'm making a Cops and Robbers GM, and want to make the following command: /pullover [playerid] [reason]... I don't have a clue of how I would do this. Could somebody please help me make this?

Thanks.


Re: Command With Playerid and Reason - Backwardsman97 - 02.02.2009

Use dcmd and sscanf.


Re: Command With Playerid and Reason - AlExAlExAlEx - 02.02.2009

wut this sould do?



Re: Command With Playerid and Reason - Backwardsman97 - 02.02.2009

pawn Код:
dcmd_pullover(playerid,params[])
{
   new giveplayerid, reason[128];
   if(sscanf(params,"ds",giveplayerid,reason))
   {
      //They left out a parameter
   }
   if(!IsPlayerConnected(giveplayerid))
   {
      //The specified player is not connected
   }
   //They specified a connected player and a reason
   //Do the rest
}



Re: Command With Playerid and Reason - LarzI - 02.02.2009

Remember that sscanf has z (optional string).
And backwardsman, this is posted for Sidhu, it's not meant to post against you :P


Re: Command With Playerid and Reason - sidhu123 - 02.02.2009

Woah, ok.. Remember, I'm new to this.. Can somebody explain that code to me?


Re: Command With Playerid and Reason - x-cutter - 02.02.2009

Check fast commands on WIKI


Re: Command With Playerid and Reason - Lazarus - 02.02.2009

pawn Код:
if(strcmp("/kick", cmdtext, true, 5) == 0) // "/kick" is 5 bytes long
    {
        if(strlen(cmdtext[6]) == 0) return SendClientMessage(playerid, 0xFF0000AA, "Usage: /kick [ID] [MSG]");
        //lenght of string at byte 6+, 0 if there is nothing there

        new id = strval(cmdtext[6]);
        //value of the string at byte 6+

        if(IsPlayerConnected(id) == 0) return SendClientMessage(playerid, 0xFF0000AA, "Player not connected");
        //check if the player is connected
       
        new pos = strfind(cmdtext, " ", true, 6);
        //get the position of the string after the space
       
        if(pos == -1) return SendClientMessage(playerid, 0xFF0000AA, "Usage: /kick [ID] [MSG]");
        //pos will be -1 if there is no space
       
        if(strlen(cmdtext[pos + 1]) == 0) return SendClientMessage(playerid, 0xFF0000AA, "Usage: /kick [ID] [MSG]");
        //check if there is a string after the space (pos is space, + 1 more byte)
       
        new string[128];
        format(string, sizeof(string), "ID %d has been kicked for %s", id, cmdtext[pos + 1]);
        SendClientMessageToAll(0xFFFFFFFF, string);
        //format your crap as needed
       
        Kick(id);
        //kick player
        return 1;
    }



Re: Command With Playerid and Reason - sidhu123 - 02.02.2009

Quote:
Originally Posted by Lazarus
pawn Код:
if(strcmp("/kick", cmdtext, true, 5) == 0) // "/kick" is 5 bytes long
    {
        if(strlen(cmdtext[6]) == 0) return SendClientMessage(playerid, 0xFF0000AA, "Usage: /kick [ID] [MSG]");
        //lenght of string at byte 6+, 0 if there is nothing there

        new id = strval(cmdtext[6]);
        //value of the string at byte 6+

        if(IsPlayerConnected(id) == 0) return SendClientMessage(playerid, 0xFF0000AA, "Player not connected");
        //check if the player is connected
       
        new pos = strfind(cmdtext, " ", true, 6);
        //get the position of the string after the space
       
        if(pos == -1) return SendClientMessage(playerid, 0xFF0000AA, "Usage: /kick [ID] [MSG]");
        //pos will be -1 if there is no space
       
        if(strlen(cmdtext[pos + 1]) == 0) return SendClientMessage(playerid, 0xFF0000AA, "Usage: /kick [ID] [MSG]");
        //check if there is a string after the space (pos is space, + 1 more byte)
       
        new string[128];
        format(string, sizeof(string), "ID %d has been kicked for %s", id, cmdtext[pos + 1]);
        SendClientMessageToAll(0xFFFFFFFF, string);
        //format your crap as needed
       
        Kick(id);
        //kick player
        return 1;
    }
Awesome, thanks man!


Re: Command With Playerid and Reason - sidhu123 - 02.02.2009

I'm making a /pullover command, and this is what I have..

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{

    if(strcmp("/pullover", cmdtext, true, 9) == 0) // "/pullover" is 9 bytes long
    {
        if(strlen(cmdtext[10]) == 0) return SendClientMessage(playerid, 0xFF0000AA, "Usage: /kick [ID] [MSG]");
        //lenght of string at byte 10+, 0 if there is nothing there

        new id = strval(cmdtext[10]);
        //value of the string at byte 10+

        if(IsPlayerConnected(id) == 0) return SendClientMessage(playerid, 0xFF0000AA, "Player not connected");
        //check if the player is connected

        new pos = strfind(cmdtext, " ", true, 10);
        //get the position of the string after the space

        if(pos == -1) return SendClientMessage(playerid, 0xFF0000AA, "Usage: /pullover [ID] [MSG]");
        //pos will be -1 if there is no space

        if(strlen(cmdtext[pos + 1]) == 0) return SendClientMessage(playerid, 0xFF0000AA, "Usage: /pullover [ID] [MSG]");
        //check if there is a string after the space (pos is space, + 1 more byte)

        new string[128];
        format(string, sizeof(string), "ID %d is being asked to pullover for %s", id, cmdtext[pos + 1]);
        SendClientMessageToAll(0xFFFFFFFF, string);
        //format your crap as needed

        Pullover(id);
        //kick player
        return 1;
    }
When I try to compile, I get this error:

C:\Users\Sidhu\Desktop\CopsN'Robbers.pwn(735) : error 017: undefined symbol "Pullover"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


1 Error.



Re: Command With Playerid and Reason - Auto-Sized - 02.02.2009



pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{

    if(strcmp("/pullover", cmdtext, true, 9) == 0)
    {
        if(strlen(cmdtext[10]) == 0) return SendClientMessage(playerid, 0xFF0000AA, "Usage: /pullover [ID] [MSG]");

        new id = strval(cmdtext[10]);

        if(IsPlayerConnected(id) == 0) return SendClientMessage(playerid, 0xFF0000AA, "Player not connected");

        new pos = strfind(cmdtext, " ", true, 10);

        if(pos == -1) return SendClientMessage(playerid, 0xFF0000AA, "Usage: /pullover [ID] [MSG]");

        if(strlen(cmdtext[pos + 1]) == 0) return SendClientMessage(playerid, 0xFF0000AA, "Usage: /pullover [ID] [MSG]");

        new string[128];
        format(string, sizeof(string), "ID %d is being asked to pullover for %s", id, cmdtext[pos + 1]);
        SendClientMessage(id, 0xFFFFFFFF, string);

        return 1;
    }
I only looked at the last part id = playerid the code he sent you was to kick and you changed it but forgot some things anyway try that. I did not test in game but it compiled fine.


Re: Command With Playerid and Reason - Lazarus - 03.02.2009

You can't just make up functions, Sidhu. If your unsure if it exists, look on the wiki:

https://sampwiki.blast.hk/wiki/Category:Scripting_Functions
https://sampwiki.blast.hk/wiki/Scripting_Functions_Old


Re: Command With Playerid and Reason - sidhu123 - 03.02.2009

Quote:
Originally Posted by Lazarus
You can't just make up functions, Sidhu. If your unsure if it exists, look on the wiki:

https://sampwiki.blast.hk/wiki/Category:Scripting_Functions
https://sampwiki.blast.hk/wiki/Scripting_Functions_Old
Well I highly doubt Pullover would exist :P, and it doesn't:P


Re: Command With Playerid and Reason - Backwardsman97 - 03.02.2009

Quote:
Originally Posted by <3 HardStyle <3 | LarzI
Remember that sscanf has z (optional string).
And backwardsman, this is posted for Sidhu, it's not meant to post against you :P
I know :P

You should really look into dcmd and sscanf. It will make things a lot easier.


Re: Command With Playerid and Reason - Lazarus - 03.02.2009

That's an opinion, not a fact :P. I find the regular strcmp version easier, personally.

I like knowing Exactly how everything works.
pawn Код:
#define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
That is Not how I role (lol) ^. Plus it means you didn't completely make the script yourself, which feels like a real bummer to me. And I find it easier to find bugs in script that you make yourself.


Re: Command With Playerid and Reason - LarzI - 03.02.2009

@Lazarus, it's kinda a fact
dcmd and sscanf is better and faster, unless the contrary is proved


Re: Command With Playerid and Reason - Lazarus - 03.02.2009

It's an option, as not everyone finds it easier. And that is a fact.

It's faster for some simple reasons, that's a fact, but not the easier thing. I never said anything about its speed.