..:D&G:.. Posted March 28, 2016 Share Posted March 28, 2016 Hello guys, so I have this function which checks if the player has a sleeping bag placed in the world: function hasPlayerSleepingBag(thePlayer) if thePlayer then local account = getAccountName(getPlayerAccount(thePlayer)) local result = db:query("SELECT owner FROM sleepingbags") if result then if account == result[1]['owner'] then return true end else return false end end end addEvent("hasPlayerSleepingBag", true) addEventHandler("hasPlayerSleepingBag", getRootElement(), hasPlayerSleepingBag) Now, I need to use this function client side, so I made this: function hasPlayerSleepingBag(thePlayer) triggerServerEvent("hasPlayerSleepingBag", thePlayer, thePlayer) end The problem is... it doesn't work -.- I did this quick test: function teestFunc() if hasPlayerSleepingBag(getLocalPlayer()) then outputChatBox("YES") else outputChatBox("NO") end end addCommandHandler("test11", teestFunc) And it always outputs NO, but server side it outputs YES... Any ideas? Thanks. Link to comment
Anubhav Posted March 28, 2016 Share Posted March 28, 2016 It will always output no, because the function doesn't return anything (hasPlayerSleepingBag). You have to use triggerClientEvent from the server side and then addEvent. Link to comment
..:D&G:.. Posted March 28, 2016 Author Share Posted March 28, 2016 It will always output no, because the function doesn't return anything (hasPlayerSleepingBag). You have to use triggerClientEvent from the server side and then addEvent. What do you mean...? I don't get it Link to comment
Dazee Posted March 28, 2016 Share Posted March 28, 2016 But you can't do an if on a function mate because it will always return true Link to comment
..:D&G:.. Posted March 28, 2016 Author Share Posted March 28, 2016 But you can't do an if on a function mate because it will always return true I've used that method before and it worked. That should return whatever the function returns. But in this case it only returns false... Link to comment
Fist Posted March 28, 2016 Share Posted March 28, 2016 But you can't do an if on a function mate because it will always return true You are totally wrong here, i use it a lot times in my own scripting. [quote name=..&G:..] It will always output no, because the function doesn't return anything (hasPlayerSleepingBag). You have to use triggerClientEvent from the server side and then addEvent. What do you mean...? I don't get it He meant that when u trigger server side event, you need get info back from server side event to client side event by using triggerClientEvent. So that is the reason why it outputs NO on client side but on server side outputs YES, because Client side doesnt know that information because you havent returned that correct info back to client side from server side. Link to comment
Anubhav Posted March 29, 2016 Share Posted March 29, 2016 But you can't do an if on a function mate because it will always return true You are totally wrong here, i use it a lot times in my own scripting. [quote name=..&G:..] It will always output no, because the function doesn't return anything (hasPlayerSleepingBag). You have to use triggerClientEvent from the server side and then addEvent. What do you mean...? I don't get it He meant that when u trigger server side event, you need get info back from server side event to client side event by using triggerClientEvent. So that is the reason why it outputs NO on client side but on server side outputs YES, because Client side doesnt know that information because you havent returned that correct info back to client side from server side. Thank you. Returns Returns true if the event trigger has been sent, false if invalid arguments were specified or a client side element was a parameter. It will always return true if the event was sent. But now in the functions you're not returning anything which causes you giving nil which gives you false value. The other information is given above by the person. Thank you again for explaining it! 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