Jump to content

OnColShapeHit table


Bean666

Recommended Posts

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
)

 

Link to comment
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! :)

  • Like 1
Link to comment
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 by Bean666
Link to comment
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 by Bean666
  • Like 1
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...