Author Topic: heartbeats and skills  (Read 4886 times)

Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
heartbeats and skills
« on: September 12, 2006, 09:08:38 AM »
code:


#include <lib.h>
#include <daemons.h>
#include <damage_types.h>

inherit LIB_DAEMON;
int counter = 0;

void heart_beat()
 {
    counter++;
    if(counter < 20) return;
    counter = 0;
 }

 mixed cmd(string str)
    {
    object target;
    string name;
    int x;

    if(!str || str == "")
    {
     write("Critical strike whom?");
     return 1;
    }

    if(!target = present(str, environment(this_player())))
       {
        write("They're not here.");
        return 1;
       }
    if(!living(target))
       {
        write("You can only do that to living beings.");
       }
     else name = target->GetName();
 
    switch(counter)
      {
       case 0:
                       write("You begin waiting for the perfect moment to strike "+ name+".");
          say(this_player()->GetName()+" begins moving back and forth glancing over"+ " "+name+" looking for the perfect moment to strike!",({target}));
          tell_object(target,this_player()->GetName()+" is moving back and forth observing your movements!");
        case 3:
        write("You viciously strike "+name+" with your weapon.");
          say(this_player()->GetName()+" strikes +"+name+" viciously with his weapon!",({target}));
          tell_object(target,this_player()->GetName()+" strikes you with his weapon!!!");
          target->eventReceiveDamage(this_player(),BLUNT,(100 *5),0,({"torso"}));
        target->AddEnemy(this_player());      
      case 6:
        write( name +" bleeds from a wound in his chest.");
          say( name + " bleeds from a gaping wound in his chest!",({target}));
          tell_object( "You bleed from a gaping wound in your chest!!!");
        target->eventReceiveDamage(this_player(),BLUNT,(10 *5),0,({"torso"}));
      case 9:
        write( name +" bleeds from a wound in his chest.");
          say( name + " bleeds from a gaping wound in his chest!",({target}));
          tell_object( "You bleed from a gaping wound in your chest!!!");
        target->eventReceiveDamage(this_player(),BLUNT,(10 *5),0,({"torso"}));
        case 12:
        write( name +" bleeds from a wound in his chest.");
          say( name + " bleeds from a gaping wound in his chest!",({target}));
          tell_object( "You bleed from a gaping wound in your chest!!!");
        target->eventReceiveDamage(this_player(),BLUNT,(10 *5),0,({"torso"}));
        default:
        write( name +" stops bleeding.");
          say( name + " stops bleeding!",({target}));
          tell_object( "You stop!!!");
       }

    }

void help() {
    message("help", "Syntax: critical <target>\n\n"
      "Get medieval on your target.\n\n",
      this_player());
}






Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
heartbeats and skills
« Reply #1 on: September 12, 2006, 09:09:03 AM »
The problem is there is no delay. I thought this was what someone suggested I use, where did I go wrong?

Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
heartbeats and skills
« Reply #2 on: September 12, 2006, 09:09:49 AM »

> critical guard

You begin waiting for the perfect moment to strike Guard.

You viciously strike Guard with your weapon.

Guard collapses to the ground.

Guard bleeds from a wound in his chest.

---

*call_other() couldn't find object

Object: /secure/sefun/sefun at /secure/sefun/communications.c:23



'<function>' at /secure/save/creators/c/capo (<function>) at /:0

'cmdAll' at /secure/save/creators/c/capo (/lib/command.c) at line 93

'cmd' at /cmds/players/critical at line 52

'tell_object' at /secure/sefun/sefun at /secure/sefun/communications.c:23

Trace written to /log/runtime


Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1020
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
heartbeats and skills
« Reply #3 on: September 12, 2006, 09:29:43 AM »

You're going to have a hard time doing this inside the cmd, and in fact,

I would strongly urge you not to. The problem is that there is only

one copy of the command loaded into memory at a time, and if

it's busy servicing your attack, I don't know what will happen

if someone else tries to use it.



I would therefore suggest avoiding delays in commands,

when possible.



It looks like you're setting up a "lasting damage" effect on the victim.



Since it does not require continuous action from the killer,

I would suggest using an invisible object for this. Put the heart_beat

in the object, put the object on the victim, have the object occasionally

hurt the victim, then destruct it when the time is up.



The bonus object in the alpha lib is an example of an invisible

object with a timed duration.



http://dead-souls.net/code/alpha/ds2.1a7/lib/lib/bonus.c">http://dead-souls.net/code/alpha/ds2.1a7/lib/lib/bonus.c



Offline tigwyk

  • Acquaintance
  • *
  • Posts: 45
    • View Profile
heartbeats and skills
« Reply #4 on: September 12, 2006, 09:34:47 AM »

That's the same error I get when I use your command. I found that it's because there are no "break;" statements after the end of each "case" in your switch.



Add a break; as the last line on each case of the switch, and it'll go through the code bit by bit. A new problem arises, though, after fixing this bug.


Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1020
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
heartbeats and skills
« Reply #5 on: September 12, 2006, 11:20:21 AM »

Capo, it would work something like this.



The invis object is coded to hang out in a person's

inventory. Every now and then, it causes damage,

and sends the appropriate messages to the person,

or the room, whatever.



The way it gets there is by having something like this

in your cmd():



object thing;

thing = new("/domains/foo/obj/devastate.c");

thing->eventMove(victim);



Where "devastate" is the object that is coded to be

invisible, do occasional damage, and self destruct

after a certain time.



-Crat



Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
heartbeats and skills
« Reply #6 on: September 12, 2006, 11:53:38 AM »
Hrm... Ok I think I get the idea but Im still not there yet.  This is what I have, two files... one in cmds/players called critical1.c and another in foo/obj called critical_wound.c



When I run the command I get this:



> critical1 fighter

You begin waiting for the perfect moment to strike Fighter.

You viciously strike Fighter with your weapon.

Try "help creator commands" for a list of some creator commands. (dont know why this keeps showing up)



It does 50 hp of damage to the npc (which it should)... but then it does no damage when the object gets transfered.  Help?



Here is critical1.c



code:





#include <lib.h>
#include <daemons.h>
#include <damage_types.h>

inherit LIB_DAEMON;

 mixed cmd(string str)
 {
    object target;
    string name;
    int x;
    object thing;
    thing = new("/domains/foo/obj/critical_wound.c");

    if(!str || str == "")
    {
     write("Critical strike whom?");
     return 1;
    }

    if(!target = present(str, environment(this_player())))
       {
        write("They're not here.");
        return 1;
       }
    if(!living(target))
       {
        write("You can only do that to living beings.");
       }
    else name = target->GetName();
        {
      write("You begin waiting for the perfect moment to strike "+ name+".");
       say(this_player()->GetName()+" begins moving back and forth glancing over"+ " "+name+" looking for the perfect moment to strike!",({target}));
       tell_object(target,this_player()->GetName()+" is moving back and forth observing your movements!");
       
      GetName()->set_heart_beat(5);
     
      write("You viciously strike "+name+" with your weapon.");
       say(this_player()->GetName()+" strikes +"+name+" viciously with his weapon!",({target}));
       tell_object(target,this_player()->GetName()+" strikes you with his weapon!!!");
       target->eventReceiveDamage(this_player(),BLUNT,(10 *5),0,({"torso"}));
      thing->eventMove(target);
         }
      }
       
void help()
  {
    message("help", "Syntax: critical <target>\n\n"
      "Get medieval on your target.\n\n",
      this_player());
  }





And here is critical_wound.c



code:


#include <lib.h>
#include <damage_types.h>
#include <vendor_types.h>

inherit LIB_ITEM;

void create()
{
    ::create();
    SetId(({"critical_wound"}));
    SetInvis(1);
    SetMass(0);
}

void heart_beat()

 {
    object ob;
    ob=environment();
   
   if(!living(ob))
     {
      this_object()->eventDestruct();
      return;
     }
   
    tell_object(ob,"You bleed heavily from your horrible wounds.");
    tell_room(environment(ob), ob->GetName()+ " bleeds heavily from "+possessive(environment())+" horrible wounds.",environment());
    ob->eventReceiveDamage(this_object(),TRAUMA,dam,10,"torso");
    return;
 }







Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1020
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
heartbeats and skills
« Reply #7 on: September 12, 2006, 11:58:51 AM »

add this to create():



set_heart_beat(5);





also, your cmd() function needs to

return 1, else you'll get that error (or possibly

you won't get it, and the input will be caught by another

command or object.)



Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
heartbeats and skills
« Reply #8 on: September 12, 2006, 12:31:39 PM »
Ok... Just wanted to keep you all up to date on this (so if someone comes along trying to learn, they can go from here)... this is what I have.  It still has two problems:



1- cmds/players/critical.c == Does not pause between command initialization and impact.



2- critical_wound.c == target will bleed to death.



> critical fighter

You begin waiting for the perfect moment to strike Fighter.

You viciously strike Fighter with your weapon.



>Fighter bleeds heavily from his horrible wounds.

Fighter bleeds heavily from his horrible wounds.

Fighter bleeds heavily from his horrible wounds.

Fighter bleeds heavily from his horrible wounds.

Fighter bleeds heavily from his horrible wounds.

Fighter bleeds heavily from his horrible wounds.

Fighter bleeds heavily from his horrible wounds.

Fighter bleeds heavily from his horrible wounds.

Fighter bleeds heavily from his horrible wounds.

Fighter bleeds heavily from his horrible wounds.

Fighter bleeds heavily from his horrible wounds.

Fighter bleeds heavily from his horrible wounds.

Fighter bleeds heavily from his horrible wounds.

Fighter bleeds heavily from his horrible wounds.

Fighter bleeds heavily from his horrible wounds.

Fighter bleeds heavily from his horrible wounds.

Fighter bleeds heavily from his horrible wounds.

Fighter bleeds heavily from his horrible wounds.

Fighter bleeds heavily from his horrible wounds.

Fighter bleeds heavily from his horrible wounds.

Fighter bleeds heavily from his horrible wounds.

Fighter bleeds heavily from his horrible wounds.

Fighter bleeds heavily from his horrible wounds.

Fighter bleeds heavily from his horrible wounds.

Fighter collapses to the ground.

Fighter bleeds heavily from his horrible wounds.

Fighter bleeds heavily from his horrible wounds.

Fighter bleeds heavily from his horrible wounds.

              ********************  [death]  ************************

   

   

                        Fighter has been slain by 0.

   

   

                ******************************************************







code:




#include <lib.h>
#include <damage_types.h>
#include <vendor_types.h>

inherit LIB_ITEM;

void create()
{
    item::create();
    SetId(({"critical_wound"}));
    SetInvis(1);
    SetMass(0);
    set_heart_beat(5);
}

void heart_beat()

 {
    object ob;
    ob=environment();

        if(!living(ob))
          {
           this_object()->eventDestruct();
           return;
          }

    tell_object(ob,"%^RED%^You bleed heavily from your horrible wounds.%^RESET%^");
    tell_room(environment(ob), ob->GetName()+ " %^RED%^bleeds heavily from "+possessive(environment())+" horrible wounds.%^RESET%^",environment());
    ob->eventReceiveDamage(this_object(),TRAUMA,15,0,"torso");
    return;
 }





code:


#include <lib.h>
#include <daemons.h>
#include <damage_types.h>

inherit LIB_DAEMON;
int counter = 0;

 mixed cmd(string str)
 {
    object target;
    string name;
    int x;
    object thing;
    thing = new("/domains/foo/obj/critical_wound.c");

    if(!str || str == "")
    {
     write("Critical strike whom?");
     return 1;
    }

    if(!target = present(str, environment(this_player())))
       {
        write("They're not here.");
        return 1;
       }
    if(!living(target))
       {
        write("You can only do that to living beings.");
       }
    else name = target->GetName();
             {
           write("You begin waiting for the perfect moment to strike "+ name+".");
           say(this_player()->GetName()+" begins moving back and forth glancing over"+ " "+name+" looking for the perfect moment to strike!",({target}));
           tell_object(target,this_player()->GetName()+" is moving back and forth observing your movements!");

           this_player()->set_heart_beat(5);

           write("You viciously strike "+name+" with your weapon.");
           say(this_player()->GetName()+" strikes +"+name+" viciously with his weapon!",({target}));
           tell_object(target,this_player()->GetName()+" strikes you with his weapon!!!");
           target->eventReceiveDamage(this_player(),BLUNT,(10 *5),0,({"torso"}));
           thing->eventMove(target);

         }
  return 1;
   }

void help()
  {
    message("help", "Syntax: critical <target>\n\n"
      "Get medieval on your target.\n\n",
      this_player());
  }

Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1020
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
heartbeats and skills
« Reply #9 on: September 12, 2006, 12:35:11 PM »

You'll want some sort of counter to count down every

heart_beat(). For example, my bonus.c example does this:



void heart_beat(){

    if(Duration) Duration--;

    else eventDestruct();

}



 



also, in your damage function, you

might want to check to make sure the target is alive:



if(environment(this_object()) && living(environment(this_object()))) {}


Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
heartbeats and skills
« Reply #10 on: September 12, 2006, 12:56:08 PM »
code:




#include <lib.h>
#include <damage_types.h>
#include <vendor_types.h>

inherit LIB_ITEM;

int Duration = 20;

void create()
{
    item::create();
    SetId(({"critical_wound"}));
    SetInvis(1);
    SetMass(0);
    set_heart_beat(5);
}


void heart_beat()

 {
    object ob;
    ob=environment();


        if(!living(ob))
          {
           this_object()->eventDestruct();
           return;
          }
    if(Duration) Duration--;
       tell_object(ob,"%^RED%^You bleed heavily from your horrible wounds.%^RESET%^");
       tell_room(environment(ob), ob->GetName()+ " %^RED%^bleeds heavily from "+possessive(environment())+" horrible wounds.%^RESET%^",environment());
       ob->eventReceiveDamage(this_object(),TRAUMA,15,0,"torso");
   else ::eventDestruct();
    return;
 }

int eventDestruct()
   {
    this_object()->eventMove("domains/default/room/furnace.c");
    return ::eventDestruct();
   }




Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1020
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
heartbeats and skills
« Reply #11 on: September 12, 2006, 12:59:36 PM »

Cratylus <ds> you need brackets



Cratylus <ds> if(thingy){ blahdyblah; } else foo();



Cratylus <ds> that else is hanging out there too far from the if



Cratylus <ds> you'll want to bracket the lines in between



Offline capo

  • Friend
  • **
  • Posts: 70
    • View Profile
heartbeats and skills
« Reply #12 on: September 12, 2006, 01:01:56 PM »
code:
<#include

#include <damage_types.h>

#include <vendor_types.h>



inherit LIB_ITEM;



int Duration = 20;



void create()

{

    item::create();

    SetId(({"critical_wound"}));

    SetInvis(1);

    SetMass(0);

    set_heart_beat(5);

}





void heart_beat()



 {

    object ob;

    ob=environment();





        if(!living(ob))

          {

           this_object()->eventDestruct();

           return;

          }

    if(Duration) Duration--;

      {

       tell_object(ob,"%^RED%^You bleed heavily from your horrible wounds.%^RESET%^");

       tell_room(environment(ob), ob->GetName()+ " %^RED%^bleeds heavily from "+possessive(environment())+" horrible wounds.%^RESET%^",environment());

       ob->eventReceiveDamage(this_object(),TRAUMA,15,0,"torso");

      }

    else ::eventDestruct();

    return;

 }



int eventDestruct()

   {

    this_object()->eventMove("domains/default/room/furnace.c");

    return ::eventDestruct();

   }

/code>

Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1020
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
heartbeats and skills
« Reply #13 on: September 12, 2006, 01:03:48 PM »

if(Duration){

Duration--;

tell_object(ob,"%^RED%^You bleed heavily from your horrible wounds.%^RESET%^");

tell_room(environment(ob), ob->GetName()+ " %^RED%^bleeds heavily from "+possessive(environment())+" horrible wounds.%^RESET%^",environment());

ob->eventReceiveDamage(this_object(),TRAUMA,15,0,"torso");

}

else ::eventDestruct();

return;

}



Offline detah

  • BFF
  • ***
  • Posts: 190
  • Ruler of 2D
    • View Profile
heartbeats and skills
« Reply #14 on: September 14, 2006, 07:02:06 AM »

On a bit of an aside.



Regarding

write( name +" bleeds from a wound in his chest.");

say( name + " bleeds from a gaping wound in his chest!",({target}));



If you are willing to add 'gaping' to the write or delete 'gaping' from the say and make both statements consistent, then I recommend that you consider the tell_room efun.



tell_room(this_player(),name+" bleeds from a gaping wound in his chest.\n");



This will eliminate the need for both a write and a say when it is the same text.