kowixd Posted April 11, 2018 Posted April 11, 2018 (edited) Hola, quisiera que cuando un jugador escriba /afk por arriba de su cabeza unas letras que diga AFK y cuando escriba /noafk estas desaparescan. Nose muy bien como usar usar el dxDrawText, por favor AYUDA Aqui les dejo el scrip del AFK: Hello, I would like that when a player writes / afk above his head some letters that say AFK and when he writes / noafk they disappear. I do not know how to use the dxDrawText, please HELP Here is the AFK scrip: addEventHandler("onPlayerJoin",getRootElement(), function () setElementData(source,"afk_state","back") setElementData(source,"HideState","disabled") --setElementData(source,"tafk",false) end) addEventHandler( "onResourceStart", getResourceRootElement(getThisResource()), function () for i,v in pairs (getElementsByType("player")) do setElementData(v,"afk_state","back") setElementData(v,"HideState","disabled") setElementData(v,"tafk",false) setElementData(v,"invencible",false) end end) function afkstart(player) local vida = getElementHealth ( player ) if getElementData(player,"afk_state") == "back" then local state = ( not getElementData ( player, "invencible" ) ) if vida < 35 then return outputChatBox ("No puedes ir AFK con la vida baja!",player,255,0,0) end if getElementData (player, "tafk", true) then outputChatBox ('#00FF00Espere 10 segundos...',player,255,0,0,true) return end local id2 = getPedWeapon (player) triggerClientEvent(player,"god_mode",player) setElementData ( player, "invencible", state ) --outputChatBox ( "AFK ".. ( state and "Activado" or "Desactivado" ) ..".", player, 255, 0, 0 ) setElementFrozen(player,true) setPlayerNametagText (player, "|AFK|" .. getPlayerName ( player )) outputChatBox(getPlayerName(player).." #ff0000 esta AFK!",getRootElement(),0,255,0, true) setElementData(player,"afk_state","afk") if id2 > 15 then giveWeapon (player, 0, 1, true) end setElementData (player, "tafk",true) toggleControl (player, "fire", false) toggleControl (player, "next_weapon", false) toggleControl (player, "previous_weapon", false) toggleControl ( player, 'vehicle_fire', false ) toggleControl (player, "aim_weapon", false) bindKey (player,"w","down","noafk") bindKey (player,"d","down","noafk") bindKey (player,"s","down","noafk") bindKey (player,"a","down","noafk") bindKey (player,"num_0","down","noafk") bindKey (player,"lctrl","down","noafk") bindKey (player,"arrow_u","down","noafk") bindKey (player,"arrow_d","down","noafk") bindKey (player,"arrow_l","down","noafk") bindKey (player,"arrow_r","down","noafk") bindKey (player,"delete","down","noafk") bindKey (player,"mouse2","down","noafk") bindKey (player,"capslock","down","noafk") if getPedOccupiedVehicle(player) then fixVehicle(getPedOccupiedVehicle(player),true) setElementFrozen(getPedOccupiedVehicle(player),true) setVehicleDamageProof(getPedOccupiedVehicle(player),true) end setElementData (player, "tafk",true) setTimer (setElementData, 10000, 1, player, "tafk", false) end end addCommandHandler("afk", afkstart ) function afkend(player) if getElementData(player,"afk_state") == "afk" then local state = ( not getElementData ( player, "invencible" ) ) setElementData(player,"afk_state","back") triggerClientEvent(player,"disable_god_mode",player) setElementFrozen(player,false) setPlayerNametagText (player, "" .. getPlayerName (player)) outputChatBox(getPlayerName(player).." #00ff00 ya no esta AFK!",getRootElement(),0,255,0, true) toggleControl (player, "fire", true) toggleControl (player, "next_weapon", true) toggleControl (player, "previous_weapon", true) toggleControl ( player, 'vehicle_fire', true ) toggleControl (player, "aim_weapon", true) setElementData ( player, "invencible", state ) --outputChatBox ( "AFK " .. ( state and "Activado" or "Desactivado" ) ..".", player, 255, 0, 0 ) unbindKey (player,"w","down","noafk") unbindKey (player,"d","down","noafk") unbindKey (player,"s","down","noafk") unbindKey (player,"a","down","noafk") unbindKey (player,"num_0","down","noafk") unbindKey (player,"lctrl","down","noafk") unbindKey (player,"arrow_u","down","noafk") unbindKey (player,"arrow_d","down","noafk") unbindKey (player,"arrow_l","down","noafk") unbindKey (player,"arrow_r","down","noafk") unbindKey (player,"delete","down","noafk") unbindKey (player,"mouse2","down","noafk") unbindKey (player,"capslock","down","noafk") if getPedOccupiedVehicle(player) then setElementFrozen(getPedOccupiedVehicle(player),false) setVehicleDamageProof(getPedOccupiedVehicle(player),false) end end end addCommandHandler("noafk", afkend ) addCommandHandler("wp", afkend ) addCommandHandler("weapon", afkend ) addCommandHandler("dim", afkend ) addEventHandler( "onResourceStop", getResourceRootElement(getThisResource()), function () for i,v in pairs (getElementsByType("player")) do setElementData(v,"afk_state","back") setElementData(v,"HideState","disabled") --setElementData(v,"tafk",false) setElementData(v,"invencible",false) end end) Edited April 11, 2018 by kowixd
Dimos7 Posted April 11, 2018 Posted April 11, 2018 (edited) addEventHandler("onClientRender", root, function() local cx, cy, cz = getCameraMatrix() local px, py, pz = getElementPosition(localPlayer) if getElementData(localPlayer, "afk_state") == afk then dist = math.squrt(px-cx)^2 + (py-cy)^2 + (pz-cz)^2) if dist < 30 then if isLineOfSightClear(px, py, pz, cx, cy, cz, true, false, false, true, false, false, true) local bx, by, bz = getPedBonePosition(localPlayer, 6) local x, y = getScreenFromWorldPosition(bx, by, bz+0.3) if x then dxDrawText("AFK", x, y, x, y tocolor(255, 255, 255, 255), 0.085+(15-dist)*0.02, "pricedown", "center", "center") end end end end end) Edited April 11, 2018 by Dimos7
Dimos7 Posted April 11, 2018 Posted April 11, 2018 addEventHandler("onClientRender", root, function() local cx, cy, cz = getCameraMatrix() local px, py, pz = getElementPosition(localPlayer) if getElementData(localPlayer, "afk_state") == afk then dist = math.sqrt(px-cx)^2 + (py-cy)^2 + (pz-cz)^2) if dist < 30 then if isLineOfSightClear(px, py, pz, cx, cy, cz, true, false, false, true, false, false, true) local bx, by, bz = getPedBonePosition(localPlayer, 6) local x, y = getScreenFromWorldPosition(bx, by, bz+0.3) if x then dxDrawText("AFK", x, y, x, y tocolor(255, 255, 255, 255), 0.085+(15-dist)*0.02, "pricedown", "center", "center") end end end end end)
kowixd Posted April 11, 2018 Author Posted April 11, 2018 1 hour ago, Dimos7 said: addEventHandler("onClientRender", root, function() local cx, cy, cz = getCameraMatrix() local px, py, pz = getElementPosition(localPlayer) if getElementData(localPlayer, "afk_state") == afk then dist = math.sqrt(px-cx)^2 + (py-cy)^2 + (pz-cz)^2) if dist < 30 then if isLineOfSightClear(px, py, pz, cx, cy, cz, true, false, false, true, false, false, true) local bx, by, bz = getPedBonePosition(localPlayer, 6) local x, y = getScreenFromWorldPosition(bx, by, bz+0.3) if x then dxDrawText("AFK", x, y, x, y tocolor(255, 255, 255, 255), 0.085+(15-dist)*0.02, "pricedown", "center", "center") end end end end end) ERROR: Loading script failed: afk2\server.lua: 'then' expected near 'local' ......(line 7)
KaMi Posted April 11, 2018 Posted April 11, 2018 4 hours ago, kowixd said: Hola, quisiera que cuando un jugador escriba /afk por arriba de su cabeza unas letras que diga AFK y cuando escriba /noafk estas desaparescan. Nose muy bien como usar usar el dxDrawText, por favor AYUDA Aqui les dejo el scrip del AFK: Hello, I would like that when a player writes / afk above his head some letters that say AFK and when he writes / noafk they disappear. I do not know how to use the dxDrawText, please HELP Here is the AFK scrip: addEventHandler("onPlayerJoin",getRootElement(), function () setElementData(source,"afk_state","back") setElementData(source,"HideState","disabled") --setElementData(source,"tafk",false) end) addEventHandler( "onResourceStart", getResourceRootElement(getThisResource()), function () for i,v in pairs (getElementsByType("player")) do setElementData(v,"afk_state","back") setElementData(v,"HideState","disabled") setElementData(v,"tafk",false) setElementData(v,"invencible",false) end end) function afkstart(player) local vida = getElementHealth ( player ) if getElementData(player,"afk_state") == "back" then local state = ( not getElementData ( player, "invencible" ) ) if vida < 35 then return outputChatBox ("No puedes ir AFK con la vida baja!",player,255,0,0) end if getElementData (player, "tafk", true) then outputChatBox ('#00FF00Espere 10 segundos...',player,255,0,0,true) return end local id2 = getPedWeapon (player) triggerClientEvent(player,"god_mode",player) setElementData ( player, "invencible", state ) --outputChatBox ( "AFK ".. ( state and "Activado" or "Desactivado" ) ..".", player, 255, 0, 0 ) setElementFrozen(player,true) setPlayerNametagText (player, "|AFK|" .. getPlayerName ( player )) outputChatBox(getPlayerName(player).." #ff0000 esta AFK!",getRootElement(),0,255,0, true) setElementData(player,"afk_state","afk") if id2 > 15 then giveWeapon (player, 0, 1, true) end setElementData (player, "tafk",true) toggleControl (player, "fire", false) toggleControl (player, "next_weapon", false) toggleControl (player, "previous_weapon", false) toggleControl ( player, 'vehicle_fire', false ) toggleControl (player, "aim_weapon", false) bindKey (player,"w","down","noafk") bindKey (player,"d","down","noafk") bindKey (player,"s","down","noafk") bindKey (player,"a","down","noafk") bindKey (player,"num_0","down","noafk") bindKey (player,"lctrl","down","noafk") bindKey (player,"arrow_u","down","noafk") bindKey (player,"arrow_d","down","noafk") bindKey (player,"arrow_l","down","noafk") bindKey (player,"arrow_r","down","noafk") bindKey (player,"delete","down","noafk") bindKey (player,"mouse2","down","noafk") bindKey (player,"capslock","down","noafk") if getPedOccupiedVehicle(player) then fixVehicle(getPedOccupiedVehicle(player),true) setElementFrozen(getPedOccupiedVehicle(player),true) setVehicleDamageProof(getPedOccupiedVehicle(player),true) end setElementData (player, "tafk",true) setTimer (setElementData, 10000, 1, player, "tafk", false) end end addCommandHandler("afk", afkstart ) function afkend(player) if getElementData(player,"afk_state") == "afk" then local state = ( not getElementData ( player, "invencible" ) ) setElementData(player,"afk_state","back") triggerClientEvent(player,"disable_god_mode",player) setElementFrozen(player,false) setPlayerNametagText (player, "" .. getPlayerName (player)) outputChatBox(getPlayerName(player).." #00ff00 ya no esta AFK!",getRootElement(),0,255,0, true) toggleControl (player, "fire", true) toggleControl (player, "next_weapon", true) toggleControl (player, "previous_weapon", true) toggleControl ( player, 'vehicle_fire', true ) toggleControl (player, "aim_weapon", true) setElementData ( player, "invencible", state ) --outputChatBox ( "AFK " .. ( state and "Activado" or "Desactivado" ) ..".", player, 255, 0, 0 ) unbindKey (player,"w","down","noafk") unbindKey (player,"d","down","noafk") unbindKey (player,"s","down","noafk") unbindKey (player,"a","down","noafk") unbindKey (player,"num_0","down","noafk") unbindKey (player,"lctrl","down","noafk") unbindKey (player,"arrow_u","down","noafk") unbindKey (player,"arrow_d","down","noafk") unbindKey (player,"arrow_l","down","noafk") unbindKey (player,"arrow_r","down","noafk") unbindKey (player,"delete","down","noafk") unbindKey (player,"mouse2","down","noafk") unbindKey (player,"capslock","down","noafk") if getPedOccupiedVehicle(player) then setElementFrozen(getPedOccupiedVehicle(player),false) setVehicleDamageProof(getPedOccupiedVehicle(player),false) end end end addCommandHandler("noafk", afkend ) addCommandHandler("wp", afkend ) addCommandHandler("weapon", afkend ) addCommandHandler("dim", afkend ) addEventHandler( "onResourceStop", getResourceRootElement(getThisResource()), function () for i,v in pairs (getElementsByType("player")) do setElementData(v,"afk_state","back") setElementData(v,"HideState","disabled") --setElementData(v,"tafk",false) setElementData(v,"invencible",false) end end) Coloca esto en tu client function dxDrawTextOnElement(TheElement,text,height,distance,R,G,B,alpha,size,font,checkBuildings,checkVehicles,checkPeds,checkDummies,seeThroughStuff,ignoreSomeObjectsForCamera,ignoredElement) local x, y, z = getElementPosition(TheElement) local x2, y2, z2 = getElementPosition(localPlayer) local distance = distance or 20 local height = height or 1 local checkBuildings = checkBuildings or true local checkVehicles = checkVehicles or false local checkPeds = checkPeds or false local checkObjects = checkObjects or true local checkDummies = checkDummies or true local seeThroughStuff = seeThroughStuff or false local ignoreSomeObjectsForCamera = ignoreSomeObjectsForCamera or false local ignoredElement = ignoredElement or nil if (isLineOfSightClear(x, y, z, x2, y2, z2, checkBuildings, checkVehicles, checkPeds , checkObjects,checkDummies,seeThroughStuff,ignoreSomeObjectsForCamera,ignoredElement)) then local sx, sy = getScreenFromWorldPosition(x, y, z+height) if(sx) and (sy) then local distanceBetweenPoints = getDistanceBetweenPoints3D(x, y, z, x2, y2, z2) if(distanceBetweenPoints < distance) then dxDrawText(text, sx+2, sy+2, sx, sy, tocolor(R or 255, G or 255, B or 255, alpha or 255), (size or 1)-(distanceBetweenPoints / distance), font or "arial", "center", "center") end end end end addEventHandler("onClientRender", root, function() if getElementData(localPlayer,"afk_state") == "afk" then dxDrawTextOnElement(localPlayer,"AFK",1,20,255,0,0,255,1,"bankgothic") else end end )
kowixd Posted April 12, 2018 Author Posted April 12, 2018 52 minutes ago, <~KaMiKaZe~> said: Coloca esto en tu client function dxDrawTextOnElement(TheElement,text,height,distance,R,G,B,alpha,size,font,checkBuildings,checkVehicles,checkPeds,checkDummies,seeThroughStuff,ignoreSomeObjectsForCamera,ignoredElement) local x, y, z = getElementPosition(TheElement) local x2, y2, z2 = getElementPosition(localPlayer) local distance = distance or 20 local height = height or 1 local checkBuildings = checkBuildings or true local checkVehicles = checkVehicles or false local checkPeds = checkPeds or false local checkObjects = checkObjects or true local checkDummies = checkDummies or true local seeThroughStuff = seeThroughStuff or false local ignoreSomeObjectsForCamera = ignoreSomeObjectsForCamera or false local ignoredElement = ignoredElement or nil if (isLineOfSightClear(x, y, z, x2, y2, z2, checkBuildings, checkVehicles, checkPeds , checkObjects,checkDummies,seeThroughStuff,ignoreSomeObjectsForCamera,ignoredElement)) then local sx, sy = getScreenFromWorldPosition(x, y, z+height) if(sx) and (sy) then local distanceBetweenPoints = getDistanceBetweenPoints3D(x, y, z, x2, y2, z2) if(distanceBetweenPoints < distance) then dxDrawText(text, sx+2, sy+2, sx, sy, tocolor(R or 255, G or 255, B or 255, alpha or 255), (size or 1)-(distanceBetweenPoints / distance), font or "arial", "center", "center") end end end end addEventHandler("onClientRender", root, function() if getElementData(localPlayer,"afk_state") == "afk" then dxDrawTextOnElement(localPlayer,"AFK",1,20,255,0,0,255,1,"bankgothic") else end end ) it's doesn't work
LLCoolJ Posted April 12, 2018 Posted April 12, 2018 local AFK = {} function getAFKTableSize(t) local count = 0 if t and type(t) == "table" then for k in next,t do if isElement(k) then count = count + 1 end end end return count end function playerDataChanges(data) if data == "afk_state" then local value = getElementData(source,data) if value == "afk" then if getAFKTableSize(AFK) == 0 then addEventHandler("onClientRender",root,Render) end AFK[source] = true elseif value == "back" then AFK[source] = nil if getAFKTableSize(AFK) == 0 then removeEventHandler("onClientRender",root,Render) end end end end addEventHandler("onClientElementDataChange",root,playerDataChanges) function Render() for player in next,AFK do if isElement(player) then local myPos = {getElementPosition(localPlayer)} local head = {getPedBonePosition(player,8)} if getDistanceBetweenPoints3D(myPos[1],myPos[2],myPos[3],head[1],head[2],head[3]) <= 30 then local x,y = getScreenFromWorldPosition(head[1],head[2],head[3]+0.3) if x and y then dxDrawText("AFK",x,y,x,y,tocolor(255,255,255,255),2,"sans","center","center") end end end end end Client side 1
kowixd Posted April 13, 2018 Author Posted April 13, 2018 8 hours ago, IRBIS said: local AFK = {} function getAFKTableSize(t) local count = 0 if t and type(t) == "table" then for k in next,t do if isElement(k) then count = count + 1 end end end return count end function playerDataChanges(data) if data == "afk_state" then local value = getElementData(source,data) if value == "afk" then if getAFKTableSize(AFK) == 0 then addEventHandler("onClientRender",root,Render) end AFK[source] = true elseif value == "back" then AFK[source] = nil if getAFKTableSize(AFK) == 0 then removeEventHandler("onClientRender",root,Render) end end end end addEventHandler("onClientElementDataChange",root,playerDataChanges) function Render() for player in next,AFK do if isElement(player) then local myPos = {getElementPosition(localPlayer)} local head = {getPedBonePosition(player,8)} if getDistanceBetweenPoints3D(myPos[1],myPos[2],myPos[3],head[1],head[2],head[3]) <= 30 then local x,y = getScreenFromWorldPosition(head[1],head[2],head[3]+0.3) if x and y then dxDrawText("AFK",x,y,x,y,tocolor(255,255,255,255),2,"sans","center","center") end end end end end Client side it works thank you
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