Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to shorten a players name?

Asked by 4 years ago

Hello,

I'm working on an admin system.

In certain commands, an admin can specify a command to work on a particular player. For example ;kill <player>

I wanted to make it so that the admin wouldn't have to specify the entire player name they wanted to effect. For example, for me, instead of having to do ;kill Tweakified, you could do ;kill Twea

How would this be achieved?

I thought of using :match to do this. However, running ;kill ified would also work.

Any advice/help you can give would be appriciated.

0
Yes, thats what I tried using, however if I used ;kill ified, it still works Tweakified 117 — 4y

3 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

After doing some additional research, I found a solution to my problem:

From this

I was able to modify the code to check only the start of the string with using the ^ This is how I modified the code:

local function GetPlayerFromString(nameString)
    local matches= {}
    for _, player in ipairs (game.Players:GetPlayers()) do
        if string.lower(player.Name):match("^".. string.lower(nameString)) then
            table.insert(matches, player)
        end
    end
    if #matches== 1 then
        return matches[1]
    else
        return nil
    end
end

Hope this helps someone in the future, Tweakified

0
make sure to mark this question as answered ProjectInfiniti 192 — 4y
0
You can't mark your own answer to your own question as answered Tweakified 117 — 4y
Ad
Log in to vote
0
Answered by
Borrahh 265 Moderation Voter
4 years ago

I don't think that this type of thing is even possible. You need to put the Full Player's Username, as Lua it's Case Sensitive.

0
It is possible did u even read his question he said how to shorten names like in an admin game. JesseSong 3916 — 4y
Log in to vote
0
Answered by 4 years ago

I'm conveniently doing the same thing. Here's my method:

local Players = game:GetService'Players';
local function GetPlayerFromSubString(Name)
    Name = Name:lower():reverse();
    for _,a in pairs(Players:GetPlayers())do
        local b = (a.Name):lower():reverse();
        if string.find(b,Name,#b-#Name)then -- Note: #(string) is the same as string.len
            return a;
        end;
    end;
end;
0
Nice, thats an interesting way of doing it! Tweakified 117 — 4y

Answer this question