Results 1 to 2 of 2

Thread: allow_rename

  1. #1
    Private
    Join Date
    Dec 2016
    Posts
    30
    Thanks
    5
    Thanked 5 Times in 5 Posts

    allow_rename

    searching for the forum, i found this script but it seems that the allow_rename is missing.

    can you tell what he does? do you have any?

    PHP Code:
    playerinit()
    {
        
    self.izno = []; //initialize player-info array
        
    self checkinitialname(); //fix initial "Unknown Soldier" names
        
    self.izno["userinfoname"] = self get_userinfo("name"); //keep track of the name as per the user's userinfo
        
    self thread monitor_namechange();
        
    self allow_rename(false);
    }

    checkinitialname()
    {
        
    name self get_userinfo("name");
        
    self.izno["realname"] = name;
        
    result checkname(name); //checkname returns true if the name is not allowed or a duplicate
        
    if(result)
        {
            
    //as i disallow duplicate names, this while() loop tries to find an open JumpersHeavenFan#NUMBER for the player to use
            
    while(result)
            {
                
    self.izno["realname"] = "JumpersHeavenFan#" randomintrange(1001000);
                
    result self checkname(self.izno["realname"]);
            }
            
    //now, to keep the userinfo the same to not excessively trigger a clientuserinfochanged event, store the user's name before renaming him
            
    userinfoname self get_userinfo("name");

            
    //this will allow clientuserinfochanged to rename the player
            
    self allow_rename(true);

            
    //change the name in the userinfo, then call the clientuserinfochanged function to do the actual renaming
            
    self set_userinfo("name"self.izno["realname"]);
            
    self clientuserinfochanged();

            
    //disallow any future user-started rename events
            
    self allow_rename(false);

            
    //restore the original userinfo
            
    self set_userinfo("name"userinfoname);
        }
        
    }

    monitor_namechange()
    {
        
    self endon("disconnect");
        while(
    true)
        {
            
    name self get_userinfo("name");

            
    //if the name in userinfo is different than the one stored serverside, the user changed his /name
            
    if(name != self.izno["userinfoname"])
            {
                
    //namechange event
                //check if user is allowed to change his name and what his real name should be
                
    self.izno["realname"] = self namechanged(name);

                
    //next few lines to the same as the renaming in checkinitialname()
                
    self set_userinfo("name"self.izno["realname"]);
                
    self allow_rename(true);
                
    self clientuserinfochanged();
                
    self allow_rename(false);
                
    self.izno["userinfoname"] = name;
                
    self set_userinfo("name"name);
            }
            
    wait 0.05;
        }
    }

    namechanged(newname)
    {
        
    in_use checkname(newname); //if the name is currently in use, try keeping your old name. If that's in use too, generate a new random name
        
    if(in_use)
        {
            
    old_in_use checkname(self.izno["realname"]);
            
    self iprintlnbold("No duplicate names allowed");
            if(!
    old_in_use)
                return 
    self.izno["realname"]; //user renaming DENIED
            
    else
            {
                
    //find a new name for this user as his old name is in use
                
    while(old_in_use)
                {
                    
    newname "JumpersHeavenFan#" randomintrange(1001000);
                    
    result self checkname(newname);
                }
                return 
    newname;
            }
        }
        else
            return 
    newname//renaming allowed
    }

    checkname(name)
    {
        
    name tolower(stripcolors(name)); //strip colors, remove capitals
        
    switch(name)
        {
            
    //you can add more names to this banned-names list.
            
    case "Unknown Soldier"
            case 
    "UnnamedPlayer":
                return 
    true;
        }
        
    players getentarray("player""classname");
        for(
    0players.sizei++)
        {
            if(
    players[i] == self)
                continue;
            if(
    tolower(stripcolors(players[i].name)) == name//another player has the same name after stripping colors
                
    return true;
        }
        return 
    false;
    }

    stripcolors(string)
    {
        
    gotcolors true;
        while(
    gotcolors)
        {
            
    gotcolors false;
            for(
    0string.size 1i++)
            {
                if(
    string[i] == "^" && isint(string[1]))
                {
                    
    newstring "";
                    if(
    0)
                        
    newstring += getsubstr(string0i);
                    if(
    string.size 2)
                        
    newstring += getsubstr(string2);
                    
    string newstring;
                    
    gotcolors true;
                    break;
                }
            }
        }
        return 
    string;
    }


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


  2. #2
    Private
    Join Date
    Feb 2018
    Posts
    28
    Thanks
    12
    Thanked 17 Times in 16 Posts
    Last edited by buLLeT_; 17th June 2018 at 00:18.

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

    kung foo man (17th June 2018)

Posting Permissions

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