-
Posts
21,935 -
Joined
-
Last visited
-
Days Won
6
Everything posted by Castillo
-
nametag = {} local nametags = {} local g_screenX,g_screenY = guiGetScreenSize() local bHideNametags = false local NAMETAG_SCALE = 0.3 --Overall adjustment of the nametag, use this to resize but constrain proportions local NAMETAG_ALPHA_DISTANCE = 50 --Distance to start fading out local NAMETAG_DISTANCE = 120 --Distance until we're gone local NAMETAG_ALPHA = 120 --The overall alpha level of the nametag --The following arent actual pixel measurements, they're just proportional constraints local NAMETAG_TEXT_BAR_SPACE = 2 local NAMETAG_WIDTH = 50 local NAMETAG_HEIGHT = 5 local NAMETAG_TEXTSIZE = 0.7 local NAMETAG_OUTLINE_THICKNESS = 1.2 -- local NAMETAG_ALPHA_DIFF = NAMETAG_DISTANCE - NAMETAG_ALPHA_DISTANCE NAMETAG_SCALE = 1/NAMETAG_SCALE * 800 / g_screenY -- 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 ) nametags[player] = true end function nametag.destroy ( player ) nametags[player] = nil 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 ) addEventHandler ( "onClientRender", g_Root, function() -- Hideous quick fix -- for i,player in ipairs(g_Players) do if player ~= g_Me then setPlayerNametagShowing ( player, false ) if not nametags[player] then nametag.create ( player ) end end end if bHideNametags then return end local x,y,z = getCameraMatrix() for player in pairs(nametags) do while true do 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 --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) 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 ) dxDrawText ( getPlayerName(player), sx + 1, sy - offset + 1, sx + 1, sy - offset + 1, tocolor(0,0,0,255), textscale*NAMETAG_TEXTSIZE, "bankgothic", "center", "bottom", false, false, false ) dxDrawColorText( getPlayerNametagText(player), sx, sy - offset, sx, sy - offset, tocolor(r,g,b,textalpha), textscale*NAMETAG_TEXTSIZE, 'bankgothic', 'center', 'bottom' ) --We draw three parts to make the healthbar. First the outline/background 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(0,0,0,alpha) ) --Next the inner background local health = getElementHealth(vehicle) health = math.max(health - 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) dxDrawRectangle ( drawX + outlineThickness, drawY + outlineThickness, width - outlineThickness*2, height - outlineThickness*2, tocolor(178,178,178,0.4*alpha) ) --Finally, the actual health dxDrawRectangle ( drawX + outlineThickness, drawY + outlineThickness, health*(width - outlineThickness*2), height - outlineThickness*2, tocolor(r,g,b,alpha) ) end break end end end ) function dxDrawColorText(str, ax, ay, bx, by, color, scale, font, alignX, alignY) if alignX then if alignX == "center" then local w = dxGetTextWidth(str:gsub("#%x%x%x%x%x%x",""), scale, font) ax = ax + (bx-ax)/2 - w/2 elseif alignX == "right" then local w = dxGetTextWidth(str:gsub("#%x%x%x%x%x%x",""), scale, font) ax = bx - w end end if alignY then if alignY == "center" then local h = dxGetFontHeight(scale, font) ay = ay + (by-ay)/2 - h/2 elseif alignY == "bottom" then local h = dxGetFontHeight(scale, font) ay = by - h end end local pat = "(.-)#(%x%x%x%x%x%x)" local s, e, cap, col = str:find(pat, 1) local last = 1 while s do if cap == "" and col then color = tocolor(tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)), 255) end if s ~= 1 or cap ~= "" then local w = dxGetTextWidth(cap, scale, font) dxDrawText(cap, ax, ay, ax + w, by, color, scale, font) ax = ax + w color = tocolor(tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)), 255) 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) end end Should be the correct one.
-
I used it via runcode, as it was just a simple test: ped = createPed(299,x,y,z) setElementHealth(ped,20)
-
You mean like Emoticons? if so, check this: https://community.multitheftauto.com/index.php?p= ... ls&id=1219
-
o_O, I didn't know about that argument .
-
I don't know, maybe you could count the lenght of the text and after X you make a new line ( \n )?
-
If I'm right, GUI-labels doesn't has word wrapping property.
-
function flagwin() local car = getPedOccupiedVehicle(source) if getElementModel(car) == 425 then exports.killmessages:outputMessage({{"image",path="win.png",width=24},getPlayerName(source),},getRootElement(),255,0,0) end end addEvent("onPlayerFinish") addEventHandler("onPlayerFinish",getRootElement(), flagwin) I'm not sure, but shouldn't go the image in killmessages resource?
-
Stolen from TAPL: https://community.multitheftauto.com/index.php?p= ... ls&id=2997
-
Well, then you are wrong, because I just set a ped health to 20%.
-
GUIEditor_Window = {} GUIEditor_Label = {} function infoGui() GUIEditor_Window[1] = guiCreateWindow(347,257,452,339,"K-Info",false) guiWindowSetMovable(GUIEditor_Window[1],false) guiWindowSetSizable(GUIEditor_Window[1],false) guiSetVisible ( GUIEditor_Window[1], false ) GUIEditor_Label[1] = guiCreateLabel(8,22,157,17,"Health:",false,GUIEditor_Window[1]) guiLabelSetColor(GUIEditor_Label[1],255,0,0) guiSetFont(GUIEditor_Label[1],"default-bold-small") GUIEditor_Label[2] = guiCreateLabel(6,53,157,17,"Armour:",false,GUIEditor_Window[1]) guiSetFont(GUIEditor_Label[2],"default-bold-small") GUIEditor_Label[3] = guiCreateLabel(7,85,157,17,"Ping:",false,GUIEditor_Window[1]) guiLabelSetColor(GUIEditor_Label[3],0,0,255) guiSetFont(GUIEditor_Label[3],"default-bold-small") GUIEditor_Label[4] = guiCreateLabel(7,115,157,17,"Serial:",false,GUIEditor_Window[1]) guiLabelSetColor(GUIEditor_Label[4],9,255,0) guiSetFont(GUIEditor_Label[4],"default-bold-small") GUIEditor_Label[5] = guiCreateLabel(7,143,157,17,"IP:",false,GUIEditor_Window[1]) guiLabelSetColor(GUIEditor_Label[5],255,255,0) guiSetFont(GUIEditor_Label[5],"default-bold-small") GUIEditor_Label[8] = guiCreateLabel(8,305,88,18,"Made By Kimmis",false,GUIEditor_Window[1]) guiLabelSetColor(GUIEditor_Label[8],0,0,255) end addEventHandler("onClientResourceStart",resourceRoot, function() bindKey ( "F2", "down", openGui ) end ) function stats() local ping = getElementData (getLocalPlayer(), "ping") local ip = getElementData (getLocalPlayer(), "ip") local serial = getElementData (getLocalPlayer(), "serial") local health = getElementData (getLocalPlayer(), "health") local armour = getElementData (getLocalPlayer(), "armour") local nick = getElementData (getLocalPlayer(), "nick") guiSetText(GUIEditor_Label[4], "Serial: " ..tostring(serial).. " " ,true, GUIEditor_Window[1]) guiSetText(GUIEditor_Label[3], "Ping: " ..tostring(ping).. " " ,true, GUIEditor_Window[1]) guiSetText(GUIEditor_Label[5], "IP: " ..tostring(ip).. " " ,true, GUIEditor_Window[1]) guiSetText(GUIEditor_Label[1], "Health: " ..tostring(health).. " " ,true, GUIEditor_Window[1]) guiSetText(GUIEditor_Label[2], "Armour: " ..tostring(armour).. " " ,true, GUIEditor_Window[1]) end function openGui() if not isElement(GUIEditor_Window[1]) then infoGui() end if not guiGetVisible(GUIEditor_Window[1]) then stats() guiSetVisible ( GUIEditor_Window[1], true ) else guiSetVisible ( GUIEditor_Window[1], false ) end end The script should work.
-
Meh, you got two nametags, choose which you want and delete the other.
-
What exactly doesn't work? do you get any error(s)?
-
Just do setElementHealth in the zombies to a lower value, i.e 50%.
-
Open nametags.lua in resource 'race' and replace it with yours?
-
Huh? the function bindKey exists..... and is client & server side, so should work...
-
Well, the only way to see if it's ok, is testing it. P.S: You didn't make it? because if you'd, then you should know where it has to be.
-
I tried it, and works fine, are you sure your image place is right?
-
You should check if the image already exists, if so, show it, else create it. function StrafHandler ( gesch, money ) if not img then GUIEditor_Label = {} img = guiCreateStaticImage(392,0,407,268,"Blitzer.png",false) guiSetAlpha(img,0.89999997615814) GUIEditor_Label[1] = guiCreateLabel(592,97,195,35,"Bahnhof",false) guiLabelSetColor(GUIEditor_Label[1],0,0,0) guiSetFont(GUIEditor_Label[1],"sa-header") setTimer(ausblenden, 3000, 1) else guiSetVisible(img, true) end end addEvent( "onStrafe", true ) addEventHandler( "onStrafe", getRootElement(), StrafHandler ) function ausblenden() if not img then return end guiSetVisible(img, false) end Test it.
-
You're welcome .
-
I've noticed this in your script: for i = 1, 23 do addEvent ( "r"..tostring ( i ), true ) addEventHandler ( "r"..tostring ( i ), getRootElement ( ), function ( image ) -- [b][u]You are replacing your current variable with this one (I don't know where you sent it from).[/u][/b] guiStaticImageLoadImage ( image, "rang/r"..tostring( i )..".png" ) lvlup = playSound("lvlup.mp3",false) setSoundVolume(lvlup,1) end ) end
-
Are you sure the image is created correctly? try adding some debug outputs into "imager" function.
-
Actually, karlis, the ranking board is not using DX drawing, default uses GUI labels. So, he'll have to change the way it works to DX drawing, isn't too hard.
-
function enterVehicle(thePlayer) local theVehicle = source local veh = getElementData(theVehicle, "sfserver.key") local pla = getElementData(thePlayer, "sfserver.key") if not getElementData(theVehicle, "sfserver.key") and getElementData(thePlayer, "sfserver.key") then setElementData(theVehicle, "sfserver.key", getElementData(thePlayer, "sfserver.key")) outputChatBox("Vehicle has now a key: " .. getElementData(thePlayer, "sfserver.key") .. ".", thePlayer, 0, 255, 0, false) elseif getElementData(theVehicle, "sfserver.key") and not veh == pla or not getElementData(thePlayer, "sfserver.key") then removePedFromVehicle(thePlayer) outputChatBox("You have an incorrect key, it means you don't own this vehicle.", thePlayer, 0, 255, 0, false) end end addEventHandler("onVehicleEnter", getRootElement(), enterVehicle) Not sure if it'll work, as i couldn't test it. P.S: The 'source 'of onVehicleEnter is the VEHICLE the player just entered.
