2 registered members (Akow, tomaslolo),
1,536
guests, and 12
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: trigger switch
[Re: Dico]
#455482
10/21/15 00:23
10/21/15 00:23
|
Malice
Unregistered
|
Malice
Unregistered
|
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
|
Malice
Unregistered
|
Malice
Unregistered
|
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
Senior Member
|
Senior Member
Joined: Feb 2012
Posts: 371
|
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 :
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
|
Malice
Unregistered
|
Malice
Unregistered
|
@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
Senior Member
|
Senior Member
Joined: Feb 2012
Posts: 371
|
@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
Serious User
|
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.
#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.
#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.
#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.
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
|
Malice
Unregistered
|
Malice
Unregistered
|
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
Senior Member
|
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 the corrected code to use just one c_scan and one while loop in player :
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
mschoenhals
OP
Member
|
OP
Member
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:
{
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:
{
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.
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|