sscanf admin command
#1

Hey, I got some trouble with a command.
I wanted to make a command with that i can respawn all cars.

But everytime i compile my script, i get this error:
Quote:

"error 033: array must be indexed ( variable "--unknown--")"

The line, in that is the error is this:
Код:
if (sscanf(params, "s", command))
here is my complete code of the command:

Код:
CMD:respawn(playerid, params[])
{
	if (IsPlayerAdmin(playerid) == 1)
	{
		new command;
		
		if (sscanf(params, "s", command))
		{
			if (command == "autos")
			{
				SendClientMessageToAll(ORANGE, "*** Autos wurden respawnt");
			}
		}
		SendClientMessage(playerid, RED, "SERVER: Befehl ist noch in Arbeit");
	}
	else
	{
		SendClientMessage(playerid, RED, "SERVER: Du bist nicht als Admin eingeloggt");
	}
	return 1;
}
please help.
i really dont know.

my includes:
Код:
#include <a_samp>
#include <zcmdsscanf>
#include <dudb>
#include <streamer>
Reply
#2

Код:
CMD:respawn(playerid, params[])
{
	if (IsPlayerAdmin(playerid) == 1)
	{
		new command[64];
		
		if (sscanf(params, "s", command))
		{
			if (!strcmp(command,"autos",true))
			{
				SendClientMessageToAll(ORANGE, "*** Autos wurden respawnt");
			}
		}
		SendClientMessage(playerid, RED, "SERVER: Befehl ist noch in Arbeit");
	}
	else
	{
		SendClientMessage(playerid, RED, "SERVER: Du bist nicht als Admin eingeloggt");
	}
	return 1;
}
Untested, but it should work
Reply
#3

Okay, now i get no error, but i guess its not needed to use sscanf AND strcmp ??
Reply
#4

If you just want a simple command that respawns your vehicles, then no. if you want a more complicated one as you are doing now then yes.
Its good the way you did it now because. you can always add on like

Код:
if (!strcmp(command,"autos",true))
{
	SendClientMessageToAll(ORANGE, "*** Autos wurden respawnt");
}
else if (!strcmp(command,"server",true))
{
	SendClientMessageToAll(ORANGE, "*** Server Has been restarted!");
	SendRconCommand("gmx");
}
then you have a command that restarts the server if you do
Код:
/respawn server
and if you do
Код:
/respawn autos
then its all the vehicles.

You see?


EDIT: Also a nice thing is this

Код:
if (sscanf(params, "s", command)) return SendClientMessage(playerid, RED, "USAGE: /respawn [Autos / Server]");
else if ((strlen(command) != "Autos") ||(strlen(command) != "Server")) return SendClientMessage(playerid, RED, "ERROR: Invalid params!");
Reply
#5

Thanks.
I tried out the command with strlen() but now i have again an error:
Quote:

Error 033: Array must be indexed (variable "-unknown-")

and another question:
how to make a script to respawn all the cars in server?
is there any pre-defined command?
Reply
#6

Can i get the line that the error is on, and the 2 lines above and under?
Reply
#7

For sure.
Sorry i forgot to post it.

Код:
if (sscanf(params, "s", command)) return SendClientMessage(playerid, RED, "USAGE: /respawn [befehl]");
		
		else if (strlen(command) != "autos") return SendClientMessage(playerid, RED, "SERVER: Ungьltiger Befehl"); // <--- Error in this line
		
		else if (!strcmp(command, "autos", true))
Reply
#8

People don't complicate and also don't use sscanf for single parameter because it's useless.

pawn Код:
CMD:respawn(playerid, params[])
{
    if (IsPlayerAdmin(playerid))
    {
        if(isnull(params))
        {
            //message how to use command
        }
        else if(!strcmp(params,"autos",true))
        {
            //respawn and whatever
        }
        else if(!strcmp(params,"something",true))
        {
            //do something else
        }
        else
        {
            //invalid option
        }
    }
    else SendClientMessage(playerid, RED, "SERVER: Du bist nicht als Admin eingeloggt");
    return 1;
}
Reply
#9

but i got the error in the line with the unknown command
Reply
#10

Then add 'return 1;' on the end of function.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)