Stevenn Posted May 14, 2012 Share Posted May 14, 2012 Hello, i have a question. How can I check if I have my element data below 50 like: -- lets say my element data is 23 which is below 50, it should do this: if getElementData ( localPlayer, "rank" ) ~= 0-50 then outputChatBox ( "hey" ) Link to comment
Guest Guest4401 Posted May 14, 2012 Share Posted May 14, 2012 if getElementData ( localPlayer, "rank" ) < 50 then outputChatBox ( "hey" ) end Link to comment
Stevenn Posted May 14, 2012 Author Share Posted May 14, 2012 "Attempted to compare string with number" Link to comment
Kenix Posted May 14, 2012 Share Posted May 14, 2012 "Attempted to compare string with number" Your data 'rank' return string type. Convert string to number with function tonumber if tonumber( getElementData ( localPlayer, 'rank' ) ) < 50 then outputChatBox 'hey' end If this not working try check what return data 'rank'. Link to comment
TAPL Posted May 14, 2012 Share Posted May 14, 2012 (edited) "Attempted to compare string with number" Your data 'rank' return string type. Convert string to number with function tonumber if tonumber( getElementData ( localPlayer, 'rank' ) ) < 50 then outputChatBox 'hey' end If this not working try check what return data 'rank'. you forgot ")" in outputChatBox Edited May 14, 2012 by Guest Link to comment
Kenix Posted May 14, 2012 Share Posted May 14, 2012 (edited) you forgot ")" in outputChatBox No. It's normal. If you call function with 1 argument and this argument is string or table you not need use '( )'. Example print 'ye' -- ye for _, s in pairs { '1', '2' } do print( s ) --[[ Output: 1 2 ]] end You can check this in lua demo http://www.lua.org/cgi-bin/demo Edited December 20, 2012 by Guest Link to comment
Stevenn Posted May 14, 2012 Author Share Posted May 14, 2012 Okay, thanks but how can I do something like this: function rank () if tonumber( getElementData ( localPlayer, "rank" ) ) < 50 then outputChatBox ( "502" ) elseif tonumber( getElementData ( localPlayer, "rank" ) ) < 50-115 then -- i know its wrong, but I have no idea.. end addEventHandler ( "onClientResourceStart", root, rank ) Link to comment
Kenix Posted May 14, 2012 Share Posted May 14, 2012 Okay, thanks but how can I do something like this: function rank () if tonumber( getElementData ( localPlayer, "rank" ) ) < 50 then outputChatBox ( "502" ) elseif tonumber( getElementData ( localPlayer, "rank" ) ) < 50-115 then -- i know its wrong, but I have no idea.. end addEventHandler ( "onClientResourceStart", root, rank ) Explain this: elseif tonumber( getElementData ( localPlayer, "rank" ) ) < 50-115 then I don't understand. Link to comment
Stevenn Posted May 14, 2012 Author Share Posted May 14, 2012 Example: If I have 0-50 points it will do something, but if I have 50-115 it will do something different, and then if I have 115-500 it will do different and so on.. Link to comment
Kenix Posted May 14, 2012 Share Posted May 14, 2012 function rank ( ) local nData = tonumber( getElementData ( localPlayer, 'rank' ) or 0 ) if nData > 0 and nData < 50 then -- TODO elseif nData > 50 and nData < 115 then -- TODO elseif nData > 115 and nData < 500 then -- TODO end end addEventHandler ( 'onClientResourceStart', resourceRoot, rank ) ? Link to comment
Stevenn Posted May 14, 2012 Author Share Posted May 14, 2012 (edited) Omg, I love you thanks kenix! Edited May 14, 2012 by Guest Link to comment
Kenix Posted May 14, 2012 Share Posted May 14, 2012 (edited) No problem Edited May 14, 2012 by Guest Link to comment
Stevenn Posted May 14, 2012 Author Share Posted May 14, 2012 one last thing then I'm done ( I think ) if I change my element data, I have to restart the resource for it to update my label, how can I add a timer or something? Link to comment
Kenix Posted May 14, 2012 Share Posted May 14, 2012 one last thing then I'm done ( I think )if I change my element data, I have to restart the resource for it to update my label, how can I add a timer or something? Why? I don't understand. Link to comment
Stevenn Posted May 14, 2012 Author Share Posted May 14, 2012 Okay so, if I kill a player I will get one point which will then be showed on a label. but, if I kill another player I have to restart the resource in order to update the label Link to comment
ben_wright Posted May 14, 2012 Share Posted May 14, 2012 use guiSetText --with setTimer --------- example ----------- myLabel = guiCreateLabel ... uText = guiSetText ( myLabel, "Example" ) --timer: updateTimer = setTimer ( uText, 1000, 1, "example update" ) Link to comment
Kenix Posted May 14, 2012 Share Posted May 14, 2012 (edited) use guiSetText --with setTimer --------- example ----------- myLabel = guiCreateLabel ... uText = guiSetText ( myLabel, "Example" ) --timer: updateTimer = setTimer ( uText, 1000, 1, "example update" ) Your example wrong updateTimer = setTimer ( uText, 1000, 1, "example update" ) You call function uText, but this function not exists. Correct local pLabel = guiCreateLabel( 0.5, 0.5, 0.5, 0.5, '', true ) guiSetText( pLabel, 'Label' ) setTimer( guiSetText, 1000, 1, pLabel, 'Updated' ) Edited May 14, 2012 by Guest Link to comment
Jaysds1 Posted May 14, 2012 Share Posted May 14, 2012 Okay so, if I kill a player I will get one point which will then be showed on a label. but, if I kill another player I have to restart the resource in order to update the label you don't have to do that, you could use a timer to destroy the label and if the player kills another person before the label could be removed, then you could reset the timer and set the label to the new killer and the player killed, use these: setTimer() --set a timer so the label could disapper resetTimer() -- reset the timer if the player kills another person again --then guiSetText() -- set the label to the player that killed again Link to comment
Stevenn Posted May 14, 2012 Author Share Posted May 14, 2012 Isn't it just possible to update the function which I use to set the guiText ? In this case: function rank () Link to comment
TAPL Posted May 14, 2012 Share Posted May 14, 2012 do you need setTimer? when you kill player you can use event onClientPlayerWasted with guiSetText() https://wiki.multitheftauto.com/wiki/OnC ... ayerWasted Link to comment
Jaysds1 Posted May 14, 2012 Share Posted May 14, 2012 ok, here's an example: addEventHandler("onClientPedWasted",root,function() if(isElement(label))then resetTimer(timer) guiSetText(label,killer" killed "..source) else label = createLabel() timer = setTimer(destroyElement,7000,1,label) end end) Link to comment
Stevenn Posted May 14, 2012 Author Share Posted May 14, 2012 function kills () local nData = tonumber( getElementData ( localPlayer, 'kills' ) or 0 ) if nData > 0 and nData <50 then guiSetText ( killLabel, "Kills: "..getElementData (localPlayer, "kills") ) elseif nData > 50 and nData < 115 then guiSetText ( killLabel, "Kills: "..getElementData (localPlayer, "kills") ) end end addEventHandler ( "onClientResourceStart", root, kills ) setTimer ( kills, 1000, 1 ) It doesn't work, if I get a new point, nothing happens until i restart the resource. Shouldn't be on any event, should be updated even if I set my element data using the admin panel Link to comment
Jaysds1 Posted May 14, 2012 Share Posted May 14, 2012 function kills () local nData = tonumber( getElementData ( localPlayer, 'kills' ) or 0 ) if nData > 0 and nData <50 then guiSetText ( killLabel, "Kills: "..getElementData (localPlayer, "kills") ) elseif nData > 50 and nData < 115 then guiSetText ( killLabel, "Kills: "..getElementData (localPlayer, "kills") ) end end addEventHandler ( "onClientResourceStart", root, kills ) setTimer ( kills, 1000, 1 ) It doesn't work, if I get a new point, nothing happens until i restart the resource. Shouldn't be on any event, should be updated even if I set my element data using the admin panel You never created a label, plus you set the timer to work 1 timer, set the 1 to 0 Link to comment
TAPL Posted May 14, 2012 Share Posted May 14, 2012 function kills () local nData = tonumber( getElementData ( localPlayer, 'kills' ) or 0 ) if nData > 0 and nData <50 then guiSetText ( killLabel, "Kills: "..getElementData (localPlayer, "kills") ) elseif nData > 50 and nData < 115 then guiSetText ( killLabel, "Kills: "..getElementData (localPlayer, "kills") ) end end addEventHandler ( "onClientResourceStart", root, kills ) setTimer ( kills, 1000, 1 ) It doesn't work, if I get a new point, nothing happens until i restart the resource. Shouldn't be on any event, should be updated even if I set my element data using the admin panel I suggest to use event onClientElementDataChange https://wiki.multitheftauto.com/wiki/OnC ... DataChange 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