1 registered members (Akow),
1,365
guests, and 7
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
ent_remove & ent_create
#357008
02/05/11 07:11
02/05/11 07:11
|
Joined: Sep 2010
Posts: 97
carla_mariz
OP
Junior Member
|
OP
Junior Member
Joined: Sep 2010
Posts: 97
|
hi.. how can i make an object remove when it is eaten and how can i make it appear again after 15 sec.? i tried to use ent_remove and ent_create but the program is crashing. im trying to put it in this script:
if(froze == 1)
{
set(my, PASSABLE);
set(my, UNLIT | BRIGHT | PASSABLE);
my.skin = 2;
my.lightrange = 200;
my.ambient = 100;
my.blue = 200;
while (vec_dist(player.x, my.x) > 80) // wait until the player comes close
{
wait (1);
}
set(my, INVISIBLE);
ent_remove(my);
wait(-15);
ent_create(ghost, vector(-608, 1072, 780), ghost1);
froze = 0;
my.skin = 1;
my.lightrange = 0;
my.ambient = 0;
my.state = 0;
}
@ this part of the code, what i want the enemy to do is to freeze for 15 sec. whenever the player gets an object. @ this point, the enemy can now be eaten by the player. and thats my problem, whenever the player ate the enemy it will be invisible and removed but it was never been created. pls someone help me..thanks
|
|
|
Re: ent_remove & ent_create
[Re: carla_mariz]
#357014
02/05/11 08:27
02/05/11 08:27
|
Joined: Apr 2005
Posts: 4,506 Germany
fogman
Expert
|
Expert
Joined: Apr 2005
Posts: 4,506
Germany
|
When you remove an entity its function will terminated after the next wait cycle.
You could try to make it PASSABLE as well, without removing it.
Also you do a ent_remove(my), but you try to use it afterwards. Won´t work, because my is empty then.
no science involved
|
|
|
Re: ent_remove & ent_create
[Re: carla_mariz]
#357016
02/05/11 08:40
02/05/11 08:40
|
Joined: Jan 2011
Posts: 120 United States
Logan
Member
|
Member
Joined: Jan 2011
Posts: 120
United States
|
Your problem is that you are using the "my" pointer after you use ent_remove(my). This is the number one thing you have to be careful with about ent_remove. You can never access that entity via pointer again, because it no longer exists--so if you ent_remove(my), and then try to set my.skin, my.lightrange, my.ambient etc a few lines later, the engine doesn't know what you're talking about, because "my" no longer exists.
It looks like you assumed ent_create() restores the "my" pointer. Easy mistake. But it doesn't, unless you specifically set it.
my = ent_create(ghost, vector(-608, 1072, 780), ghost1);
OR
My recommendation is that you do not use ent_remove or ent_create at all. These commands are slow and make things unnecessarily complicated--like with the pointers thing I was describing above. It'd be easier to just set the entity INVISIBLE and PASSABLE for 15 seconds, so it looks like he's gone, without actually removing him. Save ent_remove for the times where he's really NEVER going to appear again.
One more thing, if you stick with the ent_remove technique, you may have to set proc_mode = PROC_GLOBAL at the beginning of the function, so the function doesn't end right when you remove the my entity.
|
|
|
Re: ent_remove & ent_create
[Re: carla_mariz]
#357019
02/05/11 08:50
02/05/11 08:50
|
Joined: Jan 2011
Posts: 120 United States
Logan
Member
|
Member
Joined: Jan 2011
Posts: 120
United States
|
set(my, INVISIBLE); // sets the entity invisible reset(my, INVISIBLE); // sets the entity visible Just turn INVISIBLE on and off--stay away from VISIBLE, that's another story.
|
|
|
Re: ent_remove & ent_create
[Re: Logan]
#357024
02/05/11 09:10
02/05/11 09:10
|
Joined: Sep 2010
Posts: 97
carla_mariz
OP
Junior Member
|
OP
Junior Member
Joined: Sep 2010
Posts: 97
|
oh no..another problem again..hmmmmnn.. my code now looked like this:
if(froze == 1)
{
set(my, PASSABLE);
set(my, UNLIT | BRIGHT | PASSABLE);
my.skin = 2;
my.lightrange = 200;
my.ambient = 100;
my.blue = 200;
while (vec_dist(player.x, my.x) > 80) // wait until the player comes close
{
wait (1);
}
set(my, INVISIBLE);
wait(-15);
reset(my, INVISIBLE);
froze = 0;
my.skin = 1;
my.lightrange = 0;
my.ambient = 0;
my.state = 0;
}
the ghosts freezes but if they are not eaten after 15 sec, they are still not moving. i think the problem is in the while because the rest of the lines under it is not terminated.
|
|
|
|