Jump to content

triggerClientEvent


Recommended Posts

Hello guys, i have a little problem, when i kill a zombie, It appears a text showing how much i earned, but it appear for all players, and it suppose to appear only for who killed the zombie, here is my code:

Server

addEvent( "onZombieWasted" , true) 
addEventHandler( "onZombieWasted", getRootElement(), 
function( killer ) 
    local money = 500 
        givePlayerMoney( killer, tonumber(money)) 
        triggerClientEvent("onClientZombieWasted", killer, money) 
end) 

Client

local x,y = guiGetScreenSize() 
  
function onTest() 
        dxDrawText("+"..tostring(money), x*1211/1366, y*51/768, x*1351/1366, y*77/768, tocolor(0, 0, 0, 255), 1.00, "pricedown", "left", "top", false, false, true, false, false) 
        dxDrawText("+"..tostring(money), x*1211/1366, y*49/768, x*1351/1366, y*75/768, tocolor(0, 0, 0, 255), 1.00, "pricedown", "left", "top", false, false, true, false, false) 
        dxDrawText("+"..tostring(money), x*1209/1366, y*51/768, x*1349/1366, y*77/768, tocolor(0, 0, 0, 255), 1.00, "pricedown", "left", "top", false, false, true, false, false) 
        dxDrawText("+"..tostring(money), x*1209/1366, y*49/768, x*1349/1366, y*75/768, tocolor(0, 0, 0, 255), 1.00, "pricedown", "left", "top", false, false, true, false, false) 
        dxDrawText("+"..tostring(money), x*1210/1366, y*50/768, x*1350/1366, y*76/768, tocolor(22, 131, 38, 255), 1.00, "pricedown", "left", "top", false, false, true, false, false) 
         
--for i=1, 18 do 
--dxDrawText("A zombie got killed ".. i, x*0.2, 0 - y*0.03 + (y*0.05 * i),x,y,tocolor(255,255,255,255)) 
--end 
  
end 
  
  
addEvent("onClientZombieWasted", true) 
addEventHandler( "onClientZombieWasted", root, 
function(mon) 
    if not isTimer(moneyTimer) then 
        moneyTimer = setTimer(function() 
            removeEventHandler("onClientRender", root, onTest) 
        end, 2000, 1) 
        money = mon 
        addEventHandler("onClientRender", root, onTest) 
    else 
        money = (money + mon) 
        resetTimer(moneyTimer) 
    end 
end) 

Link to comment

-- no Need for local Money on Server . .

---ClinetSide ,

  
function onTest() 
local x,y = guiGetScreenSize() 
local money = getPlayerMoney (localPlayer) 
        dxDrawText("+"..tostring(money), x*1211/1366, y*51/768, x*1351/1366, y*77/768, tocolor(0, 0, 0, 255), 1.00, "pricedown", "left", "top", false, false, true, false, false) 
        dxDrawText("+"..tostring(money), x*1211/1366, y*49/768, x*1351/1366, y*75/768, tocolor(0, 0, 0, 255), 1.00, "pricedown", "left", "top", false, false, true, false, false) 
        dxDrawText("+"..tostring(money), x*1209/1366, y*51/768, x*1349/1366, y*77/768, tocolor(0, 0, 0, 255), 1.00, "pricedown", "left", "top", false, false, true, false, false) 
        dxDrawText("+"..tostring(money), x*1209/1366, y*49/768, x*1349/1366, y*75/768, tocolor(0, 0, 0, 255), 1.00, "pricedown", "left", "top", false, false, true, false, false) 
        dxDrawText("+"..tostring(money), x*1210/1366, y*50/768, x*1350/1366, y*76/768, tocolor(22, 131, 38, 255), 1.00, "pricedown", "left", "top", false, false, true, false, false)        
for i=1, 18 do 
dxDrawText("A zombie got killed ".. i, x*0.2, 0 - y*0.03 + (y*0.05 * i),x,y,tocolor(255,255,255,255)) 
end  
end 
  
addEvent("onClientZombieWasted", true) 
addEventHandler( "onClientZombieWasted", root, 
function(mon) 
    if not isTimer(moneyTimer) then 
        moneyTimer = setTimer(function() 
            removeEventHandler("onClientRender", root, onTest) 
        end, 2000, 1) 
        money = mon 
        addEventHandler("onClientRender",root, onTest) 
    else 
        money = (money + mon) 
        resetTimer(moneyTimer) 
    end 
end) 

---ServerSide ,

addEvent( "onZombieWasted" , true) 
addEventHandler( "onZombieWasted", getRootElement(), 
function( attacker ) 
  if ( getElementType ( attacker ) == "player" ) and ( getElementType ( source ) == "ped" ) then 
           givePlayerMoney(attacker, 500) 
       triggerClientEvent(attacker, 'onClientZombieWasted', attacker) 
         end 
   end 
   ) 

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