Player Is Not connected Bug
#1

Well, I have a bug with a code that I made, and here it is

Код:
//-----[Ban]-----
CMD:ban(playerid, params[])
{
	if(PlayerInfo[playerid][Adminlevel] < 2) return SendClientMessage(playerid,COLOR_ERROR,"[ERROR]: You are not authorized to use this command ");
	new targetid, reason[64], string[128];
	if(sscanf(params, "uz", targetid, reason)) return SendClientMessage(playerid, COLOR_SYNTAX, "[SYNTAX]: /ban [PlayerID/PartOfName] [Reason]");
	if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_ERROR, "[ERROR]: Player not connected!");
	else
	{
	new pTargetName[24], pName[24];
	GetPlayerName(playerid,pName,24);
	GetPlayerName(targetid,pTargetName,24);
	format(string, sizeof(string), ""#COL_YELLOW"[SERVER]"#COL_LRED" Admin %s has IP banned %s: %s", pName,  pTargetName, reason);
	SendClientMessageToAll(COLOR_RED,string);
	Ban(targetid);
	}
	return 1;
}
Every single one that has this line in it

Код:
if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_ERROR, "[ERROR]: Player not connected!");
Ends up not working, no matter what name or ID I put it tells me that they're not connected.
Reply
#2

remove:
'else'
'{'
'}'
as I see no use of putting an else statement there, as the command gets stopped if any of these checks return true by the 'return' function.
Reply
#3

So, just like this?

Код:
//-----[Ban]-----
CMD:ban(playerid, params[])
{
	if(PlayerInfo[playerid][Adminlevel] < 2) return SendClientMessage(playerid,COLOR_ERROR,"[ERROR]: You are not authorized to use this command ");
	new targetid, reason[64], string[128];
	if(sscanf(params, "uz", targetid, reason)) return SendClientMessage(playerid, COLOR_SYNTAX, "[SYNTAX]: /ban [PlayerID/PartOfName] [Reason]");
	if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_ERROR, "[ERROR]: Player not connected!");
	new pTargetName[24], pName[24];
	GetPlayerName(playerid,pName,24);
	GetPlayerName(targetid,pTargetName,24);
	format(string, sizeof(string), ""#COL_YELLOW"[SERVER]"#COL_LRED" Admin %s has IP banned %s: %s", pName,  pTargetName, reason);
	SendClientMessageToAll(COLOR_RED,string);
	Ban(targetid);
	}
	return 1;
}
Reply
#4

You forgot to remove the second last closing bracket, if so, compile.. errors? fix them, cant fix em? post them..
once there was a time where you didnt have to wait 120 seconds.. how can I possible help multiple people at once now.
Reply
#5

pawn Код:
if(sscanf(params, "uz", targetid, reason)) return SendClientMessage(playerid, COLOR_SYNTAX, "[SYNTAX]: /ban [PlayerID/PartOfName] [Reason]");
z is removed and replaced with a capital letter S.
Reply
#6

None of those methods seemed to have worked for me, maybe it's because I was messing with a different command

what I have now

Код:
//-----[Adminhelp]-----
CMD:kick(playerid, params[])
{
	if(PlayerInfo[playerid][Adminlevel] < 1) return SendClientMessage(playerid,COLOR_ERROR,"[ERROR]: You are not authorized to use this command ");
	new targetid, reason[64], string[128];
	if(sscanf(params, "uS", targetid, reason)) return SendClientMessage(playerid, COLOR_SYNTAX, "[SYNTAX]: /kick [PlayerID/PartOfName] [Reason]");
	if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_ERROR, "[ERROR]: Player not connected!");
	else
	{
	new pTargetName[24], pName[24];
	GetPlayerName(playerid,pName,24);
	GetPlayerName(targetid,pTargetName,24);
	format(string, sizeof(string), ""#COL_YELLOW"[SERVER]"#COL_LRED" Administrator %s has kicked %s: Reason: %s", pName, pTargetName, reason);
	SendClientMessageToAll(COLOR_RED,string);
	Kick(targetid);
	return 1;
	}
}
That works the same as the old one, but when I do this

Код:
//-----[Adminhelp]-----
CMD:kick(playerid, params[])
{
	if(PlayerInfo[playerid][Adminlevel] < 1) return SendClientMessage(playerid,COLOR_ERROR,"[ERROR]: You are not authorized to use this command ");
	new targetid, reason[64], string[128];
	if(sscanf(params, "S", targetid, reason)) return SendClientMessage(playerid, COLOR_SYNTAX, "[SYNTAX]: /kick [PlayerID/PartOfName] [Reason]");
	if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_ERROR, "[ERROR]: Player not connected!");
	else
	{
	new pTargetName[24], pName[24];
	GetPlayerName(playerid,pName,24);
	GetPlayerName(targetid,pTargetName,24);
	format(string, sizeof(string), ""#COL_YELLOW"[SERVER]"#COL_LRED" Administrator %s has kicked %s: Reason: %s", pName, pTargetName, reason);
	SendClientMessageToAll(COLOR_RED,string);
	Kick(targetid);
	return 1;
	}
}
I can kick myself by typing "/kick"
Reply
#7

Because at the second one you don't specify "id" because ur just using a string, and not "u"


And take away the else{ part
Reply
#8

Again, I'm getting same problem I was getting the first time.

Код:
//-----[Adminhelp]-----
CMD:kick(playerid, params[])
{
	if(PlayerInfo[playerid][Adminlevel] < 1) return SendClientMessage(playerid,COLOR_ERROR,"[ERROR]: You are not authorized to use this command ");
	new targetid, reason[64], string[128];
	if(sscanf(params, "uS", targetid, reason)) return SendClientMessage(playerid, COLOR_SYNTAX, "[SYNTAX]: /kick [PlayerID/PartOfName] [Reason]");
	if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_ERROR, "[ERROR]: Player not connected!");
	new pTargetName[24], pName[24];
	GetPlayerName(playerid,pName,24);
	GetPlayerName(targetid,pTargetName,24);
	format(string, sizeof(string), ""#COL_YELLOW"[SERVER]"#COL_LRED" Administrator %s has kicked %s: Reason: %s", pName, pTargetName, reason);
	SendClientMessageToAll(COLOR_RED,string);
	Kick(targetid);
	return 1;
}
And if I take out the "u" and just leave "S" it only works like this "/kick" and automatically kicks id 0
Reply
#9

Here, edit my script:


pawn Код:
CMD:kick(playerid, params[])
{
    new id;
    new reason[64];
        if(PlayerInfo[playerid][AdminLevel] >= 1)
        {
            if(!sscanf(params, "uS(no Reason given)[64]", id, reason))
            {
                if(!IsPlayerAdmin(id))
                {
                if(isspawned[playerid] == 0) return Kick(playerid);
                new string[256];
                new name[MAX_PLAYER_NAME], PlayerName[MAX_PLAYER_NAME];
                GetPlayerName(playerid, name, sizeof(name));
                GetPlayerName(id, PlayerName, sizeof(PlayerName));
                format(string, sizeof(string), "Administrator %s has just kicked %s for reason %s", name, PlayerName, reason);
                LocalChat(10000000000.0, playerid, string, 0xFF0000FF, 0xFF0000FF, 0xFF0000FF, 0xFF0000FF, 0xFF0000FF);
                GameTextForPlayer(id, "~r~You are kicked from the server!", 6000, 3);
                Kick(id);
                return 1;
                }
                else
                {
                    new name[MAX_PLAYER_NAME], PlayerName[MAX_PLAYER_NAME];
                    new string[256];
                    GetPlayerName(playerid, name, sizeof(name));
                    GetPlayerName(id, PlayerName, sizeof(PlayerName));
                    format(string, sizeof(string), "Administrator %s tried to kick %s but got counter kicked like a boss!", name, PlayerName);
                    LocalChat(10000000000.0, playerid, string, 0xFF0000FF, 0xFF0000FF, 0xFF0000FF, 0xFF0000FF, 0xFF0000FF);
                    GameTextForPlayer(playerid, "~r~You are kicked from the server!", 6000, 3);
                    Kick(playerid);
                }
                return 1;
            }
            else return SendClientMessage(playerid, 0xD8D8D8FF, "USAGE: /kick [PlayerId/PartOfName] (Reason)");
        }
        else return SendClientMessage(playerid, 0xD8D8D8FF, "You are not allowed to use this command.");
}
Reply
#10

Okay, well, here are some minor errors.

Код:
C:\Users\GTW\BaseNorton V2\gamemodes\Gamemode.pwn(1097) : error 017: undefined symbol "isspawned"
C:\Users\GTW\BaseNorton V2\gamemodes\Gamemode.pwn(1097) : warning 215: expression has no effect
C:\Users\GTW\BaseNorton V2\gamemodes\Gamemode.pwn(1097) : error 001: expected token: ";", but found "]"
C:\Users\GTW\BaseNorton V2\gamemodes\Gamemode.pwn(1097) : error 029: invalid expression, assumed zero
C:\Users\GTW\BaseNorton V2\gamemodes\Gamemode.pwn(1097) : fatal error 107: too many error messages on one line
Here's line 1097

Код:
if(isspawned[playerid] == 0) return Kick(playerid);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)