Jump to content

Dzsozi (h03)

Members
  • Posts

    696
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by Dzsozi (h03)

  1. Hello! I have a few models modded on my server that I can use with mapping, for example wall models. The problem is that they are modded on land masses, like a road from SF and such, but I would like to use their LODs, so they would be visible from a distance, the only problem is that their low LOD elements are the default GTA SA models, so a wall object has a road LOD element. I would like to change the low LOD elements of these walls to the modded object, so a wall would have a wall LOD. Here's what I came up with, but for some reason it doesn't work, the low LOD elements are the same GTA SA LODs. Does anyone know if it is possibble or know how to fix it, maybe I did something wrong in the script? I can't manage to do that by myself and I don't see any errors in the script or in the debugscript either. I would appreciate if somebody could help me with this. function fixWallModelLODs() for index, mod in pairs(mods) do if string.find(mod.fileName, "/walls/") then for k, v in pairs(getElementsByType("object")) do if getElementModel(v) == mod.modelID then setLowLODElement(v, v) end end end end end addEventHandler("onClientResourceStart",resourceRoot, function () fixWallModelLODs() end) Thank you in advance!
  2. I fixed it already, thanks to @NeXuS™, but yes, the problem was what you wrote @MrTasty. Thank you for the help!
  3. I would like to ask for help with one more thing. CLIENT: function createJunks() -- creating junks junks = {} for k, v in ipairs(junkImages) do local image = "junkyard/files/"..v[1]..".png" local size = v[2] local rot = math.random(1,360) local midX, midY = getRandomPointInCircle(board.x+board.width/2, board.y+board.width/2, board.width/2) local x, y = midX - size/2, midY - size/2 -- we want the middle of the image to be placed at that point table.insert(junks, {x = x, y = y, size = size, halfSize = size/2, img = image, rot = rot, hitradius = v[3]}) end -- creating the item (should be in another function imo) local itemSize = 64 local itemX, itemY = getRandomPointInCircle(board.x+board.width/2, board.y+board.width/2, board.width/3) itemX, itemY = itemX - itemSize/2, itemY - itemSize/2 -- we want the middle of the image to be placed at that point local itemRadius = itemSize/2 local color = tocolor(255, 0, 0, 255) -- full red by default -- no need for item to be a list of dictionaries, just a dictionary: item = {x = itemX, y = itemY, size = itemSize, halfSize = itemSize/2, radius = itemRadius, color = color} -- reseting that global itemDiscoveredAlready = false triggerServerEvent("setJunkItem", localPlayer) local foundItemImage = -- what to write here to get the number of the item from server side?? like items[foundItem][1] is the way I get it on server side, but there is no such thing as foundItem end SERVER: local isItem = false local foundItem = nil function setJunkItem() --if player and isElement(player) and getElementType(player) == "player" then foundItem = math.random(1,#items) local currentChance = math.random(1,100) if currentChance <= items[foundItem][2] then outputChatBox("Item a táblából: " .. tostring(foundItem)) outputChatBox("Saját Esély: " .. tostring(currentChance)) outputChatBox(" ") outputChatBox("Item: " .. tostring(items[foundItem][1])) outputChatBox("Item Esély: " .. tostring(items[foundItem][2])) outputChatBox("Item Mennyiség: " .. tostring(items[foundItem][3])) isItem = true else isItem = false end --end end addEvent("setJunkItem", true) addEventHandler("setJunkItem", getRootElement(), setJunkItem) function giveJunkItem(player) if player and isElement(player) and getElementType(player) == "player" then if isItem then --if item == items[foundItem][1] then exports["cg_items"]:giveItem(player, items[foundItem][1], items[foundItem][3]) outputChatBox(exports["cg_items"]:getItemName(items[foundItem][1])) --end else exports["cg_notifications"]:addNotification(player, "Sajnos semmit sem találtál.", "info") return end end end addEvent("giveJunkItem", true) addEventHandler("giveJunkItem", getRootElement(), giveJunkItem) As I wrote in a comment inside the client side script, I would like to get the item number generated in the server side script. The reason is why I want to get it is because I would like to draw the item's image instead of the red and green rectangle under the junk, but I have no idea how I can do that. Is there any way doing it? I have tried things like -- SERVER function setJunkItem() foundItem = math.random(1,#items) local currentChance = math.random(1,100) if currentChance <= items[foundItem][2] then outputChatBox("Item a táblából: " .. tostring(foundItem)) outputChatBox("Saját Esély: " .. tostring(currentChance)) outputChatBox(" ") outputChatBox("Item: " .. tostring(items[foundItem][1])) outputChatBox("Item Esély: " .. tostring(items[foundItem][2])) outputChatBox("Item Mennyiség: " .. tostring(items[foundItem][3])) isItem = true return items[foundItem][1] else isItem = false return 0 end end addEvent("setJunkItem", true) addEventHandler("setJunkItem", getRootElement(), setJunkItem) -- CLIENT local foundItemImage = nil function createJunks() -- creating junks junks = {} for k, v in ipairs(junkImages) do local image = "junkyard/files/"..v[1]..".png" local size = v[2] local rot = math.random(1,360) local midX, midY = getRandomPointInCircle(board.x+board.width/2, board.y+board.width/2, board.width/2) local x, y = midX - size/2, midY - size/2 -- we want the middle of the image to be placed at that point table.insert(junks, {x = x, y = y, size = size, halfSize = size/2, img = image, rot = rot, hitradius = v[3]}) end -- creating the item (should be in another function imo) local itemSize = 64 local itemX, itemY = getRandomPointInCircle(board.x+board.width/2, board.y+board.width/2, board.width/3) itemX, itemY = itemX - itemSize/2, itemY - itemSize/2 -- we want the middle of the image to be placed at that point local itemRadius = itemSize/2 local color = tocolor(255, 0, 0, 255) -- full red by default -- no need for item to be a list of dictionaries, just a dictionary: item = {x = itemX, y = itemY, size = itemSize, halfSize = itemSize/2, radius = itemRadius, color = color} -- reseting that global itemDiscoveredAlready = false foundItemImage = triggerServerEvent("setJunkItem", localPlayer) end But of course it's not working because - as MTA Wiki says - triggerServerEvent returns a bool, so I have no idea how I could do that. Could you help me out with this please?
  4. Hello! I am doing a police speedcamera script, but there is one problem I don't know how to fix. I have tried several methods, setting suspectVehicle to nil several times, but it's not working as I want it to work and I don't understand what could be the problem. When I'm trying to get the speed of a vehicle with the speedcam, it only works with the vehicle that I created last, it doesn't work with the other existing vehicles, and I tried restarting the resource after creating the vehicle, deleting vehicles, etc, but it doesn't work. Sometimes it works if I go a little farther from the last created vehicle, it detects the other vehicle that is for example next to it, but this is not how I want it to work. Could somebody help me fixing it? Here's my code: local sx, sy = guiGetScreenSize() local policeSpeedCameraState = false local suspectVehicle = nil local suspectVehicleVelocity = 0 local speedCamDistance = 30 local cameraLineDistance, cameraLineWidth = 200, 10 local cameraLineColor = tocolor(255,255,255,255) local randomCameraNumber = 0 function isVehicleWithinSpeedCamSight(vehicle) if vehicle and isElement(vehicle) and getElementType(vehicle) == "vehicle" then local vehiclex,vehicley,vehiclez = getElementPosition(vehicle) local screenposx, screenposy = getScreenFromWorldPosition(vehiclex,vehicley,vehiclez) if screenposx and screenposy then if screenposx >= sx/2-cameraLineDistance and screenposx <= sx/2+cameraLineDistance+cameraLineWidth and screenposy >= sy/2-cameraLineDistance and screenposy <= sy/2+cameraLineDistance+cameraLineWidth then return true else return false end end end return false end function activatePoliceSpeedCamera(cmd, state) --if getPedOccupiedVehicleSeat(localPlayer) == 1 then if policeSpeedCameraState ~= state then if state == "true" then policeSpeedCameraState = true addEventHandler("onClientRender", getRootElement(), renderSpeedCamera) setDashboardCameraForPlayer(localPlayer) randomCameraNumber = math.random(100,999) elseif state == "false" then policeSpeedCameraState = false removeEventHandler("onClientRender", getRootElement(), renderSpeedCamera) setCameraTarget(localPlayer) exports["cg_hud"]:toggleHUD(true) exports["cg_radar"]:toggleRadar(true) end end --else -- outputChatBox("csak anyósból") --end end addCommandHandler("speedcam", activatePoliceSpeedCamera) local barY = 0 function renderSpeedCamera() local occupiedVehicle = getPedOccupiedVehicle(localPlayer) if occupiedVehicle then if policeSpeedCameraState then for k, v in pairs(getElementsByType("vehicle")) do if v ~= occupiedVehicle then if isElementOnScreen(v) then if isVehicleWithinSpeedCamSight(v) then --if getVehicleController(v) then local x,y,z = getElementPosition(occupiedVehicle) local tx,ty,tz = getElementPosition(v) if getDistanceBetweenPoints3D(x, y, z, tx,ty,tz) <= speedCamDistance then local clear = isLineOfSightClear (x,y,z,tx,ty,tz,true,false,false,false,false,false,false) if clear then local vehicleVelocity = exports["cg_vehiclescripting"]:getActualVelocity(v, "mph") if vehicleVelocity then suspectVehicle = v suspectVehicleVelocity = vehicleVelocity end end end --end else suspectVehicle = nil suspectVehicleVelocity = "N/A" end end end end end end exports["cg_hud"]:toggleHUD(false) exports["cg_radar"]:toggleRadar(false) dxDrawRectangle(0,0,sx,sy,tocolor(20,140,245,50)) local barNumbers = math.ceil(sy/10) for i=1, barNumbers do barY = barY + 0.01 if barY >= barNumbers then barY = 15 end dxDrawRectangle(0,((i-1)*30) + barY - barNumbers - 15,sx,15,tocolor(255,255,255,25*math.abs(getTickCount() % 1000 - 2000) / 1000)) end -- kamera körvonal dxDrawLine(sx/2-cameraLineDistance, sy/2-cameraLineDistance-cameraLineWidth/2, sx/2-cameraLineDistance, sy/2, cameraLineColor, cameraLineWidth) dxDrawLine(sx/2-cameraLineDistance-cameraLineWidth/2, sy/2-cameraLineDistance, sx/2, sy/2-cameraLineDistance, cameraLineColor, cameraLineWidth) dxDrawLine(sx/2+cameraLineDistance, sy/2+cameraLineDistance+cameraLineWidth/2, sx/2+cameraLineDistance, sy/2, cameraLineColor, cameraLineWidth) dxDrawLine(sx/2+cameraLineDistance+cameraLineWidth/2, sy/2+cameraLineDistance, sx/2, sy/2+cameraLineDistance, cameraLineColor, cameraLineWidth) --outputChatBox(tostring(barY)) if suspectVehicle and isElement(suspectVehicle) then local vehicleX,vehicleY,vehicleZ = getElementPosition(getPedOccupiedVehicle(localPlayer)) local targetX,targetY,targetZ = getElementPosition(suspectVehicle) --[[local _, _, rotZ = getElementRotation(suspectVehicle) local angle = math.rad(10 + rotZ) local cornerX, cornerY = targetX, targetY local pointX, pointY = targetX - 2, targetY - 2 local rotatedX = math.cos(angle) * (pointX - cornerX) - math.sin(angle) * (pointY- cornerY) + cornerX local rotatedY = math.sin(angle) * (pointX - cornerX) + math.cos(angle) * (pointY - cornerY) + cornerY]] --if gettingSuspectSpeed then local screenX, screenY = getScreenFromWorldPosition(targetX,targetY,targetZ,25,true) if screenX and screenY then --dxDrawText("Mérés", screenX, screenY-50, 0, 0, tocolor(255, 0, 0, 255), 1.5, "default-bold") local crosshairSize = 25 dxDrawLine(screenX-crosshairSize, screenY, screenX+crosshairSize, screenY, tocolor(255,255,255,255), cameraLineWidth/2) dxDrawLine(screenX, screenY-crosshairSize, screenX, screenY+crosshairSize, tocolor(255,255,255,255), cameraLineWidth/2) end --end -- adatok if getDistanceBetweenPoints3D(vehicleX,vehicleY,vehicleZ, targetX,targetY, targetZ) <= speedCamDistance then if tonumber(suspectVehicleVelocity) then suspectVehicleVelocity = tostring(math.floor(suspectVehicleVelocity)) .. " MPH" end else suspectVehicleVelocity = "N/A" end end dxDrawText(tostring(suspectVehicleVelocity), sx/2+cameraLineWidth, sy/2+cameraLineDistance+cameraLineWidth, 0, 0, tocolor(255,255,255,255), 2, "default") dxDrawText("LAPD", sx/2+cameraLineDistance/2, sy/2-cameraLineDistance-cameraLineWidth*6, 0, 0, tocolor(255,255,255,255), 2, "default") dxDrawText("S", sx/2+cameraLineDistance/2, sy/2-cameraLineDistance-cameraLineWidth*4, 0, 0, tocolor(255,255,255,255), 2, "default") dxDrawText("00" .. randomCameraNumber, sx/2-cameraLineDistance, sy/2-cameraLineDistance-cameraLineWidth*6, 0, 0, tocolor(255,255,255,255), 2, "default") local timehour, timeminute = getTime() if timehour < 10 then timehour = "0" .. timehour end if timeminute < 10 then timeminute = "0" .. timeminute end dxDrawText(timehour .. ":" .. timeminute, sx/2-cameraLineWidth/2, sy/2-cameraLineDistance-cameraLineWidth*4, sx/2-cameraLineWidth/2, sy/2-cameraLineDistance-cameraLineWidth*4, tocolor(255,255,255,255), 2, "default", "center") end function setDashboardCameraForPlayer(player) local myVehicle = getPedOccupiedVehicle(player) if myVehicle then local camera = getCamera() setElementPosition(camera, 0,0,0) setElementDimension(camera, getElementDimension(myVehicle)) setElementInterior(camera, getElementInterior(myVehicle)) attachElements(camera, myVehicle, 0.25,0.75,0.6, 0,0,0) else return end end function disableSpeedCamOnVehicleExit(player, seat) if player == localPlayer and seat == 1 and policeSpeedCameraState then policeSpeedCameraState = false removeEventHandler("onClientRender", getRootElement(), renderSpeedCamera) setCameraTarget(localPlayer) exports["cg_hud"]:toggleHUD(true) exports["cg_radar"]:toggleRadar(true) end end addEventHandler("onClientVehicleStartExit", getRootElement(), disableSpeedCamOnVehicleExit)
  5. Works perfectly now, thank you so much Citizen! BTW at line 173 it changes the item picture to green and then makes it flashing, because I would like the player to see the item for 3 seconds, so he is notified about finding it.
  6. EDIT: Here's my current script, I don't get any errors in debugscript, everything works fine except the FPS drop. local sx, sy = guiGetScreenSize() local junkSize = sx/3 local junkImageDistance = 50 local junkPositionX, junkPositionY = sx/2-junkSize/2, sy/2-junkSize/2 local searchState = false local item = nil -- no item at first local junks = {} -- holds all junks images with position, rotation etc local board = {x = junkPositionX, y = junkPositionY, width = junkSize, height = junkSize} local mouseRadius = 20 -- how big the mouse's hitbox is (higher = easier to move junks) local repulseSpeed = 5 -- how fast the junks go away from mouse's hitbox local junkyardCollision = nil function createJunkyards() for k,v in ipairs(junkyards) do junkyardCollision = createColCuboid(v[1], v[2], v[3]-0.85, v[4], v[5], v[6]) end end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), createJunkyards) local junkImages = { -- image, size, hitradius {"burgershot-bag", 128, 30}, {"burgershot-bag", 128, 30}, {"burgershot-bag", 128, 30}, {"cup", 128, 25}, {"cup", 128, 25}, {"cup", 128, 25}, {"cup", 128, 25}, {"boot", 256, 75}, {"bin-bag", 256, 75}, {"bin-bag", 256, 75}, {"apple", 128, 30}, {"apple", 128, 30}, {"paper", 128, 30}, {"paper", 128, 30}, {"paper", 128, 30}, {"paper", 128, 30}, {"paper", 128, 30}, {"bottle", 128, 25}, {"bottle", 128, 25}, {"glass", 128, 50}, {"tin-can", 128, 25}, {"tin-can", 128, 25}, {"tin-can", 128, 25}, -- duplicated amount, didn't cause lag before, but now it lags even if i delete the junks under here {"burgershot-bag", 128, 30}, {"burgershot-bag", 128, 30}, {"burgershot-bag", 128, 30}, {"cup", 128, 25}, {"cup", 128, 25}, {"cup", 128, 25}, {"cup", 128, 25}, {"boot", 256, 75}, {"bin-bag", 256, 75}, {"bin-bag", 256, 75}, {"apple", 128, 30}, {"apple", 128, 30}, {"paper", 128, 30}, {"paper", 128, 30}, {"paper", 128, 30}, {"paper", 128, 30}, {"paper", 128, 30}, {"bottle", 128, 25}, {"bottle", 128, 25}, {"glass", 128, 50}, {"tin-can", 128, 25}, {"tin-can", 128, 25}, {"tin-can", 128, 25} } function createJunks() -- creating junks junks = {} for k, v in ipairs(junkImages) do local size = v[2] local rot = math.random(1,360) local midX, midY = getRandomPointInCircle(board.x+board.width/2, board.y+board.width/2, board.width/2) local x, y = midX - size/2, midY - size/2 -- we want the middle of the image to be placed at that point table.insert(junks, {x = x, y = y, size = size, img = v[1], rot = rot, hitradius = v[3]}) end -- creating the item (should be in another function imo) local itemSize = 64 local itemX, itemY = getRandomPointInCircle(board.x+board.width/2, board.y+board.width/2, board.width/3) itemX, itemY = itemX - itemSize/2, itemY - itemSize/2 -- we want the middle of the image to be placed at that point local itemRadius = itemSize/2 local color = tocolor(255, 0, 0, 255) -- full red by default -- no need for item to be a list of dictionaries, just a dictionary: item = {x = itemX, y = itemY, size = itemSize, radius = itemRadius, color = color} -- reseting that global itemDiscoveredAlready = false end --showCursor(true) -- debug (add it to your command that shows the junk) --bindKey("f5", "down", createJunks) -- debug (F5 to (re)create the junk) function renderJunk() -- Safety check just un case to prevent spamming errors if try to draw before calling createJunks if #junks == 0 or not item then return end dxDrawRectangle(board.x, board.y, board.width, board.height, tocolor(0, 0, 0, 150)) -- debug (junk board) --dxDrawCircle(board.x+board.width/2, board.y+board.width/2, board.width/4, 1, 1, 0, 360, tocolor(0, 0, 0, 255)) -- debug (spawn area - black circle) -- drawing item -- local itemX, itemY = item.x, item.y local itemSize = item.size local itemRadius = item.radius local itemColor = item.color dxDrawRectangle(itemX, itemY, itemSize, itemSize, itemColor) -- drawing junks -- local itemDiscovered = true -- will tell us after the loop if there is still a junk on it for k, j in ipairs(junks) do local cx, cy = getCursorPosition() cx, cy = cx * sx, cy * sy -- absolute cursor position local imgCenterX, imgCenterY = j.x+j.size/2, j.y+j.size/2 -- center of the junk's image dxDrawImage(j.x, j.y, j.size, j.size, "junkyard/files/" ..j.img..".png", j.rot, 0, 0, tocolor(255,255,255,255), false) --dxDrawCircle(imgCenterX, imgCenterY, j.hitradius, 1, 1, 0, 360, tocolor(0, 0, 200, 100)) -- debug (junk's hitbox - blue circle) --dxDrawCircle(cx, cy, mouseRadius, 1, 1, 0, 360, tocolor(255, 255, 0, 255)) -- debug (mouse's hitbox) -- handling item discovery local itemCenterX, itemCenterY = itemX + itemSize/2, itemY + itemSize/2 -- "if the item is still considered as discovered but the current junk's hitbox collides with the item then ..." if itemDiscovered and isCircleInCircle(imgCenterX, imgCenterY, j.hitradius, itemCenterX, itemCenterY, itemRadius) then itemDiscovered = false -- "we finally consider it's not discovered" -- Setting it to false will also stop the code to call the isCircleInCircle above for the remaining junks end dxDrawCircle(itemCenterX, itemCenterY, itemRadius, 1, 1, 0, 360, tocolor(245, 140, 20, 255)) -- debug (item's hitbox) -- Moving junks ability: if getKeyState("mouse1") and isCircleInCircle(imgCenterX, imgCenterY, j.hitradius, cx, cy, mouseRadius) then -- move it away if it collides with the cursor's hitbox if exports["sgr_main"]:isMouseInPosition(board.x, board.y, board.width, board.height) then local angle = findRotation(imgCenterX, imgCenterY, cx, cy) local newX, newY = getPointFromDistanceRotation(imgCenterX, imgCenterY, repulseSpeed, -angle + 180) local offsetX, offsetY = imgCenterX - newX, imgCenterY - newY j.x, j.y = j.x-offsetX, j.y-offsetY -- debug: --local newX, newY = getPointFromDistanceRotation(imgCenterX, imgCenterY, 200, -angle + 180) -- debug --dxDrawLine(imgCenterX, imgCenterY, newX, newY, tocolor(0, 200, 0, 255)) -- debug (shows direction where the junk is going - green line) end end end -- We drew and calculated everything for that frame. Did we just discover the item ? if itemDiscovered then item.color = tocolor(0, 255, 0, 255 * math.abs(getTickCount() % 1000 - 500) / 500) -- full green if not itemDiscoveredAlready then itemDiscoveredAlready = true -- This will prevent it to be called for every next frames setTimer(function() onItemDiscovered(item) -- call the function for when we discover the item end, 3000, 1) end end end -- called as soon as an item is discovered function onItemDiscovered(item) searchState = false outputChatBox("item discovered !") showCursor(false) triggerServerEvent("giveFoundJunkItem", localPlayer, localPlayer) removeEventHandler("onClientRender", getRootElement(), renderJunk) itemDiscovered = false exports["sgr_main"]:syncAnimationFromServer(localPlayer, false) -- do lightweight stuff here as we are still inside a onClientRender call end function startSearching() if junkyardCollision and isElement(junkyardCollision) then if isElementWithinColShape(localPlayer, junkyardCollision) then if not isPedInVehicle(localPlayer) then if not searchState then searchState = true showCursor(true) createJunks() addEventHandler("onClientRender", getRootElement(), renderJunk) exports["sgr_main"]:syncAnimationFromServer(localPlayer, "BOMBER", "BOM_Plant_Loop", -1, true, false, false, false) end else exports["cg_notifications"]:addNotification("Járműben nem használhatod ezt a parancsot!", "error") end else exports["cg_notifications"]:addNotification("Ezt a parancsot csak szeméttelepen tudod használni!", "error") end end end addCommandHandler("turkal", startSearching) function isPlayerSearchingInJunkyard(player) if player and isElement(player) and getElementType(player) == "player" then if searchState == true then return true else return false end end return false end ----------------------------------------------------- -- From https://wiki.multitheftauto.com/wiki/DxDrawCircle (was only used for debug drawings) function dxDrawCircle( posX, posY, radius, width, angleAmount, startAngle, stopAngle, color, postGUI ) if ( type( posX ) ~= "number" ) or ( type( posY ) ~= "number" ) then return false end local function clamp( val, lower, upper ) if ( lower > upper ) then lower, upper = upper, lower end return math.max( lower, math.min( upper, val ) ) end radius = type( radius ) == "number" and radius or 50 width = type( width ) == "number" and width or 5 angleAmount = type( angleAmount ) == "number" and angleAmount or 1 startAngle = clamp( type( startAngle ) == "number" and startAngle or 0, 0, 360 ) stopAngle = clamp( type( stopAngle ) == "number" and stopAngle or 360, 0, 360 ) color = color or tocolor( 255, 255, 255, 200 ) postGUI = type( postGUI ) == "boolean" and postGUI or false if ( stopAngle < startAngle ) then local tempAngle = stopAngle stopAngle = startAngle startAngle = tempAngle end for i = startAngle, stopAngle, angleAmount do local startX = math.cos( math.rad( i ) ) * ( radius - width ) local startY = math.sin( math.rad( i ) ) * ( radius - width ) local endX = math.cos( math.rad( i ) ) * ( radius + width ) local endY = math.sin( math.rad( i ) ) * ( radius + width ) dxDrawLine( startX + posX, startY + posY, endX + posX, endY + posY, color, width, postGUI ) end return true end -- From http://cgp.wikidot.com/circle-to-circle-collision-detection function isCircleInCircle(x1, y1, r1, x2, y2, r2) return math.sqrt( ( x2-x1 ) * ( x2-x1 ) + ( y2-y1 ) * ( y2-y1 ) ) < ( r1 + r2 ) end -- From https://wiki.multitheftauto.com/wiki/FindRotation function findRotation( x1, y1, x2, y2 ) local t = -math.deg( math.atan2( x2 - x1, y2 - y1 ) ) return t < 0 and t + 360 or t end -- From https://wiki.multitheftauto.com/wiki/GetPointFromDistanceRotation function getPointFromDistanceRotation(x, y, dist, angle) local a = math.rad(90 - angle); local dx = math.cos(a) * dist; local dy = math.sin(a) * dist; return x+dx, y+dy; end -- From https://gamedev.stackexchange.com/questions/26713/calculate-random-points-pixel-within-a-circle-image/26714 function getRandomPointInCircle(x, y, radius) local angle = math.random() * math.pi * 2 radius = math.random() * radius local x = x + radius * math.cos(angle) local y = y + radius * math.sin(angle) return x, y end
  7. It works perfectly, just as I wanted thank you! But I have noticed that there is (for me) a kind of big fps drop when the panel is visible, and it didn't happen before, not even when I added tons of junks. Do you have any idea why is this happening?
  8. You just made it more complex, that's not what he needs, his problem is that he don't want some words being shown, but because of the two onPlayerChat events he still can see the word he doesn't want to show. It could be an option to check on the other event - where you show the level of the chatting player - if the message has a bad word, but you would have to check it everywhere if you make another onPlayerChat event, I think there is an easier way where you don't have to check the bad words everytime.
  9. I think you can just make it inside one function, maybe something like this, I'm not quite sure tho. cancelableworld = { ":~", ":Oyou", "bitch" } addEventHandler("onPlayerChat", root, function(message, msgTyp) local Level = getElementData(source,"Level" or 0) outputChatBox("#4C7759[LVL "..Level.."] #FFFFFF"..getPlayerName(source)..": #FFFFFF"..message,getRootElement(),255,2555,255,true) local message = string.lower(message) for i,v in ipairs(cancelableworld) do if (string.find(message, cancelableworld[i])) then outputChatBox("*NO*", source, 255, 0, 0, false) cancelEvent() end end end)
  10. Oh my god thank you so much! Works perfectly, just like I wanted it to work, thank you so much again! You helped me out alot!! But there is one more thing I would like to do and can't figure it out how to do it. I would like to have an item behind the junks, so you have to move the junks away from the item to get it, but I don't know how can I detect if there is nothing in front of the item. I have tried it this way: local sx, sy = guiGetScreenSize() local junkSize = sx/3 local junkImageDistance = 50 local junkPositionX, junkPositionY = sx/2-junkSize/2, sy/2-junkSize/2 local searchingTimer = nil local searchState = false local junks = {} -- holds all junks images with position, rotation etc local board = {x = junkPositionX, y = junkPositionY, width = junkSize, height = junkSize} local item = {} local mouseRadius = 15 -- how big the mouse's hitbox is (higher = easier to move junks) local repulseSpeed = 1 -- how fast the junks go away from mouse's hitbox local junkyardCollision = nil local searchTime = 1000 local searchTimeMultiplier = 1 local minimumSearchTimeMultiplier, maximumSearchTimeMultiplier = 5, 15 local itemColor = tocolor(255,0,0,255) function createJunkyards() for k,v in ipairs(junkyards) do junkyardCollision = createColCuboid(v[1], v[2], v[3]-0.85, v[4], v[5], v[6]) end end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), createJunkyards) local junkImages = { -- image, size, hitradius {"burgershot-bag", 128, 30}, {"burgershot-bag", 128, 30}, {"burgershot-bag", 128, 30}, {"cup", 128, 25}, {"cup", 128, 25}, {"cup", 128, 25}, {"cup", 128, 25}, {"boot", 256, 75}, {"bin-bag", 256, 75}, {"bin-bag", 256, 75}, {"apple", 128, 10}, {"apple", 128, 10}, {"paper", 128, 10}, {"paper", 128, 10}, {"paper", 128, 10}, {"paper", 128, 10}, {"paper", 128, 10}, {"bottle", 128, 25}, {"bottle", 128, 25}, {"glass", 128, 50}, {"tin-can", 128, 25}, {"tin-can", 128, 25}, {"tin-can", 128, 25} } function createJunks() junks = {} item = {} for k, v in ipairs(junkImages) do local size = v[2] local rot = math.random(1,360) local midX, midY = getRandomPointInCircle(board.x+board.width/2, board.y+board.width/2, board.width/2) local x, y = midX - size/2, midY - size/2 -- we want the middle of the image to be placed at that point table.insert(junks, {x = x, y = y, size = size, img = v[1], rot = rot, hitradius = v[3]}) end local itemX, itemY = getRandomPointInCircle(board.x+board.width/2, board.y+board.width/2, board.width/3) local itemSize = 64 local itemRadius = itemSize/2 table.insert(item, {x = itemX, y = itemY, size = itemSize, radius = itemRadius}) end showCursor(true) -- debug (add it to your command that shows the junk) bindKey("f5", "down", createJunks) -- debug (F5 to (re)create the junk) function renderJunk() dxDrawRectangle(board.x, board.y, board.width, board.height, tocolor(0, 0, 0, 150)) -- debug (junk board) --dxDrawCircle(board.x+board.width/2, board.y+board.width/2, board.width/4, 1, 1, 0, 360, tocolor(0, 0, 0, 255)) -- debug (spawn area - black circle) for k, item in ipairs(item) do itemX, itemY = item.x, item.y itemSize = item.size itemRadius = item.radius dxDrawCircle(itemX+itemSize/2, itemY+itemSize/2, itemRadius, 1, 1, 0, 360, tocolor(245, 140, 20, 255)) dxDrawRectangle(itemX, itemY, itemSize, itemSize, itemColor) end for k, j in ipairs(junks) do local cx, cy = getCursorPosition() cx, cy = cx * sx, cy * sy -- absolute cursor position local imgCenterX, imgCenterY = j.x+j.size/2, j.y+j.size/2 -- center of the junk's image dxDrawImage(j.x, j.y, j.size, j.size, "junkyard/files/" ..j.img..".png", j.rot, 0, 0, tocolor(255,255,255,255), false) --dxDrawCircle(imgCenterX, imgCenterY, j.hitradius, 1, 1, 0, 360, tocolor(0, 0, 200, 255)) -- debug (junk's hitbox - blue circle) --dxDrawCircle(cx, cy, mouseRadius, 1, 1, 0, 360, tocolor(255, 255, 0, 255)) -- debug (mouse's hitbox) if getKeyState("mouse1") and isCircleInCircle(imgCenterX, imgCenterY, j.hitradius, cx, cy, mouseRadius) then -- move it away if it collides with the cursor's hitbox if exports["sgr_main"]:isMouseInPosition(board.x, board.y, board.width, board.height) then local angle = findRotation(imgCenterX, imgCenterY, cx, cy) local newX, newY = getPointFromDistanceRotation(imgCenterX, imgCenterY, repulseSpeed, -angle + 180) local offsetX, offsetY = imgCenterX - newX, imgCenterY - newY j.x, j.y = j.x-offsetX, j.y-offsetY -- debug: --local newX, newY = getPointFromDistanceRotation(imgCenterX, imgCenterY, 200, -angle + 180) -- debug --dxDrawLine(imgCenterX, imgCenterY, newX, newY, tocolor(0, 200, 0, 255)) -- debug (shows direction where the junk is going - green line) end end if not isCircleInCircle(imgCenterX, imgCenterY, j.hitradius, itemX+itemSize/2, itemY+itemSize/2, itemRadius) then itemColor = tocolor(0,255,0,255) outputChatBox("a") else itemColor = tocolor(255,0,0,255) outputChatBox("b") end end end addEventHandler("onClientRender", getRootElement(), renderJunk) function startSearching() if junkyardCollision and isElement(junkyardCollision) then if isElementWithinColShape(localPlayer, junkyardCollision) then if not searchState then searchTimeMultiplier = math.random(minimumSearchTimeMultiplier,maximumSearchTimeMultiplier) local finalSearchTime = searchTime*searchTimeMultiplier showCursor(true) createJunks() addEventHandler("onClientRender", getRootElement(), renderJunk) searchState = true triggerServerEvent("syncSearchingFromServer", localPlayer, localPlayer, finalSearchTime) searchingTimer = setTimer(function() showCursor(false) triggerServerEvent("giveFoundJunkItem", localPlayer, localPlayer) removeEventHandler("onClientRender", getRootElement(), renderJunk) end,finalSearchTime,1) end else exports["cg_notifications"]:addNotification("Ezt a parancsot csak szeméttelepen tudod használni!", "error") end end end addCommandHandler("turkal", startSearching) function isPlayerSearchingInJunkyard(player) if player and isElement(player) and getElementType(player) == "player" then if searchState == true then return true else return false end end return false end ----------------------------------------------------- -- From https://wiki.multitheftauto.com/wiki/DxDrawCircle (was only used for debug drawings) function dxDrawCircle( posX, posY, radius, width, angleAmount, startAngle, stopAngle, color, postGUI ) if ( type( posX ) ~= "number" ) or ( type( posY ) ~= "number" ) then return false end local function clamp( val, lower, upper ) if ( lower > upper ) then lower, upper = upper, lower end return math.max( lower, math.min( upper, val ) ) end radius = type( radius ) == "number" and radius or 50 width = type( width ) == "number" and width or 5 angleAmount = type( angleAmount ) == "number" and angleAmount or 1 startAngle = clamp( type( startAngle ) == "number" and startAngle or 0, 0, 360 ) stopAngle = clamp( type( stopAngle ) == "number" and stopAngle or 360, 0, 360 ) color = color or tocolor( 255, 255, 255, 200 ) postGUI = type( postGUI ) == "boolean" and postGUI or false if ( stopAngle < startAngle ) then local tempAngle = stopAngle stopAngle = startAngle startAngle = tempAngle end for i = startAngle, stopAngle, angleAmount do local startX = math.cos( math.rad( i ) ) * ( radius - width ) local startY = math.sin( math.rad( i ) ) * ( radius - width ) local endX = math.cos( math.rad( i ) ) * ( radius + width ) local endY = math.sin( math.rad( i ) ) * ( radius + width ) dxDrawLine( startX + posX, startY + posY, endX + posX, endY + posY, color, width, postGUI ) end return true end -- From http://cgp.wikidot.com/circle-to-circle-collision-detection function isCircleInCircle(x1, y1, r1, x2, y2, r2) return math.sqrt( ( x2-x1 ) * ( x2-x1 ) + ( y2-y1 ) * ( y2-y1 ) ) < ( r1 + r2 ) end -- From https://wiki.multitheftauto.com/wiki/FindRotation function findRotation( x1, y1, x2, y2 ) local t = -math.deg( math.atan2( x2 - x1, y2 - y1 ) ) return t < 0 and t + 360 or t end -- From https://wiki.multitheftauto.com/wiki/GetPointFromDistanceRotation function getPointFromDistanceRotation(x, y, dist, angle) local a = math.rad(90 - angle); local dx = math.cos(a) * dist; local dy = math.sin(a) * dist; return x+dx, y+dy; end -- From https://gamedev.stackexchange.com/questions/26713/calculate-random-points-pixel-within-a-circle-image/26714 function getRandomPointInCircle(x, y, radius) local angle = math.random() * math.pi * 2 radius = math.random() * radius local x = x + radius * math.cos(angle) local y = y + radius * math.sin(angle) return x, y end But for some reason the rectangle that represents the item is always green, even if there is junk on it, it never changes to red or outputs "b" and I don't really understand why. How can I detect if there is nothing in front of the item?
  11. Hey! I would like to create a junkyard script where you can search for items, and to search for an item you would have to play a minigame, but I bumped into problems and I don't know - how to get a random screen position inside given positions (for example I have a box in the middle of the screen and I would like to get a random position inside that box only) - how to rotate every image in other angle created from a table Like this: http://imgur.com/2Pq43OB - how to move the junk items (images) seperately, I would like to make the minigame work like when you hold the left mouse button the junk items will move in the opposite way, so it's like pushing out the junk from the middle of the box while you are holding mouse button. Like this: http://imgur.com/pxgRpRi So I would like people to play this kind of minigame when they are looking for items in a junkyard, and inside the yellow box there would be the item that they have found, if they found anything. Hope you can understand me and what I am trying to do and you can help me. Can't think about any good way to start it, here's my current code: CLIENT: local sx, sy = guiGetScreenSize() local junkSize = 128 local junkImageDistance = 50 local junkPositionX, junkPositionY = sx/2-junkSize/2, sy/2-junkSize/2 local junkyardCollision = nil local searchTime = 1000 local searchTimeMultiplier = 1 local minimumSearchTimeMultiplier, maximumSearchTimeMultiplier = 5, 15 function createJunkyards() for k,v in ipairs(junkyards) do junkyardCollision = createColCuboid(v[1], v[2], v[3]-0.85, v[4], v[5], v[6]) end end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), createJunkyards) local junks = { -- image, size {"burgershot-bag", 128}, {"cup", 128}, {"boot", 256}, {"bin-bag", 256}, {"apple", 128}, {"paper", 128}, {"bottle", 128}, {"glass", 128}, {"tin-can", 128}, } local junkRotation = 0 function rotateJunk() for k, v in ipairs(junks) do local rot = math.random(1,360) junkRotation = rot end end rotateJunk() function renderJunk() for k, v in ipairs(junks) do dxDrawImage(junkPositionX+k*junkImageDistance, junkPositionY+k*junkImageDistance, v[2], v[2], "junkyard/files/" .. v[1] ..".png", junkRotation, 0, 0, tocolor(255,255,255,255), false) end end addEventHandler("onClientRender", getRootElement(), renderJunk) function startSearching() if junkyardCollision and isElement(junkyardCollision) then if isElementWithinColShape(localPlayer, junkyardCollision) then searchTimeMultiplier = math.random(minimumSearchTimeMultiplier,maximumSearchTimeMultiplier) local finalSearchTime = searchTime*searchTimeMultiplier triggerServerEvent("syncSearchingFromServer", localPlayer, localPlayer, finalSearchTime) setTimer(function() triggerServerEvent("giveFoundJunkItem", localPlayer, localPlayer) end,finalSearchTime,1) else exports["cg_notifications"]:addNotification("Ezt a parancsot csak szeméttelepen tudod használni!", "error") end end end addCommandHandler("turkal", startSearching) GLOBALS (shared): junkyards = { -- x, y, z, width, length, height, {2164.6706542969, -1504.7607421875, 23.984375, 10, 10, 2} } items = { -- item id, chance (%), amount {13, 20, 1}, -- cigar {25, 60, 1}, -- rope {67, 40, 1}, -- lighter {68, 5, 100}, -- graffiti patron } SERVER: function syncSearchingFromServer(player, searchTime) if player and isElement(player) and getElementType(player) == "player" then setPedAnimation(player, "BOMBER", "BOM_Plant_Loop", searchTime, true, false, false, false) end end addEvent("syncSearchingFromServer", true) addEventHandler("syncSearchingFromServer", getRootElement(), syncSearchingFromServer) function giveFoundJunkItem(player) if player and isElement(player) and getElementType(player) == "player" then local foundItem = math.random(1,#items) local currentChance = math.random(1,100) if currentChance <= items[foundItem][2] then outputChatBox("Item a táblából: " .. tostring(foundItem)) outputChatBox("Saját Esély: " .. tostring(currentChance)) outputChatBox(" ") outputChatBox("Item: " .. tostring(items[foundItem][1])) outputChatBox("Item Esély: " .. tostring(items[foundItem][2])) outputChatBox("Item Mennyiség: " .. tostring(items[foundItem][3])) outputChatBox(" ") outputChatBox("megkaptad") else exports["cg_notifications"]:addNotification(player, "Sajnos semmit sem találtál.", "info") return end end end addEvent("giveFoundJunkItem", true) addEventHandler("giveFoundJunkItem", getRootElement(), giveFoundJunkItem) Thank you for your help in advance!
  12. Oh my god I can't believe that this was the problem and I didn't even try it. Thank you so much!
  13. Hello! I am trying to create a scrollable dx list for my jobs system, but I am having some issues with it. I have a table for the jobs with some basic informations, like the id of the job, the name, etc. I can make the list of the jobs, so the grid list shows all the jobs, but sometimes it shows one job multiple times, and the ordering of the jobs is just wrong, the whole thing is messed up and I don't understand what is / can't find the problem. I have tried changing lots of settings, numbers, but I always get the same or it doesn't even render. I would really appreciate if somebody could help me out with that, it really annoys me and I can't find the problem. Here's the jobs table: availableJobs = { -- job id -- name, desc, requirements, max payment [1] = { jobName = "job 1", jobDescription = "1", jobRequirements = {driverLicense = 1, weaponLicense = 0}, jobMaximumPayment = 40, }, [2] = { jobName = "job 2", jobDescription = "2", jobRequirements = {driverLicense = 1, weaponLicense = 0}, jobMaximumPayment = 20, }, [3] = { jobName = "job 3", jobDescription = "3", jobRequirements = {driverLicense = 1, weaponLicense = 0}, jobMaximumPayment = 25, }, [4] = { jobName = "job 4", jobDescription = "4", jobRequirements = {driverLicense = 1, weaponLicense = 0}, jobMaximumPayment = 30, }, [5] = { jobName = "job 5", jobDescription = "5", jobRequirements = {driverLicense = 1, weaponLicense = 0}, jobMaximumPayment = 30, }, [6] = { jobName = "job 6", jobDescription = "6", jobRequirements = {driverLicense = 1, weaponLicense = 0}, jobMaximumPayment = 30, }, [7] = { jobName = "job 7", jobDescription = "7", jobRequirements = {driverLicense = 1, weaponLicense = 0}, jobMaximumPayment = 30, }, [8] = { jobName = "job 8", jobDescription = "8", jobRequirements = {driverLicense = 1, weaponLicense = 0}, jobMaximumPayment = 30, }, [9] = { jobName = "job 9", jobDescription = "9", jobRequirements = {driverLicense = 1, weaponLicense = 0}, jobMaximumPayment = 30, }, [10] = { jobName = "job 10", jobDescription = "10", jobRequirements = {driverLicense = 1, weaponLicense = 0}, jobMaximumPayment = 30, }, } And here's the client side script where I render the panel: local sx,sy = guiGetScreenSize() local showJobsPanel = true local renderData = {} renderData.defaultWidth = 600 renderData.defaultHeight = 450 renderData.posx = sx/2 - renderData.defaultWidth/2 renderData.posy = sy/2 - renderData.defaultHeight/2 renderData.currentRow = 1 renderData.maxRows = 3 function getJobImage(job) return fileExists("files/job"..job..".png") and "files/job"..job..".png" or "files/noimage.png" end function drawJobsPanel() if showJobsPanel then dxDrawRectangle(renderData.posx,renderData.posy,renderData.defaultWidth,renderData.defaultHeight,tocolor(0,0,0,150)) local jobs = 0 local latestLine = renderData.currentRow + renderData.maxRows for k,v in pairs(availableJobs) do if k >= renderData.currentRow then if k <= latestLine then jobs = jobs + 1 renderData.posy2 = renderData.posy + 10 + (100 * (jobs - 1)) dxDrawRectangle(renderData.posx,renderData.posy2,renderData.defaultWidth,75,tocolor(0,0,0,150)) dxDrawImage(renderData.posx+5,renderData.posy2,200,75,getJobImage(k)) dxDrawText(v.jobName,renderData.posx+225,renderData.posy2+5,0,0,tocolor(255,255,255,255),1,"default-bold","left","top",false,false,false,true) dxDrawText(v.jobDescription,renderData.posx+225,renderData.posy2+20,0,0,tocolor(255,255,255,255),1,"default-bold","left","top",false,false,false,true) end end end end end addEventHandler("onClientRender",getRootElement(),drawJobsPanel) bindKey("mouse_wheel_down", "down", function() if showJobsPanel then if renderData.currentRow < #availableJobs - renderData.maxRows then renderData.currentRow = renderData.currentRow + 1 end end end ) bindKey("mouse_wheel_up", "down", function() if showJobsPanel then if renderData.currentRow > 1 then renderData.currentRow = renderData.currentRow - 1 end end end ) Thank you in advance!
  14. I totally understand why you didn't just paste the working code, and I appreciate it, because I can learn new things that way (if I you just give me hints/little instructions), and I tried it so many ways and times, but I couldn't figure out, so thank you for helping me out. The explanation comments is a good idea, I will read through carefully so I wil understand how to do these things, maybe I will be able to figure out how to do the pager script, the thing I opened another topic about, I couldn't fix it yet, kinda the same like with this script, I have tried it so many times but couldn't figure out how to fix it. Waiting for your reply, thank you again for the help!
  15. Sorry for asking alot, but I can't see the problem in my script and I don't understand why it does not work, I'm a bit tired, but I don't think that I miss something, I just don't understand. For me, I think it should work logically, but it does not, why?? I tried every possibilites I had idea of, but none of them worked, this one seems like the most logical, but it doesn't work either. local screenX, screenY = guiGetScreenSize() local dxFades = nil local timeToFade = 2000 local currentState = nil local state_ = false function fadeCameraDX(state,r,g,b) if dxFades then return end if not state then return end dxFades = {} dxFades.timeStart = getTickCount() dxFades.barStartPoint = {} dxFades.barNumber = math.ceil(screenY / 35) -- editing this will change the number of bars | less bars -> increase it, more bars -> decrease it dxFades.barHeight = math.ceil(screenY / dxFades.barNumber) dxFades.barMargin = 4 if state then state_ = state if state_ == true then currentState = "in" end end for i = 1, dxFades.barNumber do dxFades.barStartPoint[i] = math.random(300, 500) end if not tonumber(r) then r = math.random(100,255) end if not tonumber(g) then g = math.random(100,255) end if not tonumber(b) then b = math.random(100,255) end dxFades.color = {r,g,b} addEventHandler("onClientRender", root, renderDXCameraFading) outputDebugString("Num bars: " .. dxFades.barNumber) end function renderDXCameraFading() local r,g,b = unpack(dxFades.color) local rectangleWidth = screenX local rectanglePosX = 0 local borderSize = screenY / 24 local startEnd, outEnd local now = getTickCount() if currentState == "in" then startEnd = dxFades.timeStart + timeToFade local elapsedTime = now - dxFades.timeStart local duration = startEnd - dxFades.timeStart local progress = elapsedTime / duration rectangleWidth = interpolateBetween( 0,0,0, screenX + 600,0,0, progress, "InOutQuad" ) else outEnd = dxFades.outStart + timeToFade local elapsedTime = now - dxFades.outStart local duration = outEnd - dxFades.outStart local progress = elapsedTime / duration rectanglePosX = interpolateBetween( 0,0,0, screenX + 600,0,0, progress, "InOutQuad" ) if outEnd <= now then removeEventHandler("onClientRender", root, renderDXCameraFading) currentState = false end end if tonumber(startEnd) and startEnd <= now then if state_ == false then currentState = "out" outputDebugString("OUT") dxFades.outStart = now end end for i = 1, dxFades.barNumber do local startWidth = dxFades.barStartPoint[i] if currentState == "in" then dxDrawRectangle(0 - 500, (i - 1) * dxFades.barHeight, rectangleWidth + startWidth, dxFades.barHeight - dxFades.barMargin,tocolor(r,g,b,255)) exports.vice_util:dxDrawBorder(0 - 500, (i - 1) * dxFades.barHeight, rectangleWidth + startWidth, dxFades.barHeight - dxFades.barMargin,dxFades.barHeight/10,tocolor(0,0,0,255)) else dxDrawRectangle(rectanglePosX - startWidth, (i - 1) * dxFades.barHeight, rectangleWidth + startWidth, dxFades.barHeight - dxFades.barMargin,tocolor(r,g,b,255)) exports.vice_util:dxDrawBorder(rectanglePosX - startWidth, (i - 1) * dxFades.barHeight, rectangleWidth + startWidth, dxFades.barHeight - dxFades.barMargin,dxFades.barHeight/10,tocolor(0,0,0,255)) end end end fadeCameraDX(true) setTimer(function() fadeCameraDX(false) outputChatBox("fading away now") end, 5000, 1)
  16. I tried to copy the method of your script from the other topic but I don't really get it how should it work and why it does not work. local pagerPosX, pagerPosY, pagerSizeX, pagerSizeY = 0, 20, 200, 100 local pagerStartTick = 0 local pagerStopTick = 0 local startShowingPager = false local screenRenderTarget = dxCreateRenderTarget(pagerSizeX, pagerSizeY, true) local str = nil local textWidth = nil local startAt = nil local stopAt = nil local speed = nil function sendPagerNotification(message) if message and tostring(message) then pagerStartTick = getTickCount() pagerStopTick = pagerStartTick + 1000 startShowingPager = true str = message textWidth = dxGetTextWidth(str, 1, "pricedown") startAt = pagerSizeX+100 stopAt = pagerPosX-50-textWidth speed = 2.5 playSoundFrontEnd(49) else return false end end function drawPager() --if str ~= nil then local startEndPager, outEndPager local pagerOutTick local now = getTickCount() if startShowingPager == true then startEndPager = pagerStartTick + pagerStopTick local elapsedTime = now - pagerStartTick local duration = startEndPager - pagerStartTick local progress = elapsedTime / duration local pagerPosX = interpolateBetween( -pagerSizeX,0,0, 125,0,0, progress, "InOutQuad" ) local screenSizeMultiplierX, screenSizeDistanceY = 20, 15 local screenPosX, screenPosY, screenSizeX, screenSizeY = pagerPosX+screenSizeMultiplierX, pagerPosY+screenSizeDistanceY, pagerSizeX-screenSizeMultiplierX*2, 40 local buttonSizeX, buttonSizeY = pagerSizeX/6, pagerSizeY/4 local buttonPosX, buttonPosY = pagerPosX+pagerSizeX/2-buttonSizeX/2, screenPosY+screenSizeY+10 local dotSize = 10 local dotPosX, dotPosY = buttonPosX+buttonSizeX/2-dotSize/2, buttonPosY+buttonSizeY/2-dotSize/2 local brandText = "vicePAGE" local brandPosX, brandPosY = pagerPosX+10, pagerSizeY dxDrawRectangle(pagerPosX, pagerPosY, pagerSizeX, pagerSizeY, tocolor(0,0,0,225)) dxDrawText(brandText, brandPosX, brandPosY, 0, 0, tocolor(100,100,100,255), 1, "default", "left", "top", false, false, false, true) dxDrawRectangle(screenPosX, screenPosY, screenSizeX, screenSizeY, tocolor(175,200,125,255)) exports.vice_util:dxDrawBorder(screenPosX, screenPosY, screenSizeX, screenSizeY, 4, tocolor(100,100,100,255)) dxDrawRectangle(buttonPosX, buttonPosY, buttonSizeX, buttonSizeY, tocolor(100,100,100,255)) dxDrawRectangle(dotPosX, dotPosY, dotSize, dotSize, tocolor(255,0,0,255)) dxSetRenderTarget(screenRenderTarget, true) startAt = startAt - speed if startAt > stopAt then dxDrawText(str, startAt, screenSizeY, 0, 0, tocolor(0,0,0,255), 1, "pricedown", "left", "top", false, false, false, true) else --outputChatBox("most tűnik el") startShowingPager = false end dxSetRenderTarget() dxDrawImage(screenPosX, screenPosY-pagerSizeY/3, pagerSizeX-40, pagerSizeY, screenRenderTarget) else outEndPager = pagerOutTick + pagerStopTick local elapsedTime = now - pagerStartTick local duration = outEndPager - pagerStartTick local progress = elapsedTime / duration local pagerPosX = interpolateBetween( 125,0,0, -pagerSizeX,0,0, progress, "InOutQuad" ) local screenSizeMultiplierX, screenSizeDistanceY = 20, 15 local screenPosX, screenPosY, screenSizeX, screenSizeY = pagerPosX+screenSizeMultiplierX, pagerPosY+screenSizeDistanceY, pagerSizeX-screenSizeMultiplierX*2, 40 local buttonSizeX, buttonSizeY = pagerSizeX/6, pagerSizeY/4 local buttonPosX, buttonPosY = pagerPosX+pagerSizeX/2-buttonSizeX/2, screenPosY+screenSizeY+10 local dotSize = 10 local dotPosX, dotPosY = buttonPosX+buttonSizeX/2-dotSize/2, buttonPosY+buttonSizeY/2-dotSize/2 local brandText = "vicePAGE" local brandPosX, brandPosY = pagerPosX+10, pagerSizeY dxDrawRectangle(pagerPosX, pagerPosY, pagerSizeX, pagerSizeY, tocolor(0,0,0,225)) dxDrawText(brandText, brandPosX, brandPosY, 0, 0, tocolor(100,100,100,255), 1, "default", "left", "top", false, false, false, true) dxDrawRectangle(screenPosX, screenPosY, screenSizeX, screenSizeY, tocolor(175,200,125,255)) exports.vice_util:dxDrawBorder(screenPosX, screenPosY, screenSizeX, screenSizeY, 4, tocolor(100,100,100,255)) dxDrawRectangle(buttonPosX, buttonPosY, buttonSizeX, buttonSizeY, tocolor(100,100,100,255)) dxDrawRectangle(dotPosX, dotPosY, dotSize, dotSize, tocolor(255,0,0,255)) if outEndPager <= now then startShowingPager = false end end if tonumber(startEndPager) and startEndPager <= now and startShowingPager == true then startShowingPager = false outputDebugString("OUT") pagerOutTick = now end --else -- return false --end end addEventHandler("onClientRender", root, drawPager) sendPagerNotification("a")
  17. There is a little problem right now. The moving and the sizes are fine, but it always starts the animation and ends it after. So I mean, it fades the screen if I don't give the state, and then it fades away, but it shouldn't. I want to make it work like the default fadeCamera function, like if the state argument is true then the rectangles come in and it only fades away if I set the state to false, not instatly after. How is this possible to make? So for example I have this test script right here: fadeCameraDX(true) setTimer(function() fadeCameraDX(false) end, 15000, 1) It should fade the camera away, so show the rectangles when the resource starts, and then after 15 seconds it should start fade it away. But when I use ANY argument at state, even if I use false on the resource start it starts the animation and then fades it away as well, same with argument true. Hope you know what I mean, if you don't then test it and you will see.
  18. Hello! I am doing a pager script for my project for missions and other notifications. The first part of it works perfectly, it appears with an animation, text comes in and goes away, and the variable changes but instead of animating away it just disappears, and I don't understand why. I have been looking through the code for like 20 mins and I can't find the problem. Could somebody help me with this please? I just want it to go away with the same style of animation when it appears. local pagerPosX, pagerPosY, pagerSizeX, pagerSizeY = 0, 20, 200, 100 local pagerStartTick = 0 local pagerStopTick = 0 local startShowingPager = false local screenRenderTarget = dxCreateRenderTarget(pagerSizeX, pagerSizeY, true) local str = nil local textWidth = nil local startAt = nil local stopAt = nil local speed = nil function sendPagerNotification(message) if message and tostring(message) then pagerStartTick = getTickCount() pagerStopTick = pagerStartTick + 1000 startShowingPager = true str = message textWidth = dxGetTextWidth(str, 1, "pricedown") startAt = pagerSizeX+100 stopAt = pagerPosX-50-textWidth speed = 2.5 playSoundFrontEnd(49) else return false end end function drawPager() --if str ~= nil then if startShowingPager == true then local now = getTickCount() local elapsedTime = now - pagerStartTick local duration = pagerStopTick - pagerStartTick local progress = elapsedTime / duration local pagerPosX = interpolateBetween( -pagerSizeX,0,0, 125,0,0, progress, "InOutQuad" ) local screenSizeMultiplierX, screenSizeDistanceY = 20, 15 local screenPosX, screenPosY, screenSizeX, screenSizeY = pagerPosX+screenSizeMultiplierX, pagerPosY+screenSizeDistanceY, pagerSizeX-screenSizeMultiplierX*2, 40 local buttonSizeX, buttonSizeY = pagerSizeX/6, pagerSizeY/4 local buttonPosX, buttonPosY = pagerPosX+pagerSizeX/2-buttonSizeX/2, screenPosY+screenSizeY+10 local dotSize = 10 local dotPosX, dotPosY = buttonPosX+buttonSizeX/2-dotSize/2, buttonPosY+buttonSizeY/2-dotSize/2 local brandText = "vicePAGE" local brandPosX, brandPosY = pagerPosX+10, pagerSizeY dxDrawRectangle(pagerPosX, pagerPosY, pagerSizeX, pagerSizeY, tocolor(0,0,0,225)) dxDrawText(brandText, brandPosX, brandPosY, 0, 0, tocolor(100,100,100,255), 1, "default", "left", "top", false, false, false, true) dxDrawRectangle(screenPosX, screenPosY, screenSizeX, screenSizeY, tocolor(175,200,125,255)) exports.vice_util:dxDrawBorder(screenPosX, screenPosY, screenSizeX, screenSizeY, 4, tocolor(100,100,100,255)) dxDrawRectangle(buttonPosX, buttonPosY, buttonSizeX, buttonSizeY, tocolor(100,100,100,255)) dxDrawRectangle(dotPosX, dotPosY, dotSize, dotSize, tocolor(255,0,0,255)) dxSetRenderTarget(screenRenderTarget, true) startAt = startAt - speed if startAt > stopAt then dxDrawText(str, startAt, screenSizeY, 0, 0, tocolor(0,0,0,255), 1, "pricedown", "left", "top", false, false, false, true) else --outputChatBox("most tűnik el") startShowingPager = false end dxSetRenderTarget() dxDrawImage(screenPosX, screenPosY-pagerSizeY/3, pagerSizeX-40, pagerSizeY, screenRenderTarget) else local now = getTickCount() local elapsedTime = now - pagerStartTick local duration = pagerStopTick - pagerStartTick local progress = elapsedTime / duration local pagerPosX = interpolateBetween( 125,0,0, -pagerSizeX,0,0, progress, "InOutQuad" ) local screenSizeMultiplierX, screenSizeDistanceY = 20, 15 local screenPosX, screenPosY, screenSizeX, screenSizeY = pagerPosX+screenSizeMultiplierX, pagerPosY+screenSizeDistanceY, pagerSizeX-screenSizeMultiplierX*2, 40 local buttonSizeX, buttonSizeY = pagerSizeX/6, pagerSizeY/4 local buttonPosX, buttonPosY = pagerPosX+pagerSizeX/2-buttonSizeX/2, screenPosY+screenSizeY+10 local dotSize = 10 local dotPosX, dotPosY = buttonPosX+buttonSizeX/2-dotSize/2, buttonPosY+buttonSizeY/2-dotSize/2 local brandText = "vicePAGE" local brandPosX, brandPosY = pagerPosX+10, pagerSizeY dxDrawRectangle(pagerPosX, pagerPosY, pagerSizeX, pagerSizeY, tocolor(0,0,0,225)) dxDrawText(brandText, brandPosX, brandPosY, 0, 0, tocolor(100,100,100,255), 1, "default", "left", "top", false, false, false, true) dxDrawRectangle(screenPosX, screenPosY, screenSizeX, screenSizeY, tocolor(175,200,125,255)) exports.vice_util:dxDrawBorder(screenPosX, screenPosY, screenSizeX, screenSizeY, 4, tocolor(100,100,100,255)) dxDrawRectangle(buttonPosX, buttonPosY, buttonSizeX, buttonSizeY, tocolor(100,100,100,255)) dxDrawRectangle(dotPosX, dotPosY, dotSize, dotSize, tocolor(255,0,0,255)) end --else -- return false --end end addEventHandler("onClientRender", root, drawPager) sendPagerNotification("a") What is the problem, why it doesn't use the animation when the startShowingPager variable is false?
  19. I'm not quite sure how should I do this because of the loop.
×
×
  • Create New...