-.Paradox.- Posted May 10, 2014 Share Posted May 10, 2014 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 Link to comment
Castillo Posted May 10, 2014 Share Posted May 10, 2014 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. Link to comment
-.Paradox.- Posted May 10, 2014 Author Share Posted May 10, 2014 How? Actually i did not understand what you're trying to say.. Link to comment
Castillo Posted May 10, 2014 Share Posted May 10, 2014 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". Link to comment
-.Paradox.- Posted May 10, 2014 Author Share Posted May 10, 2014 (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 May 10, 2014 by Guest Link to comment
Castillo Posted May 10, 2014 Share Posted May 10, 2014 function onTestExp(experience) Remove "experience" from there and change "tonumber" to "tostring". Link to comment
-.Paradox.- Posted May 11, 2014 Author Share Posted May 11, 2014 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. Link to comment
Castillo Posted May 11, 2014 Share Posted May 11, 2014 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. Link to comment
-.Paradox.- Posted May 11, 2014 Author Share Posted May 11, 2014 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 Link to comment
Castillo Posted May 11, 2014 Share Posted May 11, 2014 No need to use killTimer nor getTickCount, just isTimer and resetTimer. Link to comment
-.Paradox.- Posted May 11, 2014 Author Share Posted May 11, 2014 Okay, and what i should do to increase the value of the experience variable with the value sent from server side? Link to comment
Castillo Posted May 11, 2014 Share Posted May 11, 2014 Well, it's quite easy, all you have to do is: experience = ( experience + expe ) Link to comment
-.Paradox.- Posted May 11, 2014 Author Share Posted May 11, 2014 (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 May 19, 2014 by Guest Link to comment
TAPL Posted May 20, 2014 Share Posted May 20, 2014 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) Link to comment
undefined Posted May 20, 2014 Share Posted May 20, 2014 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. Link to comment
-.Paradox.- Posted May 20, 2014 Author Share Posted May 20, 2014 Thanks TAPL gonna try. and @AbaZaSiRiN00 Post the part where you triggered the client event "onTestExp" Link to comment
undefined Posted May 20, 2014 Share Posted May 20, 2014 givePlayerExp = math.random(50, 75) triggerClientEvent("onTestExp", killer, givePlayerExp) Link to comment
-.Paradox.- Posted May 20, 2014 Author Share Posted May 20, 2014 Copy my code. Replace experience with givePlayerExp. and replace expe with give. If it doesn't work, put the whole server side code. Link to comment
undefined Posted May 20, 2014 Share Posted May 20, 2014 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. Link to comment
-.Paradox.- Posted May 20, 2014 Author Share Posted May 20, 2014 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. : ) 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