Bebras Posted September 16, 2013 Share Posted September 16, 2013 Hello, so my topic name is not very informative as i don't really know where the problem is... Anyway, this is my server-side code: function checkPlayer(playerNick) local result = mysql_query(handler,"SELECT * FROM users WHERE Name = '"..playerNick.."'") if( not result) then outputDebugString("MySQL Fail ("..mysql_errno(handler)..") Error:"..mysql_error(handler)) end if(mysql_num_rows(result) == 0) then triggerClientEvent("onRegister",getRootElement()) outputDebugString("Should be triggered") else row = mysql_fetch_row(result) end mysql_free_result(result) end addEventHandler("onPlayerConnect",getRootElement(),checkPlayer) and this is my client-side code: function registerHandler() outputDebugString("Function for registering is called") end addEvent("onRegister",true) addEventHandler("onRegister",getRootElement(),registerHandler) And the string "function for registering is called" isn't printed out.. I did it exactly like in the wiki, and yet i failed somehow... where is the problem? Link to comment
kevenvz Posted September 16, 2013 Share Posted September 16, 2013 What if you use getLocalPlayer () and not getRootElement () Link to comment
Bebras Posted September 16, 2013 Author Share Posted September 16, 2013 If you meant here: addEventHandler("onRegister",getLocalPlayer(),registerHandler) , then it didn't help Link to comment
kevenvz Posted September 16, 2013 Share Posted September 16, 2013 No look: triggerClientEvent("onRegister",getLocalPlayer()) You are triggering a client event and you need a player to handle that. Link to comment
Bebras Posted September 16, 2013 Author Share Posted September 16, 2013 Tried it, got this error: attempt to call global 'getLocalPlayer' Off-topic: what is "nil" is it like null? Link to comment
kevenvz Posted September 16, 2013 Share Posted September 16, 2013 Nil is it doesn't contain a value. How about you use: getPlayerFromName(playerNick) Link to comment
Bebras Posted September 16, 2013 Author Share Posted September 16, 2013 No errors, but still it is not printed Link to comment
denny199 Posted September 16, 2013 Share Posted September 16, 2013 It's because this: if(mysql_num_rows(result) == 0) then It checks if the rows are 0 then trigger it to the client. and kevenz, getLocalPlayer()[localPlayer] on the server? LAL, that doesn't make any sense Link to comment
kevenvz Posted September 16, 2013 Share Posted September 16, 2013 I know it is source, totally forgot that Link to comment
Bebras Posted September 16, 2013 Author Share Posted September 16, 2013 It's because this: if(mysql_num_rows(result) == 0) then It checks if the rows are 0 then trigger it to the client. and kevenz, getLocalPlayer()[localPlayer] on the server? LAL, that doesn't make any sense I'm sorry, what is wrong with it? Because you just described what i want it to do Link to comment
denny199 Posted September 17, 2013 Share Posted September 17, 2013 Wel, you should debug it: function checkPlayer(playerNick) local result = mysql_query(handler,"SELECT * FROM users WHERE Name = '"..playerNick.."'") outputChatBox ( "Result: "..result ) if( not result) then outputDebugString("MySQL Fail ("..mysql_errno(handler)..") Error:"..mysql_error(handler)) end outputChatBox ("mysql_num_rows: " ..mysql_num_rows(result)) if(mysql_num_rows(result) == 0) then triggerClientEvent("onRegister",getRootElement()) outputDebugString("Should be triggered") else row = mysql_fetch_row(result) outputChatBox ("row: " ..mysql_num_rows(result)) end mysql_free_result(result) end addEventHandler("onPlayerConnect",getRootElement(),checkPlayer) Link to comment
EstrategiaGTA Posted September 17, 2013 Share Posted September 17, 2013 No look: triggerClientEvent("onRegister",getLocalPlayer()) You are triggering a client event and you need a player to handle that. triggerClientEvent is server-side only and getLocalPlayer is client-side only. Link to comment
Bebras Posted September 18, 2013 Author Share Posted September 18, 2013 Wel, you should debug it: function checkPlayer(playerNick) local result = mysql_query(handler,"SELECT * FROM users WHERE Name = '"..playerNick.."'") outputChatBox ( "Result: "..result ) if( not result) then outputDebugString("MySQL Fail ("..mysql_errno(handler)..") Error:"..mysql_error(handler)) end outputChatBox ("mysql_num_rows: " ..mysql_num_rows(result)) if(mysql_num_rows(result) == 0) then triggerClientEvent("onRegister",getRootElement()) outputDebugString("Should be triggered") else row = mysql_fetch_row(result) outputChatBox ("row: " ..mysql_num_rows(result)) end mysql_free_result(result) end addEventHandler("onPlayerConnect",getRootElement(),checkPlayer) It does output: "should be triggered" Link to comment
Techial Posted September 18, 2013 Share Posted September 18, 2013 triggerClientEvent(PlayerToSendInfoTo, "onRegister", root) Link to comment
denny199 Posted September 19, 2013 Share Posted September 19, 2013 triggerClientEvent(PlayerToSendInfoTo, "onRegister", root) Thats optional, is your meta.xml allright, have you tried changing the trigger name from onRegister to "login:onRegister"?? 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