Forum

> > CS2D > General > If (Trigger) then
Forums overviewCS2D overviewGeneral overviewLog in to reply

English If (Trigger) then

1 reply
To the start Previous 1 Next To the start

old closed If (Trigger) then

gabpro
User Off Offline

Quote
How to do,for example,if the trigger "Day" is on then...
Look at the 6º line.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
addhook("movetile","work")
function work(id,x,y)
	-- Day Jobs
	-- Medic
	if (sample.classes.class[id]==1) then
		--EXAMPLE : IF (TRIGGER==TRUE OR 1 OR ETC) THEN
		if (x>15) then
			parse("setpos "..id.." 320 192")
			msg2(id,"©255000000Do not exit,you are working now!")
		end
		if (y>19) then
			parse("setpos "..id.." 320 192")
			msg2(id,"©255000000Do not exit,you are working now!")
		end
	end

How to do that?

Admin/mod comment

No Lua Questions in the Main Forum /Lee

old closed Re: If (Trigger) then

Lee
Moderator Off Offline

Quote
Please do not post Lua questions in the main forum, we have a specific thread for Lua questions at http://unrealsoftware.de/forum_posts.php?post=120848

There's also a dedicated Lua forum for CS2D at http://cs2d.org/

info.txt has written
trigger(trigger,source)                         on trigger (once per trigger)
-trigger: trigger name
-source: triggered by 0=map/1=script
>return:     0 - proceed normally
          1 - don't trigger


Add this code at the top of your script.
1
2
3
4
5
6
7
sample.trigger = false -- or the default trigger setting.
addhook("trigger","sample.trigger_callback")
function sample.trigger_callback(name,source)
	if name == "DAY" then
		sample.trigger = not sample.trigger -- Toggles it
	end
end

To use:

1
2
3
4
5
if sample.trigger then
	--Execute if triggered
else
	--Execute if not
end

This assumes that when it's day time, the day trigger will not be triggered multiple times.
To the start Previous 1 Next To the start
Log in to replyGeneral overviewCS2D overviewForums overview