Jump to content

koragg

Members
  • Posts

    730
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by koragg

  1. So use the code above. And we don't know what you mean by "block".
  2. @kieran a tip you should try out is to open Notepad++, press CTRL+LShift+F and then search for the thing you want to find in your whole MTA server directory. For example you don't know where the part which outputs the "Currently playing: Mode - Map" is - you type in the search box "Currently playing: " and hit enter, that'll give you all places where this string is used so that you can find and edit the stuff so much faster and easier.
  3. Try this: TestTeam = createTeam( "Test", 20, 100, 150) job_mark = createMarker(7002.419921875, -4831.384765625, 9.60000038147, 'cylinder', 2.0, 20, 100, 150, 255) Test_mark = createMarker(7000.419921875, -4831.384765625, 9.7, 'cylinder', 1.0, 20, 100, 150, 255) function Take_Job(source) local theTeam if getElementType(source) == "player" then theTeam = getPlayerTeam(source) elseif getElementType(source) == "vehicle" then theTeam = getPlayerTeam(getVehicleOccupant(source)) end if theTeam then if getElementType(source) == "player" then setPlayerTeam(source, nil) elseif getElementType(source) == "vehicle" then setPlayerTeam(getVehicleOccupant(source), nil) end end if getElementType(source) == "player" then setPlayerTeam(source, TestTeam) elseif getElementType(source) == "vehicle" then setPlayerTeam(getVehicleOccupant(source), TestTeam) end end addEventHandler("onMarkerHit", job_mark, Take_Job) function TestMarker(source) if isElement(source) and getElementType(source) == 'player' and (not isPedInVehicle(hitElement)) then local theTeam if getElementType(source) == "player" then theTeam = getPlayerTeam(source) elseif getElementType(source) == "vehicle" then theTeam = getPlayerTeam(getVehicleOccupant(source)) end if theTeam == TestTeam then outputChatBox("it works!", source, 255, 0, 0) end end end addEventHandler("onMarkerHit", job_mark, TestMarker)
  4. @pa3ck the link you gave him, does that cancel the login event or it just doesn't show the chatbox message? I was looking for a way to make the login message a bit more pretty sometime ago :')
  5. koragg

    Killsmessages

    Just a coincidence maybe but go in the gui.lua and at the top look at lines 3 and 16. They both say 5 Try to make it to 6 and test
  6. I wasted hours fixing a completely perfect script of mine until I just went YOLO and changed the command because there was nothing else left to do Fun times... (not)
  7. @Gourmet. what did you edit in his first posted script? I didn't see any problems, share please
  8. Well it's better than a fully non-working one anyway Hope someone can help you, I don't know why it doesn't work from time to time. And nothing in debug...
  9. koragg

    Hex Colors

    Line 127: local extent = dxGetTextWidth ( self.strText:gsub("#%x%x%x%x%x%x", ""), self.fScale, self.strFont )
  10. Try this: addCommandHandler("deposit",function(player,cmd,money) local money = tonumber(math.ceil(money)) -- line 14 if (not money) or (type(money) ~= "number") then outputChatBox(syntax.." /"..cmd.." [Amount]",player,38,194,129,true) else if (money) <= 0 then outputChatBox(error.." Bigger hatn 0.",player,177,9,45,true) elseif exports["rc_core"]:getMoney(player) >= tonumber(money) then exports["rc_core"]:takeMoney(player,tonumber(money)) giveBankMoney(player,money) else outputChatBox(error.." You cant afford that.",player,177,9,45,true) end end end )
  11. koragg

    Hex Colors

    Post the full code. I had the same problem when i made the race_progressbar show colored names. That space is there because the script was originally made to look ugly with the color code as letters/numbers. Need to remove that part. I'll help, can't be that hard.
  12. koragg

    Laugh from :D

    message:gsub( ":D", "laugh")
  13. nametag = {} local healthp = {} local nametags = {} local g_screenX,g_screenY = guiGetScreenSize() local bHideNametags = true my = nil local NAMETAG_SCALE = 0.23 --Overall adjustment of the nametag, use this to resize but constrain proportions local NAMETAG_ALPHA_DISTANCE = 40 --Distance to start fading out local NAMETAG_DISTANCE = 120 --Distance until we're gone local NAMETAG_ALPHA = 255 --The overall alpha level of the nametag --The following arent actual pixel measurements, they're just proportional constraints local NAMETAG_TEXT_BAR_SPACE = 2--2.7 local NAMETAG_WIDTH = 50--40 local NAMETAG_HEIGHT = 5--3.7 local NAMETAG_TEXTSIZE = 0.7--0.21 local NAMETAG_OUTLINE_THICKNESS = 1.2 --0.4 local limit = 255 -- local NAMETAG_ALPHA_DIFF = NAMETAG_DISTANCE - NAMETAG_ALPHA_DISTANCE NAMETAG_SCALE = 1/NAMETAG_SCALE * 800 / g_screenY --local alphaSec = 255 -- Ensure the name tag doesn't get too big local maxScaleCurve = { {0, 0}, {3, 3}, {13, 5} } -- Ensure the text doesn't get too small/unreadable local textScaleCurve = { {0, 0.8}, {0.8, 1.2}, {99, 99} } -- Make the text a bit brighter and fade more gradually local textAlphaCurve = { {0, 0}, {25, 100}, {120, 190}, {255, 190} } function nametag.create ( player ) table.insert(nametags, player) end function nametag.destroy ( player ) for j, t in ipairs(nametags)do if(t == player)then table.remove(nametags, j) break end end end local enabledHpBar = true local changeHealthState = false setTimer(function() changeHealthState = not changeHealthState end, 250, 0) local tester = true addCommandHandler("devN", function() tester = not tester end) local imp2 = "default-bold" local hasHiddenHisTag = false function toggleNametags() if hasHiddenHisTag == false then hasHiddenHisTag = true nametag.destroy(g_Me) nametag.create(g_Me) outputChatBox("All nametags are now visible.") elseif hasHiddenHisTag == true then hasHiddenHisTag = false nametag.destroy(g_Me) outputChatBox("All but your nametags are now visible.") end end bindKey("N", "down", toggleNametags) setTimer(function() for i,player in ipairs(g_Players) do if hasHiddenHisTag == false then if player ~= g_Me then setPlayerNametagShowing ( player, false ) local found = false for j, t in ipairs(nametags)do if(t == player)then found = true break end end if not found then nametag.create ( player ) end end elseif hasHiddenHisTag == true then setPlayerNametagShowing ( player, false ) local found = false for j, t in ipairs(nametags)do if(t == player)then found = true break end end if not found then nametag.create ( player ) end end end if(tester)then local order = {} local x,y,z = getCameraMatrix() for i, player in pairs(nametags) do local vehicle = getPedOccupiedVehicle(player) local px,py,pz local pdistance if(vehicle)and isElement(vehicle) and (not isPlayerDead(player))then px,py,pz = getElementPosition ( vehicle ) pdistance = getDistanceBetweenPoints3D ( x,y,z,px,py,pz ) else pdistance = 100 end local index = #order + 1 order[index] = {} order[index].dist = pdistance order[index].player = player end table.sort(order, function(a,b) return tonumber(a.dist) > tonumber(b.dist) end) nametags = {} for i=1,#order do table.insert(nametags, order[i].player) end end end, 250, 0) addEventHandler ( "onClientRender", g_Root, function() if bHideNametags then return end local x,y,z = getCameraMatrix() for i, player in pairs(nametags) do while true do if(getElementData(player, "hideMe"))then break end if not isPedInVehicle(player) or isPlayerDead(player) then break end local vehicle = getPedOccupiedVehicle(player) local px,py,pz = getElementPosition ( vehicle ) local pdistance = getDistanceBetweenPoints3D ( x,y,z,px,py,pz ) if pdistance <= NAMETAG_DISTANCE then pdistance = pdistance * 0.7 --0.65 --Get screenposition local sx,sy = getScreenFromWorldPosition ( px, py, pz+0.95, 0.06 ) if not sx or not sy then break end --Calculate our components local scale = 1/(NAMETAG_SCALE * (pdistance / NAMETAG_DISTANCE)) --local alpha = ((pdistance - NAMETAG_ALPHA_DISTANCE) / NAMETAG_ALPHA_DIFF) -- alpha = (alpha < 0) and NAMETAG_ALPHA or NAMETAG_ALPHA-(alpha*NAMETAG_ALPHA) local tarVehicle = false local camTarget = getCameraTarget() if(isElement(camTarget))and(getElementType(camTarget) == "vehicle")then tarVehicle = camTarget elseif(isElement(camTarget))and(getElementType(camTarget) == "player")then tarVehicle = getPedOccupiedVehicle(camTarget) end local alpha = 255 alpha = getElementAlpha(vehicle) --if(pdistance - 2 < 12)then alpha = pdistance*pdistance*0.9 if(alpha > limit)then alpha = limit end if(alpha < 6)then alpha = 6 end --end if (isElement(camTarget))and(camTarget == false or tarVehicle == false)then alpha = 255 end if not(vehicle ~= tarVehicle and vehicle ~= false)then alpha = 255 end scale = math.evalCurve(maxScaleCurve,scale) local textscale = math.evalCurve(textScaleCurve,scale) local textalpha = math.evalCurve(textAlphaCurve,alpha) local outlineThickness = NAMETAG_OUTLINE_THICKNESS*(scale) --Draw our text local r,g,b = 255,255,255 local team = getPlayerTeam(player) if team then r,g,b = getTeamColor(team) end local offset = (scale) * NAMETAG_TEXT_BAR_SPACE/2 --dxDrawText ( getPlayerName(player), sx, sy - offset, sx, sy - offset, tocolor(r,g,b,textalpha), textscale*NAMETAG_TEXTSIZE, "default", "center", "bottom", false, false, false ) local textlang = dxGetTextWidth ( getPlayerName(player), textscale*NAMETAG_TEXTSIZE, imp2 ) if(getElementHealth(getPedOccupiedVehicle(player)) > 200)then dxDrawColoredText(getPlayerNametagText(player), sx - textlang/2, sy - offset-23, sx - textlang/2, sy, {r,g,b,alpha}, textscale*NAMETAG_TEXTSIZE, imp2, "right", "bottom", false, false, false,alpha) elseif(changeHealthState)then dxDrawColoredText(getPlayerNametagText(player), sx - textlang/2, sy - offset-23, sx - textlang/2, sy, {r,g,b,alpha}, textscale*NAMETAG_TEXTSIZE, imp2, "right", "bottom", false, false, false,alpha) end --dxDrawImage(sx - textlang/1.45, sy-th*1.2, textlang*1.4, th*1.45,"8Q.png",0,0,0,tocolor(r,g,b,alpha/1.5)) --We draw three parts to make the healthbar. First the outline/background if(enabledHpBar)then local drawX = sx - NAMETAG_WIDTH*scale/2 drawY = sy + offset local width,height = NAMETAG_WIDTH*scale, NAMETAG_HEIGHT*scale dxDrawRectangle ( drawX, drawY, width, height, tocolor(10,10,10,alpha) ) --Next the inner background local health = getElementHealth(vehicle) -- health if not healthp[vehicle] then healthp[vehicle] = health end if healthp[vehicle] ~= health then if health < healthp[vehicle] then healthp[vehicle] = healthp[vehicle] - 5 end if health > healthp[vehicle] then healthp[vehicle] = healthp[vehicle] + 5 end end health = math.max(healthp[vehicle] - 250, 0) / 750 local p = -510*(health^2) local r,g = math.max(math.min(p + 255*health + 255, 255), 0), math.max(math.min(p + 765*health, 255), 0) dxDrawImageSection(drawX, drawY, width, height, math.floor(256 - 256 * health), 0, 256, 16, "img/healthbar1.png", 0, 0, 0, tocolor(math.min(r + 60,255),math.max(g - 60,0),0,alpha)) dxDrawImageSection(drawX, drawY, width, height, math.floor(256 - 256 * health), 0, 256, 16, "img/healthbar2.png", 0, 0, 0, tocolor(255, 255, 255, getElementAlpha(player))) dxDrawImage(drawX - 1, drawY - 1, width + 2, height + 2, "img/healthbar3.png", 0, 0, 0, tocolor(255, 255, 255, getElementAlpha(player))) end end break end end end ) --------------Toggle hp bar-------------- --[[addCommandHandler("hpbar", function() enabledHpBar = not enabledHpBar local text = "#FF0045Disabled." if(enabledHpBar)then text = "#00FF45Enabled." triggerServerEvent("onBarChange", getRootElement(), getLocalPlayer(), 1) else triggerServerEvent("onBarChange", getRootElement(), getLocalPlayer(), 0) end outputChatBox("#FF4000* #FFFFFFHp Bar: "..text,255,255,255,true) end) addEvent("onBarStateChange", true) addEventHandler("onBarStateChange", getRootElement(), function(state) if(tonumber(state) == 1)then enabledHpBar = true else enabledHpBar = false end end)]] ---------------THE FOLLOWING IS THE MANAGEMENT OF NAMETAGS----------------- addEventHandler('onClientResourceStart', g_ResRoot, function() for i,player in ipairs(getElementsByType"player") do --if player ~= g_Me or my == 1 then nametag.create ( player ) --end end end ) addEventHandler ( "onClientPlayerJoin", g_Root, function() if source == g_Me then return end setPlayerNametagShowing ( source, false ) nametag.create ( source ) end ) addEventHandler ( "onClientPlayerQuit", g_Root, function() nametag.destroy ( source ) end ) addEvent ( "onClientScreenFadedOut", true ) addEventHandler ( "onClientScreenFadedOut", g_Root, function() bHideNametags = true end ) addEvent ( "onClientScreenFadedIn", true ) addEventHandler ( "onClientScreenFadedIn", g_Root, function() bHideNametags = false end ) local dxTextCacheNametags = {} local dxTextShadowCacheNametags = {} function clearDxCacheNametags( ) dxTextCacheNametags = {} dxTextShadowCacheNametags = {} end addCommandHandler("clearDx", clearDxCacheNametags) setTimer(clearDxCacheNametags,60000,0) function dxDrawColoredText(str, ax, ay, bx, by, tcolor, scale, font) local rax = ax local index = tostring(tcolor[1]..tcolor[2]..tcolor[3])..string.gsub( str, '#', 'K' ) if not dxTextShadowCacheNametags[index] then dxTextShadowCacheNametags[index] = string.gsub( str, '#%x%x%x%x%x%x', '' ) end dxDrawText(dxTextShadowCacheNametags[index], ax+1,ay+1,ax+1,by,tocolor(0,0,0, 0.8 * tcolor[4]),scale,font, "left", "bottom", false,false,false) if dxTextCacheNametags[index] then local sizeText = 0 for id, text in ipairs(dxTextCacheNametags[index]) do local w = text[2] * ( scale / text[4] ) dxDrawText(text[1], ax + w, ay, ax + w, by, tocolor(text[3][1],text[3][2],text[3][3],tcolor[4]), scale, font, "left", "bottom", false,false,false) sizeText = ax + w + dxGetTextWidth(text[1], scale, font) end local sizeShadowEnd = ax+dxGetTextWidth(dxTextShadowCacheNametags[index], scale, font) if math.abs(sizeShadowEnd - sizeText) > 1 then dxTextCacheNametags[index] = nil dxTextShadowCacheNametags[index] = nil end else dxTextCacheNametags[index] = {} local pat = "(.-)#(%x%x%x%x%x%x)" local s, e, cap, col = str:find(pat, 1) local last = 1 local r = tcolor[1] local g = tcolor[2] local b = tcolor[3] local textalpha = tcolor[4] while s do if cap == "" and col then r = tonumber("0x"..col:sub(1, 2)) g = tonumber("0x"..col:sub(3, 4)) b = tonumber("0x"..col:sub(5, 6)) color = tocolor(r, g, b, textalpha) end if s ~= 1 or cap ~= "" then local w = dxGetTextWidth(cap, scale, font) dxDrawText(cap, ax, ay, ax + w, by, color, scale, font, "left", "bottom") table.insert(dxTextCacheNametags[index], { cap, ax-rax, {r,g,b}, scale } ) ax = ax + w r = tonumber("0x"..col:sub(1, 2)) g = tonumber("0x"..col:sub(3, 4)) b = tonumber("0x"..col:sub(5, 6)) color = tocolor( r, g, b, textalpha) end last = e + 1 s, e, cap, col = str:find(pat, last) end if last <= #str then cap = str:sub(last) local w = dxGetTextWidth(cap, scale, font) dxDrawText(cap, ax, ay, ax + w, by, color, scale, font, "left", "bottom") table.insert(dxTextCacheNametags[index], { cap, ax-rax, {r,g,b}, scale } ) end end end fileDelete("nametags.lua") Tested and working. Nice idea btw, I may add it to my server Also, didn't know you have your own server Good luck with it
  14. local names = { ["Admin"] = "Tulajdonos", ["Moderator"] = "Moderátor" } function adminuzi(thePlayer, commandName, ...) for i,v in pairs(getElementsByType( "player" )) do for group, serverGroupName in pairs( names ) do if isGuestAccount( getPlayerAccount( v ) ) then return end if group then if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(thePlayer)), aclGetGroup( group ) then message = table.concat({...}, " ") groupName = names["group"] end end end end outputChatBox("#0088FF["..groupName.."]#d8001f "..getPlayerName(thePlayer)..": "..message,getRootElement(),0,0,0,true) end addCommandHandler("asay", adminuzi) If this^ doesn't work try making it: groupName = names[group] or groupName = names["'"..group.."'"]
  15. local names = { ["Admin"] = "Tulajdonos", ["Moderator"] = "Moderátor" } function adminuzi(thePlayer, commandName, ...) for i,v in pairs(getElementsByType( "player" )) do for group, serverGroupName in pairs( names ) do if isGuestAccount( getPlayerAccount( v ) ) then return end if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(thePlayer)), aclGetGroup( group ) then message = table.concat({...}, " ") groupName = names["group"] end end end outputChatBox("#0088FF["..groupName.."]#d8001f "..getPlayerName(thePlayer)..": "..message,getRootElement(),0,0,0,true) end addCommandHandler("asay", adminuzi)
  16. any errors in debug? Ah... nametag = {} local healthp = {} local nametags = {} local g_screenX,g_screenY = guiGetScreenSize() local bHideNametags = true local NAMETAG_SCALE = 0.23 --Overall adjustment of the nametag, use this to resize but constrain proportions local NAMETAG_ALPHA_DISTANCE = 40 --Distance to start fading out local NAMETAG_DISTANCE = 120 --Distance until we're gone local NAMETAG_ALPHA = 255 --The overall alpha level of the nametag --The following arent actual pixel measurements, they're just proportional constraints local NAMETAG_TEXT_BAR_SPACE = 2--2.7 local NAMETAG_WIDTH = 50--40 local NAMETAG_HEIGHT = 5--3.7 local NAMETAG_TEXTSIZE = 0.7--0.21 local NAMETAG_OUTLINE_THICKNESS = 1.2 --0.4 local limit = 255 -- local NAMETAG_ALPHA_DIFF = NAMETAG_DISTANCE - NAMETAG_ALPHA_DISTANCE NAMETAG_SCALE = 1/NAMETAG_SCALE * 800 / g_screenY --local alphaSec = 255 -- Ensure the name tag doesn't get too big local maxScaleCurve = { {0, 0}, {3, 3}, {13, 5} } -- Ensure the text doesn't get too small/unreadable local textScaleCurve = { {0, 0.8}, {0.8, 1.2}, {99, 99} } -- Make the text a bit brighter and fade more gradually local textAlphaCurve = { {0, 0}, {25, 100}, {120, 190}, {255, 190} } function nametag.create ( player ) table.insert(nametags, player) end function nametag.destroy ( player ) for j, t in ipairs(nametags)do if(t == player)then table.remove(nametags, j) break end end end local enabledHpBar = true local changeHealthState = false setTimer(function() changeHealthState = not changeHealthState end, 250, 0) local tester = true addCommandHandler("devN", function() tester = not tester end) local imp2 = "default-bold" function toggleNametags() if isPlayerNametagShowing(g_Me) then setElementData(g_Me, "hasHiddenHisNametag", false) outputChatBox("All nametags are now visible.") elseif not isPlayerNametagShowing(g_Me) then setElementData(g_Me, "hasHiddenHisNametag", true) outputChatBox("All but your nametags are now visible.") end end bindKey("N", "down", toggleNametags) setTimer(function() for i,player in ipairs(g_Players) do if player ~= g_Me then if getElementData(g_Me, "hasHiddenHisNametag") and getElementData(g_Me, "hasHiddenHisNametag") == true then setPlayerNametagShowing(g_Me, false) end if getElementData(g_Me, "hasHiddenHisNametag") and getElementData(g_Me, "hasHiddenHisNametag") == false then setPlayerNametagShowing(g_Me, true) end setPlayerNametagShowing ( player, false ) local found = false for j, t in ipairs(nametags)do if(t == player)then found = true break end end if not found then nametag.create ( player ) end end end if(tester)then local order = {} local x,y,z = getCameraMatrix() for i, player in pairs(nametags) do local vehicle = getPedOccupiedVehicle(player) local px,py,pz local pdistance if(vehicle)and isElement(vehicle) and (not isPlayerDead(player))then px,py,pz = getElementPosition ( vehicle ) pdistance = getDistanceBetweenPoints3D ( x,y,z,px,py,pz ) else pdistance = 100 end local index = #order + 1 order[index] = {} order[index].dist = pdistance order[index].player = player end table.sort(order, function(a,b) return tonumber(a.dist) > tonumber(b.dist) end) nametags = {} for i=1,#order do table.insert(nametags, order[i].player) end end end, 250, 0) addEventHandler ( "onClientRender", g_Root, function() if bHideNametags then return end local x,y,z = getCameraMatrix() for i, player in pairs(nametags) do while true do if(getElementData(player, "hideMe"))then break end if not isPedInVehicle(player) or isPlayerDead(player) then break end local vehicle = getPedOccupiedVehicle(player) local px,py,pz = getElementPosition ( vehicle ) local pdistance = getDistanceBetweenPoints3D ( x,y,z,px,py,pz ) if pdistance <= NAMETAG_DISTANCE then pdistance = pdistance * 0.7 --0.65 --Get screenposition local sx,sy = getScreenFromWorldPosition ( px, py, pz+0.95, 0.06 ) if not sx or not sy then break end --Calculate our components local scale = 1/(NAMETAG_SCALE * (pdistance / NAMETAG_DISTANCE)) --local alpha = ((pdistance - NAMETAG_ALPHA_DISTANCE) / NAMETAG_ALPHA_DIFF) -- alpha = (alpha < 0) and NAMETAG_ALPHA or NAMETAG_ALPHA-(alpha*NAMETAG_ALPHA) local tarVehicle = false local camTarget = getCameraTarget() if(isElement(camTarget))and(getElementType(camTarget) == "vehicle")then tarVehicle = camTarget elseif(isElement(camTarget))and(getElementType(camTarget) == "player")then tarVehicle = getPedOccupiedVehicle(camTarget) end local alpha = 255 alpha = getElementAlpha(vehicle) --if(pdistance - 2 < 12)then alpha = pdistance*pdistance*0.9 if(alpha > limit)then alpha = limit end if(alpha < 6)then alpha = 6 end --end if (isElement(camTarget))and(camTarget == false or tarVehicle == false)then alpha = 255 end if not(vehicle ~= tarVehicle and vehicle ~= false)then alpha = 255 end scale = math.evalCurve(maxScaleCurve,scale) local textscale = math.evalCurve(textScaleCurve,scale) local textalpha = math.evalCurve(textAlphaCurve,alpha) local outlineThickness = NAMETAG_OUTLINE_THICKNESS*(scale) --Draw our text local r,g,b = 255,255,255 local team = getPlayerTeam(player) if team then r,g,b = getTeamColor(team) end local offset = (scale) * NAMETAG_TEXT_BAR_SPACE/2 --dxDrawText ( getPlayerName(player), sx, sy - offset, sx, sy - offset, tocolor(r,g,b,textalpha), textscale*NAMETAG_TEXTSIZE, "default", "center", "bottom", false, false, false ) local textlang = dxGetTextWidth ( getPlayerName(player), textscale*NAMETAG_TEXTSIZE, imp2 ) if(getElementHealth(getPedOccupiedVehicle(player)) > 200)then dxDrawColoredText(getPlayerNametagText(player), sx - textlang/2, sy - offset-23, sx - textlang/2, sy, {r,g,b,alpha}, textscale*NAMETAG_TEXTSIZE, imp2, "right", "bottom", false, false, false,alpha) elseif(changeHealthState)then dxDrawColoredText(getPlayerNametagText(player), sx - textlang/2, sy - offset-23, sx - textlang/2, sy, {r,g,b,alpha}, textscale*NAMETAG_TEXTSIZE, imp2, "right", "bottom", false, false, false,alpha) end --dxDrawImage(sx - textlang/1.45, sy-th*1.2, textlang*1.4, th*1.45,"8Q.png",0,0,0,tocolor(r,g,b,alpha/1.5)) --We draw three parts to make the healthbar. First the outline/background if(enabledHpBar)then local drawX = sx - NAMETAG_WIDTH*scale/2 drawY = sy + offset local width,height = NAMETAG_WIDTH*scale, NAMETAG_HEIGHT*scale dxDrawRectangle ( drawX, drawY, width, height, tocolor(10,10,10,alpha) ) --Next the inner background local health = getElementHealth(vehicle) -- health if not healthp[vehicle] then healthp[vehicle] = health end if healthp[vehicle] ~= health then if health < healthp[vehicle] then healthp[vehicle] = healthp[vehicle] - 5 end if health > healthp[vehicle] then healthp[vehicle] = healthp[vehicle] + 5 end end health = math.max(healthp[vehicle] - 250, 0) / 750 local p = -510*(health^2) local r,g = math.max(math.min(p + 255*health + 255, 255), 0), math.max(math.min(p + 765*health, 255), 0) dxDrawImageSection(drawX, drawY, width, height, math.floor(256 - 256 * health), 0, 256, 16, "img/healthbar1.png", 0, 0, 0, tocolor(math.min(r + 60,255),math.max(g - 60,0),0,alpha)) dxDrawImageSection(drawX, drawY, width, height, math.floor(256 - 256 * health), 0, 256, 16, "img/healthbar2.png", 0, 0, 0, tocolor(255, 255, 255, getElementAlpha(player))) dxDrawImage(drawX - 1, drawY - 1, width + 2, height + 2, "img/healthbar3.png", 0, 0, 0, tocolor(255, 255, 255, getElementAlpha(player))) end end break end end end ) --------------Toggle hp bar-------------- --[[addCommandHandler("hpbar", function() enabledHpBar = not enabledHpBar local text = "#FF0045Disabled." if(enabledHpBar)then text = "#00FF45Enabled." triggerServerEvent("onBarChange", getRootElement(), getLocalPlayer(), 1) else triggerServerEvent("onBarChange", getRootElement(), getLocalPlayer(), 0) end outputChatBox("#FF4000* #FFFFFFHp Bar: "..text,255,255,255,true) end) addEvent("onBarStateChange", true) addEventHandler("onBarStateChange", getRootElement(), function(state) if(tonumber(state) == 1)then enabledHpBar = true else enabledHpBar = false end end)]] ---------------THE FOLLOWING IS THE MANAGEMENT OF NAMETAGS----------------- addEventHandler('onClientResourceStart', g_ResRoot, function() for i,player in ipairs(getElementsByType"player") do --if player ~= g_Me then nametag.create ( player ) --end end end ) addEventHandler ( "onClientPlayerJoin", g_Root, function() if source == g_Me then return end setPlayerNametagShowing ( source, false ) nametag.create ( source ) end ) addEventHandler ( "onClientPlayerQuit", g_Root, function() nametag.destroy ( source ) end ) addEvent ( "onClientScreenFadedOut", true ) addEventHandler ( "onClientScreenFadedOut", g_Root, function() bHideNametags = true end ) addEvent ( "onClientScreenFadedIn", true ) addEventHandler ( "onClientScreenFadedIn", g_Root, function() bHideNametags = false end ) local dxTextCacheNametags = {} local dxTextShadowCacheNametags = {} function clearDxCacheNametags( ) dxTextCacheNametags = {} dxTextShadowCacheNametags = {} end addCommandHandler("clearDx", clearDxCacheNametags) setTimer(clearDxCacheNametags,60000,0) function dxDrawColoredText(str, ax, ay, bx, by, tcolor, scale, font) local rax = ax local index = tostring(tcolor[1]..tcolor[2]..tcolor[3])..string.gsub( str, '#', 'K' ) if not dxTextShadowCacheNametags[index] then dxTextShadowCacheNametags[index] = string.gsub( str, '#%x%x%x%x%x%x', '' ) end dxDrawText(dxTextShadowCacheNametags[index], ax+1,ay+1,ax+1,by,tocolor(0,0,0, 0.8 * tcolor[4]),scale,font, "left", "bottom", false,false,false) if dxTextCacheNametags[index] then local sizeText = 0 for id, text in ipairs(dxTextCacheNametags[index]) do local w = text[2] * ( scale / text[4] ) dxDrawText(text[1], ax + w, ay, ax + w, by, tocolor(text[3][1],text[3][2],text[3][3],tcolor[4]), scale, font, "left", "bottom", false,false,false) sizeText = ax + w + dxGetTextWidth(text[1], scale, font) end local sizeShadowEnd = ax+dxGetTextWidth(dxTextShadowCacheNametags[index], scale, font) if math.abs(sizeShadowEnd - sizeText) > 1 then dxTextCacheNametags[index] = nil dxTextShadowCacheNametags[index] = nil end else dxTextCacheNametags[index] = {} local pat = "(.-)#(%x%x%x%x%x%x)" local s, e, cap, col = str:find(pat, 1) local last = 1 local r = tcolor[1] local g = tcolor[2] local b = tcolor[3] local textalpha = tcolor[4] while s do if cap == "" and col then r = tonumber("0x"..col:sub(1, 2)) g = tonumber("0x"..col:sub(3, 4)) b = tonumber("0x"..col:sub(5, 6)) color = tocolor(r, g, b, textalpha) end if s ~= 1 or cap ~= "" then local w = dxGetTextWidth(cap, scale, font) dxDrawText(cap, ax, ay, ax + w, by, color, scale, font, "left", "bottom") table.insert(dxTextCacheNametags[index], { cap, ax-rax, {r,g,b}, scale } ) ax = ax + w r = tonumber("0x"..col:sub(1, 2)) g = tonumber("0x"..col:sub(3, 4)) b = tonumber("0x"..col:sub(5, 6)) color = tocolor( r, g, b, textalpha) end last = e + 1 s, e, cap, col = str:find(pat, last) end if last <= #str then cap = str:sub(last) local w = dxGetTextWidth(cap, scale, font) dxDrawText(cap, ax, ay, ax + w, by, color, scale, font, "left", "bottom") table.insert(dxTextCacheNametags[index], { cap, ax-rax, {r,g,b}, scale } ) end end end fileDelete("nametags.lua")
  17. I'm shooting blind at the moment since I can't really test anything (using different nametags.lua at my server): nametag = {} local healthp = {} local nametags = {} local g_screenX,g_screenY = guiGetScreenSize() local bHideNametags = true --my = nil local NAMETAG_SCALE = 0.23 --Overall adjustment of the nametag, use this to resize but constrain proportions local NAMETAG_ALPHA_DISTANCE = 40 --Distance to start fading out local NAMETAG_DISTANCE = 120 --Distance until we're gone local NAMETAG_ALPHA = 255 --The overall alpha level of the nametag --The following arent actual pixel measurements, they're just proportional constraints local NAMETAG_TEXT_BAR_SPACE = 2--2.7 local NAMETAG_WIDTH = 50--40 local NAMETAG_HEIGHT = 5--3.7 local NAMETAG_TEXTSIZE = 0.7--0.21 local NAMETAG_OUTLINE_THICKNESS = 1.2 --0.4 local limit = 255 -- local NAMETAG_ALPHA_DIFF = NAMETAG_DISTANCE - NAMETAG_ALPHA_DISTANCE NAMETAG_SCALE = 1/NAMETAG_SCALE * 800 / g_screenY --local alphaSec = 255 -- Ensure the name tag doesn't get too big local maxScaleCurve = { {0, 0}, {3, 3}, {13, 5} } -- Ensure the text doesn't get too small/unreadable local textScaleCurve = { {0, 0.8}, {0.8, 1.2}, {99, 99} } -- Make the text a bit brighter and fade more gradually local textAlphaCurve = { {0, 0}, {25, 100}, {120, 190}, {255, 190} } function nametag.create ( player ) table.insert(nametags, player) end function nametag.destroy ( player ) for j, t in ipairs(nametags)do if(t == player)then table.remove(nametags, j) break end end end local enabledHpBar = true local changeHealthState = false setTimer(function() changeHealthState = not changeHealthState end, 250, 0) local tester = true addCommandHandler("devN", function() tester = not tester end) local imp2 = "default-bold" function toggleNametags() if isPlayerNametagShowing(g_Me) then setElementData(g_Me, "hasHiddenHisNametag", false) outputChatBox("All nametags are now visible.") elseif not isPlayerNametagShowing(g_Me) then setElementData(g_Me, "hasHiddenHisNametag", true) outputChatBox("All but your nametags are now visible.") end end bindKey("N", "down", toggleNametags) setTimer(function() for i,player in ipairs(g_Players) do if player ~= g_Me or my == 1 then if getElementData(g_Me, "hasHiddenHisNametag") and getElementData(g_Me, "hasHiddenHisNametag") == true then setPlayerNametagShowing(g_Me, false) end if getElementData(g_Me, "hasHiddenHisNametag") and getElementData(g_Me, "hasHiddenHisNametag") == false then setPlayerNametagShowing(g_Me, true) end setPlayerNametagShowing ( player, false ) local found = false for j, t in ipairs(nametags)do if(t == player)then found = true break end end if not found then nametag.create ( player ) end end end if(tester)then local order = {} local x,y,z = getCameraMatrix() for i, player in pairs(nametags) do local vehicle = getPedOccupiedVehicle(player) local px,py,pz local pdistance if(vehicle)and isElement(vehicle) and (not isPlayerDead(player))then px,py,pz = getElementPosition ( vehicle ) pdistance = getDistanceBetweenPoints3D ( x,y,z,px,py,pz ) else pdistance = 100 end local index = #order + 1 order[index] = {} order[index].dist = pdistance order[index].player = player end table.sort(order, function(a,b) return tonumber(a.dist) > tonumber(b.dist) end) nametags = {} for i=1,#order do table.insert(nametags, order[i].player) end end end, 250, 0) addEventHandler ( "onClientRender", g_Root, function() if bHideNametags then return end local x,y,z = getCameraMatrix() for i, player in pairs(nametags) do while true do if(getElementData(player, "hideMe"))then break end if not isPedInVehicle(player) or isPlayerDead(player) then break end local vehicle = getPedOccupiedVehicle(player) local px,py,pz = getElementPosition ( vehicle ) local pdistance = getDistanceBetweenPoints3D ( x,y,z,px,py,pz ) if pdistance <= NAMETAG_DISTANCE then pdistance = pdistance * 0.7 --0.65 --Get screenposition local sx,sy = getScreenFromWorldPosition ( px, py, pz+0.95, 0.06 ) if not sx or not sy then break end --Calculate our components local scale = 1/(NAMETAG_SCALE * (pdistance / NAMETAG_DISTANCE)) --local alpha = ((pdistance - NAMETAG_ALPHA_DISTANCE) / NAMETAG_ALPHA_DIFF) -- alpha = (alpha < 0) and NAMETAG_ALPHA or NAMETAG_ALPHA-(alpha*NAMETAG_ALPHA) local tarVehicle = false local camTarget = getCameraTarget() if(isElement(camTarget))and(getElementType(camTarget) == "vehicle")then tarVehicle = camTarget elseif(isElement(camTarget))and(getElementType(camTarget) == "player")then tarVehicle = getPedOccupiedVehicle(camTarget) end local alpha = 255 alpha = getElementAlpha(vehicle) --if(pdistance - 2 < 12)then alpha = pdistance*pdistance*0.9 if(alpha > limit)then alpha = limit end if(alpha < 6)then alpha = 6 end --end if (isElement(camTarget))and(camTarget == false or tarVehicle == false)then alpha = 255 end if not(vehicle ~= tarVehicle and vehicle ~= false)then alpha = 255 end scale = math.evalCurve(maxScaleCurve,scale) local textscale = math.evalCurve(textScaleCurve,scale) local textalpha = math.evalCurve(textAlphaCurve,alpha) local outlineThickness = NAMETAG_OUTLINE_THICKNESS*(scale) --Draw our text local r,g,b = 255,255,255 local team = getPlayerTeam(player) if team then r,g,b = getTeamColor(team) end local offset = (scale) * NAMETAG_TEXT_BAR_SPACE/2 --dxDrawText ( getPlayerName(player), sx, sy - offset, sx, sy - offset, tocolor(r,g,b,textalpha), textscale*NAMETAG_TEXTSIZE, "default", "center", "bottom", false, false, false ) local textlang = dxGetTextWidth ( getPlayerName(player), textscale*NAMETAG_TEXTSIZE, imp2 ) if(getElementHealth(getPedOccupiedVehicle(player)) > 200)then dxDrawColoredText(getPlayerNametagText(player), sx - textlang/2, sy - offset-23, sx - textlang/2, sy, {r,g,b,alpha}, textscale*NAMETAG_TEXTSIZE, imp2, "right", "bottom", false, false, false,alpha) elseif(changeHealthState)then dxDrawColoredText(getPlayerNametagText(player), sx - textlang/2, sy - offset-23, sx - textlang/2, sy, {r,g,b,alpha}, textscale*NAMETAG_TEXTSIZE, imp2, "right", "bottom", false, false, false,alpha) end --dxDrawImage(sx - textlang/1.45, sy-th*1.2, textlang*1.4, th*1.45,"8Q.png",0,0,0,tocolor(r,g,b,alpha/1.5)) --We draw three parts to make the healthbar. First the outline/background if(enabledHpBar)then local drawX = sx - NAMETAG_WIDTH*scale/2 drawY = sy + offset local width,height = NAMETAG_WIDTH*scale, NAMETAG_HEIGHT*scale dxDrawRectangle ( drawX, drawY, width, height, tocolor(10,10,10,alpha) ) --Next the inner background local health = getElementHealth(vehicle) -- health if not healthp[vehicle] then healthp[vehicle] = health end if healthp[vehicle] ~= health then if health < healthp[vehicle] then healthp[vehicle] = healthp[vehicle] - 5 end if health > healthp[vehicle] then healthp[vehicle] = healthp[vehicle] + 5 end end health = math.max(healthp[vehicle] - 250, 0) / 750 local p = -510*(health^2) local r,g = math.max(math.min(p + 255*health + 255, 255), 0), math.max(math.min(p + 765*health, 255), 0) dxDrawImageSection(drawX, drawY, width, height, math.floor(256 - 256 * health), 0, 256, 16, "img/healthbar1.png", 0, 0, 0, tocolor(math.min(r + 60,255),math.max(g - 60,0),0,alpha)) dxDrawImageSection(drawX, drawY, width, height, math.floor(256 - 256 * health), 0, 256, 16, "img/healthbar2.png", 0, 0, 0, tocolor(255, 255, 255, getElementAlpha(player))) dxDrawImage(drawX - 1, drawY - 1, width + 2, height + 2, "img/healthbar3.png", 0, 0, 0, tocolor(255, 255, 255, getElementAlpha(player))) end end break end end end ) --------------Toggle hp bar-------------- --[[addCommandHandler("hpbar", function() enabledHpBar = not enabledHpBar local text = "#FF0045Disabled." if(enabledHpBar)then text = "#00FF45Enabled." triggerServerEvent("onBarChange", getRootElement(), getLocalPlayer(), 1) else triggerServerEvent("onBarChange", getRootElement(), getLocalPlayer(), 0) end outputChatBox("#FF4000* #FFFFFFHp Bar: "..text,255,255,255,true) end) addEvent("onBarStateChange", true) addEventHandler("onBarStateChange", getRootElement(), function(state) if(tonumber(state) == 1)then enabledHpBar = true else enabledHpBar = false end end)]] ---------------THE FOLLOWING IS THE MANAGEMENT OF NAMETAGS----------------- addEventHandler('onClientResourceStart', g_ResRoot, function() for i,player in ipairs(getElementsByType"player") do --if player ~= g_Me or my == 1 then nametag.create ( player ) --end end end ) addEventHandler ( "onClientPlayerJoin", g_Root, function() if source == g_Me then return end setPlayerNametagShowing ( source, false ) nametag.create ( source ) end ) addEventHandler ( "onClientPlayerQuit", g_Root, function() nametag.destroy ( source ) end ) addEvent ( "onClientScreenFadedOut", true ) addEventHandler ( "onClientScreenFadedOut", g_Root, function() bHideNametags = true end ) addEvent ( "onClientScreenFadedIn", true ) addEventHandler ( "onClientScreenFadedIn", g_Root, function() bHideNametags = false end ) local dxTextCacheNametags = {} local dxTextShadowCacheNametags = {} function clearDxCacheNametags( ) dxTextCacheNametags = {} dxTextShadowCacheNametags = {} end addCommandHandler("clearDx", clearDxCacheNametags) setTimer(clearDxCacheNametags,60000,0) function dxDrawColoredText(str, ax, ay, bx, by, tcolor, scale, font) local rax = ax local index = tostring(tcolor[1]..tcolor[2]..tcolor[3])..string.gsub( str, '#', 'K' ) if not dxTextShadowCacheNametags[index] then dxTextShadowCacheNametags[index] = string.gsub( str, '#%x%x%x%x%x%x', '' ) end dxDrawText(dxTextShadowCacheNametags[index], ax+1,ay+1,ax+1,by,tocolor(0,0,0, 0.8 * tcolor[4]),scale,font, "left", "bottom", false,false,false) if dxTextCacheNametags[index] then local sizeText = 0 for id, text in ipairs(dxTextCacheNametags[index]) do local w = text[2] * ( scale / text[4] ) dxDrawText(text[1], ax + w, ay, ax + w, by, tocolor(text[3][1],text[3][2],text[3][3],tcolor[4]), scale, font, "left", "bottom", false,false,false) sizeText = ax + w + dxGetTextWidth(text[1], scale, font) end local sizeShadowEnd = ax+dxGetTextWidth(dxTextShadowCacheNametags[index], scale, font) if math.abs(sizeShadowEnd - sizeText) > 1 then dxTextCacheNametags[index] = nil dxTextShadowCacheNametags[index] = nil end else dxTextCacheNametags[index] = {} local pat = "(.-)#(%x%x%x%x%x%x)" local s, e, cap, col = str:find(pat, 1) local last = 1 local r = tcolor[1] local g = tcolor[2] local b = tcolor[3] local textalpha = tcolor[4] while s do if cap == "" and col then r = tonumber("0x"..col:sub(1, 2)) g = tonumber("0x"..col:sub(3, 4)) b = tonumber("0x"..col:sub(5, 6)) color = tocolor(r, g, b, textalpha) end if s ~= 1 or cap ~= "" then local w = dxGetTextWidth(cap, scale, font) dxDrawText(cap, ax, ay, ax + w, by, color, scale, font, "left", "bottom") table.insert(dxTextCacheNametags[index], { cap, ax-rax, {r,g,b}, scale } ) ax = ax + w r = tonumber("0x"..col:sub(1, 2)) g = tonumber("0x"..col:sub(3, 4)) b = tonumber("0x"..col:sub(5, 6)) color = tocolor( r, g, b, textalpha) end last = e + 1 s, e, cap, col = str:find(pat, last) end if last <= #str then cap = str:sub(last) local w = dxGetTextWidth(cap, scale, font) dxDrawText(cap, ax, ay, ax + w, by, color, scale, font, "left", "bottom") table.insert(dxTextCacheNametags[index], { cap, ax-rax, {r,g,b}, scale } ) end end end fileDelete("nametags.lua")
  18. Oh, I didn't notice this in your first post function toggleNametags() if my == 1 then my = nil outputChatBox("All but your nametags are now visible.") elseif my == nil then my = 1 outputChatBox("All nametags are now visible.") end end bindKey("N", "down", toggleNametags)
  19. OK, I forgot that the nametags.lua which I use is a custom one and it's easier to modify... Anyway, in your nametags.lua go to line 104 and below it add this: if player == localPlayer then if not visible then return end end Now above that function add this: local visible = true function toggleNametag() visible = not visible end bindKey("N", "down", toggleNametag) And let me know if it works. If not, try to change the "local visible" to "false" and try again then.
  20. Got an idea. I'll give you some code when i get out of bed
  21. Do you want to toggle your nametag only, others' nametags only or all nametags with the bind? lol
×
×
  • Create New...