Jump to content

Help


manve1

Recommended Posts

I made a script ( it might make no sense ) and i can't figure out that when i click on the grid and on my or my mates name, serial stay's the same, could you possibly fix it?

addEventHandler( 'onClientGUIClick', aGrid, 
function() 
local pRow = guiGridListGetSelectedItem( aGrid ) 
if (pRow and pRow ~= -1) then 
guiSetText ( aSerial, "Serial: " .. getPlayerSerial( localPlayer, pRow, 1 ) ) 
end 
end 
) 

Link to comment
  • MTA Team

getPlayerSerial() client-side only returns the client's serial, not the one's you want to know.

However, guiSetText() doesn't work for grids as far as I know, you must use guiGridListSetItemText().

Use the code below, haven't tested it and I assume you have a player column in your gridlist and it is the first column? If yes, then it should work, if not, then change the columns in the below script.

Client-side

addEvent("onClientPlayerSerialFetched", true) 
addEventHandler("onClientPlayerSerialFetched", root, 
    function(serial, row) 
        guiGridListSetItemText(aGrid, row, 1, "Serial: " .. serial, false, false) 
    end 
) 
  
addEventHandler("onClientGUIClick", aGrid, 
    function() 
    local pRow = guiGridListGetSelectedItem(aGrid) 
        if (pRow and pRow ~= -1) then 
            triggerServerEvent("onClientPlayerSerialRequested", localPlayer, guiGridListGetItemText(aGrid, pRow, 1), pRow) 
        end 
    end 
) 

Server-side

addEvent("onClientPlayerSerialRequested", true) 
addEventHandler("onClientPlayerSerialRequested", root, 
    function(player, row) 
        if player and getPlayerFromName(player) then 
            triggerClientEvent(source, "onClientPlayerSerialFetched", source, getPlayerSerial(getPlayerFromName(player)), row) 
        else 
            outputChatBox("DEBUG: 'onClientPlayerSerialRequested' returned false.", source, 245, 40, 40, false) 
        end 
    end 
) 

Link to comment
  • MTA Team

It's very weird then. It should return their serial if the player is found with the exact name listed in the gridlist.

If gridlist removes hex codes and the player uses hex codes anyway, it will mess up. I can give you a findPlayer function soon for no need for such exact matches.

Link to comment
  • MTA Team
Lol? how can't it be found if he is playing D:

Probably because the gridlist doesn't show his hex color codes if he has any and they have been removed by your script. Also if the gridlist shows partial names, it won't find the player.

You can try the following code:

Server-side

function findPlayer(name, player) 
    if name == "*" and getElementType(player) == "player" then 
        return player 
    else 
        local matches = {} 
        for i,v in ipairs(getElementsByType("player")) do 
            if getPlayerName(v) == name and isLogged(v) then 
                return v 
            end 
            local playerName = getPlayerName(v):gsub("#%x%x%x%x%x%x", "") 
            playerName = playerName:lower() 
            if playerName:find(name:lower(), 0) and isLogged(v) then 
                table.insert(matches, v) 
            end 
        end 
        if #matches == 1 then 
            return matches[1] 
        end 
        return false 
    end 
end 
  
addEvent("onClientPlayerSerialRequested", true) 
addEventHandler("onClientPlayerSerialRequested", root, 
    function(player, row) 
        local target = findPlayer(player, source) 
        if target then 
            triggerClientEvent(source, "onClientPlayerSerialFetched", source, getPlayerSerial(getPlayerFromName(target)), row) 
        else 
            outputChatBox("DEBUG: 'onClientPlayerSerialRequested' returned false.", source, 245, 40, 40, false) 
        end 
    end 
) 

Link to comment
function findPlayer(name, player) 
    if name == "*" and getElementType(player) == "player" then 
        return player 
    else 
        local matches = {} 
        for i,v in ipairs(getElementsByType("player")) do 
            if getPlayerName(v) == name and not isGuestAccount ( getPlayerAccount ( v ) ) then 
                return v 
            end 
            local playerName = getPlayerName(v):gsub("#%x%x%x%x%x%x", "") 
            playerName = playerName:lower() 
            if playerName:find(name:lower(), 0) and not isGuestAccount ( getPlayerAccount ( v ) ) then 
                table.insert(matches, v) 
            end 
        end 
        if #matches == 1 then 
            return matches[1] 
        end 
        return false 
    end 
end 
  
addEvent("onClientPlayerSerialRequested", true) 
addEventHandler("onClientPlayerSerialRequested", root, 
    function(player, row) 
        local target = findPlayer(player, source) 
        if target then 
            triggerClientEvent(source, "onClientPlayerSerialFetched", source, getPlayerSerial(getPlayerFromName(target)), row) 
        else 
            outputChatBox("DEBUG: 'onClientPlayerSerialRequested' returned false.", source, 245, 40, 40, false) 
        end 
    end 
) 

Link to comment
  • MTA Team
Why are you using a function that does not exist?

Forgot to remove it, I use it in my scripts and I added that to make sure the player is logged in.

So aparently you saying it didn't find me?

Does your gridlist have the names of the players on it? Also, are you logged in?

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...