Skream Posted August 12, 2018 Share Posted August 12, 2018 (edited) addEvent('browser:onClientTryLogin', true) addEventHandler('browser:onClientTryLogin', resourceRoot, function(username, password) triggerServerEvent('server:onClientTryLogin', localPlayer, username, password) end) this is my code clientside this is my code serverside function tryLogin(username, password) local formOptions = { method = 'POST', formFields = { ['username'] = username, ['password'] = password, } } fetchRemote(loginURL['login'], formOptions, function(data, info) if info.statusCode == 200 then local fetchData = fromJSON(data) local errorCode = tonumber(fetchData['response_code']) if errorCode ~= 0 then triggerClientEvent(client, 'client:onClientLoginFail', client, authErrors[errorCode]) triggerEvent('server:onClientLoginFail', client, authErrors[errorCode]) else setElementData(client, 'account:id', tonumber(fetchData['account']['id'])) setElementData(client, 'account:username', tostring(fetchData['account']['username'])) end end end ) end addEvent('server:onClientTryLogin', true) addEventHandler('server:onClientTryLogin', root, tryLogin) it prints me bad argument @setElementData expected element got nil but even if I print client ou source as a string I get the same userdata I tried to pass localPlayer as another var and it worked but I think it is not supposed to be like that Edited August 12, 2018 by Skream Link to comment
Keiichi1 Posted August 12, 2018 Share Posted August 12, 2018 (edited) Warning: You should use the global variable clientserverside instead of passing the localPlayer by parameter or source. Otherwise event faking (passing another player instead of the localPlayer) would be possible. More information at addEventHandler Copied from triggerServerEvent's wiki page. Edited August 12, 2018 by Keiichi1 Link to comment
Skream Posted August 12, 2018 Author Share Posted August 12, 2018 (edited) 5 minutes ago, Keiichi1 said: Warning: You should use the global variable clientserverside instead of passing the localPlayer by parameter or source. Otherwise event faking (passing another player instead of the localPlayer) would be possible. More information at addEventHandler Copied from triggerServerEvent's wiki page. As my code show I'm already doing it at least as I understood it says serverside Edited August 12, 2018 by Skream Link to comment
Saml1er Posted August 12, 2018 Share Posted August 12, 2018 (edited) fetchRemote(loginURL['login'], formOptions, function(data, info, client) -- and this if info.statusCode == 200 then local fetchData = fromJSON(data) local errorCode = tonumber(fetchData['response_code']) if errorCode ~= 0 then triggerClientEvent(client, 'client:onClientLoginFail', client, authErrors[errorCode]) triggerEvent('server:onClientLoginFail', client, authErrors[errorCode]) else setElementData(client, 'account:id', tonumber(fetchData['account']['id'])) setElementData(client, 'account:username', tostring(fetchData['account']['username'])) end end end, "", false, client -- this ) Edited August 12, 2018 by Saml1er 1 Link to comment
Skream Posted August 12, 2018 Author Share Posted August 12, 2018 (edited) 12 minutes ago, Saml1er said: fetchRemote(loginURL['login'], formOptions, function(data, info, client) -- and this if info.statusCode == 200 then local fetchData = fromJSON(data) local errorCode = tonumber(fetchData['response_code']) if errorCode ~= 0 then triggerClientEvent(client, 'client:onClientLoginFail', client, authErrors[errorCode]) triggerEvent('server:onClientLoginFail', client, authErrors[errorCode]) else setElementData(client, 'account:id', tonumber(fetchData['account']['id'])) setElementData(client, 'account:username', tostring(fetchData['account']['username'])) end end end, "", false, client -- this ) still not working same expected element at argument 1 got nil The only way it works is if I do this local theSource = client and use theSource as the element Edited August 12, 2018 by Skream Link to comment
aka Blue Posted August 13, 2018 Share Posted August 13, 2018 change localPlayer by getLocalPlayer() and 'client' by 'source'. 1 Link to comment
Skream Posted August 13, 2018 Author Share Posted August 13, 2018 (edited) 20 minutes ago, aka Blue said: change localPlayer by getLocalPlayer() and 'client' by 'source'. They're the same thing as wiki says. Source doesn't work either. Its funny cuz in my character creation script I passed the variable the same as I do in login and it works fine. Edited August 13, 2018 by Skream Link to comment
VenomOG Posted August 13, 2018 Share Posted August 13, 2018 Just now, Skream said: They're the same thing as wiki says. Source doesn't work either. Its funny cuz in my character creation script I passed the variable the same as I do in login and it works. fine. Try changing getLocalPlayer() to getRootElement() and source root Link to comment
Skream Posted August 13, 2018 Author Share Posted August 13, 2018 (edited) 50 minutes ago, Saml1er said: fetchRemote(loginURL['login'], formOptions, function(data, info, client) -- and this if info.statusCode == 200 then local fetchData = fromJSON(data) local errorCode = tonumber(fetchData['response_code']) if errorCode ~= 0 then triggerClientEvent(client, 'client:onClientLoginFail', client, authErrors[errorCode]) triggerEvent('server:onClientLoginFail', client, authErrors[errorCode]) else setElementData(client, 'account:id', tonumber(fetchData['account']['id'])) setElementData(client, 'account:username', tostring(fetchData['account']['username'])) end end end, "", false, client -- this ) Guys, Saml1er was almost correct. I find it looking it on wiki the problem was in fetchRemote I had to pass client as a table after my function thank you guys for all your help I appreaciated it Edited August 13, 2018 by Skream 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