/ban help
#1

i have /ban command from tutorial i want it to say reason plz show me.

pawn Код:
dcmd_ban(playerid,params[])
{
    new id, name[MAX_PLAYER_NAME],on[MAX_PLAYER_NAME];
    new tmp[256], Index, str[49];
    tmp = strtok(params,Index), id = strval(tmp);
    GetPlayerName(id,on,sizeof(on));
    GetPlayerName(playerid,name,sizeof(name));
    if(pInfo[playerid][Level] < 3) return SendClientMessage(playerid,RED,">> You Need To Be Level 3+ To Use This Command!");
    if(!strlen(params)) return SendClientMessage(playerid,RED,"USAGE: /ban [id] ");
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid,RED,">> Invalid [id]!");
    format(str,sizeof(str),">> Administrator %s Has Banned %s From The Server!",name,on);
    SendClientMessageToAll(RED,str);
    Ban(id);
    return 1;
}
Reply
#2

pawn Код:
dcmd_ban(playerid,params[])
{
    new id, name[MAX_PLAYER_NAME],on[MAX_PLAYER_NAME];
    new tmp[256], Index, str[49];
    tmp = strrest(params,idx);
    id = strval(tmp);
    GetPlayerName(id,on,sizeof(on));
    GetPlayerName(playerid,name,sizeof(name));
    if(pInfo[playerid][Level] < 3) return SendClientMessage(playerid,RED,">> You Need To Be Level 3+ To Use This Command!");
    if(!strlen(params)) return SendClientMessage(playerid,RED,"USAGE: /ban [id] [reason]");
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid,RED,">> Invalid [id]!");
    format(str,sizeof(str),">> Administrator %s Has Banned %s Reason: %s",name,on,tmp);
    SendClientMessageToAll(RED,str);
    Ban(id);
    return 1;
}
And put this to your gamemode
pawn Код:
stock strrest(const string[], index)
{
    new length = strlen(string),offset = index,result[256];
    while ((index < length) && ((index - offset) < (sizeof(result) - 1)) && (string[index] > '\r'))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}
Reply
#3

pawn Код:
dcmd_ban(playerid,params[])
{
    new id, name[MAX_PLAYER_NAME],on[MAX_PLAYER_NAME];
    new tmp[256], Index, str[49];
    tmp = strtok(params,Index), id = strval(tmp);
    GetPlayerName(id,on,sizeof(on));
    GetPlayerName(playerid,name,sizeof(name));
    if(pInfo[playerid][Level] < 3) return SendClientMessage(playerid,RED,">> You Need To Be Level 3+ To Use This Command!");
    if(!strlen(params)) return SendClientMessage(playerid,RED,"USAGE: /ban [id] ");
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid,RED,">> Invalid [id]!");
    tmp = strrest(params, idx);
    if(!strlen(tmp)) return SendClientMessage(playerid, RED, "/USEAGE: /ban [id] [reason]");
    format(str,sizeof(str),">> Administrator %s Has Banned %s From The Server! (%s)",name,on, tmp);
    SendClientMessageToAll(RED,str);
    Ban(id);
    return 1;
}

stock strrest(const string[], index)
{
    new length = strlen(string),offset = index,result[256];
    while ((index < length) && ((index - offset) < (sizeof(result) - 1)) && (string[index] > '\r'))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}
alby's won't work... with id = strval(tmp) you are getting the number of e.g. "0 You are a noob"..
id will be 0.... if you now enter: "1 you are noob"... it will still be 0 as "you are noob" is still within the string but no number and strval creates an integer of the whole string, so if it isn't a number it always returns 0
Reply
#4

please explain how i can add reasons and id's to commands of this such<And plz show me what u did :S wiki is hard to understand :S
Reply
#5

pawn Код:
dcmd_ban(playerid,params[])
{
    new id, name[MAX_PLAYER_NAME],on[MAX_PLAYER_NAME];
    new tmp[256], Index, str[49];
    tmp = strtok(params,Index), id = strval(tmp);  //gets the id of the player so the first characters that are behind each other without a space between and converts it into an integer
    GetPlayerName(id,on,sizeof(on));
    GetPlayerName(playerid,name,sizeof(name));
    if(pInfo[playerid][Level] < 3) return SendClientMessage(playerid,RED,">> You Need To Be Level 3+ To Use This Command!");
    if(!strlen(params)) return SendClientMessage(playerid,RED,"USAGE: /ban [id] ");
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid,RED,">> Invalid [id]!");
    tmp = strrest(params, idx);  //this gets the rest of the string, excluded the id... e.g. if you enter "/ban 10 you are a fool", it gets the "you are a fool"
    if(!strlen(tmp)) return SendClientMessage(playerid, RED, "/USEAGE: /ban [id] [reason]"); //if there is no reason it sends this message
    format(str,sizeof(str),">> Administrator %s Has Banned %s From The Server! (%s)",name,on, tmp);  //the %s and the tmp include the reason into the string
    SendClientMessageToAll(RED,str);
    Ban(id);
    return 1;
}

stock strrest(const string[], index)   //this is the code you need to get the "rest" of a string which is not used by a strtok or so before
{
    new length = strlen(string),offset = index,result[256];
    while ((index < length) && ((index - offset) < (sizeof(result) - 1)) && (string[index] > '\r'))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}
I hope that helped a bit lol
Reply
#6

Quote:
Originally Posted by Sascha
Посмотреть сообщение
I hope that helped a bit lol
Briefly XD...Ahh could u explain how to do it in sccanf xD i sorta found the "uz" s**t a bit easier to understand xD

EDIT: with the code

Код:
error 017: undefined symbol "idx"
Reply
#7

Quote:
Originally Posted by YungGee
Посмотреть сообщение
Briefly XD...Ahh could u explain how to do it in sccanf xD i sorta found the "uz" s**t a bit easier to understand xD

EDIT: with the code

Код:
error 017: undefined symbol "idx"
Under onplayercommandtext
pawn Код:
new idx;
Edit: Use Sscanf and zcmd.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)