|
Re: flag event
[Re: Abarudra]
#427636
08/11/13 02:51
08/11/13 02:51
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
Do i realy have to add a while loop just to check once for if(my.flagX) The while loop is one possibility. or is it possible to have something like an event-function that is only triggered when a flag gets set to 1? Not natively. But you can easily call that function every time after manipulating the skill:
my_special_ent->skill1 += 1;
skill_was_changed(my_special_ent);
If you're doing this frequently you can also write a setter function:
void set_skill1(ENTITY* ent,fixed value)
{
if (!ent)
return;
ent->skill1 = value;
skill_was_changed(ent);
}
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Re: flag event added - code example
[Re: Uhrwerk]
#427638
08/11/13 08:52
08/11/13 08:52
|
Joined: Mar 2012
Posts: 44
Abarudra
OP
Newbie
|
OP
Newbie
Joined: Mar 2012
Posts: 44
|
Thank you for your ideas, i will try it. You are right i should have added more details. I have this situation. The entities i mentioned are remote triggered explosives. The action sets several skills set the damage, delay, aoe etc. I store the pointer of this entity in a skill of the detonator-entity. I want to detonate it by setting one of its flags to 1 and then execute the explosion function. The problem is this function contains an ent_create function, and it is necessary that the you pointer for the created entity is set to the explosive and not to the detonator. I will try to get my code in a readable state and post it here. Ok i dont have access to my computer right now, so i will just post a general example -- EDIT --
1. The Detonator
void trigger_explo(ENTITY* explosive) // Will set the Flag of the saved entity to 1
{
[...]
set(explosive,FLAG1);
[...]
}
action detonator() // Has stored all explosives-pointer in its entity-skills
{
[...]
my.skill1 = spawn_explosive(); // create explosive and save its pointer
while(1)
{
[...]
if(i_want_to detonate) // check if eg. button for detonation is pressed
{
trigger_explo((ENTIY*) my.skill1);
[...]
}
wait(1);
}
}
2. The Explosive
void detonate_ent() // aoe damage and shrapnelspawning
{
[...]
ent_create("shrapnel.mdl",my.x,shrapnel_func);
//you.parent = me;
}
void explosive_ent()
{
[...]
set_stats_from_other_source(source); // With this function i save the stats of the explosive and the generated shrapnels in skills of this entity
while(1)
{
if(is(my,FLAG1)){detonate_ent();} // i just would like to avoid many entities with short loops that check only for one changing flag
wait(1);
}
}
3. The Shrapnel
void set_stats_from(ENTITY* from) // all properties of the shrapnel are save in skills in the explosive_entiy
{
my.skill10 = from.skill10;
}
void shrapnel_func()
{
set_stats_from(you); // get stats from your creator
[...]
while(1)
{
do_stuff();
wait(1);
}
}
I know i can avoid the whileloop if i run detonate_ent() inside the detonator action. But then you would point to the detonator and not the explosive.
It would work if i save the stats in detonator.skills instead of explosive.skills, but i want to avoid that if possible, cause i dont have enough free skills if i want to support the number of explosives i need.
I hope my idea is now better to understand and i thank you for ideas / answers. Regards
Last edited by Abarudra; 08/11/13 13:29. Reason: Codeexample added
|
|
|
Re: flag event added - code example
[Re: Abarudra]
#427648
08/11/13 14:38
08/11/13 14:38
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
Set the you pointer yourself to the explosive, then call detonate_ent(). Something like this should work:
void trigger_explo(ENTITY* explosive) // Will set the Flag of the saved entity to 1
{
wait(1); // This is important as it returns to the caller, and gives us the chance to alter the you pointer opaque to the caller but visible to our callees
you = explosive;
detonate_ent();
}
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
Re: flag event added - code example
[Re: WretchedSid]
#427649
08/11/13 14:48
08/11/13 14:48
|
Joined: Mar 2012
Posts: 44
Abarudra
OP
Newbie
|
OP
Newbie
Joined: Mar 2012
Posts: 44
|
Thank you JustSid, i will give it a try. I had sth. similar before but i forgot the "wait(1);" My approach was this
ENTITY* created = ent_create(...);
created.skill1 = explosive;
But it crashed because i checked the skill before it had the right value.
|
|
|
Re: flag event added - code example
[Re: Abarudra]
#427652
08/11/13 15:44
08/11/13 15:44
|
Joined: Mar 2012
Posts: 44
Abarudra
OP
Newbie
|
OP
Newbie
Joined: Mar 2012
Posts: 44
|
Ok i have tried it. But it seems i have interpreted your code wrong or i'm just stupid. If i set the you pointer before the ent_create, shouldn't it be overwritten? I wrote this code to check it
#include <acknex.h>
#include <atypes.h>
#include <default.c>
void bomb()
{
my.skill3 = 100;
}
void shard()
{
wait(1); // <-- added
//my.skill1 = you.skill3;
my.skill1 = my.parent.skill3; // <-- added
while(1)
{
my.pan -= my.skill1*time_step;
wait(1);
}
}
void detonate_ent(ENTITY* e)
{
//ent_create(CUBE_MDL,vector(my.x,my.y,my.z+200),shard);
ENTIY* created = ent_create(CUBE_MDL,vector(my.x,my.y,my.z+200),shard); //<-- added
created.parent = e; // <-- added
}
void trigger_ent(ENTITY* e)
{
//wait(1);
//you=e;
// detoante_ent(you);
detonate_ent(e); //<-- added
}
void detonator()
{
ENTITY* test= ent_create(CUBE_MDL,vector(0,100,0),bomb);
my.skill3 = 1;
while(1)
{
if(key_d){trigger_ent(test);return;}
wait(1);
}
}
function main()
{
video_switch(8,0,2);
level_load(NULL);
vec_set(screen_color,vector(255,0,0)); // blau
wait(3);
fps_max = 60;
ent_create(CUBE_MDL,nullvector,detonator);
camera.x -= 1000;
}
The shard in this example is rotating slowly (as expected) cause its skill1 is set to 1 and not to 100 as i need it to be. Ok i think i was too fast. I made a view changes and now i think its working for now. The removed parts are commented and the new lines are marked with "//<-- added"
Last edited by Abarudra; 08/11/13 15:46.
|
|
|
|