How can I do this? - 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: How can I do this? (
/showthread.php?tid=282561)
How can I do this? -
Tigerbeast11 - 11.09.2011
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?
Re: How can I do this? -
Gertin - 11.09.2011
What commandtext you use ? That normal OnPlayerCommandText or dCMD or smthing that ?
Re: How can I do this? -
Tigerbeast11 - 11.09.2011
well, i would like this in my filterscript and I use dcmd in my filterscript.
Re: How can I do this? -
Mean - 11.09.2011
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;
}
Re: How can I do this? -
[M]onsieur - 11.09.2011
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;
}
Re: How can I do this? -
Mean - 11.09.2011
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.
Re: How can I do this? -
Tigerbeast11 - 11.09.2011
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?
Re: How can I do this? -
Mean - 11.09.2011
You could use
strfind.
Re: How can I do this? -
scottyishere - 11.09.2011
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.
Re: How can I do this? -
Tigerbeast11 - 11.09.2011
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"?