zixxonx Posted July 11, 2015 Share Posted July 11, 2015 Hello, I have a table with 5 cuboids: cuboid[1] = {x,y,z,10,10,10} cuboid[2] = {x,y,z,10,10,10} etc and I wanna check if there is any vehicle on these cuboids, if no then break the table i tried it for _,v in ipairs(getElementsByType('vehicle')) do outputChatBox('checking from ' .. getVehicleName(v) .. ' perspective') for i=1, 5 do if isElementWithinColShape(v, cuboid[i]) then outputChatBox(i .. ' taken by ' .. getVehicleName(v)) else outputChatBox(i .. ' free') end end end So i spawn 2 cars at 2 cuboids, infernus at 1st, cheetah at 2nd checking from Cheetah perspective 1 free 2 taken by Cheetah 3 free 4 free 5 free checking from Infernus perspective 1 taken by Infernus 2 free 3 free 4 free 5 free the problem is that Cheetah sees that cuboid 1 is free while it's taken and infernus sees 1 is free Could you help me? Link to comment
manawydan Posted July 11, 2015 Share Posted July 11, 2015 this?: function isInAnyFiveCuboid() local vehicles = getElementsByType("vehicle") for k,v in ipairs(vehicles)do if(isElementWithinColShape(v,cuboid[1]) or isElementWithinColShape(v,cuboid[2]) or isElementWithinColShape(v,cuboid[3]) or isElementWithinColShape(v,cuboid[4]) or isElementWithinColShape(v,cuboid[5])) then outputChatBox(getVehicleName(v).."is in cuboid") else outputChatBox(getVehicleName(v).."is out cuboid") end end end Link to comment
zixxonx Posted July 12, 2015 Author Share Posted July 12, 2015 Looks like it partially works. Now I wanted to make it that If a vehicle is in cuboid it adds +1 to the variable but it counts all the cars I have on the server So if I have 5 cuboids for 5 parking places cuboid[1] cuboid[2] cuboid[3] cuboid[4] cuboid[5] And i have something like it: (at top of the script) count = 0 local vehicles = getElementsByType("vehicle") for k,v in ipairs(vehicles)do if(isElementWithinColShape(v,cuboid[1]) or isElementWithinColShape(v,cuboid[2]) or isElementWithinColShape(v,cuboid[3]) or isElementWithinColShape(v,cuboid[4]) or isElementWithinColShape(v,cuboid[5])) then count =count +1 else createVehicle(foo) end end And I spawn first car then count is 1, but when I spawn second count is 2, and... when I'm trying to spawn the third count is 4 because it's add +1 2x to variable. It's hard to explain but I want it done so badly. Link to comment
Gr0x Posted July 12, 2015 Share Posted July 12, 2015 (edited) count = 0 takenColShapes = {} for _,v in ipairs(getElementsByType('vehicle')) do for i=1, 5 do if isElementWithinColShape(v, cuboid[i]) then takenColShapes[i] = v count = count+1 end end end for i = 1,#takenColShapes do if takenColShapes[i] then outputChatBox(i .. " is taken by " .. getVehicleName(takenColShapes[i])) else outputChatBox(i .. " is free") end end outputChatBox(count) (Nevermind, this is wrong.) Edited July 13, 2015 by Guest Link to comment
zixxonx Posted July 12, 2015 Author Share Posted July 12, 2015 1 is free 1 is taken by Infernus 2 is free 1 is free and again it spawns car at 1 wtfff Link to comment
zixxonx Posted July 15, 2015 Author Share Posted July 15, 2015 f55 refrreshing anyone? Link to comment
GTX Posted July 15, 2015 Share Posted July 15, 2015 Actually, Gr0x his code is alright, with slight modifications. taken = {} for i, v in ipairs(getElementsByType"vehicle") do for i=1, 5 do if isElementWithinColShape(v, cuboid[i]) then taken[i] = v break end end end for i=1, 5 do if taken[i] then outputChatBox(i.." taken by "..getVehicleName(taken[i])) else outputChatBox(i.." is free") end end If this doesn't work, give me the full code, I'll test it. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now