βurak Posted January 28, 2020 Share Posted January 28, 2020 (edited) hello im trying call text with triggerClientEvent but saying ERROR: server triggered clientside event showHUD but event not is not added clientside and my client side code draw nil on the screen im trying to 58.line in server side my purpose is transfer server side data to client side client local screenW, screenH = guiGetScreenSize() function EXP_HUD(exp) dxDrawText( tostring( exp ), screenW/2, screenH/2, screenW/2, screenH/2, tocolor( 255,255,255,255 ), 1, "bankgothic", "center", "center" ) end addEventHandler("onClientRender", root, EXP_HUD) addEvent( "showHUD", true ) addEventHandler( "showHUD", localPlayer, EXP_HUD ) server function math.round( number ) return number - number % 1 end --====================================================================+ --INFO: Setter Getter Functions EXP AND LEVEL --====================================================================+ function getRequiredEXP( level ) if not ( level ) then return false end return math.round( math.pow( level, 2 ) * 300 ) end function getPlayerEXP( player ) if not ( player ) then return false end return getElementData( player, "ZR_EXP" ) end function setPlayerEXP( player, value ) if not ( player or value ) then return false end return setElementData( player, "ZR_EXP", tonumber( value ) ) end function getPlayerLevel( player ) if not ( player ) then return false end return getElementData( player, "ZR_LEVEL" ) end function setPlayerLevel( player, newlevel ) if not ( player or newlevel ) then return false end return setElementData( player, "ZR_LEVEL", tonumber( newlevel ) ) end function level_UP( player ) if not (player) then return false end local mylevel = getPlayerLevel( player ) local myexp = getPlayerEXP( player ) local required = getRequiredEXP( mylevel ) if myexp >= required then while myexp >= required do setPlayerLevel( player, mylevel + 1 ) outputChatBox( getPlayerLevel( player ) ) required = getRequiredEXP( mylevel + 1 ) outputChatBox( required ) end end end function addEXP( player, value ) if not ( player or value ) then return false end local myexp = getPlayerEXP( player ) setPlayerEXP( player, myexp + tonumber( value ) ) level_UP( player ) end function callHUD() local myexp = getPlayerEXP( source ) triggerClientEvent( source, "showHUD", source, myexp ) end -- initiliaze exp/level stuff addEventHandler( "onPlayerJoin", getRootElement(), function() setElementData(source, "ZR_LEVEL", 1) setElementData(source, "ZR_EXP", 0) callHUD( source ) end ) addCommandHandler( "getlevelexp", function( player ) local mylevel = getPlayerLevel( player ) local myexp = getPlayerEXP( player ) local required = getRequiredEXP( mylevel ) outputChatBox( "You Level: "..tostring( mylevel ) ) outputChatBox( "You EXP: "..tostring( myexp ) ) outputChatBox( "Need EXP: "..tostring( required ) ) end ) addCommandHandler("giveexp", function( player ) addEXP( player, 100 ) end ) Edited January 28, 2020 by Burak5312 Link to comment
ArcAngeL Posted January 28, 2020 Share Posted January 28, 2020 local screenW, screenH = guiGetScreenSize() function EXP_HUD(myexp) local exp = getElementData( localPlayer, "ZR_EXP" ) dxDrawText( tostring(exp) , screenW/2, screenH/2, screenW/2, screenH/2, tocolor( 255,255,255,255 ), 1, "bankgothic", "center", "center" ) end addEventHandler("onClientRender", root, EXP_HUD) addEvent( "showHUD", true ) addEventHandler( "showHUD", localPlayer, EXP_HUD ) ı think this will work. Link to comment
Multi1996 Posted January 28, 2020 Share Posted January 28, 2020 local screenW, screenH = guiGetScreenSize() function EXP_HUD(exppoints) if(exppoints)then setElementData(localPlayer, "exp", tostring(exppoints)) addEventHandler("onClientRender", localPlayer, draw) end end addEvent( "showHUD", true ) addEventHandler( "showHUD", localPlayer, EXP_HUD ) function draw() dxDrawText(tostring(getElementData(localPlayer, "exp")) , screenW/2, screenH/2, screenW/2, screenH/2, tocolor( 255,255,255,255 ), 1, "bankgothic", "center", "center" ) end per Handy! Link to comment
βurak Posted January 28, 2020 Author Share Posted January 28, 2020 (edited) 8 minutes ago, ArcAngeL said: local screenW, screenH = guiGetScreenSize() function EXP_HUD(myexp) local exp = getElementData( localPlayer, "ZR_EXP" ) dxDrawText( tostring(exp) , screenW/2, screenH/2, screenW/2, screenH/2, tocolor( 255,255,255,255 ), 1, "bankgothic", "center", "center" ) end addEventHandler("onClientRender", root, EXP_HUD) addEvent( "showHUD", true ) addEventHandler( "showHUD", localPlayer, EXP_HUD ) ı think this will work. thanks man worked! actually i write getter setters client version will be better 7 minutes ago, Multi1996 said: local screenW, screenH = guiGetScreenSize() function EXP_HUD(exppoints) if(exppoints)then setElementData(localPlayer, "exp", tostring(exppoints)) addEventHandler("onClientRender", localPlayer, draw) end end addEvent( "showHUD", true ) addEventHandler( "showHUD", localPlayer, EXP_HUD ) function draw() dxDrawText(tostring(getElementData(localPlayer, "exp")) , screenW/2, screenH/2, screenW/2, screenH/2, tocolor( 255,255,255,255 ), 1, "bankgothic", "center", "center" ) end per Handy! thank you Edited January 28, 2020 by Burak5312 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