Jump to content

onElementDataChange problem


Recommended Posts

Posted

Hello people, I recently made a ranking system but it's kinda messed up it does play sound when player login is it possible to cancel it?

Server

function outputChange(dataName,oldValue) 
    if getElementType(source) == "player" and dataName == "Army.rank" then  
        local newValue = getElementData(source,dataName) 
        outputChatBox("Congratulations your rank now is #FFFFFF'"..tostring(newValue).."'",source, 255, 0, 0, true) 
        triggerClientEvent(source, "onRankUp", source) 
    end 
end 
addEventHandler("onElementDataChange",getRootElement(),outputChange) 

Client

local sx, sy = guiGetScreenSize ( ) 
  
function onRankUpGreet() 
    dxDrawRectangle(sx*(707/1024), sy*(425/768), sx*(115/1024), sy*(27/768), tocolor(44, 44, 44, 221), true) 
    dxDrawText("Rank up+", sx*(716/1024), sy*(429/768), sx*(808/1024), sy*(448/768), tocolor(0, 255, 0, 221), 0.70, "bankgothic", "left", "top", false, false, true, false, false) 
end 
  
function onRankUp( killer ) 
    local sound = playSound("sounds/level.mp3") 
    setSoundVolume(sound, 50) 
    setSoundMaxDistance( sound, 5000 ) 
    addEventHandler("onClientRender", root, onRankUpGreet) 
        setTimer( 
        function () 
                removeEventHandler ( "onClientRender", root, onRankUpGreet ) 
        end, 6000, 1) 
end 
addEvent( "onRankUp", true ) 
addEventHandler( "onRankUp", getRootElement(), onRankUp ) 

P.S: My ranking script is working perfectly and no need to post it, It's a hard work though i dont want other get to it, Thanks in advance.

Posted

Try this ,

---ClientSide

local sx, sy = guiGetScreenSize ( ) 
function onRankUpGreet() 
    dxDrawRectangle(sx*(707/1024), sy*(425/768), sx*(115/1024), sy*(27/768), tocolor(44, 44, 44, 221), true) 
    dxDrawText("Rank up +", sx*(716/1024), sy*(429/768), sx*(808/1024), sy*(448/768), tocolor(0, 255, 0, 221), 0.70, "bankgothic", "left", "top", false, false, true, false, false) 
end 
  
addEvent( "onRankUp", true ) 
addEventHandler( "onRankUp", 
function ( ) 
    local sound = playSound("sounds/level.mp3") 
    setSoundVolume(sound, 0.5) 
    setSoundMaxDistance( sound, 5000 ) 
    addEventHandler("onClientRender", root, onRankUpGreet) 
        setTimer( 
        function () 
                removeEventHandler ( "onClientRender", root, onRankUpGreet ) 
        end, 6000, 1) 
             end 
       ) 

---ServerSide

addEventHandler("onElementDataChange",root, 
function (ElementData) 
    if ( ElementData == "Army.rank" ) then 
    local newValue = getElementData(source,ElementData) 
    outputChatBox("Congratulations your rank now is #FFFFFF'"..tostring(newValue).."'",source, 255, 0, 0, true) 
    triggerClientEvent(source, "onRankUp", source) 
 end 
end 
) 

/debugscrip 3 to see if there is any erros ,

Can you show me how do you set the element data for the killer ?

Posted
Try this ,

---ClientSide

local sx, sy = guiGetScreenSize ( ) 
function onRankUpGreet() 
    dxDrawRectangle(sx*(707/1024), sy*(425/768), sx*(115/1024), sy*(27/768), tocolor(44, 44, 44, 221), true) 
    dxDrawText("Rank up +", sx*(716/1024), sy*(429/768), sx*(808/1024), sy*(448/768), tocolor(0, 255, 0, 221), 0.70, "bankgothic", "left", "top", false, false, true, false, false) 
end 
  
addEvent( "onRankUp", true ) 
addEventHandler( "onRankUp", 
function ( ) 
    local sound = playSound("sounds/level.mp3") 
    setSoundVolume(sound, 0.5) 
    setSoundMaxDistance( sound, 5000 ) 
    addEventHandler("onClientRender", root, onRankUpGreet) 
        setTimer( 
        function () 
                removeEventHandler ( "onClientRender", root, onRankUpGreet ) 
        end, 6000, 1) 
             end 
       ) 

---ServerSide

addEventHandler("onElementDataChange",root, 
function (ElementData) 
    if ( ElementData == "Army.rank" ) then 
    local newValue = getElementData(source,ElementData) 
    outputChatBox("Congratulations your rank now is #FFFFFF'"..tostring(newValue).."'",source, 255, 0, 0, true) 
    triggerClientEvent(source, "onRankUp", source) 
 end 
end 
) 

/debugscrip 3 to see if there is any erros ,

Can you show me how do you set the element data for the killer ?

Where is the second argument here?

addEventHandler( "onRankUp", 

What's the point of removing the element check?

That wont change anything...

Posted
Try this ,

---ClientSide

local sx, sy = guiGetScreenSize ( ) 
function onRankUpGreet() 
    dxDrawRectangle(sx*(707/1024), sy*(425/768), sx*(115/1024), sy*(27/768), tocolor(44, 44, 44, 221), true) 
    dxDrawText("Rank up +", sx*(716/1024), sy*(429/768), sx*(808/1024), sy*(448/768), tocolor(0, 255, 0, 221), 0.70, "bankgothic", "left", "top", false, false, true, false, false) 
end 
  
addEvent( "onRankUp", true ) 
addEventHandler( "onRankUp", 
function ( ) 
    local sound = playSound("sounds/level.mp3") 
    setSoundVolume(sound, 0.5) 
    setSoundMaxDistance( sound, 5000 ) 
    addEventHandler("onClientRender", root, onRankUpGreet) 
        setTimer( 
        function () 
                removeEventHandler ( "onClientRender", root, onRankUpGreet ) 
        end, 6000, 1) 
             end 
       ) 

---ServerSide

addEventHandler("onElementDataChange",root, 
function (ElementData) 
    if ( ElementData == "Army.rank" ) then 
    local newValue = getElementData(source,ElementData) 
    outputChatBox("Congratulations your rank now is #FFFFFF'"..tostring(newValue).."'",source, 255, 0, 0, true) 
    triggerClientEvent(source, "onRankUp", source) 
 end 
end 
) 

/debugscrip 3 to see if there is any erros ,

Can you show me how do you set the element data for the killer ?

Not working, I fixed the second argument in addEventHandler but still playing the sound and showing the Greet after logging in, Hope someone help, Thanks.

Posted

Try this.

function outputChange(dataName,oldValue) 
    if getElementType(source) == "player" and dataName == "Army.rank" and oldValue then 
        local newValue = getElementData(source,dataName) 
        outputChatBox("Congratulations your rank now is #FFFFFF'"..tostring(newValue).."'",source, 255, 0, 0, true) 
        triggerClientEvent(source, "onRankUp", source) 
    end 
end 
addEventHandler("onElementDataChange",getRootElement(),outputChange) 

Posted
Try this.
function outputChange(dataName,oldValue) 
    if getElementType(source) == "player" and dataName == "Army.rank" and oldValue then 
        local newValue = getElementData(source,dataName) 
        outputChatBox("Congratulations your rank now is #FFFFFF'"..tostring(newValue).."'",source, 255, 0, 0, true) 
        triggerClientEvent(source, "onRankUp", source) 
    end 
end 
addEventHandler("onElementDataChange",getRootElement(),outputChange) 

Thanks dude. :signthanks:

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