Xeno Posted January 29, 2012 Share Posted January 29, 2012 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 Link to comment
JR10 Posted January 29, 2012 Share Posted January 29, 2012 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) Link to comment
Xeno Posted January 29, 2012 Author Share Posted January 29, 2012 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. Link to comment
Xeno Posted January 29, 2012 Author Share Posted January 29, 2012 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 Link to comment
JR10 Posted January 29, 2012 Share Posted January 29, 2012 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 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