Forum

> > CS2D > Maps/Editor > Trigger_if not working
Forums overviewCS2D overview Maps/Editor overviewLog in to reply

English Trigger_if not working

10 replies
To the start Previous 1 Next To the start

old Trigger_if not working

Accurator
User Off Offline

Quote
I put a Trigger_if entity in my map with the following script in the condition box:
1
item(id,"type")==51 and item(id,"x")==11 and item(id,"y")==16 and item(id,"exists")

It should check if there is a grenade at position x 11 y 16, and if that's the case, trigger a few other entities. But it doesn't work. What's the problem?

old Re: Trigger_if not working

UnkN
User Off Offline

Quote
1
local itemlist=item(0,"table") for _,id in pairs(itemlist) do if item(id,"type")==51 and item(id,"x")==11 and item(id,"y")==16 and item(id,"exists") then

old Re: Trigger_if not working

Accurator
User Off Offline

Quote
If shouldn't be inputted in trigger_if. It already is there. Only added the then, but that didn't help either.

1
local itemlist=item(0,"table") for _,id in pairs(itemlist) do if item(id,"type")==51 and item(id,"x")==11 and item(id,"y")==16 and item(id,"exists") then

Would turn into:

1
if local itemlist=item(0,"table") for _,id in pairs(itemlist) do if item(id,"type")==51 and item(id,"x")==11 and item(id,"y")==16 and item(id,"exists") then

old Re: Trigger_if not working

MikuAuahDark
User Off Offline

Quote
1
(function() for _,id in pairs(item(0,"table")) do if item(id,"type")==51 and item(id,"x")==11 and item(id,"y")==16 then return true end end)()
Also make sure that you have cs2d cmd mp_luamap set to 1

old Re: Trigger_if not working

DC
Admin Off Offline

Quote
The expression put in cs2d entity Trigger_If must be a Boolean expression. This means Lua must be able to evaluate it and it has to be either true or false and nothing else.

So it's always wrong to start it with "if" and to end it with "then". This is just an incomplete expression and can't work at all.

It's certainly possible to put this in one single Trigger_If but it's dirty and hard to read.

Create a map script instead (a Lua file called like the map and being in the maps folder. e.g.: your map is called mymap.map then create a Lua file called mymap.lua in the maps folder) and write this function into it:

1
2
3
4
5
6
7
8
9
function doesItemExist()
	local itemlist=item(0,"table")
	for _,id in pairs(itemlist) do
		if item(id,"type")==51 and item(id,"x")==11 and item(id,"y")==16 and item(id,"exists") then
			return true
		end
	end
	return false
end

And simply put
1
doesItemExist()
into the Trigger_If.

Also I guess the part
1
and item(id,"exists")
can be removed because only items which exist are returned by cs2d lua cmd item(0,"table")
To the start Previous 1 Next To the start
Log in to reply Maps/Editor overviewCS2D overviewForums overview