Bean666 Posted February 14, 2021 Posted February 14, 2021 hi, i created colshapes via table, but there's a problem with the onColShapeHit that i dont know how to fix. the onColShapeHit functions dont work whenever i hit it. but when i leave one colshape on the table it works, how do i trigger it for all the colshapes inside the table? local lowspawnrates = { { 1690.6787109375, 182.8291015625, 100, 100 }, { 1379.966796875, -127.736328125, 100, 100}, {1026.0546875, 15.234375, 400, 150} } function lowspawnzones() for i, z in ipairs(lowspawnrates) do lowspawn = createColRectangle ( z[1], z[2], z[3], z[4]) lowspawnradar = createRadarArea ( z[1], z[2], z[3], z[4], 200, 150, 0, 200) end end addEventHandler("onResourceStart", resourceRoot, lowspawnzones) addEventHandler ( "onColShapeHit", resourceRoot, function ( hitElement ) if source == lowspawn then if getElementType( hitElement ) == "player" then setElementData(hitElement, "threat", "low") end end end )
Tekken Posted February 14, 2021 Posted February 14, 2021 local lowspawn = {}; local lowspawnradar = {}; lowspawn[#lowspawn + 1] = createColRectangle(z[1], z[2], z[3], z[4]); lowspawnradar[#lowspawnradar + 1] = createRadarArea(z[1], z[2], z[3], z[4], 200, 150, 0, 200); addEventHandler("onColShapeHit", resourceRoot, function(hitElement) for i = 1, #lowspawn do if source == lowspawn[i] then if getElementType( hitElement ) == "player" then setElementData(hitElement, "threat", "low"); end end end); Try to understand the code if you have any problems leave a reply! 1
Bean666 Posted February 14, 2021 Author Posted February 14, 2021 (edited) 3 hours ago, Tekken said: local lowspawn = {}; local lowspawnradar = {}; lowspawn[#lowspawn + 1] = createColRectangle(z[1], z[2], z[3], z[4]); lowspawnradar[#lowspawnradar + 1] = createRadarArea(z[1], z[2], z[3], z[4], 200, 150, 0, 200); addEventHandler("onColShapeHit", resourceRoot, function(hitElement) for i = 1, #lowspawn do if source == lowspawn[i] then if getElementType( hitElement ) == "player" then setElementData(hitElement, "threat", "low"); end end end); Try to understand the code if you have any problems leave a reply! Alright thank you so much again tekken, so you gave all the locations inside the table a variable(?)? or what do you call that, then you did a loop on the onColShapeHit starting from the first line of the table until all the numbers inside the table, so that all locations inside the table are recognized? EDIT: im getting an error for i,z in ipairs(lowspawn) do lowspawn[#lowspawn + 1] = createColRectangle(z[1], z[2], z[3], z[4]); end attempt to index local z(a user data value) Edited February 14, 2021 by Bean666
Tekken Posted February 14, 2021 Posted February 14, 2021 Well you will have to create a separate table for spawnpoints Like you had lowspawnrate
Bean666 Posted February 14, 2021 Author Posted February 14, 2021 (edited) 14 minutes ago, Tekken said: Well you will have to create a separate table for spawnpoints Like you had lowspawnrate so basically like this? local lowspawn = {}; local lowspawnrates = { locations } function lowspawnzones() for i, z in ipairs(lowspawnrates) do lowspawn[#lowspawn + 1] = createColRectangle(z[1], z[2], z[3], z[4]); end end addEventHandler("onResourceStart", resourceRoot, lowspawnzones) EDIT: it worked, thank you verymuch, understand what u mean now, got it, thanks again! Edited February 14, 2021 by Bean666 1
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