What's wrong with getting the UUID in this function?
#1
Hi,
I'm about getting the UUID of a user to add them to a text file. It somehow doesn't work. :/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
local addusertofile = function(OtherPlayer)
    if OtherPlayer:GetName() == Split[3] then
        if OtherPlayer:GetUUID() == nil or OtherPlayer:GetUUID() == "" then
            friendusername = cMojangAPI:GetUUIDFromPlayerName(Split[3], true)
        else
            friendusername = OtherPlayer:GetUUID()
        end
        local file = io.open(friendDir.."\\friends.txt", "a")
        file:write(friendusername.."\n")
        file:close()
        Player:SendMessageSuccess("Friend added. You can check with /friend [playername]")
    else
        Player:SendMessageFailure("Fail")
    end
end
if not cRoot:Get():FindAndDoWithPlayer(Split[3], addusertofile) then
    Player:SendMessageFailure("Invalid Playername")
end
end

=> Always says "Invalid Playername" ingame so FindAndDoWith... was not successfull?!
Reply
Thanks given by:
#2
Try this instead:
1
2
3
4
5
6
7
8
9
10
local UUID = cMojangAPI:GetUUIDFromPlayerName(Split[3], true)
if (UUID == "") then
   Player:SendMessageFailure("Invalid Playername")
   return true
end
 
local file = io.open(friendDir .. "/friends.txt", "a")
file:write(UUID, "\n")
file:close()
Player:SendMessageSuccess("Friend added. You can check with /friend [playername]")

You're using FindAndDoWithPlayer, but that means he already came online at least once. This means his UUID is already known in the database.
Reply
Thanks given by:
#3
I've got now:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
local addusertofile = function(OtherPlayer)
    if OtherPlayer:GetName() == Split[3] then
        friendusername = OtherPlayer:GetUUID()
        local file = io.open(friendDir.."\\friends.txt", "a")
        file:write(friendusername.."\n")
        file:close()
        Player:SendMessageSuccess("Friend added. You can check with /friend [playername]")
    else
        Player:SendMessageFailure("Fail")
    end
end
if not cRoot:Get():FindAndDoWithPlayer(Split[3], addusertofile) then
    local UUID = cMojangAPI:GetUUIDFromPlayerName(Split[3], true)
    if (UUID == "" or UUID == nil) then
        Player:SendMessageFailure("Invalid Playername")
    return true
    end
    local file = io.open(friendDir .. "/friends.txt", "a")
    file:write(UUID, "\n")
    file:close()
    Player:SendMessageSuccess("Friend added. You can check with /friend [playername]")
end

Still invalid player.
Reply
Thanks given by:
#4
You don't need FindAndDoWithPlayer. Try my code instead of all your code..
Reply
Thanks given by:
#5
(11-19-2015, 05:31 AM)NiLSPACE Wrote: You don't need FindAndDoWithPlayer. Try my code instead of all your code..

What's the difference between cClientHandle UUID and MojangAPI UUID call? I though the latter one uses more bandwidth (performance?).
Reply
Thanks given by:
#6
cClientHandle:GetUUID is a member variable. You can only get it when a player is online. cMojangAPI, when using cached only, will get the info from a sql database next to the executable. It won't affect the bandwidth at all.
Reply
Thanks given by:
#7
I see, thanks for explaining.

I've got now the following code:
1
2
3
4
5
6
7
8
9
local friendusername = cMojangAPI:GetUUIDFromPlayerName(Split[3], true)
if (friendusername == "" or friendusername == nil) then
    Player:SendMessageFailure("Invalid Playername")
    return true
end
local file = io.open(friendDir.."\\friends.txt", "a")
file:write(friendusername.."\n")
file:close()
Player:SendMessageSuccess("Friend added. You can check with /friend [playername]")

Still invalid playername. Is the MojangAPI broken?
I tried another function (/useruid <friendusername>):
1
2
local friendusername = cMojangAPI:GetUUIDFromPlayerName(Split[2], true)
Player:SendMessageInfo("Found player:"..friendusername)
Returns nil while the player definitely exists.
Reply
Thanks given by:
#8
The username you're trying to get did already come online right? Also, I believe the function is case sensitive. If I search for gamerboy59 while you logged in as Gamerboy59 you wouldn't show up.
Reply
Thanks given by:
#9
(11-19-2015, 10:48 PM)NiLSPACE Wrote: The username you're trying to get did already come online right?
No.

(11-19-2015, 10:48 PM)NiLSPACE Wrote: Also, I believe the function is case sensitive. If I search for gamerboy59 while you logged in as Gamerboy59 you wouldn't show up.
Yes, tried case sensitive doesn't matter.
Reply
Thanks given by:
#10
You are using true in the function cMojangAPI:GetUUIDFromPlayerName(Split[2], true).
True means that only the local cache will be used to lookup the uuid of the player. Set it to false, then it will connect to mojang to get the uuid.
cMojangAPI:GetUUIDFromPlayerName(Split[2], false)
Reply
Thanks given by:




Users browsing this thread: