trigger switch

Posted By: mschoenhals

trigger switch - 10/16/15 19:09

Hi all,

Super-Noob here... shocked

I'm trying to animate a switch moving into the top position. I've got a frame called "top" on the Model in MED (only 1 frame - top1).

My code keeps returning a 1515 error. It has to do with my animation line. How do I fix this?

Code:
ENTITY* t_trigger;

function turn_on()
{
	var trig_percentage =0;
	
	while(1)
	{
		trig_percentage %= 100;
		trig_percentage += 2*time_step;
		ent_animate(me, "top", trig_percentage, ANM_SKIP);
		wait(1);
	}
}

action trigger_switch()
{
	t_trigger=me; //this is a pointer defining the entity listed at the top
	on_enter = turn_on;
}

Posted By: Dico

Re: trigger switch - 10/16/15 19:23

Try this


Code:
var trig_percentage = 0;

function turn_on()
{
 trig_percentage = 1;

}

action trigger_switch()
{
	t_trigger=me; //this is a pointer defining the entity listed at the top
	on_enter = turn_on;
        while(1)
	{
            If(trig_percentage)
           {
		trig_percentage %= 100;
		trig_percentage += 2*time_step;
		ent_animate(me, "top", trig_percentage, ANM_SKIP);
           }
		wait(1);
	}


}

Posted By: mschoenhals

Re: trigger switch - 10/16/15 19:48

that totally worked; thanks. laugh
I guess I shouldn't have put the animation under the function? It should have stayed with the action?
Posted By: Kartoffel

Re: trigger switch - 10/17/15 10:26

The problem is the 'me' you've used in your turn_on-function.
Maybe this was done by mistake since you already created an entity-pointer and set it properly ('t_trigger').

However, you still used me in ent_animate() but the me-pointer is invalid here because it's a different function than the entities' action.

Replacing the 'me' with 't_trigger' should do the trick aswell.
Posted By: mschoenhals

Re: trigger switch - 10/17/15 18:58

Ok, so my latest version of the trigger is an action that changes the switch from off to on everytime the player kits "enter". Unfortunately, I get just a black screen now. Here's the code:

Code:
ENTITY* t_trigger;

var trig_percentage;

action trigger_switch()
{
	t_trigger = me; //this is a pointer defining the entity listed at the top

	while(1)
	if (key_enter)
	{

		if(trig_percentage = 1)
		{
			trig_percentage %= 100;
			trig_percentage += 2*time_step;
			ent_animate(t_trigger, "on", trig_percentage, ANM_SKIP);
			trig_percentage = 0;
		}
		else
		trig_percentage %= 100;
		trig_percentage += 2*time_step;
		ent_animate(t_trigger, "off", trig_percentage, ANM_SKIP);
		trig_percentage = 1;
		
		wait(1);

	}


}

Posted By: Dico

Re: trigger switch - 10/17/15 19:06

try this :
Code:
ENTITY* t_trigger;

var trig_percentage;

action trigger_switch()
{
	t_trigger = me; //this is a pointer defining the entity listed at the top

	while(1)
	{
		if (key_enter)
		{
			if(trig_percentage = 1)
			{
				trig_percentage %= 100;
				trig_percentage += 2*time_step;
				ent_animate(t_trigger, "on", trig_percentage, ANM_SKIP);
				trig_percentage = 0;
			}
			else
			{
				trig_percentage %= 100;
				trig_percentage += 2*time_step;
				ent_animate(t_trigger, "off", trig_percentage, ANM_SKIP);
				trig_percentage = 1;				
			}
			
			
		}
		wait(1);
	}

}



the wait function must be in while else your engine window will freeze
Posted By: mschoenhals

Re: trigger switch - 10/17/15 19:12

Yeah, that's what I thought but I'm such a total noob (just finished the workshop tutorials) that I don't know where to place it.
Posted By: mschoenhals

Re: trigger switch - 10/17/15 20:03

Ok, that totally worked. Except I was hoping that each time the enter button is hit, the switch would move to the opposite direction (on or off). I've added another if statement and included and else one too but the switch only moves to the "on" position and that's the end of it.
Code:
action trigger_switch()
{
	t_trigger = me; //this is a pointer defining the entity listed at the top

	while(1)
	{
		if (key_enter)
		{

			if(trig_percentage = 1)
			{
				trig_percentage %= 100;
				trig_percentage += 2*time_step;
				ent_animate(t_trigger, "on", trig_percentage, ANM_SKIP);
				trig_percentage = 0;
			}
			if(trig_percentage = 0)
			{
				trig_percentage %= 100;
				trig_percentage += 2*time_step;
				ent_animate(t_trigger, "off", trig_percentage, ANM_SKIP);
				trig_percentage = 1;
			}
			else
			{
				trig_percentage %= 100;
				trig_percentage += 2*time_step;
				ent_animate(t_trigger, "on", trig_percentage, ANM_SKIP);
				trig_percentage = 0;
			}
		}
		wait(1);
	}

}

Posted By: Dico

Re: trigger switch - 10/17/15 20:13

Try this

Code:
action trigger_switch()
{
	t_trigger = me; //this is a pointer defining the entity listed at the top
   var active_tri = 0;
	while(1)
	{
		if (key_enter)
		{
			if(active_tri == 0)
			{
				active_tri = 1;
			}
			if(active_tri == 2)
			{
				active_tri = 3;
			}
		}			
		if (active_tri == 1)
		{
			while(trig_percentage > 0)
			{
				trig_percentage -= 2*time_step;
				ent_animate(t_trigger, "off", trig_percentage, ANM_CYCLE);
				wait(1);
			}
			while(trig_percentage < 100)
			{
				trig_percentage += 2*time_step;
				ent_animate(t_trigger, "on", trig_percentage, ANM_CYCLE);
				wait(1);
			}
			active_tri = 2;
		}
		
		if (active_tri == 3)
		{
			while(trig_percentage > 0)
			{
				trig_percentage -= 2*time_step;
				ent_animate(t_trigger, "on", trig_percentage, ANM_CYCLE);
				wait(1);
			}
			while(trig_percentage < 100)
			{
				trig_percentage += 2*time_step;
				ent_animate(t_trigger, "off", trig_percentage, ANM_CYCLE);
				wait(1);
			}
			active_tri = 0;
		}
		wait(1);
	}

}

Posted By: mschoenhals

Re: trigger switch - 10/17/15 20:58

Ok, it went a step further now - the switch will go to off (down), then on (up) but stops there.

I was thinking about the variable active_tri; should I have a statement for when it equals 0?
Posted By: mschoenhals

Re: trigger switch - 10/17/15 21:05

Looking at the code further (thank you so much by the way):
I see that active_tri has three states: 0, 1, 2, 3. However, my switch only has three positions (middle, up, down). My plan is that each of those three states will lead to a different position for doors/platforms. Do I really need the 4th state then?
Posted By: Dico

Re: trigger switch - 10/17/15 21:28

the method of active_tri like this :

when you hit enter and active_tri = 0 then the variable turn to 1 (active_tri = 1)

and if active_tri = 1 your model should play "on" animation and when he fenish it he turn the var active_tri to 2.

and if the variable active_tri = 2 and you hit enter the active_tri turn to 3 so its play animation "off" and when he finish it , it turn variable active_tri to 0 so its the begining.
Posted By: mschoenhals

Re: trigger switch - 10/17/15 23:08

So right now, I hit enter and the switch moves to the down position. When I hit enter again, nothing happens. hit it again, and it moves up. After that, it stops working all together.

I'm curious about the trig_percentage check in the while statement. Why is that used?

Code:
action trigger_switch()
{
	t_trigger = me; //this is a pointer defining the entity listed at the top
	var active_tri = 0;

	while(1)
	{
		if (key_enter)
		{
			if(active_tri == 0)  //this is the initial state of the trigger (middle)
			{
				active_tri = 1;  //position for up
			}
			if(active_tri == 1)
			{
				active_tri = 2;  //postion for down
			}
			if(active_tri == 2)
			{
				active_tri = 1;
			}
		}
		if(active_tri == 1)
		{
			while(trig_percentage > 0)
			{
				//			trig_percentage %= 100;
				trig_percentage += 2*time_step;
				ent_animate(t_trigger, "on", trig_percentage, ANM_SKIP);
				wait(1);
				//			trig_percentage = 0;
			}
			while(trig_percentage < 100)
			{
				//			trig_percentage %= 100;
				trig_percentage += 2*time_step;
				ent_animate(t_trigger, "off", trig_percentage, ANM_SKIP);
				wait(1);
				//			trig_percentage = 1;
			}
			active_tri = 2;
		}
		if (active_tri == 2)
		{
			while(trig_percentage > 0)
			{
				//			trig_percentage %= 100;
				trig_percentage += 2*time_step;
				ent_animate(t_trigger, "on", trig_percentage, ANM_SKIP);
				wait(1);
				//			trig_percentage = 0;
			}
			while(trig_percentage < 100)
			{
				//			trig_percentage %= 100;
				trig_percentage += 2*time_step;
				ent_animate(t_trigger, "off", trig_percentage, ANM_SKIP);
				wait(1);
				//			trig_percentage = 1;
			}
			active_tri = 1;
		}
		wait(1);
	}

}

Posted By: Dico

Re: trigger switch - 10/17/15 23:17

remove this
Code:
if(active_tri == 2)
{
    active_tri = 1;
}



the code it work without it for up and down animation .
but i want to ask you. what do you want to do with this function ?
Posted By: mschoenhals

Re: trigger switch - 10/17/15 23:54

Ultimately I want to use it so when the player hits it, it will rotate door(s) one way and when hit again, it rotates the other way. I'm slowly working towards that.

This is also helping me learn how to code. I'm a work in progress. laugh

Right now the switch will move down when I hit enter but then it moves up on it's own and stays there.

I'd like to learn how to debug better. I tried to take the variable active_tri out of the action and list it at the top of the screen so I could follow it in SED watch but the value never changes. Am I missing something?
Posted By: mschoenhals

Re: trigger switch - 10/18/15 23:30

Hi all,
Still working on my trigger switch behavior. I'm really trying to simplify it (to better understand what I'm doing) and also to learn how to debug it.

Right now I can hit enter and the level will move up but when I hit enter again, nothing happens. I have used the watch window and can see that the active_tri variable moves from 0 to 1 but that's where it stops.

Any ideas?

Code:
///////////////////////////////
#include <acknex.h>
#include <default.c>
///////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

ENTITY* t_trigger;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

var trig_percentage;
var active_tri = 0;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

action trigger_switch()
{
	t_trigger = me; //this is a pointer defining the entity listed at the top

	while(1)
	{
		if (key_enter)
		{
			if(active_tri == 0)
			{
				while(1)
				{
					trig_percentage += 2*time_step;
					ent_animate(t_trigger, "on", trig_percentage, ANM_SKIP);
					active_tri = 1;
					wait(1);
				}

			}

			if (active_tri == 1)
			{
				while(1)
				{
					trig_percentage += 2*time_step;
					ent_animate(t_trigger, "off", trig_percentage, ANM_SKIP);
					active_tri = 0;
					wait(1);
				}
			}
		}
		wait(1);
	}
}

function main()
{
	level_load ("switch.wmb");
	wait(2);
	vec_set(camera.x, vector(-250, 0, 15));
}

Posted By: Dico

Re: trigger switch - 10/18/15 23:41

because you have an infinite loop here :
Code:
while(1)
				{
					trig_percentage += 2*time_step;
					ent_animate(t_trigger, "on", trig_percentage, ANM_SKIP);
					active_tri = 1;
					wait(1);
				}

Posted By: Dico

Re: trigger switch - 10/18/15 23:44

correct code :

Code:
action trigger_switch()
{
	t_trigger = me; //this is a pointer defining the entity listed at the top

	while(1)
	{
		if (key_enter)
		{
			if(active_tri == 0)
			{
				trig_percentage = 0;
				while(trig_percentage < 100)
				{
					trig_percentage += 2*time_step;
					ent_animate(t_trigger, "on", trig_percentage, ANM_CYCLE);
					wait(1);
				}
				active_tri = 1;				
			}
			else
			{
				trig_percentage = 0;
				while(trig_percentage < 100)
				{
					trig_percentage += 2*time_step;
					ent_animate(t_trigger, "off", trig_percentage, ANM_CYCLE);
					wait(1);
				}		
				active_tri = 0;
			}
		}
		wait(1);
	}
}

Posted By: mschoenhals

Re: trigger switch - 10/19/15 16:52

Ok, that works!
Thanks very much Dico. I'm off to try the next step in this code: trigger only when the player is near.

Thanks again.
Posted By: mschoenhals

Re: trigger switch - 10/19/15 17:48

I've now got my trigger system so it detects the player and will only active if the player is near and hits enter. What I want to do now is so when the switch is triggered in one direction, a platform or door moves one way and when the switch is hit again, it moves another way. Therefore I'm going to need a new action that is applied to the door/platform and a way of identifying which switch triggers what door/platform. That's likely going to be a skill defined when adding the door/platform behavior. Any ideas on where to start?

Here's my code so far:

Code:
ENTITY* t_switch;

var trig_percentage;
var t_switch_range = 150;

action trigger_switch()
{
	while (!player) {wait (1);} // wait until the player is loaded
	vec_set (my.skill61, my.x); // store the xyz initial position of the switch inside skill61... 63
	t_trigger = me; //this is a pointer defining the entity listed at the top
	var active_tri = 0; //variable defining where the switch is currently at.

	while(1)
	{
		c_scan(my.x, my.pan, vector(360, 180, t_switch_range), IGNORE_ME | SCAN_ENTS); // each switch scans around it, trying to detect the player
		if (you) // detected an entity?
		{
			if (you == player) // and that entity is the player?
			{
				if (key_enter)
				{
					if(active_tri == 0)
					{
						trig_percentage =0;
						while(trig_percentage < 100)  //stops an infinite loop. 
						{
							trig_percentage += 2*time_step;
							ent_animate(t_switch, "on", trig_percentage, ANM_SKIP);
							wait(1);
						}
						active_tri = 1;

					}

					else
					{
						trig_percentage = 0;
						while(trig_percentage < 100)  //stops an infinite loop. 
						{
							trig_percentage += 2*time_step;
							ent_animate(t_switch, "off", trig_percentage, ANM_SKIP);
							wait(1);
						}
						active_tri = 0;
					}
				}
			}
		}
		wait(1);
	}
}

Posted By: Anonymous

Re: trigger switch - 10/19/15 17:56

Wow, Dico - Nice Guy!
Posted By: Anonymous

Re: trigger switch - 10/19/15 18:22

You need a ID skill for your switch
Opps EDIT's needed
EDIT 2 - Broken first IF in door action

so
Code:
ENTITY* t_trigger[500]; // set a hard max and do not exceed
var trigger_ids=0;
action trigger_switch()
{
t_trigger[trigger_ids] = me; // index from 0-499
trigger_ids+=1;

my.active_tri = 0; /// active_tri must be moved to a skill not a var
......... All the rest
}

var door_ids=0;
action door_or_platform()
{
 wait(3); /// or other wait to make sure level is loaded 
door_ids +=1;
my.skill80 =door_ids // 1-500 this id matches t_trigger +1. so t_trigger[2] == my.skill80=3;

my.skill10 = 0;

while(1)
{

 my.skill10 = t_trigger[my.skill80-1].active_tri;
 

  if(my.skill10 == 0)
  { 

    ...move me one way
   }
   if(my.skill10 ==1)
   {

    ...move me the other way
   } 
wait(1);
}



That should work --- But I think it's sleep time for me now.. Have fun !
Mal
Posted By: mschoenhals

Re: trigger switch - 10/20/15 23:19

Hmm, stuck again. I'm getting an error with this:
Code:
my.skill10 = 0;



I'm not sure if the variable door_ids needs to be local or global. That's my noobness showing. wink Any ideas on how to fix this is very appreciated! laugh

Here's what I've got so far:
Code:
ENTITY* t_switch;
ENTITY* t_trigger[100]; // set a hard max and do not exceed

var trig_percentage;
var t_switch_range = 150;
var trigger_ids=0;

action trigger_switch()
{
	while (!player) {wait (1);} // wait until the player is loaded
	vec_set (my.skill61, my.x); // store the xyz initial position of the switch inside skill61... 63
	t_trigger = me; //this is a pointer defining the entity listed at the top
	//	var active_tri = 0; //variable defining where the switch is currently at.
	t_trigger[trigger_ids] = me; // index from 0-499
	trigger_ids+=1;

	my.skill10 = 0; /// active_tri must be moved to a skill not a var

	while(1)
	{
		c_scan(my.x, my.pan, vector(360, 180, t_switch_range), IGNORE_ME | SCAN_ENTS); // each switch scans around it, trying to detect the player
		if (you) // detected an entity?
		{
			if (you == player) // and that entity is the player?
			{
				if (key_enter)
				{
					if(my.skill10 == 0)
					{
						trig_percentage =0;
						while(trig_percentage < 100)  //stops an infinite loop. 
						{
							trig_percentage += 2*time_step;
							ent_animate(t_switch, "on", trig_percentage, ANM_SKIP);
							wait(1);
						}
						my.skill10 = 1;

					}

					else
					{
						trig_percentage = 0;
						while(trig_percentage < 100)  //stops an infinite loop. 
						{
							trig_percentage += 2*time_step;
							ent_animate(t_switch, "off", trig_percentage, ANM_SKIP);
							wait(1);
						}
						my.skill10 = 0;
					}
				}
			}
		}
		wait(1);
	}
}

action door_or_platform()
{
	wait(3); /// or other wait to make sure level is loaded
	var door_ids;
	door_ids += 1;
	my.skill80 = door_ids // 1-500 this id matches t_trigger +1. so t_trigger[2] == my.skill80=3;

	my.skill10 = 0;

	while(1)
	{

		my.skill10 = t_trigger[my.skill80-1].active_tri;
		

		if(my.skill10 == 0)
		{ 

my.x += 25
		}
		if(my.skill10 == 1)
		{

my.x -= 25
		} 
		wait(1);
	}
}

Posted By: Anonymous

Re: trigger switch - 10/20/15 23:37

Ok your error is the line before

Code:
my.skill80 = door_ids // 1-500 this id matches t_trigger +1. so t_trigger[2] == my.skill80=3;

	my.skill10 = 0;


semi-colon missing
Code:
my.skill80 = door_ids; 

	my.skill10 = 0;




Next - Yes door_ids was place in my code above the action door but below the trigger action . Any var place out of a function is Global.

Here is the thing about my code - I wrote it so you can use many doors and many triggers.

However you seem to be focused on just one door/trigger.

You'll have to think ahead or hack after, but you should know if you are writing one door/trigger or many doors/triggers.

With just one, then the whole ids' isn't even needed.

Good luck
Mal

EDITS - there are errors in your code - REMOVE t_trigger = me;

More edits - you moved the active_tri to skill10 however you need to mod the door function. Look for a next post I'm going to edit your whole code..
Posted By: Dico

Re: trigger switch - 10/20/15 23:46

This code not tested , so test it and tell me if it work or not:

Code:
action door()
{
	while(1)
	{
		if(my.skill2  == 1)
		{
			var tmp_z = my.z + 50;
			while(my.z < tmp_z)
			{
				my.z += 5;
				wait(1);
			}
			my.skill2 = 2;
		}
		if(my.skill2  == 3)
		{
			var tmp_z = my.z - 50;
			while(my.z > tmp_z)
			{
				my.z -= 5;
				wait(1);
			}
			my.skill2 = 0;
		}
		wait(1);
	}
}

action opener()
{
	while(1)
	{
		c_scan(my.x, my.pan, vector(360, 180, t_switch_range), IGNORE_ME | SCAN_ENTS);
		if(you)
		{
			if((you == player)&&(key_enter))
			{
				for(you = ent_next(NULL); you; you = ent_next(you))
				{
					if(you == door_ent)
					{
						if(you.skill1 == my.skill1)
						{
							while(!key_enter){wait(1);}
							if(you.skill2 == 0)
							{
								var trig_percentage = 0;
								while(trig_percentage < 100)  //stops an infinite loop. 
								{
									trig_percentage += 2*time_step;
									ent_animate(me, "on", trig_percentage, ANM_CYCLE);
									wait(1);
								}
								you.skill2 = 1;
							}
							else
							{
								if(you.skill2 == 2)
								{
									var trig_percentage =0;
									while(trig_percentage < 100)  //stops an infinite loop. 
									{
										trig_percentage += 2*time_step;
										ent_animate(me, "on", trig_percentage, ANM_CYCLE);
										wait(1);
									}
									you.skill2 = 3;
								}								
							}
						}
					}
				}
				
			}
		}
		wait(1);
	}
}




to use this code , just add a door and give it action door , then add an opener for that door and give it the action opener.

every door and opener have the same skill1 will be connected , i mean if door have skill1 = 1 , and the opener have in skill1 = 1 then this opener is for this door. you can add lot of doors and you can also open all door with one opener or multiple opener .
Posted By: Anonymous

Re: trigger switch - 10/20/15 23:46

Code:
ENTITY* t_switch;
ENTITY* t_trigger[100]; // set a hard max and do not exceed

var trig_percentage;
var t_switch_range = 150;
var trigger_ids=0;

#define skill10 active_tri

action trigger_switch()
{
	while (!player) {wait (1);} // wait until the player is loaded
	vec_set (my.skill61, my.x); // store the xyz initial position of the switch inside skill61... 63
	// REMOVED BY MAL t_trigger = me; //this is a pointer defining the entity listed at the top
	//	var active_tri = 0; //variable defining where the switch is currently at.
	t_trigger[trigger_ids] = me; // index from 0-499
	trigger_ids+=1;

	my.active_tri = 0; /// active_tri must be moved to a skill not a var

	while(1)
	{
		c_scan(my.x, my.pan, vector(360, 180, t_switch_range), IGNORE_ME | SCAN_ENTS); // each switch scans around it, trying to detect the player
		if (you) // detected an entity?
		{
			if (you == player) // and that entity is the player?
			{
				if (key_enter)
				{
					if(my.active_tri == 0)
					{
						trig_percentage =0;
						while(trig_percentage < 100)  //stops an infinite loop. 
						{
							trig_percentage += 2*time_step;
							ent_animate(t_switch, "on", trig_percentage, ANM_SKIP);
							wait(1);
						}
						my.active_tri = 1;

					}

					else
					{
						trig_percentage = 0;
						while(trig_percentage < 100)  //stops an infinite loop. 
						{
							trig_percentage += 2*time_step;
							ent_animate(t_switch, "off", trig_percentage, ANM_SKIP);
							wait(1);
						}
						my.active_tri = 0;
					}
				}
			}
		}
		wait(1);
	}
}
var door_ids =0; // SET AS GLOB BY MAL 
#define skill10 door_active
action door_or_platform()
{
	wait(3); /// or other wait to make sure level is loaded
	
	door_ids += 1;
	my.skill80 = door_ids;// ADDED SEMI-COL MAL // 1-500 this id matches t_trigger +1. so t_trigger[2] == my.skill80=3;

	my.door_active = 0;

	while(1)
	{

		my.door_active = t_trigger[my.skill80-1].active_tri;
		

		if(my.door_active== 0)
		{ 

my.x += 25
		}
		if(my.door_active== 1)
		{

my.x -= 25
		} 
		wait(1);
	}
}




Ok give it a look over and a test --- Sorry I can't test and i tend to make many minor errors. But I'll check back soon

Mal
Posted By: Anonymous

Re: trigger switch - 10/20/15 23:49

Ok use Dico's way...


Good luck have fun
Mal
Posted By: Anonymous

Re: trigger switch - 10/21/15 00:13

@Dico you have a problem with the pointer below. Only one door at a time can be held in this pointer. So regardless of the skill1 settings, this should only open one door or fail here.

Code:
if(you == door_ent)
					{



Because the door_ent point only holds one reference.

You could use my door_ids idea with your skill1 id

Code:
ENTITY *door_ent[100];

action trigger()
{
 my.skill1 =1;

 ..................
  if(you == door_ent[my.skill1])
					{

...
}

action door()
{
my.skill1 =1;
 door_ent[my.skill1] = my; 

............
}




Also if I follow correct,then there is no need for a second check of skill1. However if you instead use a type id

Code:
if(you.skill79 == 420)// 420 type code id for all doors 
					{



Then the second skill1 check can be used as you wish to open many doors.

Sorry I'm just bored
Mal
Posted By: Dico

Re: trigger switch - 10/21/15 00:19

hi malice , thanks for this note , but what i forget its just ENTITY* door_ent;

and for opener he will search for all doors named door_ent then it will search for its skill 1 and if this skill is the same skill that have the opener then it will open .
Posted By: Dico

Re: trigger switch - 10/21/15 00:21

this code is corrected for what i forget:

Code:
ENTITY* door_ent;
action door()
{
        door_ent = me;
	while(1)
	{
		if(my.skill2  == 1)
		{
			var tmp_z = my.z + 50;
			while(my.z < tmp_z)
			{
				my.z += 5;
				wait(1);
			}
			my.skill2 = 2;
		}
		if(my.skill2  == 3)
		{
			var tmp_z = my.z - 50;
			while(my.z > tmp_z)
			{
				my.z -= 5;
				wait(1);
			}
			my.skill2 = 0;
		}
		wait(1);
	}
}

action opener()
{
	while(1)
	{
		c_scan(my.x, my.pan, vector(360, 180, t_switch_range), IGNORE_ME | SCAN_ENTS);
		if(you)
		{
			if((you == player)&&(key_enter))
			{
				for(you = ent_next(NULL); you; you = ent_next(you))
				{
					if(you == door_ent)
					{
						if(you.skill1 == my.skill1)
						{
							while(!key_enter){wait(1);}
							if(you.skill2 == 0)
							{
								var trig_percentage = 0;
								while(trig_percentage < 100)  //stops an infinite loop. 
								{
									trig_percentage += 2*time_step;
									ent_animate(me, "on", trig_percentage, ANM_CYCLE);
									wait(1);
								}
								you.skill2 = 1;
							}
							else
							{
								if(you.skill2 == 2)
								{
									var trig_percentage =0;
									while(trig_percentage < 100)  //stops an infinite loop. 
									{
										trig_percentage += 2*time_step;
										ent_animate(me, "on", trig_percentage, ANM_CYCLE);
										wait(1);
									}
									you.skill2 = 3;
								}								
							}
						}
					}
				}
				
			}
		}
		wait(1);
	}
}



Thanks Malice
Posted By: Anonymous

Re: trigger switch - 10/21/15 00:23

Dico ENTITY* door_ent; is a pointer that can not be assigned to many doors.

anyways have fun
Mal
Posted By: Anonymous

Re: trigger switch - 10/21/15 01:01

Ok we create a empty ENTITY struct with pointer ENTITY* door_ent;

We create a action call door()

We assign that action to 3 of any of the entity types (model, sprite, map_ent).

Each of these 3 get a automatically assigned a entity struct, and each get a memory pointer. Each are created one at a time.

Each of the 3 is then assigned into the empty pointer struct door_ent=my;
thous - only that last create entity actual shares a memory pointer address with door_ent.

Posted By: Dico

Re: trigger switch - 10/21/15 01:14

Originally Posted By: Malice
Ok we create a empty ENTITY struct with pointer ENTITY* door_ent;

We create a action call door()

We assign that action to 3 of any of the entity types (model, sprite, map_ent).

Each of these 3 get a automatically assigned a entity struct, and each get a memory pointer. Each are created one at a time.

Each of the 3 is then assigned into the empty pointer struct door_ent=my;
thous - only that last create entity actual shares a memory pointer address with door_ent.



Wow man i was sooo stupid , haha (when i create this script my mind it not in scripting ) so i correct the code :

Code:
action door()
{
	my.skill99 = 100; /// its a door
	while(1)
	{
		if(my.skill2  == 1)
		{
			var tmp_z = my.z + 50;
			while(my.z < tmp_z)
			{
				my.z += 5;
				wait(1);
			}
			my.skill2 = 2;
		}
		if(my.skill2  == 3)
		{
			var tmp_z = my.z - 50;
			while(my.z > tmp_z)
			{
				my.z -= 5;
				wait(1);
			}
			my.skill2 = 0;
		}
		wait(1);
	}
}

action opener()
{
	while(1)
	{
		c_scan(my.x, my.pan, vector(360, 180, t_switch_range), IGNORE_ME | SCAN_ENTS);
		if(you)
		{
			if((you == player)&&(key_enter))
			{
				for(you = ent_next(NULL); you; you = ent_next(you))
				{
					if(you.skill99 == 100)
					{
						if(you.skill1 == my.skill1)
						{
							while(!key_enter){wait(1);}
							if(you.skill2 == 0)
							{
								var trig_percentage = 0;
								while(trig_percentage < 100)  //stops an infinite loop. 
								{
									trig_percentage += 2*time_step;
									ent_animate(me, "on", trig_percentage, ANM_CYCLE);
									wait(1);
								}
								you.skill2 = 1;
							}
							else
							{
								if(you.skill2 == 2)
								{
									var trig_percentage =0;
									while(trig_percentage < 100)  //stops an infinite loop. 
									{
										trig_percentage += 2*time_step;
										ent_animate(me, "off", trig_percentage, ANM_CYCLE);
										wait(1);
									}
									you.skill2 = 3;
								}								
							}
						}
					}
				}
				
			}
		}
		wait(1);
	}
}


Posted By: Anonymous

Re: trigger switch - 10/21/15 03:20

@Dico, lol we all been there. I thought maybe it was my poor speaking or my drunk typing.

Awesome method, using two skills is less memory and easier then a array of pointers. I always loved a global id skill system. An id number for every type. I use a decimal myself so 5.5, so 5 for monsters and .5 for werewolves.

UIDN - lol

Thanks
Mal
Posted By: Dico

Re: trigger switch - 10/21/15 10:12

Originally Posted By: Malice
@Dico, lol we all been there. I thought maybe it was my poor speaking or my drunk typing.

Awesome method, using two skills is less memory and easier then a array of pointers. I always loved a global id skill system. An id number for every type. I use a decimal myself so 5.5, so 5 for monsters and .5 for werewolves.

UIDN - lol

Thanks
Mal


Thanks
Posted By: txesmi

Re: trigger switch - 10/21/15 12:42

Hi,
I would advise some changes to enhance the performance and readability.

Use macros in order to rename the relevant skills and get them named into WED.

Code:
#define Door_ID    skill1
...
#define State      skill98
#define Type       skill99
...

// uses: Door_ID
action actDoor ()
{...

...
// uses: Door_ID
action actTrigger ()
{...



Identify the doors linked to the trigger before the loop and save them into a local array, so when the trigger is activated it only goes through the saved entities instead of the whole level entities.

Code:
#define MC_DOOR_MAX_BY_TRIGGER   4 // whatever
action actTrigger ()
{
   // Set starting values
   ... 
   wait(1); // wait a frame, so all level entities are created.
   ENTITY *entDoors[MC_DOOR_MAX_BY_TRIGGER];
   int iDoorCount = 0;
   ENTITY *ent = ent_next ( NULL );
   for ( ; ent!=NULL; ent=ent_next(ent) )
   {
      if ( ent.Type != TYPE_DOOR )
         continue;
      if ( ent.Door_ID != my.Door_ID )
         continue;
      entDoors[iDoorCount] = ent;
      iDoorCount += 1;
   }
   ...
   int i = 0;
   for ( ; i<iDoorCount; i+=1 )
   {
      if ( entDoors[i].State % 2 == 1 )
      {
         entDoors[i].State += 1;
         entDoors[i].State %= 4;
      }
   }
   ...



Use entity groups in order to scan relevant entities exclusively by ignoring the rest of entities on the scan.

Code:
#define GROUP_DOORS     2
#define GROUP_TRIGGERS  3
...

action actTrigger ()
{
   my.group = GROUP_TRIGGERS;
   ...

action actDoor ()
{
   my.group = GROUP_DOORS;
   ...

action actPlayer ()
{
   ...
   c_ignore ( GROUP_DOORS, ..., 0 );
   c_scan ( ...



Execute the scan only when the enter key is pressed, only once and inside the player action loop.

Code:
action actPlayer ()
{
   ...
   var nKeyEnter = 0;
   while (1)
   {
      ...
      if ( key_enter )
      {
         if ( !nKeyEnter )
         {
            nKeyEnter = 1;
            c_ignore ( GROUP_DOORS, ..., 0 );
            c_scan ( ...
            if ( you )
            {
               if ( you.Type == TYPE_TRIGGER ) // May be different scaneable types of entities...
               {
                  if ( you.State % 2 == 1 )
                  {
                     you.State += 1;
                     you.State %= 4;
                  }
               }
            }
         }
      }
      else if ( nKeyEnter )
      {
         nKeyEnter = 0;
      }
      ...



Anyway I would use the scan event for triggers, so the called event performs all the trigger and doors animations. This way there is no need of a continuous loop for each of them. There shall be a loop for animated ones only.

Salud!
Posted By: Anonymous

Re: trigger switch - 10/21/15 20:12

Txesmi - WOW! - Yes this is exactly what the EVENT system is built for, and it run's engine level in the moment/frame as the scan..

I think we all made the newbie's brain explode ...lol.
Posted By: Dico

Re: trigger switch - 10/21/15 20:47

Wow new method , you re right Txesmi using more than loop and with c_scan can slow down the game if it has lot of models laugh

the corrected code to use just one c_scan and one while loop in player :

Code:
ENTITY* tmp_opener;
var max_doors_z = 100;
action door()
{
	my.skill99 = 100; /// its a door
}

action opener()
{
	my.skill99 = 99; /// its an opener
}

function player_scan_openers()
{
	if((key_enter)) // do the scan only when button enter pressed
	{	
		c_scan(my.x, my.pan, vector(360, 0, 300), IGNORE_ME | SCAN_ENTS);
		if(you)
		{
			if(you.skill99 == 99)
			{
				tmp_opener = you;
				for(you = ent_next(NULL); you; you = ent_next(you))
				{
					if(you.skill99  == 100)
					{
						if(tmp_opener.skill1 == you.skill1)
						{
							if(you.skill2 == 0)
							{
								you.skill2 = 1;								
								var trig_percentage = 0;
								while(trig_percentage < 100) 
								{
									trig_percentage += 10 * time_step;
									ent_animate(tmp_opener, "on", trig_percentage, ANM_CYCLE);
									wait(1);
								}
								
								var tmp_z = you.z + 100;
								while(you.z < tmp_z)
								{
									you.z += 5;
									wait(1);
								}
								you.skill2 = 2;
							}
							else
							{
								if(you.skill2 == 2)
								{
									you.skill2 = 1;
									var trig_percentage =0;
									while(trig_percentage < 100)
									{
										trig_percentage += 10 * time_step;
										ent_animate(tmp_opener, "off", trig_percentage, ANM_CYCLE);
										wait(1);
									}
																		
									var tmp_z = you.z - 100;
									while(you.z > tmp_z)
									{
										you.z -= 5;
										wait(1);
									}
									you.skill2 = 0;
								}								
							}
						}
					}
				}
			}
		}
	}
}




Not tested
Posted By: mschoenhals

Re: trigger switch - 12/07/15 16:48

Hi all,

I've got the trigger system working the way I need it but I'm having an issue with integrating it into the Multiplayer Game Template. I know I need to identify the 'player' who is hitting the trigger but I'm unsure how to do so. I think the player identity is in this code:
Code:
{
			if(my.player_id > 0 && !my.client_id) str_cpy(str_pl_names[my.player_id-1],"Server Player");
		}
		mp_random_assign(my);



But I'm unsure how to call that up in the trigger. Right now I keep getting an undeclared identifier error. The above code creates an unique id for each multiplayer, right? How do I look for that in the trigger code:

Code:
{
		c_scan(my.x, my.pan, vector(360, 180, t_switch_range), IGNORE_ME | SCAN_ENTS);
		if(you)
		{
			if((you == ent_players[i]])&&(key_space))
			{
				for(you = ent_next(NULL); you; you = ent_next(you))
				{
					if(you.skill99 == 100)
					{
						if(you.skill1 == my.skill1)



Any light you can shine on this one would be greatly appreciated. laugh
Posted By: KilljoyHeathen

Re: trigger switch - 12/07/15 18:31

This is a very informative post...The weatlh of info here is amazing...

*Drops to knee's in tears*
*Wayne's World flashback*
*We're not worthy, we're not worthy*

...Sorry I'm sick, and like Malice pointed out newbies head on the verge of exploding here...haha
Posted By: EpsiloN

Re: trigger switch - 12/07/15 20:02

You shouldnt jump to mp yet...

But, if you're determined, read my mp tutorial to understand the concepts. It is very different from single player.

Link in signature (or contributions section).
Posted By: mschoenhals

Re: trigger switch - 12/08/15 17:25

Thanks KilljoyHeathen,
That was...interesting but yet, not all that helpful. Although I do appreciate a post from a fellow newbie Canadian. laugh
Posted By: mschoenhals

Re: trigger switch - 12/08/15 17:26

I think that's sound advice EpsiloN. Unfortunately, I'm committed to this one.
Posted By: EpsiloN

Re: trigger switch - 12/08/15 20:39

If thats the case, put everything on hold and read my tutorial, so that you can see the differences in design, convert yours and plan ahead. Shouldnt take you more than 2 hours.

MP isnt difficult at all, it just needs a different approach and a little planning...

PS.: If something isnt clear, dont hesitate to contact me. I'd be happy to bring you up to speed on MP if you're willing to learn. laugh
Posted By: mschoenhals

Re: trigger switch - 12/08/15 22:53

Thanks EpsiloN; I really appreciate the input. laugh
Posted By: Anonymous

Re: trigger switch - 12/09/15 00:13

Quote:
PS.: If something isnt clear, dont hesitate to contact me. I'd be happy to bring you up to speed on MP if you're willing to learn.


You will be needing to do that. I got lost following the tutorial and the 'thinking' shift for MP. Simple things for people who have the full understanding of MP are in fact Complex for others. Using these tutorials gives you something to work with, however I quickly discovered I didn't learn how to create and innovate my own ideas. I never correctly added my race cars drift and slide into any of the simple bit/key sends used. Other uses like why my shaders only worked on the server - Not issue of his tutorial but I lack of understanding.

However, EpsiloN is quite qualified to instruct you.
Posted By: EpsiloN

Re: trigger switch - 12/09/15 11:34

Actually, I went through half of the tutorial last night, and I did notice what isn't explained the way it should. I sometimes describe things confusingly, because I was rushing to catch up the explanations on the actual development.

And the poorly described part is the most important one! (Client-Server architecture) I don't know why I've missed this before...

I will revise it some day, when I get the time. For now, anyone interested is welcome on my Private Messages page for a better description on the 'thinking' part laugh
Posted By: mschoenhals

Re: trigger switch - 12/10/15 16:38

Thanks EpsiloN. I'm going through the tutorial this morning.
© 2024 lite-C Forums