Jump to content

Dzsozi (h03)

Members
  • Posts

    682
  • Joined

  • Last visited

  • Days Won

    2

Dzsozi (h03) last won the day on February 20 2022

Dzsozi (h03) had the most liked content!

Details

  • Location
    Hungary

Recent Profile Visitors

6,439 profile views

Dzsozi (h03)'s Achievements

Crime Partner

Crime Partner (30/54)

86

Reputation

  1. Thank you, I didn't know I could do this with getElementsByType ?
  2. This is a great idea and would be much simpler and easier indeed, now that you said I realised it. But I think the reason I wanted to do a scanning type solution is because of the custom placed objects (i know I can check those and I already did in the original script), but also, more likely because of the removed world models. What would you suggest to check that, if I were doing the solution you mentioned? I have some custom maps which for sure remove some lamps, I made some that removes even a whole street.
  3. Sorry for bumping this topic that late, I got some free time now, I still wasn’t able to finish this project based on the examples, also I just realised that the scan will be going diagonally if I add to x and y at the same time, therefore the scan wouldn’t apply to the whole world. I would like to achieve an effect of scanning such as from the top left corner of the map to the bottom right, going sideways, and when the camera reaches the right side, it snaps back to the left and gets offset on the y axis. I am not sure about how to achieve this between the range of -3000 to 3000 on the x and y axis inside a coroutine function with loops, am I even doing it the right way by using for loop? I would have to prevent the loop from happening on the y axis before the scanX reaches the right side. Right now I can’t send my current code and I can’t remember what errors I got, I’m at work but I wanted to reply and let you know that I’m still interested and trying to fix & get it done. I will post my code asap, could you please maybe help me finishing and correcting it?
  4. Thank you for teaching me, really, I tried to make the scanning with these functions, I get an error spam "cannot resume dead coroutine" because of the timer (this line) STREET_LIGHTS.SCAN_TIMER = setTimer(resumeScan, 1000, 0) Here's my current code, could you help me with what am I doing wrong? local STREET_LIGHTS = { VALID_MODELS = { [1294] = {name = "mlamppost", offsets = {Vector3(0,0.3,1)}, radius = {start = 0.075, stop = 50}}, [1297] = {name = "lamppost1", offsets = {Vector3(0,0.3,1)}, radius = {start = 0.075, stop = 50}}, [1290] = {name = "lamppost2", offsets = {Vector3(3,0.03,5.4), Vector3(-3,0.03,5.4)}, radius = {start = 0.075, stop = 75}}, [1226] = {name = "lamppost3", offsets = {Vector3(-1.3,0.165,3.675)}, radius = {start = 0.075, stop = 50}}, }, OBJECT_LIGHTS = {}, } local SCAN = { current = Vector2(-3000, -3000), } local SCAN_WORLD = coroutine.create(function() for x = SCAN.current.x, 3000, 10 do if math.abs(x) % 100 == 100 then SCAN.current.x = x print"yield" coroutine.yield() end for y = SCAN.current.y, 3000, 10 do if SCAN.current.x >= 3000 and SCAN.current.y >= 3000 then if isTimer(STREET_LIGHTS.SCAN_TIMER) then killTimer(STREET_LIGHTS.SCAN_TIMER) end STREET_LIGHTS.SCAN_TIMER = nil setCameraTarget(localPlayer) coroutine.yield() break end if math.abs(y) % 100 == 100 then SCAN.current.y = y coroutine.yield() end setCameraMatrix(x, y, 500, x, y, 0) local hit, _,_,_,_,_,_,_,_,_,_,worldModelID,worldX,worldY,worldZ,worldRotX,worldRotY,worldRotZ,_ = processLineOfSight( x, y, 500, x + 5, y + 5, 0, true, false, false, true, false, false, false, false, nil, true, false ) if hit then --if STREET_LIGHTS.VALID_MODELS[worldModelID] then print(worldModelID) -- do i actually get the models on screen? i get some numbers for sure but camera is stuck and position is not updating --end end end end return true end) local function resumeScan() return coroutine.resume(SCAN_WORLD) end addEventHandler("onClientResourceStart", resourceRoot, function() if not isTimer(STREET_LIGHTS.SCAN_TIMER) then STREET_LIGHTS.SCAN_TIMER = setTimer(resumeScan, 1000, 0) end return true end) And actually I don't even get the "yield" output as expected from this line: if math.abs(x) % 100 == 100 then SCAN.current.x = x print"yield" coroutine.yield() end Camera is stuck at one place on the top right corner of the map and first I get a bunch of spam of 3 or 4 numbers, then the error about cannot resume dead coroutine.
  5. Sorry I didn’t make time to reply, my fault. Actually it is not so clear, I don’t really know how to use coroutine functions, I never did before. Not so sure how to implement it for the purpose I need. Thank you for the advice I didn’t even think about that and actually makes sense to do it.
  6. Hello! I would like to get the positions of all the lampposts. I was trying to use processLineOfSight to achieve this, since getElementsByType("object") doesn't return default world objects. I tried using a loop from 0 to 3000 on the x and y axis, but I get an infinite running script error. Why do I get this error and how could I achieve a scan on the world? Here's my current code: (I commented out most parts while trying to find the cause of the problem, so I would only see the positions of all the lamps if the scan was successful) local STREET_LIGHTS = { VALID_MODELS = { [1294] = {name = "mlamppost", offsets = {Vector3(0,0.3,1)}, radius = {start = 0.075, stop = 50}}, [1297] = {name = "lamppost1", offsets = {Vector3(0,0.3,1)}, radius = {start = 0.075, stop = 50}}, [1290] = {name = "lamppost2", offsets = {Vector3(3,0.03,5.4), Vector3(-3,0.03,5.4)}, radius = {start = 0.075, stop = 75}}, [1226] = {name = "lamppost3", offsets = {Vector3(-1.3,0.165,3.675)}, radius = {start = 0.075, stop = 50}}, }, OBJECT_LIGHTS = {}, } function processStreetLights() for x = 0, 3000, 5 do for y = 0, 3000, 5 do local hit, _,_,_,_,_,_,_,_,_,_,worldModelID,worldX,worldY,worldZ,worldRotX,worldRotY,worldRotZ,_ = processLineOfSight( x, y, 0, x + 5, y + 5, 500, true, false, false, true, false, false, false, false, nil, true, false ) if hit then --[[if STREET_LIGHTS.VALID_MODELS[worldModelID] then local data = STREET_LIGHTS.VALID_MODELS[worldModelID] local searchlights = {} for i, offset in pairs(data.offsets) do local startPos = Vector3(worldX, worldY, worldZ + offset.z) --Vector3(exports["sa_utility"]:getPositionFromElementOffset(obj, offset.x, offset.y, offset.z)) startPos.x = worldX + math.sin( math.rad( worldRotZ ) ) * offset.x startPos.y = worldY + math.cos( math.rad( worldRotZ ) ) * offset.y local endPos = startPos --Vector3(exports["sa_utility"]:getPositionFromElementOffset(obj, offset.x, offset.y, 0.25)) endPos.z = worldZ + 0.25 searchlights[i] = SearchLight(startPos, endPos, data.radius.start, data.radius.stop, true) end --STREET_LIGHTS.OBJECT_LIGHTS[obj] = searchlights table.insert(STREET_LIGHTS.OBJECT_LIGHTS, searchlights) end]] print(worldX, worldY, worldZ) end end end --[[for k, obj in pairs(getElementsByType("object")) do if STREET_LIGHTS.VALID_MODELS[obj.model] then local data = STREET_LIGHTS.VALID_MODELS[obj.model] local searchlights = {} for i, offset in pairs(data.offsets) do local startPos = Vector3(exports["sa_utility"]:getPositionFromElementOffset(obj, offset.x, offset.y, offset.z)) local endPos = Vector3(exports["sa_utility"]:getPositionFromElementOffset(obj, offset.x, offset.y, 0.25)) searchlights[i] = SearchLight(startPos, endPos, data.radius.start, data.radius.stop, true) end STREET_LIGHTS.OBJECT_LIGHTS[obj] = searchlights end end]] return true end addEventHandler("onClientResourceStart", resourceRoot, function() processStreetLights() return true end) Thank you for help in advance!
  7. It is working and the text is drawn, the problem is that you are setting the text position outside of the render target canvas size. When you are drawing inside a render target, the positions start from 0 again. textureWidth, textureHeight = 100, 50 texture = dxCreateRenderTarget(textureWidth, textureHeight, true) dxSetRenderTarget(texture, true) dxDrawText("text", 5, 5, textureWidth, textureHeight) dxSetRenderTarget() dxDrawImage(posx, posy, textureWidth, textureHeight, texture) This will draw the render target as an image wherever you want, and inside of it will be the text on the top left corner, offset by 5 pixels.
  8. Thank you so much, it works and I also managed to do the step 4 to manage remaining items, so I can add to main inventory or drop them. I appreciate it and your time
  9. Hello! I started re-doing my inventory system, I made some functions based on this topic I did everything without a problem, everything works fine, except a calculation I am trying to do when giving an item to a container. I have stack limits defined for items inside an ITEM_TABLE. The stack limit for, let's say Apple item is 5. When calling the giveItem function, I would like to check if the count exceeds the stack limit, then loop the item giving process until the newly calculated count value is less than the stack limit. So let's say I call -- itemID, count giveItem(1, 8) -- give 8 apples, but the apple has a stack limit of 5, so I would like the player to end up with 2 apple items, one with a count of 5 and one with a count of 3 So then I would like the player to have 2 different apple items, one with a count of 5 and one with a count of 3 This is how I was trying to do it, but it seems like I can't use the repeat until/while loop properly, or I am missing calculations, I can't get the result I want. function ContainerMethods:giveItem(itemID, count) local itemDetails = getItemDetails(itemID) if not itemDetails then return false end count = tonumber(count) or 1 local carrySlot = self:findExistingItemSlot(itemID) if carrySlot and carrySlot.count + count <= itemDetails.stacklimit then -- if the container has an item like this and it's less than the stack limit, add the count carrySlot.count = carrySlot.count + count else local tempCount = count repeat -- i don't know if i should use repeat until, or while loop, repeat until seems like the correct way of doing it --while tempCount > itemDetails.stacklimit do local slotX, slotY = self:findFreeSlotForItem(itemID) if slotX and slotY then -- i am working with a grid inventory with different item sizes for x = slotX, slotX + itemDetails.size.x - 1, 1 do for y = slotY, slotY + itemDetails.size.y - 1, 1 do self.grid[x][y] = true end end local newItem = { ["itemID"] = itemID, ["count"] = tempCount, -- should i make calculations here as well?? i don't think so but i could be wrong ["slot"] = {x = slotX, y = slotY}, } table.insert(self.items, newItem) tempCount = tempCount - itemDetails.stacklimit -- tempCount is the difference print(tempCount) else print("no empty space for item '" .. itemID .. "' in container '" .. self.name .. "'") return false end --end until tempCount < itemDetails.stacklimit -- repeat adding a new item until the count is less than the stack limit end return true end But the result I get is: Notice that the debugscript prints 3, but my inventory has only one item with the count of 8, instead of 5 and 3. How can I make this function properly, so I don't have to worry about it in the future when I give an item to the player? Thank you for your help in advance!
  10. Sorry for not responding, meanwhile I solved the problem and this topic went unnoticed by me. I solved it by using Kam's updated scripts made by gold_fish ([REL] KAM's GTA Scripts (2018) / UPD: 31.05.2020 / - Tools - GTAForums). I read that this updated script supports exporting and importing normals and also reflections, therefore the problems were solved. Also I think I had some issues with the model itself, I was playing around with the smoothing groups and etc. Using the updated scripts solves the problem, however I will have to remake my model tho. This topic can be locked.
  11. setElementData might come handy in these cases. Good luck with scripting!
  12. The second function has a problem returning the occupied vehicle, I don't know if that could be the cause of the problem you are having, or is that just a typo while you were writing the examples on forum. function toggleLights(playerSource, cmd) local vehicle = getPedOccupiedVehicle(playerSource) -- use playerSource instead of thePlayer, thePlayer is not defined so this will return an error and toggling lights won't happen if (vehicle) then Yes, this would cause lag and lots of unnecessary data flow. You don't have to get a mysql result everytime you lock/start a vehicle. If I were doing toggleLock and toggleEngine functions for vehicles, I would just simply use them when a player types a command / presses a key, as you are doing, inside those toggleLock and toggleEngine functions simply use setVehicleLocked and setVehicleEngineState like function toggleLock(vehicle, state) if not vehicle then return false end setVehicleLocked(vehicle, state) return true end For the command you would do function lockCommand(player, command) local vehicle = getPedOccupiedVehicle(player) if vehicle then toggleLock(vehicle, not isVehicleLocked(vehicle)) end end addCommandHandler("lockveh", lockCommand) Keep the actual toggle functions seperate from the command functions, that way it will be easier for you to see, utilize and use those functions later as well. Then have a different save resource or function to save the data to mysql. You can make a timer every 5 seconds to call the saving, and inside the save function you would get every desired vehicle and their state of engine and locks to update mysql data with the new ones. This would make data usage and network flow much more less in my opinion, other than calling for mysql everytime a player types a command; imagine if they start spamming. Of course you can make anti-spam checks, but overall that way would be much more inefficient. Also there is a resource that you can use to check the usage of resources: performancebrowser - Multi Theft Auto: Wiki I believe it is already included in default MTA resources.
  13. Try muzzle_texture* instead of muzzle_texture4 engineApplyShaderToWorldTexture(theTechnique, "muzzle_texture*")
  14. Possibility to create functioning ladders, create a ladder without the custom object, for default world ladders, or create a brand new one. Only vertical ladders are supported with Z rotation. Features one custom object. Easy to use functions, ~240 lines of code. Sprint button for fast climbing Jump button for jumping off a ladder Forward button for climbing up Backward button for climbing down You can basically create any length ladder with correct positions, since you can adjust offsets for start and end positions, so shifting leadders in the ground is a possibility to match the height of a building. Ladder is using collision tuboids for player detection. Contains a "/getladderpos" utility command to get the corrected position and rotation in front of player, copies Vector3 and int rotation to clipboard. Power of creating more interesting maps, possibility and an idea for a new "ladder parkour" gamemode, or just create more interesting roleplay / deathmatch / other scenarios by adding climbable ladders to the environment. I am planning to add custom animations, these default ones are good for now, and default world ladder positions in the future. I'm waiting for your feedback, let me know if you like it and/or have any suggestions!
  15. Thank you again! I will try to make and implement it! Really appreciate your time, have a nice day!
×
×
  • Create New...