How can I do this?
#1

Hey!

I want to make a command where you type /nextgamemode drifting and the script looks through a list of gamemodes to see which is most related to what the player typed.

So, if the gamemode was called 'drifter' and I typed /nextmode drifting, it will see that the most related name is drifter and then I can do this:

pawn Код:
new string[128];
format(string,sizeof(string),"changemode %s",nameofgamemode);
SendRconCommand(string);
How can I do this?
Reply
#2

What commandtext you use ? That normal OnPlayerCommandText or dCMD or smthing that ?
Reply
#3

well, i would like this in my filterscript and I use dcmd in my filterscript.
Reply
#4

pawn Код:
public OnPlayerCommandText( playerid, cmdtext[ ] ) {
    dcmd( "nextmode", 8, cmdtext );
    return false;
}

dcmd_nextmode( playerid, params[ ] ) {
    if( !IsPlayerAdmin( playerid ) ) return false; // You need to be a RCON administrator to use this.
    if( !strlen( params ) ) return SendClientMessage( playerid, -1, "You need to enter an AMX name (/nextmode [AMX name])." );
    new str[ 50 ]; // You may increase/decrease this since I don't know the length of your gamemode names.
    format( str, sizeof str, "changemode %s", params );
    SendRconCommand( str );
    return true;
}
Reply
#5

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(!strcmp(cmdtext, "/nextmode", true, 9) && IsPlayerAdmin(playerid))
    {
        if(strlen(cmdtext) < 9)
        {
            return SendClientMessage(playerid, 0xFF0000FF, "USAGE: /nextmode [name]");
        }

        static
                 string[128]
        ;

        format(string, sizeof(string), "changemode %s", str, cmdtext[10]);

        return SendRconCommand(string), true;
    }
    return false;
}
Reply
#6

Quote:
Originally Posted by [M]onsieur
Посмотреть сообщение
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(!strcmp(cmdtext, "/nextmode", true, 9) && IsPlayerAdmin(playerid))
    {
        if(strlen(cmdtext) < 9)
        {
            return SendClientMessage(playerid, 0xFF0000FF, "USAGE: /nextmode [name]");
        }

        static
                 string[128]
        ;

        format(string, sizeof(string), "changemode %s", str, cmdtext[10]);

        return SendRconCommand(string), true;
    }
    return false;
}
Why did you use a static? It's not exactly good here... As far as I know, statics are meant to be used outside the function, unlike new. So basically if he has "string" somewhere else, it will shadow a variable and return a warning.
Reply
#7

Thanks for your replies, but I want it so that I don't have to type the exact .amx name. I just type something like the .amx name and it finds the right one. Is this possible?
Reply
#8

You could use strfind.
Reply
#9

pawn Код:
new scripts[][]={ "drift1", "drift2", "drift3" };

stock ReturnFullScriptNameIfExists(partofscript[])
{
   for(new i=0;i<sizeof(scripts);i++)
   {
       if(strfind(scripts[i],partofscript,true)!=-1)
       {
            return scripts[i];
       }
   }
   return "none";
}
Maybe this helps. I did it very fast, not tested. You can enter your script names in the scripts thingy and then you'll get the full script name returned.
Reply
#10

Quote:
Originally Posted by scottyishere
Посмотреть сообщение
pawn Код:
new scripts[][]={ "drift1", "drift2", "drift3" };

stock ReturnFullScriptNameIfExists(partofscript[])
{
   for(new i=0;i<sizeof(scripts);i++)
   {
       if(strfind(scripts[i],partofscript,true)!=-1)
       {
            return scripts[i];
       }
   }
   return "none";
}
Maybe this helps. I did it very fast, not tested. You can enter your script names in the scripts thingy and then you'll get the full script name returned.
Oh, so if I typed "drifter" find the correct name of GM which is "drift1"?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)