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 5 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 — 5y

3 answers

Log in to vote
1
Answered by 5 years ago
Edited 5 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:

01local function GetPlayerFromString(nameString)
02    local matches= {}
03    for _, player in ipairs (game.Players:GetPlayers()) do
04        if string.lower(player.Name):match("^".. string.lower(nameString)) then
05            table.insert(matches, player)
06        end
07    end
08    if #matches== 1 then
09        return matches[1]
10    else
11        return nil
12    end
13end

Hope this helps someone in the future, Tweakified

0
make sure to mark this question as answered ProjectInfiniti 192 — 5y
0
You can't mark your own answer to your own question as answered Tweakified 117 — 5y
Ad
Log in to vote
0
Answered by
Borrahh 265 Moderation Voter
5 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 — 5y
Log in to vote
0
Answered by 5 years ago

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

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

Answer this question