Jump to content

getElementData


Stevenn

Recommended Posts

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
"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
"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 by Guest
Link to comment
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 by Guest
Link to comment

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 ) 
  

:idea:

Link to comment
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 ) 
  

:idea:

Explain this:

elseif tonumber( getElementData ( localPlayer, "rank" ) ) < 50-115 then 

I don't understand.

Link to comment
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
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 by Guest
Link to comment
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

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
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
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
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

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...