Jump to content

triggerClientEvent


Recommended Posts

Posted

Hello guys, i'm trying to trigger an dxText which it will show how much XP i earned after i kill someone, here is my code

Client:

sWidth,sHeight = guiGetScreenSize() 
function onTestExp(X) 
    dxDrawText("#00FF000 +"..tonumber(X), (539/1024)*sWidth, (745/768)*sHeight, (289/1024)*sWidth, (250/768)*sHeight, tocolor (255, 255, 255, 255), (0.7/1366)*sWidth,(0.7/768)*sHeight,"bankgothic","left","top",false,false,false,true)    
end 
      
addEvent("onTestExp", true) 
addEventHandler( "onTestExp", root, 
function() 
        addEventHandler("onClientRender", root, onTestExp) 
        setTimer( 
        function () 
                removeEventHandler ( "onClientRender", root, onTestExp ) 
        end, 3000, 1) 
end) 

Server:

--just some lines of the code 
        local X = math.random(5, 45) 
        triggerClientEvent("onTestExp", killer, X) 

And killer is defined here:

function win(killer, weapon, bodypart) 
    if (killer and getElementType(killer) == "player" and killer ~= source) then 

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted

You can't pass arguments using addEventHandler, that means that "X" is nil.

What yo ucan do is:

Define a global variable using the data sent from the server side.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

How? Actually i did not understand what you're trying to say..

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted

Example:

local experience = 0 -- Define global variable 

Now, in your trigger, you are sending the experience value, so, you must add the argument in the client side function:

addEvent ( "onTestExp", true ) 
addEventHandler ( "onTestExp", root, 
    function ( expe ) -- Here you are defining an argument, in this case, the value is what is sent from the server side. 
    end 
) 

So, all what you have to do next is set the "experience" variable value, which you can do it like this:

experience = expe 

After that, you add the event handler to render it, and in dxDrawText you use "experience" variable instead of "X".

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Gonna try thanks

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted (edited)

Here is the client side part,

sWidth, sHeight = guiGetScreenSize() 
function onTestExp() 
    dxDrawText("#00FF000 +"..tostring(experience), (539/1024)*sWidth, (745/768)*sHeight, (289/1024)*sWidth, (250/768)*sHeight, tocolor (255, 255, 255, 255), (0.7/1366)*sWidth,(0.7/768)*sHeight,"bankgothic","left","top",false,false,false,true)   
end 
      
addEvent("onTestExp", true) 
addEventHandler( "onTestExp", root, 
function( expe ) 
experience = expe 
        addEventHandler("onClientRender", root, onTestExp) 
        setTimer( 
        function () 
                removeEventHandler ( "onClientRender", root, onTestExp ) 
        end, 3000, 1) 
end) 

I will send you the Server side in pm if it's possible..

Edited by Guest

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted
function onTestExp(experience) 

Remove "experience" from there and change "tonumber" to "tostring".

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Thanks Castillo.

And is it possible to do the following?

If i killed like example 2 people in the same time, it will count automatically how much i earned like example.

I killed the first one and i got 24 xp and after i kill the second one i got 22, so it will output 46 if you know what i mean, if it's not possible then never mind thanks.

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted

Help?

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted

Anything is possible if you know how to do it.

I would suggest to define your timer, so then you can use isTimer to know if the timer is still running, and if it is, you can reset it and increase the value of the "experience" variable with the value sent from the server side.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

I undertand, but i'll have to do it manually..

What if i killed 3 players like example? It will cancel the first text and it will ouput a new one.

Oh btw are those the exact functions:

setTimer 
isTimer 
killTimer 
resetTimer 
getTickCount 

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted

No need to use killTimer nor getTickCount, just isTimer and resetTimer.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Okay, and what i should do to increase the value of the experience variable with the value sent from server side?

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted

Well, it's quite easy, all you have to do is:

experience = ( experience + expe ) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted (edited)
sWidth, sHeight = guiGetScreenSize() 
function onTestExp() 
    dxDrawText("#FFFFCC +"..tostring(experience), (539/1024)*sWidth, (545/768)*sHeight, (289/1024)*sWidth, (250/768)*sHeight, tocolor (255, 255, 255, 255), (0.7/1366)*sWidth,(0.7/768)*sHeight,"bankgothic","left","top",false,false,false,true)    
end 
      
addEvent("onTestExp", true) 
addEventHandler( "onTestExp", root, 
function( expe ) 
experience = expe 
        addEventHandler("onClientRender", root, onTestExp) 
        setTimer( 
        function () 
                removeEventHandler ( "onClientRender", root, onTestExp ) 
        end, 2000, 1) 
        if isTimer(source) then 
            resetTimer(source) 
            experience = ( experience + expe ) 
            setTimer( 
        function () 
                removeEventHandler ( "onClientRender", root, onTestExp ) 
        end, 2000, 1) 
        end 
end) 

Edited by Guest

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted

Help?

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted

Help please.

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted
sWidth, sHeight = guiGetScreenSize() 
function onTestExp() 
    dxDrawText("#FFFFCC +"..tostring(experience), (539/1024)*sWidth, (545/768)*sHeight, (289/1024)*sWidth, (250/768)*sHeight, tocolor (255, 255, 255, 255), (0.7/1366)*sWidth,(0.7/768)*sHeight,"bankgothic","left","top",false,false,false,true)    
end 
  
addEvent("onTestExp", true) 
addEventHandler( "onTestExp", root, 
function(expe) 
    if not isTimer(expTimer) then 
        expTimer = setTimer(function() 
            removeEventHandler("onClientRender", root, onTestExp) 
        end, 2000, 1) 
        experience = expe 
        addEventHandler("onClientRender", root, onTestExp) 
    else 
        experience = (experience + expe) 
        resetTimer(expTimer) 
    end 
end) 

CiTLh.png
Posted

I'm working on exp / level system.

Im make this but i have a problem.

Exp have been changed, must disappearing after 2500 milliseconds. But for the first time the changing exp triggers.

How to fix it?

local sWidth, sHeight = guiGetScreenSize () 
function onTestExp() 
    dxDrawText("+"..tostring(givePlayerExp), (1542/1680)*sWidth, (10/1050)*sHeight, (1594/1680)*sWidth, (29/1050)*sHeight, tocolor(255, 20, 0, 255), (0.60/1680)*sWidth, (0.60/1050)*sHeight, "bankgothic", "left", "top", false, false, true, true, false) 
end 
  
handlerExist = false 
addEvent("onTestExp", true) 
addEventHandler( "onTestExp", root, 
function( expe ) 
    givePlayerExp = expe 
     
    if (handlerExist == false) then 
    addEventHandler( "onClientRender", root, onTestExp ) 
    handlerExist = true 
    setTimer( function ()  
        if (handlerExist == true) then 
        removeEventHandler( "onClientRender", root, onTestExp ) 
        handlerExist = false 
        end 
end, 2500, 1 ) 
    else 
    removeEventHandler( "onClientRender", root, onTestExp ) 
    addEventHandler( "onClientRender", root, onTestExp ) 
    handlerExist = true 
    setTimer( function ()  
        if (handlerExist == true) then 
        removeEventHandler( "onClientRender", root, onTestExp ) 
        handlerExist = false 
        end 
end, 2500, 1 ) 
    end 
end 
) 

Sry for bad English.

Posted

Thanks TAPL gonna try.

and @AbaZaSiRiN00 Post the part where you triggered the client event "onTestExp"

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted

Copy my code.

Replace experience with givePlayerExp.

and replace expe with give.

If it doesn't work, put the whole server side code.

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted

Oh no. It's work perfectly. My problem is timing. Each exp arrives, I want you to start from the beginning of 2500 milliseconds. My only problem is it.

Posted

Explain...

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

Posted
sWidth, sHeight = guiGetScreenSize() 
function onTestExp() 
    dxDrawText("#FFFFCC +"..tostring(experience), (539/1024)*sWidth, (545/768)*sHeight, (289/1024)*sWidth, (250/768)*sHeight, tocolor (255, 255, 255, 255), (0.7/1366)*sWidth,(0.7/768)*sHeight,"bankgothic","left","top",false,false,false,true)    
end 
  
addEvent("onTestExp", true) 
addEventHandler( "onTestExp", root, 
function(expe) 
    if not isTimer(expTimer) then 
        expTimer = setTimer(function() 
            removeEventHandler("onClientRender", root, onTestExp) 
        end, 2000, 1) 
        experience = expe 
        addEventHandler("onClientRender", root, onTestExp) 
    else 
        experience = (experience + expe) 
        resetTimer(expTimer) 
    end 
end) 

Thanks TAPL. : )

If you're looking for a cheap paid scripter, don't hesitate to contact me.

Great minds discuss ideas, Average minds discuss events and small minds discuss people.

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