Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: custom ID ban

  1. #1
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts

    custom ID ban

    Hi all,

    Im working on a banfunction that bans with clientID
    Code:
    			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?

  2. #2
    Private First Class
    Join Date
    Oct 2013
    Posts
    219
    Thanks
    56
    Thanked 105 Times in 66 Posts
    PHP Code:
    if(isdefined(args[2]) && isint(args[2]))
        
    id int(args[2]);
    else
        return; 

  3. The Following User Says Thank You to filthy_freak_ For This Useful Post:

    Ni3ls (12th November 2015)

  4. #3
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    Quote Originally Posted by filthy_freak_ View Post
    PHP Code:
    if(isdefined(args[2]) && isint(args[2]))
        
    id int(args[2]);
    else
        return; 
    isint is an unknown function

  5. #4
    Private First Class
    Join Date
    Oct 2013
    Posts
    219
    Thanks
    56
    Thanked 105 Times in 66 Posts
    Quote Originally Posted by Ni3ls View Post
    isint is an unknown function
    Oops, you need libcod and this;

    PHP Code:
    isint(char)
    {
        
    asc getAscii(char);
        return 
    asc <= 57 && asc >= 48;


  6. The Following User Says Thank You to filthy_freak_ For This Useful Post:

    Ni3ls (12th November 2015)

  7. #5
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    Works perfectly!

  8. #6
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    No, it does not.

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

    Use this instead:
    PHP Code:
    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?
    }
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  9. The Following 2 Users Say Thank You to IzNoGoD For This Useful Post:

    filthy_freak_ (12th November 2015),Ni3ls (12th November 2015)

  10. #7
    Private First Class
    Join Date
    Oct 2013
    Posts
    219
    Thanks
    56
    Thanked 105 Times in 66 Posts
    That's right. isint I have is only good for using with 1 size char. Thanks for reminding me

  11. The Following User Says Thank You to filthy_freak_ For This Useful Post:

    Ni3ls (12th November 2015)

  12. #8
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    How does this
    Code:
        asc = getAscii(char);
        return asc <= 57 && asc >= 48;
    actually work?

  13. #9
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts

    10characters
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  14. The Following User Says Thank You to IzNoGoD For This Useful Post:

    Ni3ls (12th November 2015)

  15. #10
    Private First Class
    Join Date
    Oct 2013
    Posts
    219
    Thanks
    56
    Thanked 105 Times in 66 Posts
    Quote Originally Posted by Ni3ls View Post
    How does this
    Code:
        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.

  16. The Following User Says Thank You to filthy_freak_ For This Useful Post:

    Ni3ls (12th November 2015)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •