Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/25/24 10:20
Trading Journey
by howardR. 04/24/24 20:04
M1 Oversampling
by Petra. 04/24/24 10:34
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (AndrewAMD, Quad, EternallyCurious, 1 invisible), 726 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 4 of 5 1 2 3 4 5
Re: trigger switch [Re: Dico] #455482
10/21/15 00:23
10/21/15 00:23

M
Malice
Unregistered
Malice
Unregistered
M



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

anyways have fun
Mal

Re: trigger switch [Re: ] #455484
10/21/15 01:01
10/21/15 01:01

M
Malice
Unregistered
Malice
Unregistered
M



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.


Last edited by Malice; 10/21/15 01:02.
Re: trigger switch [Re: ] #455485
10/21/15 01:14
10/21/15 01:14
Joined: Feb 2012
Posts: 371
Dico Offline
Senior Member
Dico  Offline
Senior Member

Joined: Feb 2012
Posts: 371
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);
	}
}



Last edited by Dico; 10/21/15 10:13.
Re: trigger switch [Re: Dico] #455491
10/21/15 03:20
10/21/15 03:20

M
Malice
Unregistered
Malice
Unregistered
M



@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

Re: trigger switch [Re: ] #455493
10/21/15 10:12
10/21/15 10:12
Joined: Feb 2012
Posts: 371
Dico Offline
Senior Member
Dico  Offline
Senior Member

Joined: Feb 2012
Posts: 371
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

Re: trigger switch [Re: Dico] #455496
10/21/15 12:42
10/21/15 12:42
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
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!

Re: trigger switch [Re: txesmi] #455526
10/21/15 20:12
10/21/15 20:12

M
Malice
Unregistered
Malice
Unregistered
M



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.

Last edited by Malice; 10/21/15 20:14.
Re: trigger switch [Re: ] #455528
10/21/15 20:47
10/21/15 20:47
Joined: Feb 2012
Posts: 371
Dico Offline
Senior Member
Dico  Offline
Senior Member

Joined: Feb 2012
Posts: 371
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

Last edited by Dico; 10/21/15 21:01.
Re: trigger switch [Re: Dico] #456740
12/07/15 16:48
12/07/15 16:48
Joined: Aug 2013
Posts: 101
M
mschoenhals Offline OP
Member
mschoenhals  Offline OP
Member
M

Joined: Aug 2013
Posts: 101
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

Re: trigger switch [Re: mschoenhals] #456741
12/07/15 18:31
12/07/15 18:31
Joined: Feb 2015
Posts: 9
Alberta, Canada
K
KilljoyHeathen Offline
Newbie
KilljoyHeathen  Offline
Newbie
K

Joined: Feb 2015
Posts: 9
Alberta, Canada
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

Page 4 of 5 1 2 3 4 5

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1