Jump to content

Says localPlayer is not a element serverside


Skream

Recommended Posts

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 by Skream
Link to comment
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 by Skream
Link to comment
    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 by Saml1er
  • Like 1
Link to comment
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 by Skream
Link to comment
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 by Skream
Link to comment
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
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 by Skream
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...