AlfaMTA Posted April 6, 2014 Share Posted April 6, 2014 Hi guys! Again I here to ask your help Well, I trying to do a function in my gamemode to check if a player is VIP or not... To call this function I use triggerServerEvent triggerServerEvent("checkIfPlayerIsVIP", localPlayer) And I'm using the triggerServerEvent inside a if, see: if (triggerServerEvent("checkIfPlayerIsVIP", localPlayer)) == true then In the gamemode I put it: addEvent( "checkIsVIP", true ) addEventHandler( "checkIsVIP", root, function () local accName = getAccountName(getPlayerAccount(source)) if isObjectInACLGroup("user.".. accName, aclGetGroup("VIP")) then return true else return false end end) So I would want that the function in gamemode return a boolean value to use on my if to check if player is VIP or not I hope you understood my situation! Thanks for all! Link to comment
pa3ck Posted April 6, 2014 Share Posted April 6, 2014 triggerServerEvent returns true if it was succefully sent, false otherwise. You can't do it like that, you either make a triggerClientEvent from server side to client side to return true / false or create an exports function which returns true if a player is in the VIP group false otherwise. Link to comment
ixjf Posted April 7, 2014 Share Posted April 7, 2014 (edited) create an exports function which returns true if a player is in the VIP group false otherwise. Exports are for inter-resource communication, and you cannot call server exports from the client, nor vice-versa. Edited April 7, 2014 by Guest Link to comment
TAPL Posted April 7, 2014 Share Posted April 7, 2014 Put this server side: addEventHandler("onPlayerLogin", root, function(_, acc) local accName = getAccountName(acc) if isObjectInACLGroup("user."..accName, aclGetGroup("VIP")) then setElementData(source, "VIP", true) end end) Then use this client side: if getElementData(localPlayer, "VIP") == true then Lua tag is broken. Link to comment
pa3ck Posted April 7, 2014 Share Posted April 7, 2014 create an exports function which returns true if a player is in the VIP group false otherwise. Exports are for inter-resource communication, and you cannot call server exports from the client, nor vice-versa. I meant with the triggers, but yea, SetElementData is much better. Link to comment
AlfaMTA Posted April 7, 2014 Author Share Posted April 7, 2014 Put this server side: addEventHandler("onPlayerLogin", root, function(_, acc) local accName = getAccountName(acc) if isObjectInACLGroup("user."..accName, aclGetGroup("VIP")) then setElementData(source, "VIP", true) end end) Then use this client side: if getElementData(localPlayer, "VIP") == true then Lua tag is broken. My question were "How can I do return values through triggerEventServer or triggerEventClient to communicate serverside and clientside???" but your suggestion is a good way to resolve my problem Nice solution, I'm going to test it! Thank you! Link to comment
arezu Posted April 7, 2014 Share Posted April 7, 2014 (edited) My question were "How can I do return values through triggerEventServer or triggerEventClient to communicate serverside and clientside???" You cant return a value in such a way, since it takes time for the server to receive the data and to send it back, and that would mean you would have to freeze the client and wait for answer. The solution is to use triggerClientEvent server sided in the event that you trigged to trigger back to client. -- Client sided: addEvent("onReceiveVIPData", true) addEventHandler("onReceiveVIPData", resourceRoot, function(isVIP) -- You are a VIP if isVIP is true end) triggerServerEvent("checkIfPlayerIsVIP", resourceRoot) -- Server sided: addEvent("checkIfPlayerIsVIP", true) addEventHandler("checkIfPlayerIsVIP", resourceRoot, function() -- 'client' variable is set by mta to the player that triggered the event from client-side local accName = getAccountName(getPlayerAccount(client)) local isVIP = false if isObjectInACLGroup("user.".. accName, aclGetGroup("VIP")) then isVIP = true end triggerClientEvent(client, "onReceiveVIPData", resourceRoot, isVIP) end) But a better solution here would be to use onPlayerLogin and setElementData to the player as VIP, or maybe even set the players team to VIP team. Edited April 8, 2014 by Guest Link to comment
Moderators IIYAMA Posted April 7, 2014 Moderators Share Posted April 7, 2014 @arezu ]] function test () end [/code] --[[ [code=lua] Link to comment
arezu Posted April 8, 2014 Share Posted April 8, 2014 @arezu ]] [/code] --[[ [code=lua] Thanks Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now