drk Posted February 21, 2012 Share Posted February 21, 2012 Hi again! I'm trying to make a Level system now. It works but when a player connect's and logIn I get error "Attempt to concatenate a bolean value". I tried to solve this but I get the error anyway. And, another problem, when the player logOut, the Level in the scoreboard don't change to Guest Here the code: addEventHandler( 'onPlayerLogin',root, function( ) local level = getAccountData(getPlayerAccount(source),'My Level') timer[ source ] = setTimer( function(thePlayer) local account = getPlayerAccount( thePlayer ) local result = executeSQLQuery("SELECT money FROM Money WHERE player= '"..getPlayerName(thePlayer).."'") local money = result[1]['money'] if money <= 50000 then setAccountData( account,'My Level','Newbie' ) setElementData( thePlayer,'Level','Newbie' ) elseif money <= 250000 and tonumber(money) > 50000 then setAccountData( account,'My Level','Regular' ) setElementData( thePlayer,'Level','Regular' ) elseif money <= 450000 and tonumber(money) > 250000 then setAccountData( account,'My Level','Experienced' ) setElementData( thePlayer,'Level','Experienced' ) elseif money <= 1000000 and tonumber(money) > 450000 then setAccountData( account,'My Level','Veteran' ) setElementData( thePlayer,'Level','Veteran' ) elseif money <= 5000000 and tonumber(money) > 1000000 then setAccountData( account,'My Level','Guru' ) setElementData( thePlayer,'Level','Guru' ) elseif money > 10000000 then setAccountData( account,'My Level','Legend' ) setElementData( thePlayer, 'Level', 'Legend' ) end end, 500,0,source ) --output data if level == 'Newbie' then triggerEvent('onNewbieLogin',source) elseif level == 'Regular' then triggerEvent('onRegularLogin',source) elseif level == 'Experienced' then triggerEvent('onExperiencedLogin',source) elseif level == 'Veteran' then triggerEvent('onVeteranLogin',source) elseif level == 'Guru' then triggerEvent('onGuruLogin',source) elseif level == 'Legend' then triggerEvent('onLegendLogin',source) end end) addEventHandler('onPlayerLogout',root, function() timer [ source ] = nil timer [ source ] = setTimer ( function(thePlayer) setElementData(thePlayer,'My Level','Guest') end, 500,1,source) end) Link to comment
Kenix Posted February 21, 2012 Share Posted February 21, 2012 Try local uTimers = { } addEventHandler( 'onPlayerLogin',root, function( ) local account = getPlayerAccount( source ) if account then local level = getAccountData( account ,'My Level' ) or 0 uTimers[ source ] = setTimer( function( thePlayer,account ) local result = executeSQLQuery( "SELECT money FROM Money WHERE player = '"..getPlayerName( thePlayer ).."'" ) local money = result[1]['money'] if money <= 50000 then setAccountData( account,'My Level','Newbie' ) setElementData( thePlayer,'Level','Newbie' ) elseif money <= 250000 and tonumber( money ) > 50000 then setAccountData( account,'My Level','Regular' ) setElementData( thePlayer,'Level','Regular' ) elseif money <= 450000 and tonumber( money ) > 250000 then setAccountData( account,'My Level','Experienced' ) setElementData( thePlayer,'Level','Experienced' ) elseif money <= 1000000 and tonumber( money ) > 450000 then setAccountData( account,'My Level','Veteran' ) setElementData( thePlayer,'Level','Veteran' ) elseif money <= 5000000 and tonumber( money ) > 1000000 then setAccountData( account,'My Level','Guru' ) setElementData( thePlayer,'Level','Guru' ) elseif money > 10000000 then setAccountData( account,'My Level','Legend' ) setElementData( thePlayer, 'Level', 'Legend' ) end end, 500,0,source,account ) --output data if level == 'Newbie' then triggerEvent( 'onNewbieLogin',source ) elseif level == 'Regular' then triggerEvent( 'onRegularLogin',source ) elseif level == 'Experienced' then triggerEvent( 'onExperiencedLogin',source ) elseif level == 'Veteran' then triggerEvent( 'onVeteranLogin',source ) elseif level == 'Guru' then triggerEvent( 'onGuruLogin',source ) elseif level == 'Legend' then triggerEvent('onLegendLogin',source ) end end end ) addEventHandler( 'onPlayerLogout',root, function( ) uTimers [ source ] = setTimer ( function( thePlayer ) setElementData( thePlayer,'My Level','Guest' ) end, 500,1,source ) end ) addEventHandler( 'onPlayerQuit',root, function( ) uTimers [ source ] = nil end ) Link to comment
drk Posted February 21, 2012 Author Share Posted February 21, 2012 function( thePlayer,account ) local result = executeSQLQuery( "SELECT money FROM Money WHERE player = '"..getPlayerName( thePlayer ).."'" ) local money = result[1]['money'] Link to comment
Kenix Posted February 21, 2012 Share Posted February 21, 2012 local uTimers = { } addEventHandler( 'onPlayerLogin',root, function( ) local account = getPlayerAccount( source ) if account then local level = getAccountData( account ,'My Level' ) or 0 uTimers[ source ] = setTimer( function( thePlayer,account ) local result = executeSQLQuery( "SELECT money FROM Money WHERE player = '"..getPlayerName( thePlayer ).."'" ) if not result or #result == 0 then outputChatBox 'table is empty' else local money = result[1]['money'] if money <= 50000 then setAccountData( account,'My Level','Newbie' ) setElementData( thePlayer,'Level','Newbie' ) elseif money <= 250000 and tonumber( money ) > 50000 then setAccountData( account,'My Level','Regular' ) setElementData( thePlayer,'Level','Regular' ) elseif money <= 450000 and tonumber( money ) > 250000 then setAccountData( account,'My Level','Experienced' ) setElementData( thePlayer,'Level','Experienced' ) elseif money <= 1000000 and tonumber( money ) > 450000 then setAccountData( account,'My Level','Veteran' ) setElementData( thePlayer,'Level','Veteran' ) elseif money <= 5000000 and tonumber( money ) > 1000000 then setAccountData( account,'My Level','Guru' ) setElementData( thePlayer,'Level','Guru' ) elseif money > 10000000 then setAccountData( account,'My Level','Legend' ) setElementData( thePlayer, 'Level', 'Legend' ) end end end, 500,0,source,account ) --output data if level == 'Newbie' then triggerEvent( 'onNewbieLogin',source ) elseif level == 'Regular' then triggerEvent( 'onRegularLogin',source ) elseif level == 'Experienced' then triggerEvent( 'onExperiencedLogin',source ) elseif level == 'Veteran' then triggerEvent( 'onVeteranLogin',source ) elseif level == 'Guru' then triggerEvent( 'onGuruLogin',source ) elseif level == 'Legend' then triggerEvent('onLegendLogin',source ) end end end ) addEventHandler( 'onPlayerLogout',root, function( ) uTimers [ source ] = setTimer ( function( thePlayer ) setElementData( thePlayer,'My Level','Guest' ) end, 500,1,source ) end ) addEventHandler( 'onPlayerQuit',root, function( ) uTimers [ source ] = nil end ) Because result table is empty. Link to comment
drk Posted February 21, 2012 Author Share Posted February 21, 2012 (edited) Ty, more one problem. When the player logout, the player level don't sets to Guest. I get expected element at argument 1. I have to kill the uTimers[ source ] timer and set the timer again? Edit: I tried to kill and create a new timer but It don't changes. I don't get any errors now. Edited February 21, 2012 by Guest Link to comment
Kenix Posted February 21, 2012 Share Posted February 21, 2012 local uTimers = { } local uTimersLogout = { } addEventHandler( 'onPlayerLogin',root, function( ) local account = getPlayerAccount( source ) if account then local level = getAccountData( account ,'My Level' ) or 0 uTimers[ source ] = setTimer( function( thePlayer,account ) local result = executeSQLQuery( "SELECT money FROM Money WHERE player = '"..getPlayerName( thePlayer ).."'" ) if not result or #result == 0 then outputChatBox 'table is empty' else local money = result[1]['money'] if money <= 50000 then setAccountData( account,'My Level','Newbie' ) setElementData( thePlayer,'Level','Newbie' ) elseif money <= 250000 and tonumber( money ) > 50000 then setAccountData( account,'My Level','Regular' ) setElementData( thePlayer,'Level','Regular' ) elseif money <= 450000 and tonumber( money ) > 250000 then setAccountData( account,'My Level','Experienced' ) setElementData( thePlayer,'Level','Experienced' ) elseif money <= 1000000 and tonumber( money ) > 450000 then setAccountData( account,'My Level','Veteran' ) setElementData( thePlayer,'Level','Veteran' ) elseif money <= 5000000 and tonumber( money ) > 1000000 then setAccountData( account,'My Level','Guru' ) setElementData( thePlayer,'Level','Guru' ) elseif money > 10000000 then setAccountData( account,'My Level','Legend' ) setElementData( thePlayer, 'Level', 'Legend' ) end end end, 500,0,source,account ) --output data if level == 'Newbie' then triggerEvent( 'onNewbieLogin',source ) elseif level == 'Regular' then triggerEvent( 'onRegularLogin',source ) elseif level == 'Experienced' then triggerEvent( 'onExperiencedLogin',source ) elseif level == 'Veteran' then triggerEvent( 'onVeteranLogin',source ) elseif level == 'Guru' then triggerEvent( 'onGuruLogin',source ) elseif level == 'Legend' then triggerEvent('onLegendLogin',source ) end end end ) addEventHandler( 'onPlayerLogout',root, function( ) if isTimer( uTimers [ source ] ) then killTimer( uTimers [ source ] ) end uTimersLogout [ source ] = setTimer ( function( thePlayer ) setElementData( thePlayer,'My Level','Guest' ) end, 500,1,source ) end ) addEventHandler( 'onPlayerQuit',root, function( ) uTimers [ source ] = nil uTimersLogout [ source ] = nil end ) You need destroy old timer ( timer in event onPlayerLogin ) if player logout ? And then create new timer. Right? Link to comment
Kenix Posted February 21, 2012 Share Posted February 21, 2012 You need destroy old timer ( timer in event onPlayerLogin ) if player logout ? And then create new timer.Right? You mean it or no? Say line please. We not telepaths Link to comment
drk Posted February 21, 2012 Author Share Posted February 21, 2012 Sorry. I get no error, onPlayerLogin works fine. Only don't change level to Guest when player logout local uTimers = { } local uTimersLogout = { } addEventHandler('onResourceStart',resourceRoot, function() call(getResourceFromName('scoreboard'),'addScoreboardColumn','Level') setElementData(source,'Level','Guest') end) addEventHandler( 'onPlayerLogin',root, function( ) local account = getPlayerAccount( source ) if account then local level = getAccountData( account ,'My Level' ) or 0 uTimers[ source ] = setTimer( function( thePlayer,account ) local result = executeSQLQuery( "SELECT money FROM Money WHERE player = '"..getPlayerName( thePlayer ).."'" ) if not result or #result == 0 then local create = executeSQLQuery("INSERT INTO Money VALUES ( '"..getPlayerName(thePlayer).."','0')") setAccountData(account,'My Level','Newbie') setElementData(thePlayer,'Level','Newbie') else local money = result[1]['money'] if money <= 50000 then setAccountData( account,'My Level','Newbie' ) setElementData( thePlayer,'Level','Newbie' ) elseif money <= 250000 and tonumber( money ) > 50000 then setAccountData( account,'My Level','Regular' ) setElementData( thePlayer,'Level','Regular' ) elseif money <= 450000 and tonumber( money ) > 250000 then setAccountData( account,'My Level','Experienced' ) setElementData( thePlayer,'Level','Experienced' ) elseif money <= 1000000 and tonumber( money ) > 450000 then setAccountData( account,'My Level','Veteran' ) setElementData( thePlayer,'Level','Veteran' ) elseif money <= 5000000 and tonumber( money ) > 1000000 then setAccountData( account,'My Level','Guru' ) setElementData( thePlayer,'Level','Guru' ) elseif money > 10000000 then setAccountData( account,'My Level','Legend' ) setElementData( thePlayer, 'Level', 'Legend' ) end end end, 500,0,source, account ) --output data if level == 'Newbie' then triggerEvent( 'onNewbieLogin',source ) elseif level == 'Regular' then triggerEvent( 'onRegularLogin',source ) elseif level == 'Experienced' then triggerEvent( 'onExperiencedLogin',source ) elseif level == 'Veteran' then triggerEvent( 'onVeteranLogin',source ) elseif level == 'Guru' then triggerEvent( 'onGuruLogin',source ) elseif level == 'Legend' then triggerEvent('onLegendLogin',source ) end end end ) addEventHandler( 'onPlayerLogout',root, function( ) if isTimer( uTimers [ source ] ) then killTimer( uTimers [ source ] ) end uTimersLogout [ source ] = setTimer ( function( thePlayer ) setElementData( thePlayer,'My Level','Guest' ) end, 500,1,source ) end ) addEventHandler('onPlayerJoin',root, function() setElementData ( source, 'Level', 'Guest' ) end ) addEventHandler('onPlayerQuit',root, function() uTimers[ source ] = nil uTimersLogout[ source ] = nil end ) Link to comment
Kenix Posted February 21, 2012 Share Posted February 21, 2012 local uTimers = { } local uTimersLogout = { } addEventHandler('onResourceStart',resourceRoot, function( ) call( getResourceFromName( 'scoreboard' ),'addScoreboardColumn','Level' ) for _,v in pairs( getElementsByType 'player' ) do setElementData( v,'Level','Guest' ) end end ) addEventHandler( 'onPlayerLogin',root, function( ) local account = getPlayerAccount( source ) if account then local level = getAccountData( account ,'My Level' ) or 0 uTimers[ source ] = setTimer( function( thePlayer,account ) local result = executeSQLQuery( "SELECT money FROM Money WHERE player = '"..getPlayerName( thePlayer ).."'" ) if not result or #result == 0 then local create = executeSQLQuery( "INSERT INTO Money VALUES ( '"..getPlayerName( thePlayer ).."','0')" ) setAccountData( account,'My Level','Newbie' ) setElementData( thePlayer,'Level','Newbie' ) else local money = result[1]['money'] if money <= 50000 then setAccountData( account,'My Level','Newbie' ) setElementData( thePlayer,'Level','Newbie' ) elseif money <= 250000 and tonumber( money ) > 50000 then setAccountData( account,'My Level','Regular' ) setElementData( thePlayer,'Level','Regular' ) elseif money <= 450000 and tonumber( money ) > 250000 then setAccountData( account,'My Level','Experienced' ) setElementData( thePlayer,'Level','Experienced' ) elseif money <= 1000000 and tonumber( money ) > 450000 then setAccountData( account,'My Level','Veteran' ) setElementData( thePlayer,'Level','Veteran' ) elseif money <= 5000000 and tonumber( money ) > 1000000 then setAccountData( account,'My Level','Guru' ) setElementData( thePlayer,'Level','Guru' ) elseif money > 10000000 then setAccountData( account,'My Level','Legend' ) setElementData( thePlayer, 'Level', 'Legend' ) end end end, 500,0,source, account ) --output data if level == 'Newbie' then triggerEvent( 'onNewbieLogin',source ) elseif level == 'Regular' then triggerEvent( 'onRegularLogin',source ) elseif level == 'Experienced' then triggerEvent( 'onExperiencedLogin',source ) elseif level == 'Veteran' then triggerEvent( 'onVeteranLogin',source ) elseif level == 'Guru' then triggerEvent( 'onGuruLogin',source ) elseif level == 'Legend' then triggerEvent('onLegendLogin',source ) end end end ) addEventHandler( 'onPlayerLogout',root, function( ) if isTimer( uTimers [ source ] ) then killTimer( uTimers [ source ] ) end uTimersLogout [ source ] = setTimer ( function( thePlayer ) setElementData( thePlayer,'Level','Guest' ) end, 500,1,source ) end ) addEventHandler( 'onPlayerJoin',root, function( ) setElementData ( source, 'Level', 'Guest' ) end ) addEventHandler( 'onPlayerQuit',root, function( ) uTimers[ source ] = nil uTimersLogout[ source ] = nil end ) Corrected full code. addEventHandler('onResourceStart',resourceRoot, function() call(getResourceFromName('scoreboard'),'addScoreboardColumn','Level') setElementData(source,'Level','Guest') end) You setElementData to resource ? Why you need? addEventHandler('onResourceStart',resourceRoot, function( ) call( getResourceFromName( 'scoreboard' ),'addScoreboardColumn','Level' ) for _,v in pairs( getElementsByType 'player' ) do setElementData( v,'Level','Guest' ) end end ) Maybe you mean this? And addEventHandler( 'onPlayerLogout',root, function( ) if isTimer( uTimers [ source ] ) then killTimer( uTimers [ source ] ) end uTimersLogout [ source ] = setTimer ( function( thePlayer ) setElementData( thePlayer,'My Level','Guest' ) end, 500,1,source ) end ) Your code. You setElementData( ..,'My level',... ) So it's not data Level ( not see in scoreboard ). So if you use this data ( My level ) it not show in scoreboard. addEventHandler( 'onPlayerLogout',root, function( ) if isTimer( uTimers [ source ] ) then killTimer( uTimers [ source ] ) end uTimersLogout [ source ] = setTimer ( function( thePlayer ) setElementData( thePlayer,'Level','Guest' ) end, 500,1,source ) end ) Correct. Finally:Why you not use sql db for all? You use account data/and sql functions. My opinion is not correct Link to comment
drk Posted February 21, 2012 Author Share Posted February 21, 2012 (edited) local uTimers = { } local uTimersLogout = { } addEventHandler('onResourceStart',resourceRoot, function( ) call( getResourceFromName( 'scoreboard' ),'addScoreboardColumn','Level' ) for _,v in pairs( getElementsByType 'player' ) do setElementData( v,'Level','Guest' ) end end ) addEventHandler( 'onPlayerLogin',root, function( ) local account = getPlayerAccount( source ) if account then local level = getAccountData( account ,'My Level' ) or 0 uTimers[ source ] = setTimer( function( thePlayer,account ) local result = executeSQLQuery( "SELECT money FROM Money WHERE player = '"..getPlayerName( thePlayer ).."'" ) if not result or #result == 0 then local create = executeSQLQuery( "INSERT INTO Money VALUES ( '"..getPlayerName( thePlayer ).."','0')" ) setAccountData( account,'My Level','Newbie' ) setElementData( thePlayer,'Level','Newbie' ) else local money = result[1]['money'] if money <= 50000 then setAccountData( account,'My Level','Newbie' ) setElementData( thePlayer,'Level','Newbie' ) elseif money <= 250000 and tonumber( money ) > 50000 then setAccountData( account,'My Level','Regular' ) setElementData( thePlayer,'Level','Regular' ) elseif money <= 450000 and tonumber( money ) > 250000 then setAccountData( account,'My Level','Experienced' ) setElementData( thePlayer,'Level','Experienced' ) elseif money <= 1000000 and tonumber( money ) > 450000 then setAccountData( account,'My Level','Veteran' ) setElementData( thePlayer,'Level','Veteran' ) elseif money <= 5000000 and tonumber( money ) > 1000000 then setAccountData( account,'My Level','Guru' ) setElementData( thePlayer,'Level','Guru' ) elseif money > 10000000 then setAccountData( account,'My Level','Legend' ) setElementData( thePlayer, 'Level', 'Legend' ) end end end, 500,0,source, account ) --output data if level == 'Newbie' then triggerEvent( 'onNewbieLogin',source ) elseif level == 'Regular' then triggerEvent( 'onRegularLogin',source ) elseif level == 'Experienced' then triggerEvent( 'onExperiencedLogin',source ) elseif level == 'Veteran' then triggerEvent( 'onVeteranLogin',source ) elseif level == 'Guru' then triggerEvent( 'onGuruLogin',source ) elseif level == 'Legend' then triggerEvent('onLegendLogin',source ) end end end ) addEventHandler( 'onPlayerLogout',root, function( ) if isTimer( uTimers [ source ] ) then killTimer( uTimers [ source ] ) end uTimersLogout [ source ] = setTimer ( function( thePlayer ) setElementData( thePlayer,'Level','Guest' ) end, 500,1,source ) end ) addEventHandler( 'onPlayerJoin',root, function( ) setElementData ( source, 'Level', 'Guest' ) end ) addEventHandler( 'onPlayerQuit',root, function( ) uTimers[ source ] = nil uTimersLogout[ source ] = nil end ) Corrected full code. addEventHandler('onResourceStart',resourceRoot, function() call(getResourceFromName('scoreboard'),'addScoreboardColumn','Level') setElementData(source,'Level','Guest') end) You setElementData to resource ? Why you need? addEventHandler('onResourceStart',resourceRoot, function( ) call( getResourceFromName( 'scoreboard' ),'addScoreboardColumn','Level' ) for _,v in pairs( getElementsByType 'player' ) do setElementData( v,'Level','Guest' ) end end ) Maybe you mean this? And addEventHandler( 'onPlayerLogout',root, function( ) if isTimer( uTimers [ source ] ) then killTimer( uTimers [ source ] ) end uTimersLogout [ source ] = setTimer ( function( thePlayer ) setElementData( thePlayer,'My Level','Guest' ) end, 500,1,source ) end ) Your code. You setElementData( ..,'My level',... ) So it's not data Level ( not see in scoreboard ). So if you use this data ( My level ) it not show in scoreboard. addEventHandler( 'onPlayerLogout',root, function( ) if isTimer( uTimers [ source ] ) then killTimer( uTimers [ source ] ) end uTimersLogout [ source ] = setTimer ( function( thePlayer ) setElementData( thePlayer,'Level','Guest' ) end, 500,1,source ) end ) Correct. Finally:Why you not use sql db for all? You use account data/and sql functions. My opinion is not correct I don't know why, I'm crazy It worked, Thanks. Edited February 21, 2012 by Guest Link to comment
Kenix Posted February 21, 2012 Share Posted February 21, 2012 So you test it? It working? Link to comment
Kenix Posted February 21, 2012 Share Posted February 21, 2012 It worked, Thanks. No problem 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