Jump to content

Timer


-.Paradox.-

Recommended Posts

Hello i want draw +1500 text every time a zombie get killed, and disappear after 3 seconds thanks for help.

addEvent( "onZombieWasted" ); 
addEventHandler( "onZombieWasted", getRootElement(), 
       function( killer ) 
           givePlayerMoney( killer, 1500 ); 
       end 
) 
  
addEventHandler("onZombieWasted", getRootElement(), 
function () 
        dxDrawText("+1500", 1211, 51, 1351, 77, tocolor(0, 0, 0, 255), 1.00, "pricedown", "left", "top", false, false, true, false, false) 
  
        dxDrawText("+1500", 1211, 49, 1351, 75, tocolor(0, 0, 0, 255), 1.00, "pricedown", "left", "top", false, false, true, false, false) 
  
        dxDrawText("+1500", 1209, 51, 1349, 77, tocolor(0, 0, 0, 255), 1.00, "pricedown", "left", "top", false, false, true, false, false) 
  
        dxDrawText("+1500", 1209, 49, 1349, 75, tocolor(0, 0, 0, 255), 1.00, "pricedown", "left", "top", false, false, true, false, false) 
  
        dxDrawText("+1500", 1210, 50, 1350, 76, tocolor(0, 100, 35, 255), 1.00, "pricedown", "left", "top", false, false, true, false, false) 
  
end 
) 

Link to comment

Like that? I made this code in my iPhone but idk what I must put to show the text only when zombie get killed thanks for help

  
function onTest() 
dxDrawText("+1500", 1211, 51, 1351, 77, tocolor(0, 0, 0, 255), 1.00, "pricedown", "left", "top", false, false, true, false, false)  
dxDrawText("+1500", 1211, 49, 1351, 75, tocolor(0, 0, 0, 255), 1.00, "pricedown", "left", "top", false, false, true, false, false)  
dxDrawText("+1500", 1209, 51, 1349, 77, tocolor(0, 0, 0, 255), 1.00, "pricedown", "left", "top", false, false, true, false, false)  
dxDrawText("+1500", 1209, 49, 1349, 75, tocolor(0, 0, 0, 255), 1.00, "pricedown", "left", "top", false, false, true, false, false)  
dxDrawText("+1500", 1210, 50, 1350, 76, tocolor(0, 100, 35, 255), 1.00, "pricedown", "left", "top", false, false, true, false, false) 
end 
addEventHandler("onClientRender", getRootElement, onTest) 
  
setTimer( 
function () 
removeEventHandler("onClientRender", getRootElement, onTest) 
end 
, 3000, 1 
) 
  

Link to comment

Yeah, just like that, except you have to do

addEventHandler("onClientRender", root, onTest) 
setTimer(removeEventHandler, 3000, 1, "onClientRender", root, onTest) 

whenever a zombie gets killed. So the proper code should look like this:

function onTest() 
dxDrawText("+1500", 1211, 51, 1351, 77, tocolor(0, 0, 0, 255), 1.00, "pricedown", "left", "top", false, false, true, false, false) 
dxDrawText("+1500", 1211, 49, 1351, 75, tocolor(0, 0, 0, 255), 1.00, "pricedown", "left", "top", false, false, true, false, false) 
dxDrawText("+1500", 1209, 51, 1349, 77, tocolor(0, 0, 0, 255), 1.00, "pricedown", "left", "top", false, false, true, false, false) 
dxDrawText("+1500", 1209, 49, 1349, 75, tocolor(0, 0, 0, 255), 1.00, "pricedown", "left", "top", false, false, true, false, false) 
dxDrawText("+1500", 1210, 50, 1350, 76, tocolor(0, 100, 35, 255), 1.00, "pricedown", "left", "top", false, false, true, false, false) 
end 
  
addEvent( "onZombieWasted" ); 
addEventHandler( "onZombieWasted", root, 
function( killer ) 
        givePlayerMoney( killer, 1500 ); 
        addEventHandler("onClientRender", root, onTest) 
        setTimer(removeEventHandler, 3000, 1, "onClientRender", root, onTest) 
end) 
  

You are probably still going to tweak this a bit, so it behaves properly when two zombies get killed in a period shorter than three seconds.

Link to comment
function onTest() 
dxDrawText("+1500", 1211, 51, 1351, 77, tocolor(0, 0, 0, 255), 1.00, "pricedown", "left", "top", false, false, true, false, false) 
dxDrawText("+1500", 1211, 49, 1351, 75, tocolor(0, 0, 0, 255), 1.00, "pricedown", "left", "top", false, false, true, false, false) 
dxDrawText("+1500", 1209, 51, 1349, 77, tocolor(0, 0, 0, 255), 1.00, "pricedown", "left", "top", false, false, true, false, false) 
dxDrawText("+1500", 1209, 49, 1349, 75, tocolor(0, 0, 0, 255), 1.00, "pricedown", "left", "top", false, false, true, false, false) 
dxDrawText("+1500", 1210, 50, 1350, 76, tocolor(0, 100, 35, 255), 1.00, "pricedown", "left", "top", false, false, true, false, false) 
end 
  
addEvent( "onZombieWasted" ); 
addEventHandler( "onZombieWasted", root, 
function( killer ) 
        givePlayerMoney( killer, 1500 ); 
        addEventHandler("onClientRender", root, onTest) 
        setTimer( function ( ) 
                removeEventHandler ( "onClientRender", root, onTest ) 
                end, 3000, 1 ) 
end) 

Link to comment

I don't know what zombie gamemode do you use, so I don't know whether "onClientZombieWasted" exists. Assuming it does not, you could use this code serverside:

addEvent( "onZombieWasted" ) 
addEventHandler( "onZombieWasted", getRootElement(), 
function( killer ) 
        givePlayerMoney( killer, 1500 ) 
        triggerClientEvent(killer,"onClientZombieWasted", resourceRoot) 
end 

and this code clientside:

function onTest() 
        dxDrawText("+1500", 1211, 51, 1351, 77, tocolor(0, 0, 0, 255), 1.00, "pricedown", "left", "top", false, false, true, false, false) 
        dxDrawText("+1500", 1211, 49, 1351, 75, tocolor(0, 0, 0, 255), 1.00, "pricedown", "left", "top", false, false, true, false, false) 
        dxDrawText("+1500", 1209, 51, 1349, 77, tocolor(0, 0, 0, 255), 1.00, "pricedown", "left", "top", false, false, true, false, false) 
        dxDrawText("+1500", 1209, 49, 1349, 75, tocolor(0, 0, 0, 255), 1.00, "pricedown", "left", "top", false, false, true, false, false) 
        dxDrawText("+1500", 1210, 50, 1350, 76, tocolor(0, 100, 35, 255), 1.00, "pricedown", "left", "top", false, false, true, false, false) 
end 
      
addEvent( "onClientZombieWasted" ) 
addEventHandler( "onClientZombieWasted", root, 
function() 
        addEventHandler("onClientRender", root, onTest) 
        setTimer( 
        function () 
                removeEventHandler ( "onClientRender", root, onTest ) 
        end, 3000, 1) 
end) 

Again, I don't know what zombie resource do you use, so it may not work properly.

Link to comment

You would still need to check whether the "source" is a zombie using

isPedZombie() 

, which is a serverside function, so it would still require triggering server events and all that stuff. Or maybe there's some other way to check whether a ped is a zombie (eg. getElementData()), but I don't know of any other because I've never ran that zombie gamemode myself.

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