Jump to content

Set Element is not updating..


Xeno

Recommended Posts

Posted

This is meant to add +10 onto a scoreboard collumn.

It WORKS but only when I relog, And I don't know why... Here is my script:

  
function addPlayerZombieXP(killer) 
    local account = getPlayerAccount(killer) 
    if isGuestAccount(account) then return end 
    local zombieXP = getAccountData(account,"Experience points") 
    if not zombieXP then setAccountData(account,"Experience points",0) end 
    setAccountData(account,"Experience points",tonumber(zombieXP)+10) 
end 
addEventHandler("onZombieWasted", getRootElement(), addPlayerZombieXP) 

I would appreciate if you could help me

Posted

Because you're not using setElementData to update.

  
function addPlayerZombieXP(killer) 
    local account = getPlayerAccount(killer) 
    if isGuestAccount(account) then return end 
    local zombieXP = getAccountData(account,"Experience points") 
    if not zombieXP then setAccountData(account,"Experience points",0) end 
    setAccountData(account,"Experience points",tonumber(zombieXP)+10) 
    setElementData ( killer , "Experience points" , tonumber(zombieXP)+10) 
end 
addEventHandler("onZombieWasted", getRootElement(), addPlayerZombieXP) 

Business System viewtopic.php?f=108&t=35797

Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726

SQLite Tutorial viewtopic.php?f=148&t=38203

Posted
Because you're not using setElementData to update.
  
function addPlayerZombieXP(killer) 
    local account = getPlayerAccount(killer) 
    if isGuestAccount(account) then return end 
    local zombieXP = getAccountData(account,"Experience points") 
    if not zombieXP then setAccountData(account,"Experience points",0) end 
    setAccountData(account,"Experience points",tonumber(zombieXP)+10) 
    setElementData ( killer , "Experience points" , tonumber(zombieXP)+10) 
end 
addEventHandler("onZombieWasted", getRootElement(), addPlayerZombieXP) 

Thanks very much.

Posted

Sorry for the double post, but I have another problem. I'm trying to destroy dxDrawText after a few seconds, I set a timer on it but it does not seem to disapear..

local rootElement = getRootElement() 
local screenWidth, screenHeight = guiGetScreenSize() 
local maxrange = 6 
function NPCnametag() 
    local pedX,pedY,pedZ = getElementPosition(getLocalPlayer()) 
    local sx,sy = getScreenFromWorldPosition (pedX,pedY,pedZ) 
    local cameraX,cameraY,cameraZ = getCameraMatrix() 
    if sx then  
        if getDistanceBetweenPoints3D(cameraX,cameraY,cameraZ,pedX,pedY,pedZ) <= maxrange then 
            dxDrawText("hi",sx,sy-100,screenWidth, screenHeight+2,tocolor ( 255, 0, 0, 255 ), 2,"sans") 
        end 
    end 
end 
  
function HandleTheRendering() 
    addEventHandler("onClientRender",rootElement, NPCnametag) 
setTimer(dxDrawRe,1000,1) 
end 
addEvent("HandleTheRendering", true) 
addEventHandler("HandleTheRendering", getRootElement(), HandleTheRendering) 
  
function dxDrawRe() 
removeEventHandler("onClientRender", rootElement, HandleTheRendering) 
end 

Please help.

Xeno

Posted

You've a wrong function in removeEventHandler, it should be 'NPCnametag' not 'HandleTheRendering'.

local rootElement = getRootElement() 
local screenWidth, screenHeight = guiGetScreenSize() 
local maxrange = 6 
function NPCnametag() 
    local pedX,pedY,pedZ = getElementPosition(getLocalPlayer()) 
    local sx,sy = getScreenFromWorldPosition (pedX,pedY,pedZ) 
    local cameraX,cameraY,cameraZ = getCameraMatrix() 
    if sx then 
        if getDistanceBetweenPoints3D(cameraX,cameraY,cameraZ,pedX,pedY,pedZ) <= maxrange then 
            dxDrawText("hi",sx,sy-100,screenWidth, screenHeight+2,tocolor ( 255, 0, 0, 255 ), 2,"sans") 
        end 
    end 
end 
  
function HandleTheRendering() 
    addEventHandler("onClientRender",rootElement, NPCnametag) 
setTimer(dxDrawRe,1000,1) 
end 
addEvent("HandleTheRendering", true) 
addEventHandler("HandleTheRendering", getRootElement(), HandleTheRendering) 
  
function dxDrawRe() 
removeEventHandler("onClientRender", rootElement, NPCnametag) 
end 

Business System viewtopic.php?f=108&t=35797

Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726

SQLite Tutorial viewtopic.php?f=148&t=38203

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