Author Topic: New Verb  (Read 3374 times)

Offline sorin

  • Acquaintance
  • *
  • Posts: 5
    • View Profile
New Verb
« on: February 15, 2014, 04:05:21 AM »
Ok, after reading the tutorial about creating new verbs, and looking a bit in the backstab and attack verbs, I came to this little, a beggining of a verb, but I couldn't progress because: If I put no pharsing rule, can_uppercut() and do_uppercut(), it works just fine, if I do it with liv, I get the message, you can't uppercut that

Code: [Select]
#include <lib.h>
#include <position.h>
#include "damage_types.h"


inherit LIB_VERB;

static void create() {
    verb::create();
    SetVerb("uppercut");
    SetRules("LIV");
    SetErrorMessage("Uppercut whom?");
    SetHelp("Syntax: uppercut <LIVING>\n\n"
            "With a clenched fist, a warrior is able to deliver a powerful upwards blow that will cause his foe severe pain. The added benefit to this technique is that if the warrior is holding a weapon in his hand, the added weight of the weapon will aid in delivering an even more powerful blow.");
}

mixed can_uppercut_liv(object ob) {
if (this_player()->GetClass() != "fighter") {
return "Fighter only, sorry!";
}
return this_player()->CanManipulate();
}

//definitions
int uppercut_damage();

mixed do_uppercut_liv(object ob) {
this_player()->SetAttack(ob);
this_player()->eventPrint("Baam! You hit the fucker in the chin! Kidding, just testing shit Anyhow, you woulda done "+uppercut_damage()+" damage points! Good job!");
return 1;
}

int uppercut_damage() {
int damage_done = this_player()->GetStatLevel("strength");
damage_done += this_player()->GetSkillLevel("melee attack");
damage_done += random(20)-10;
return damage_done;
}

Offline Nilrin

  • Friend
  • **
  • Posts: 85
    • View Profile
Re: New Verb
« Reply #1 on: February 15, 2014, 09:21:53 AM »
With any object that you interact with using a verb, you require a direct or indirect function which returns 1. For your example, add this to a select NPC to try it out.

Code: [Select]
mixed direct_uppercut_liv(){
    return 1;
}

Then your verb works.

Offline quixadhal

  • BFF
  • ***
  • Posts: 631
    • View Profile
    • WileyMUD
Re: New Verb
« Reply #2 on: February 15, 2014, 03:58:41 PM »
Of course.

Once you've verified that it works the way you want it to work, you will probably then want to move it to something more NPC's inherit.  In the case of an uppercut, that probably only works on humanoids, or perhaps quadrapeds (anything with a jaw), so placing it in the right couple of inheritables will prevent you from having to tag each and every NPC you want it to work on.  Also, don't forget players! :)

Offline sorin

  • Acquaintance
  • *
  • Posts: 5
    • View Profile
Re: New Verb
« Reply #3 on: February 16, 2014, 12:19:33 PM »
Ok, fixed it, thanks!

In this kind of situations, it is better to set commands instead of verbs?
« Last Edit: February 16, 2014, 12:24:35 PM by sorin »

Offline quixadhal

  • BFF
  • ***
  • Posts: 631
    • View Profile
    • WileyMUD
Re: New Verb
« Reply #4 on: February 16, 2014, 04:55:42 PM »
It really depends on the problem you're trying to solve.

Verbs are useful in cases where:

You want to be able to use them on a variety of target situations, such as "kill orc" or "kill all orcs" or "kill the green orc", as the verb system will try hard to find the right target for you.

You want to ensure that all your code is consistent.  IE: avoid the "guess the verb" game where one thing uses "turn" and another thing uses "rotate" and another thing uses "twist", to all do the same thing... open something.

You want to use the same "word" in multiple contexts without having to special-case code every time a new use context comes us.  Consider "open".  You want to open a door, you want to open a backpack, maybe you want to open a portal, or even open someone's guts?  If you code it as a command, the open code has to special-case all these different uses.  If you code it as a verb, you simply add the direct_open() or indirect_open() functions to things that can be opened.

Offline sorin

  • Acquaintance
  • *
  • Posts: 5
    • View Profile
Re: New Verb
« Reply #5 on: February 17, 2014, 05:17:39 AM »
I was thinking at those combat commands like uppercut, slash, behead etc

Offline quixadhal

  • BFF
  • ***
  • Posts: 631
    • View Profile
    • WileyMUD
Re: New Verb
« Reply #6 on: February 17, 2014, 09:50:25 PM »
Right, that's kinda the point.  *YOU* currently think of "uppercut", "slash", and "behead" as combat commands only.  What about in three years when someone on your staff (maybe you) codes a crafting system and wants to use "behead" and "slash" as commands for gutting and cooking fish?

I'm not saying everything should be a verb (if you believe that, you should be using LIMA), but it depends how often you're going to find collisions, and how much you want to change different parts of the code to handle them.

The verb system calls routines in the target to determine how the command behaves.  A command has to have that code internal, or mimic verbs -- in which case why not use verbs?

Offline Nilrin

  • Friend
  • **
  • Posts: 85
    • View Profile
Re: New Verb
« Reply #7 on: February 18, 2014, 09:17:35 PM »
I look at it the same way, in a rather simplified manner.

There are exceptions to everything, but generally if I'm coding something in which I expect to act upon another object, the logical choice would be to use a verb. If its something that implies no physical action against another object, I code a command, such as score, or status, or who.

Kinda redundant after what quixadhal said, just felt I should mention my gut feeling when deciding how to write a new command.

Offline Hilapdatus

  • Acquaintance
  • *
  • Posts: 11
    • View Profile
    • Dreamverse Support Site
Re: New Verb
« Reply #8 on: February 25, 2014, 07:21:00 PM »
George Reese wrote a pretty fantastic description of the verb parser.  You can google around a bit to find copies, here is one:

  http://ringbreak.dnd.utwente.nl/~krimud/Docs/NMAdmin/Parser/


Offline dragosani

  • Acquaintance
  • *
  • Posts: 6
    • View Profile
Re: New Verb
« Reply #9 on: February 27, 2014, 09:06:28 AM »
Like it Sorin - "Baam, you hit the fucker in the chin!"

Class :P