PDA

View Full Version : custom ID ban



Ni3ls
12th November 2015, 13:39
Hi all,

Im working on a banfunction that bans with clientID

case "@ban":
if (!isdefined(self.pers["admin"]) || self.pers["admin"] < 1)
{
self iprintlnbold("No admin!");
return;
}
if(isdefined(args[2]))
id = int(args[2]);
else
return;

if (!isdefined(args[3])) /// || args[3].size<1)
reden = "no reason";
else
{
//reden = "Reason: ";
reden = "";
for (i = 3; i < args.size; i++)
reden += args[i] + " ";
}
players = getentarray("player", "classname");
for(i = 0; i < players.size; i++)
{
if(players[i] getEntityNumber() == id)
{
self thread tellmessage("PLAYER: "+players[i].name +" ID: "+players[i] getEntityNumber());
/*id = players[i] getEntityNumber();
ip = players[i] getIP();
guid = players[i] getGUID();
if(guid != 0)
players[i] thread guidbanplayer(self, reden, id, guid);
else
players[i] thread ipbanplayer(self, reden, id, ip);*/
}
else
self thread tellmessage("NO PLAYER");
}
return;

When I write a non existence ID (101), like !@ban 101 REASON, it will show me the message "NO PLAYER".
When I write the correct ID, it will ban me.
However, when I write a string (aaaa) it will still kick the player with ID=0.
How to fix this?

filthy_freak_
12th November 2015, 13:56
if(isdefined(args[2]) && isint(args[2]))
id = int(args[2]);
else
return;

Ni3ls
12th November 2015, 14:11
if(isdefined(args[2]) && isint(args[2]))
id = int(args[2]);
else
return;


isint is an unknown function

filthy_freak_
12th November 2015, 14:13
isint is an unknown function

Oops, you need libcod and this;



isint(char)
{
asc = getAscii(char);
return asc <= 57 && asc >= 48;
}

Ni3ls
12th November 2015, 14:23
Works perfectly!

IzNoGoD
12th November 2015, 14:30
No, it does not.

Try kicking a player over 9, it will crash on the isint() part.

Use this instead:


isint(string)
{
return ((int(string) + "") == string + "");
}

However this will fail to recognize -0 as a number, but that shouldnt be too big of a deal right?
}

filthy_freak_
12th November 2015, 14:38
That's right. isint I have is only good for using with 1 size char. Thanks for reminding me :o

Ni3ls
12th November 2015, 14:43
How does this

asc = getAscii(char);
return asc <= 57 && asc >= 48;

actually work?

IzNoGoD
12th November 2015, 14:58
http://www.asciitable.com/index/asciifull.gif
10characters

filthy_freak_
12th November 2015, 14:58
How does this

asc = getAscii(char);
return asc <= 57 && asc >= 48;

actually work?

Have a look at http://www.asciitable.com/

getAscii returns the ascii number for that char.

Then it checks if that number is between 48 and 57, which are the ascii numbers for 0-9.

EDIT: Sniped.

Ni3ls
2nd December 2015, 20:03
Sorry to bump this

if (getAscii(args[1][0]) >= 20 && getAscii(args[1][0]) <= 22)
For the ingame b3/commands.
But how does this respond to the Ascii table?

kung foo man
2nd December 2015, 21:11
Seems to be just some magic values for something engine internal, IIRC there was no meaning to them besides messing up chat messages.



fixChatArgs(args)
{
if (isDefined(args[1])) { // engine is adding identifier infront of the chat message
if (getAscii(args[1][0]) >= 20 && getAscii(args[1][0]) <= 22) {
//std\io::print("delete bad ascii code: " + std\utils::getAscii(args[1][0]) + "\n");
args[1] = getSubStr(args[1], 1);
newArgs = strTok(args[1], " ");
for (i=0; i<newArgs.size; i++)
args[1+i] = newArgs[i];
}
}
return args;
}