Jump to content

How to send getPlayerSerial form the server to client?


Hiding

Recommended Posts

Hi, I would like to ask how can I check the player's serial on the server side and send it to the client?

 


-- Server side
function isPlayerAllowed(player)
    return allowedPlayers[getPlayerSerial(player)] ~= nil
end

-- Client side
function handleKey(button, press)
    if not imagesEnabled and press and getKeyState("mouse2") then return false
	 	
	for i, allowedImage in ipairs(allowedImages) do
		if button == allowedImage.key then
			if isPlayerAllowed(localPlayer) then
				...
			end
		end
	end       
end
addEventHandler("onClientKey", root, handleKey)

 

Link to comment
3 hours ago, Hiding said:

Hi, I would like to ask how can I check the player's serial on the server side and send it to the client?

 


-- Server side
function isPlayerAllowed(player)
    return allowedPlayers[getPlayerSerial(player)] ~= nil
end

-- Client side
function handleKey(button, press)
    if not imagesEnabled and press and getKeyState("mouse2") then return false
	 	
	for i, allowedImage in ipairs(allowedImages) do
		if button == allowedImage.key then
			if isPlayerAllowed(localPlayer) then
				...
			end
		end
	end       
end
addEventHandler("onClientKey", root, handleKey)

 

--clientside
 

function handleKey(button, press)
    if not imagesEnabled and press and getKeyState("mouse2") then return false end

    for i, allowedImage in ipairs(allowedImages) do
        if button == allowedImage.key then
            triggerServerEvent("checkPlayerAllowed",localPlayer)
        end
    end
end
addEventHandler("onClientKey", root, handleKey)

--serverside
 

function isPlayerAllowed(player)
    return allowedPlayers[getPlayerSerial(player)] ~= nil
end

addEvent("checkPlayerAllowed",true)
addEventHandler("checkPlayerAllowed",resourceRoot,
   function()
      if isPlayerAllowed(client) then
            --whatever you do, write server side functions or do client operations with triggerClientEvent
       end 
   end)

 

Link to comment
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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