About Store Forum Documentation Contact
Donations:
392$/mo



Post Reply 
Sry, another question
Author Message
dbuman Offline
Member

Post: #1
Sry, another question
I am trying to set up a respawn for monsters, and I was wondering how would the best way be?

right now I have the system that sets a flt and then counts down with time.d(), but it wont cause my respawn().

heres my code that causes a mobs death. so far ragdollenable works because i see the monster fall down and no longer attack, i have living set to 0 and used as a condition for the monster to attack and run after you. deletemob is the factor and the number is supposed to equal seconds. plr.attackedmob is a flt which determines if the player attacked this monster, and causes the player to gain experience based on the monster's defense and health. I have a condition set so it calls my level up process. everything in die() works as far as I know.:

Code:
void AI::die()
{  
   Player &plr = Players[i];
   ragdollEnable();
   living = 0;
   deletemob = 10;
   if(plr.attackedmob==1)
   { plr.attackedmob = 0;
    
   experience = (maxhealth+defense) - plr.attackdmg;
   plr.experience+= experience;
   if(plr.experience >= plr.nextlevel)
   {
      plr.Levelup();
   }}
}

then the timer to cause respawn() in AI::update(). This is where Im having the problem, I feel like the timer isnt working appropriately, not counting down and causing respawn()

Code:
if(Time.curTime() - deletemob >= 1)
         {
           deletemob = Time.curTime() - deletemob;
            }
       if(deletemob <= 0)
       {
          respawn();
       }

and finally the respawn code, which moves the ragdoll and disables the ragdoll so the monster can resume AI commands.

Code:
void AI::respawn()
{
  
      ragdollDisable();
      pos(ctrl_pos);
      living = 1;
      health = maxhealth;
}

if headers are a concern here are the definitions:
Code:
flt experience;
   flt maxhealth;
   flt deletemob;
   flt defense,
       attackdmg,
       level;
   Vec ctrl_pos;
   void respawn();

Should the void be virtual?
WOOPS!? lol I seemed to have fixed it

I set a flt pointintime then when it calls die() it sets pointintime=Time.CurTime()

then i have a code which causes the accurate timer

Code:
if(living == 0)
         {if(Time.curTime() - pointintime >= 20)
         {

          respawn();
          pointintime = 0;
         }}

so all is fixed, the mob respawns at 20 seconds after death. Just need to know how to delete the mob or make it disappear after a few seconds so it doesnt look like it just moved.

I can keep the coding as is, but id like to make the monster disappear if anyone can help me with a code like that... Im thinking it may be comprised of changing its pos to (0,1000000000000,0) to make people never able to see it. hmmm... another issue resolved prematurely i suppose until the next issue. I hope this helps someone.
(This post was last modified: 06-25-2011 02:57 AM by dbuman.)
06-25-2011 02:41 AM
Find all posts by this user Quote this message in a reply
Post Reply