PDA

View Full Version : Player Is Not connected Bug


Mike97300
12/06/2012, 11:09 PM
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.

Mike_Peterson
12/06/2012, 11:12 PM
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.

Mike97300
12/06/2012, 11:16 PM
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;
}

Mike_Peterson
12/06/2012, 11:21 PM
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.

milanosie
12/06/2012, 11:24 PM
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.

Mike97300
12/06/2012, 11:40 PM
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"

milanosie
12/06/2012, 11:41 PM
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

Mike97300
12/06/2012, 11:50 PM
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

milanosie
12/06/2012, 11:54 PM
Here, edit my script:



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.");
}

Mike97300
13/06/2012, 12:08 AM
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);