SendClientMessageToAll Help -
ofir060 - 01.03.2013
Hey, I've made a simply command using the SendClientMessageToAll.
COMMAND:kick(playerid, params[])
{
if(IsPlayerAdmin(playerid)||PInfo[playerid][pAdmin] > 0){
new id;
new reason[256];
if (!sscanf(params, "us", id,reason)){
if(id != INVALID_PLAYER_ID){
format(string,sizeof(string),"AdmWrn: %s was kicked by %s reason: "COL_YELLOW"%s",PlayerName(id),PlayerName(playerid ),reason);
SendClientMessageToAll(COLOR_RED,string);
Kick(id);
}else return SendPM(playerid, COLOR_GRAD2, "The player is disconnected");
}else return SendPM(playerid, COLOR_GRAD2, "/kick [id] [reason]");
}
return 1;
}
When I did that on myself, It didnt sent me the SendClientMessageToAll, I recived only a message of the Kick(id).
The same bug/problem happends with anything else im scripting with SendClientMessageToAll and Kick.
Re: SendClientMessageToAll Help - Patrick - 01.03.2013
try this. hope it helps
pawn Код:
COMMAND:kick(playerid, params[])
{
new
id,
reason[128]
;
if(IsPlayerAdmin(playerid) || PInfo[playerid][pAdmin] < 0) return SendPM(playerid, -1,"You're Not Authorized to use this command");
if(sscanf(params, "us[128]", id,reason)) return SendPM(playerid, COLOR_GRAD2, "/kick [id] [reason]");
if(id == INVALID_PLAYER_ID) return SendPM(playerid, COLOR_GRAD2, "The player is disconnected");
format(string,sizeof(string),"AdmWrn: %s[%d] was kicked by %s[%d] reason: "COL_YELLOW"%s",PlayerName(id),id,PlayerName(playerid),playerid,reason);
SendClientMessageToAll(COLOR_RED,string);
Kick(id);
return 1;
}
Cheers
PDS2012
Re: SendClientMessageToAll Help -
AndreT - 01.03.2013
A small bit of advice here: you should return 1 in the command. On every occasion, I mean, including the error cases. As SendPM is not a native function and we don't know its return value, you should resort to writing code like this:
pawn Код:
return SendPM(playerid, ..., "..."), true;
... to return true, when helping others in help topics.
Also, SendClientMessage does not have a documented return value. So this is why it should be preferred for practice.
Re: SendClientMessageToAll Help -
ofir060 - 01.03.2013
Quote:
Originally Posted by pds2012
try this. hope it helps
pawn Код:
COMMAND:kick(playerid, params[]) { new id, reason[128] ; if(IsPlayerAdmin(playerid) || PInfo[playerid][pAdmin] < 0) return SendPM(playerid, -1,"You're Not Authorized to use this command"); if(sscanf(params, "us[128]", id,reason)) return SendPM(playerid, COLOR_GRAD2, "/kick [id] [reason]"); if(id == INVALID_PLAYER_ID) return SendPM(playerid, COLOR_GRAD2, "The player is disconnected"); format(string,sizeof(string),"AdmWrn: %s[%d] was kicked by %s[%d] reason: "COL_YELLOW"%s",PlayerName(id),id,PlayerName(playerid),playerid,reason); SendClientMessageToAll(COLOR_RED,string); Kick(id); return 1; }
Cheers
PDS2012
|
Thank you.
I'll check it out as soon i'll be at my place.
Quote:
Originally Posted by AndreT
A small bit of advice here: you should return 1 in the command. On every occasion, I mean, including the error cases. As SendPM is not a native function and we don't know its return value, you should resort to writing code like this:
pawn Код:
return SendPM(playerid, ..., "..."), true;
... to return true, when helping others in help topics.
Also, SendClientMessage does not have a documented return value. So this is why it should be preferred for practice.
|
I wondered about it too, Didnt knew how to properly do it.
Thank you.
Btw, the SendPM is SendClientMessage.
Re: SendClientMessageToAll Help -
ofir060 - 01.03.2013
Quote:
Originally Posted by pds2012
try this. hope it helps
pawn Код:
COMMAND:kick(playerid, params[]) { new id, reason[128] ; if(IsPlayerAdmin(playerid) || PInfo[playerid][pAdmin] < 0) return SendPM(playerid, -1,"You're Not Authorized to use this command"); if(sscanf(params, "us[128]", id,reason)) return SendPM(playerid, COLOR_GRAD2, "/kick [id] [reason]"); if(id == INVALID_PLAYER_ID) return SendPM(playerid, COLOR_GRAD2, "The player is disconnected"); format(string,sizeof(string),"AdmWrn: %s[%d] was kicked by %s[%d] reason: "COL_YELLOW"%s",PlayerName(id),id,PlayerName(playerid),playerid,reason); SendClientMessageToAll(COLOR_RED,string); Kick(id); return 1; }
Cheers
PDS2012
|
Didnt worked, Same problem :S
Note that this is not happening just in /kick, on all the other things related to Kick/Ban &SendClientMsgToAll..
Ah and I have a question.
Why on error messages there's a return?
example:
CMD:hey(playerid,params[])
{
if(x != 1) reuturn SendPM(playerid,x...,x...), true;
return 1;
}
When it can just use the return below it?
Re: SendClientMessageToAll Help - Patrick - 01.03.2013
there is many way to do that. but i mostly use that because its only 1 line and convserved space
pawn Код:
CMD:hey(playerid,params[])//1st Pattern i always use
{
if(x != 1) reuturn SendPM(playerid,x...,x...); // you dont need true
return 1;
}
CMD:hey(playerid, params[])//i never tried this one
{
if(x != 1)
{
SendPM(playerid,x...,x...);
return 1;
}
return 1;
}
CMD:hey(playerid, params[])//sometimes i use
{
if(x != 1)
{
return SendPM(playerid,x...,x...);
}
return 1;
}
CMD:hey(playerid, params[]//most people use this way
{
if(x != 1)
{
//stuff in here
}
else SendPM(playerid,x...,x...);
return 1;
}
Re: SendClientMessageToAll Help -
AndreT - 01.03.2013
pds2012, the 2 codes below are not identical:
Код:
return SendPM(playerid, -1, "What?");
Код:
return SendPM(playerid, -1, "What?"), true;
ofir060, in SA-MP 0.3x, when the client receives a packet saying it is kicked from the server, no further communication is held with the server from what I know. This behavior is necessary to prevent some cheats. To prevent the kicked player from not receiving the messages, please set the player to be kicked in a timer.
Refer to:
http://forum.sa-mp.com/showpost.php?...2&postcount=14
Re: SendClientMessageToAll Help -
ofir060 - 01.03.2013
@AndreT - Thank's for help, Really don't get that new setting..
@pds2012 ikr?!
Thank you all for helping me, I think this is all been solved.
Re: SendClientMessageToAll Help -
mittukuttan - 02.03.2013
CMD:kick(playerid,params[])
{
new id,name1[MAX_PLAYER_NAME], reason[35], string[128], logstring[256];
if(PlayerInfo[playerid][pAdmin] < 2) return ShowPlayerDialog(playerid,0, DIALOG_STYLE_MSGBOX,"ERROR:","YOU ARE NOT HIGH ENOUGH TO USE THIS COMMAND BUY VIP LEVEL 2 @
WWW.LFGR.SMMFY.COM","Ok","");
else if(sscanf(params,"uz",id,reason)) return SendClientMessage(playerid, COLOR_WHITE,"USAGE: /kick [playerid/PartOfName] [reason]");
else if(!IsPlayerConnected(id)) return SendClientMessage(playerid, COLOR_GREY,"Invalid player specified !");
else if(PlayerInfo[id][pAdmin] > PlayerInfo[playerid][pAdmin]) return SendClientMessage(playerid, COLOR_GRAD2, " You can't ban higher level administrators !");
else
{
new year, month, day;
getdate(year, month, day);
GetPlayerName(id,name1,sizeof(name1));
format(string, sizeof(string),"AdmCmd: %s has been kicked by %s, reason: %s",name1, GetName(playerid), reason);
SendClientMessageToAll(COLOR_LIGHTRED,string);
Kick(id);
format(logstring, sizeof(logstring), "AdmCmd: %s was kicked by %s, reason: %s (%d-%d-%d).", name1, GetName(playerid), reason, month, day, year);
KickLog(logstring);
}
return 1;
}
Re: SendClientMessageToAll Help -
Denying - 02.03.2013
This is the first post made by you:
pawn Код:
COMMAND:kick(playerid, params[])
{
if(IsPlayerAdmin(playerid)||PInfo[playerid][pAdmin] > 0){
new id;
new reason[256];
if (!sscanf(params, "us", id,reason)){
if(id != INVALID_PLAYER_ID){
format(string,sizeof(string),"AdmWrn: %s was kicked by %s reason: "COL_YELLOW"%s",PlayerName(id),PlayerName(playerid),reason);
SendClientMessageToAll(COLOR_RED,string);
Kick(id);
}else return SendPM(playerid, COLOR_GRAD2, "The player is disconnected");
}else return SendPM(playerid, COLOR_GRAD2, "/kick [id] [reason]");
}
return 1;
}
This is mine:
PHP код:
forward KickTimer(playerid);
public KickTimer(playerid)
{
Kick(playerid);
}
stock KickMessage(playerid, message[128])
{
SendClientMessage(playerid, COLOR_ADMIN, message);
SetTimerEx("KickTimer", 90, 0, "d", playerid);
}
And now..
pawn Код:
COMMAND:kick(playerid, params[])
{
if(IsPlayerAdmin(playerid)||PInfo[playerid][pAdmin] > 0){
new id;
new reason[256];
if (!sscanf(params, "us", id,reason)){
if(id != INVALID_PLAYER_ID){
format(string,sizeof(string),"AdmWrn: %s was kicked by %s reason: "COL_YELLOW"%s",PlayerName(id),PlayerName(playerid),reason);
KickMessage(id, string);
Kick(id);
}else return SendPM(playerid, COLOR_GRAD2, "The player is disconnected");
}else return SendPM(playerid, COLOR_GRAD2, "/kick [id] [reason]");
}
return 1;
}