-
Posts
730 -
Joined
-
Last visited
-
Days Won
2
Everything posted by koragg
-
He wants to keep everything active even if user closes the browser window.
-
Sounds legit
-
Still I don't understand why players can't just download the needed files from their original directories.
-
I've been wondering about this for a while now. Why's the 'resources-cache' folder even created? As far as I see it has all client files from resources and maps. But, again, why? It makes a copy of it all and adds a huge amount of MB to my server's size. Just server is 670MB, with the resources-cache it's 1.20GB and that folder just has copies of scripts. Clarification is welcome
-
Make the positions of everything look ok for YOUR resolution only (just numbers, no multiplications). Then post your code and say on what resolution you've made it. I'll take a look then and try to fix it for any screen. Btw what's that "isMouseSetColor" thing? I can't find it on the wiki.
-
Try this, I can't really test but this is the way I make all my dxDrawText show ok on any screen. local x, y = guiGetScreenSize() local sx, sy = x/1440, y/900 local coloracc local colordec function jobwindow() if isMouseSetColor (x*0.26302083, y*0.48056, x*0.039583, y*0.03425926) then coloracc = tocolor(0, 153, 0, 255) end if isMouseSetColor (x*0.36979167, y*0.48056, x*0.039583, y*0.03425926) then colordec = tocolor(255, 0, 0, 255) end dxSetAspectRatioAdjustmentEnabled(true) dxDrawImage(x*0.1859375, y*0.14907407, x*0.2864583, y*0.4167, imagepath, 0, 0, 0, tocolor(255, 255, 255, 255), false) dxDrawText("Accept", x*0.26302083, y*0.48056, x*0.039583, y*0.03426, coloracc, 1*sy, newFont, "left", "top", false, false, false, false, false) dxDrawRectangle(x*0.26302083, y*0.48056, x*0.039583, y*0.03426, tocolor(0, 0, 0, 0), false) dxDrawText("Decline", x*0.36979167, y*0.48056, x*0.039583, y*0.03426, colordec, 1*sy, newFont, "left", "top", false, false, false, false, false) dxDrawRectangle(x*0.36979167, y*0.48056, x*0.039583, y*0.03426, tocolor(0, 0, 0, 0), false) coloracc = tocolor(255, 255, 255, 255) colordec = tocolor(255, 255, 255, 255) end EDIT: Your code can work too I think but you've made a mistake in the text size. 1.00*sx should be 1.00*sy in lines 9 and 11 of your first post's code.
-
Floating point number = 0.12345 etc. Try doing those calculations and replacing the values with screenW*float and screenH*float. I'll try fix it for you once i get on my pc but try yourself first with the way i described.
-
It should be where you want it to be
-
Well today there was no lag but I put the setTimer in the "addDates" function which is tied to the "onClientResourceStart" event handler just in case. This way I think the timer will get set just once, on client player join.
-
I tried your code but still got the same "server triggered clientside event drawBday but event is not added clientside". I worked on it a bit and made everything be client side. local screenW, screenH = guiGetScreenSize() local px,py = 1600,900 local x,y = (screenW/px), (screenH/py) ------------------------------------------------------------------------------------------------------------------------- local time = getRealTime() local bday = false local age = false local nick = false ------------------------------------------------------------------------------------------------------------------------- function dxDrawBday() if time.monthday == bday.day and time.month+1 == bday.month then dxDrawText(nick:gsub('#%x%x%x%x%x%x', '').." turned "..age.." today!", screenW * 0.0000+1, screenH * 0.1648+1, screenW * 1.0000+1, screenH * 0.3861+1, tocolor(0, 0, 0, 255), 1*y, "bankgothic", "center", "center", false, false, false, false, false) dxDrawText(nick.." #FFFFFFturned "..age.." today!", screenW * 0.0000, screenH * 0.1648, screenW * 1.0000, screenH * 0.3861, tocolor(255, 255, 255, 255), 1*y, "bankgothic", "center", "center", false, false, false, true, false) end setTimer(function() removeEventHandler("onClientRender", root, dxDrawBday) end, 23000, 1) end addEventHandler("onClientRender", root, dxDrawBday) ------------------------------------------------------------------------------------------------------------------------- function addDates() if time.monthday == 11 and time.month+1 == 2 then bday = { day = time.monthday, month = time.month+1, year = 1997 } age = time.year+1900 - bday.year nick = "#00FF00[SiK]#FEFE22Megas" else bday = { day = 0, month = 0, year = 0 } age = 0 nick = "0" end end addEventHandler("onClientResourceStart", root, addDates) But there was a time when I kept randomly losing my FPS (from 60 to 50, even to 42 once!) and I'm not sure if it's because of my code^ or just because I haven't restarted MTA for a long time (sometimes I lag because of this). When I restarted my server and my MTA it seems like it's fixed but I still wanted to ask, is anything in my code above maybe responsible for making those FPS drops or it's just because I haven't restarted my game after all those resource restarts and reconnects.
-
Last night in 2 AM a brillian idea came to mind, why not make a script which displays to all players that join when a certain player has a birthday on screen with dxDrawText? I know that for that to work I need events as dxDrawText is a client function only. But even though I added the event to my client-side the server still doesn't see it. Can anyone help with this? Client-Side local screenW, screenH = guiGetScreenSize() local px,py = 1600,900 local x,y = (screenW/px), (screenH/py) addEvent("drawBday", true) function dxDrawBday(nick, age) dxDrawText(nick.." #FFFFFFturned "..age.." today!", screenW * 0.0000, screenH * 0.1648, screenW * 1.0000, screenH * 0.3861, tocolor(255, 255, 255, 255), 1*y, "bankgothic", "center", "center", false, false, false, true, false) if isEventHandlerAdded("onClientRender", root, dxDrawBday) == false then addEventHandler("onClientRender", root, dxDrawBday) end setTimer(stopDrawingBday,5000,1) end addEventHandler("drawBday", root, dxDrawBday) ------------------------------------------------------------------------------------------------------------------------- function stopDrawingBday() removeEventHandler("onClientRender", root, dxDrawBday) end ------------------------------------------------------------------------------------------------------------------------- function isEventHandlerAdded(sEventName, pElementAttachedTo, func) if type(sEventName) == 'string' and isElement(pElementAttachedTo) and type(func) == 'function' then local aAttachedFunctions = getEventHandlers(sEventName, pElementAttachedTo) if type(aAttachedFunctions) == 'table' and #aAttachedFunctions > 0 then for i, v in ipairs(aAttachedFunctions) do if v == func then return true end end end end return false end Server-Side local time = getRealTime() local bday = false local age = false local nick = false function BdayText() if time.monthday == 17 and time.month+1 == 12 then bday = { day = 17, month = 12, year = 1997 } age = time.year+1900 - bday.year nick = "#00FF00[SiK]#FEFE22Megas" end if time.monthday == bday.day and time.month+1 == bday.month then --outputChatBox(nick.." #FFFFFFturned "..age.." today!", source, 255, 255, 255, true) triggerClientEvent(source, "drawBday", source, nick, age) end end addEventHandler("onPlayerJoin", root, BdayText)
-
I don't know what you mean by "other hud". Anyway, see line 111 and a bit below it here. You can choose which parts to hide and can also do it either with a command or when some resource starts or whenever you want to hide it. Up to your imagination.
-
@Best-Killer follow this example and it'll work for sure. I also tried with the way you're trying and i couldn't see the text i wanted to fix until i used the method with the floating point numbers (I'm on 1920x1080 btw).
-
Full working code: (delayindicator_client.lua) local screenW, screenH = guiGetScreenSize() local x, y = screenW/1440, screenH/900 local lastDelayTime = false local lastOptional = false local coloredName = false local blackName = false local sourcecp = false ------------------------------------------------------------------------------------------------------------------------- addEvent("showDelay", true) addEventHandler("showDelay", root, function(delayTime, optional) lastDelayTime = delayTime lastOptional = optional coloredName = addTeamColor(source) blackName = getPlayerName(source):gsub('#%x%x%x%x%x%x', '') sourcecp = getElementData(source, "race.checkpoint") if tonumber(optional) then if isEventHandlerAdded("onClientRender", root, drawMinusPlayerText) == false and isEventHandlerAdded("onClientRender", root, drawPlusTopText) == false and isEventHandlerAdded("onClientRender", root, drawMinusTopText) == false then addEventHandler("onClientRender", root, drawMinusPlayerText) end setTimer(function() removeEventHandler("onClientRender", root, drawMinusPlayerText) end, 2000, 1, source) elseif type(optional) == "table" then if delayTime < 0 then if isEventHandlerAdded("onClientRender", root, drawPlusTopText) == false then addEventHandler("onClientRender", root, drawPlusTopText) end setTimer(function() removeEventHandler("onClientRender", root, drawPlusTopText) end, 2000, 1, source) elseif delayTime > 0 then if isEventHandlerAdded("onClientRender", root, drawMinusTopText) == false then addEventHandler("onClientRender", root, drawMinusTopText) end setTimer(function() removeEventHandler("onClientRender", root, drawMinusTopText) end, 2000, 1, source) end else if isEventHandlerAdded("onClientRender", root, drawPlusPlayerText) == false then addEventHandler("onClientRender", root, drawPlusPlayerText) end setTimer(function() removeEventHandler("onClientRender", root, drawPlusPlayerText) end, 2000, 1, source) end end ) ------------------------------------------------------------------------------------------------------------------------- function drawPlusTopText() if type(lastOptional) == "table" then dxDrawText("#000000+"..msToTimeStr(-lastDelayTime).." record #"..lastOptional[1], screenW * 0.0000 + 1, screenH * 0.3667 + 1, screenW * 1.0000 + 1, screenH * 0.3954 + 1, tocolor(255, 255, 255, 255), 1.2*y, "default-bold", "center", "center", false, false, false, true, false) dxDrawText("#FFFF00+"..msToTimeStr(-lastDelayTime).." record #"..lastOptional[1], screenW * 0.0000, screenH * 0.3667, screenW * 1.0000, screenH * 0.3954, tocolor(255, 255, 255, 255), 1.2*y, "default-bold", "center", "center", false, false, false, true, false) end end ------------------------------------------------------------------------------------------------------------------------- function drawMinusTopText() if type(lastOptional) == "table" then dxDrawText("#000000-"..msToTimeStr(lastDelayTime).." record #"..lastOptional[1], screenW * 0.0000 + 1, screenH * 0.3667 + 1, screenW * 1.0000 + 1, screenH * 0.3954 + 1, tocolor(255, 255, 255, 255), 1.2*y, "default-bold", "center", "center", false, false, false, true, false) dxDrawText("#00FFFF-"..msToTimeStr(lastDelayTime).." record #"..lastOptional[1], screenW * 0.0000, screenH * 0.3667, screenW * 1.0000, screenH * 0.3954, tocolor(255, 255, 255, 255), 1.2*y, "default-bold", "center", "center", false, false, false, true, false) end end ------------------------------------------------------------------------------------------------------------------------- function drawMinusPlayerText() if tonumber(lastOptional) then local cps = getElementData(localPlayer, "race.checkpoint") - lastOptional if cps < 2 then cps = "" else cps = "(-"..cps.." CPs) " end dxDrawText("#000000-"..msToTimeStr(lastDelayTime).." "..cps..blackName, screenW * 0.0000 + 1, screenH * 0.3667 + 1, screenW * 1.0000 + 1, screenH * 0.3954 + 1, tocolor(255, 255, 255, 255), 1.2*y, "default-bold", "center", "center", false, false, false, true, false) dxDrawText("#00FF00-"..msToTimeStr(lastDelayTime).." "..cps.."#FFFFFF"..coloredName, screenW * 0.0000, screenH * 0.3667, screenW * 1.0000, screenH * 0.3954, tocolor(255, 255, 255, 255), 1.2*y, "default-bold", "center", "center", false, false, false, true, false) end end ------------------------------------------------------------------------------------------------------------------------- function drawPlusPlayerText() local cps = sourcecp - getElementData(localPlayer, "race.checkpoint") if cps < 2 then cps = "" else cps = "(+"..cps.." CPs) " end dxDrawText("#000000+"..msToTimeStr(lastDelayTime).." "..cps..blackName, screenW * 0.0000 + 1, screenH * 0.3667 + 1, screenW * 1.0000 + 1, screenH * 0.3954 + 1, tocolor(255, 255, 255, 255), 1.2*y, "default-bold", "center", "center", false, false, false, true, false) dxDrawText("#FF0000+"..msToTimeStr(lastDelayTime).." "..cps.."#FFFFFF"..coloredName, screenW * 0.0000, screenH * 0.3667, screenW * 1.0000, screenH * 0.3954, tocolor(255, 255, 255, 255), 1.2*y, "default-bold", "center", "center", false, false, false, true, false) end ------------------------------------------------------------------------------------------------------------------------- function isEventHandlerAdded(sEventName, pElementAttachedTo, func) if type(sEventName) == 'string' and isElement(pElementAttachedTo) and type(func) == 'function' then local aAttachedFunctions = getEventHandlers(sEventName, pElementAttachedTo) if type(aAttachedFunctions) == 'table' and #aAttachedFunctions > 0 then for i, v in ipairs(aAttachedFunctions) do if v == func then return true end end end end return false end ------------------------------------------------------------------------------------------------------------------------- function msToTimeStr(ms) if not ms then return '' end local centiseconds = tostring(math.floor(math.fmod(ms, 1000))) if #centiseconds == 2 then centiseconds = '0'..centiseconds elseif #centiseconds == 1 then centiseconds = '00'..centiseconds end local s = math.floor(ms / 1000) local seconds = tostring(math.fmod(s, 60)) if #seconds == 1 then seconds = '0' .. seconds end local minutes = tostring(math.floor(s / 60)) return minutes .. ':' .. seconds .. ':' .. centiseconds end ------------------------------------------------------------------------------------------------------------------------- -- Exported function for settings menu, KaliBwoy function showCPDelays() triggerServerEvent( "onClientShowCPDelays", resourceRoot ) end ------------------------------------------------------------------------------------------------------------------------- function hideCPDelays() triggerServerEvent( "onClientHideCPDelays", resourceRoot ) end ------------------------------------------------------------------------------------------------------------------------- function addTeamColor(player) local playerTeam = getPlayerTeam ( player ) if ( playerTeam ) then local r,g,b = getTeamColor ( playerTeam ) local n1 = toHex(r) local n2 = toHex(g) local n3 = toHex(b) if r <= 16 then n1 = "0"..n1 end if g <= 16 then n2 = "0"..n2 end if b <= 16 then n3 = "0"..n3 end return "#"..n1..""..n2..""..n3..""..getPlayerNametagText(player) else return getPlayerNametagText(player) end end ------------------------------------------------------------------------------------------------------------------------- function toHex(n) local hexnums = {"0","1","2","3","4","5","6","7", "8","9","A","B","C","D","E","F"} local str,r = "",n%16 if n-r == 0 then str = hexnums[r+1] else str = toHex((n-r)/16)..hexnums[r+1] end return str end
-
@dugasz1 looks like it's working Thanks mate (nice hax with the saving xd)!
-
Is it possible to somehow ignore color codes in ESC-Settings when you set your nickname? I mean, now if you type one color code it takes up 7 spaces from the nickname's slot. Would be great if the space for nick gets used only for the nickname itself (not the colorcodes). Like if it sees '#' and 6 hex symbols after it, it would not count that space as used for the nickname. Idk if that made sense but can't really explain it better Ofc I mean all of this - in 1.6
- 64 replies
-
- awesomeness
- mtasa 1.5.3
-
(and 4 more)
Tagged with:
-
Yea I know that would work normally but here I actually need to draw the " delayTime" and the "optional" variables, which are only accessible in the function tied to " showDelay ". So in other words, I can't draw it in another function and just add/remove event handlers So, really, no idea what to do to make this work...
-
Did this and still same, half a second and rip text. local screenW, screenH = guiGetScreenSize() addEvent("showDelay", true) function drawText(delayTime, optional) if tonumber(optional) then local cps = getElementData(g_Me, "race.checkpoint") - optional if cps < 2 then cps = "" else cps = "(-"..cps.."CPs) " end delayDisplayBehind:text("-"..msToTimeStr(delayTime).." "..cps..string.gsub(getPlayerName(source), "#%x%x%x%x%x%x", "")) delayDisplayBehind:visible(true) behindTick = getTickCount() setTimer(hideDelayDisplay, TIME_TO_DISPLAY, 1, false) elseif type(optional) == "table" then if delayTime < 0 then --delayDisplayFront:text("+"..msToTimeStr(-delayTime).." record #"..optional[1]) dxDrawText("#FEFE22+"..msToTimeStr(-delayTime).." record #"..optional[1], screenW * 0.0000, screenH * 0.3657, screenW * 1.0000, screenH * 0.3972, tocolor(255, 255, 255, 255), 1.5, "default", "center", "center", false, false, false, true, false) elseif delayTime > 0 then --delayDisplayFront:text("-"..msToTimeStr(delayTime).." record #"..optional[1]) dxDrawText("#00FFFF-"..msToTimeStr(delayTime).." record #"..optional[1], screenW * 0.0000, screenH * 0.3657, screenW * 1.0000, screenH * 0.3972, tocolor(255, 255, 255, 255), 1.00, "default", "center", "center", false, false, false, true, false) end --delayDisplayFront:visible(true) frontTick = getTickCount() setTimer(hideDelayDisplay, TIME_TO_DISPLAY, 1, true) else --[[local cps = getElementData(source, "race.checkpoint") - getElementData(g_Me, "race.checkpoint") if cps < 2 then cps = "" else cps = "(+"..cps.."CPs) " end delayDisplayFront:text("+"..msToTimeStr(delayTime).." "..cps..string.gsub(getPlayerName(source), "#%x%x%x%x%x%x", "")) delayDisplayFront:color(255, 0, 0) delayDisplayFront:visible(true) frontTick = getTickCount() setTimer(hideDelayDisplay, TIME_TO_DISPLAY, 1, true)--]] end end addEventHandler("showDelay", g_Root, drawText) addEventHandler("onClientRender", root, drawText)
-
I just replaced line 33 and line 37 with dxDrawText and deleted lines 34, 38 and 40. I got rid of " delayDisplayFront " and replaced all lines in which text was being drawn with dxDrawText lines.
-
Thanks, I tried adding "onClientRender" to the function that draws it but still same result.
-
Whenever I try to put any kind of dxDrawText in that file it just draws it for less than a second and then text vanishes. Why? There are no errors, I replaced all needed things to dxDrawText lines and still it only draws it for half a second or less... Below is the original code, no idea what I gotta do so that it leaves dxDrawText stuff stay on-screen for longer. local g_Root = getRootElement() local g_ResRoot = getResourceRootElement(getThisResource()) local g_Me = getLocalPlayer() local DISTANCE_FRONT_BEHIND = 0.03 local SCALE = 1.5 local TIME_TO_DISPLAY = 2000 local frontTick local behindTick local delayDisplayFront = dxText:create("", 0.5, 0.37, true, "default", SCALE) local delayDisplayBehind = dxText:create("", 0.5, 0.43, true, "default", SCALE) delayDisplayFront:color(255, 0, 0) delayDisplayBehind:color(0, 255, 0) addEvent("showDelay", true) addEventHandler("showDelay", g_Root, function(delayTime, optional) if tonumber(optional) then local cps = getElementData(g_Me, "race.checkpoint") - optional if cps < 2 then cps = "" else cps = "(-"..cps.."CPs) " end delayDisplayBehind:text("-"..msToTimeStr(delayTime).." "..cps..string.gsub(getPlayerName(source), "#%x%x%x%x%x%x", "")) delayDisplayBehind:visible(true) behindTick = getTickCount() setTimer(hideDelayDisplay, TIME_TO_DISPLAY, 1, false) elseif type(optional) == "table" then if delayTime < 0 then -- outputChatBox("-"..msToTimeStr(-delayTime).." current record") delayDisplayFront:text("+"..msToTimeStr(-delayTime).." record #"..optional[1]) delayDisplayFront:color(255, 255, 0) elseif delayTime > 0 then -- outputChatBox("+"..msToTimeStr(delayTime).." current record") delayDisplayFront:text("-"..msToTimeStr(delayTime).." record #"..optional[1]) delayDisplayFront:color(0, 255, 255) end delayDisplayFront:visible(true) frontTick = getTickCount() setTimer(hideDelayDisplay, TIME_TO_DISPLAY, 1, true) else local cps = getElementData(source, "race.checkpoint") - getElementData(g_Me, "race.checkpoint") if cps < 2 then cps = "" else cps = "(+"..cps.."CPs) " end delayDisplayFront:text("+"..msToTimeStr(delayTime).." "..cps..string.gsub(getPlayerName(source), "#%x%x%x%x%x%x", "")) delayDisplayFront:color(255, 0, 0) delayDisplayFront:visible(true) frontTick = getTickCount() setTimer(hideDelayDisplay, TIME_TO_DISPLAY, 1, true) end end ) function hideDelayDisplay(front) if front == "both" then delayDisplayFront:visible(false) delayDisplayBehind:visible(false) elseif front then local pastTime = getTickCount() - frontTick if pastTime >= TIME_TO_DISPLAY then delayDisplayFront:visible(false) else if pastTime < 50 then pastTime = 50 end setTimer(hideDelayDisplay, pastTime, 1, true) -- outputChatBox("front dalassen") end else local pastTime = getTickCount() - behindTick if pastTime >= TIME_TO_DISPLAY then delayDisplayBehind:visible(false) else if pastTime < 50 then pastTime = 50 end setTimer(hideDelayDisplay, pastTime, 1, false) -- outputChatBox("behind dalassen") end end end addEventHandler('onClientResourceStart', g_ResRoot, function() local settingsFile = xmlLoadFile("settings.xml") if settingsFile then local pos = xmlNodeGetAttributes(settingsFile) delayDisplayFront:position(pos.x, pos.y - DISTANCE_FRONT_BEHIND) delayDisplayBehind:position(pos.x, pos.y + DISTANCE_FRONT_BEHIND) else settingsFile = xmlCreateFile("settings.xml","settings") xmlNodeSetAttribute(settingsFile,"x",0.5) xmlNodeSetAttribute(settingsFile,"y",0.4) end xmlSaveFile(settingsFile) xmlUnloadFile(settingsFile) end ) addCommandHandler("setdelaypos", function(cmd,x,y) if x and y then if tonumber(x) and tonumber(y) then delayDisplayFront:position(x, y - DISTANCE_FRONT_BEHIND) delayDisplayBehind:position(x, y + DISTANCE_FRONT_BEHIND) delayDisplayFront:text("FRONT") delayDisplayBehind:text("BEHIND") delayDisplayFront:color(255, 0, 0) delayDisplayBehind:color(0, 255, 0) delayDisplayFront:visible(true) delayDisplayBehind:visible(true) setTimer(hideDelayDisplay, TIME_TO_DISPLAY, 1, "both") local settingsFile = xmlLoadFile("settings.xml") if settingsFile then xmlNodeSetAttribute(settingsFile,"x",x) xmlNodeSetAttribute(settingsFile,"y",y) end xmlSaveFile(settingsFile) xmlUnloadFile(settingsFile) else outputChatBox("WRONG PARAMETERS! Syntax is /setdelaypos x y", 255, 0, 0) end else outputChatBox("WRONG PARAMETERS! Syntax is /setdelaypos x y", 255, 0, 0) end end ) function msToTimeStr(ms) if not ms then return '' end local centiseconds = tostring(math.floor(math.fmod(ms, 1000))) if #centiseconds == 2 then centiseconds = '0'..centiseconds elseif #centiseconds == 1 then centiseconds = '00'..centiseconds end local s = math.floor(ms / 1000) local seconds = tostring(math.fmod(s, 60)) if #seconds == 1 then seconds = '0' .. seconds end local minutes = tostring(math.floor(s / 60)) return minutes .. ':' .. seconds .. ':' .. centiseconds end -- Exported function for settings menu, KaliBwoy function showCPDelays() triggerServerEvent( "onClientShowCPDelays", resourceRoot ) end function hideCPDelays() triggerServerEvent( "onClientHideCPDelays", resourceRoot ) end
-
Didn't know some keyboards don't have that. Then I better leave it as it is or people will be screwed
-
Pretty much what the title says, is there a way to disable the Console showing when a player presses F8? I want to use that key to show this window. Console can also be opened with the ~ key which is just before the number 1 on the main keyboard so I don't need it on F8 as well (taking up precious buttons for other scripts).
-
Note: The values for group and index can be determined by using the client command showsound in conjunction with setDevelopmentMode