Welcome to the Builder Academy

Question Skill question

More
29 Mar 2018 21:25 #7847 by thomas
Replied by thomas on topic Skill question
please read the file doc/act.txt to learn about the input to the act() function.

The #if / #endif pairs makes it easy to "uncomment" the part between them (switch out the 0 with a 1). Don't use them unless debugging.

Please Log in or Create an account to join the conversation.

More
29 Mar 2018 21:47 - 29 Mar 2018 21:49 #7848 by JTP
Replied by JTP on topic Skill question
Imo that file only shows exambles of ch, 0, vict
Nothing about vict, 0, ch

All over the code both sulutions are Used.
Last edit: 29 Mar 2018 21:49 by JTP.

Please Log in or Create an account to join the conversation.

More
30 Mar 2018 00:32 #7851 by thomas
Replied by thomas on topic Skill question
quote github.com/tbamud/tbamud/blob/master/doc/act.txt#L35 :

void act(const char *str, int hide_invisible, struct char_data *ch,
struct obj_data *obj, const void *vict_obj, int type)

Please read the above. I mean, really read it. It tells you the name of the parameters.

Then, it goes on to tell you what they mean github.com/tbamud/tbamud/blob/master/doc/act.txt#L40 :

str: This is the basic string, a null terminated character array, including
control characters (see section 1.4 on ‘Control Characters’), to be sent to
characters designated by the targets.

hide_invisible: A TRUE or FALSE value indicating whether or not to hide the
entire output from any characters that cannot see the “performing character”.

ch: The “performing character”. This is the character that the output string
is associated with. The character is used to determine the room for the output
of the action in question.

obj: An object (an actual item – obj_data) used in the course of the action.

vict_obj: This can be either a character involved in the action, another
object, or even a predefined string of text.

type: One of TO_VICT, TO_CHAR, TO_NOTVICT, or TO_ROOM. This indicates who it
is to be targeted at.

1.3 The Parameters
Of the various parameters passed to the act() function, the str is the most
important, as it is the basis for the actual final output. If this parameter
is a null-pointer or points to a null-character, then the function returns
immediately. The next important parameter is the ch parameter. This, as
mentioned, points to the central character associated with the output string
and action.

obj is an object of type struct obj_data *that is passed to the function. If
there is no object to pass to the function, then a NULL or 0 should be passed
in this location.

The next parameter vict_objcan be a number of things ranging from a game object
(strcut obj_data *), through to a character (struct char_data *), and even a
null terminated character array (char *).

Do note, however, that obj and vict_obj are both ignored if there is no control
character reference (see section 1.4 ‘Control Characters’) to them and the type
is set to TO_ROOM or TO_CHAR. In these cases, NULL should be supplied as the
input to the function.

The hide_invisible flag dictates whether or not the action output should be
hidden from characters that cannot see ch. If the flag is set to TRUE
(non-zero), then this is the case.

The type determines who the output is to be sent to. There are four options for
this (all defined in comm.h) described below:

TO_ROOM: This sends the output to everybody in the room, except ch.

TO_VICT: This option sends the output to the character pointed to by vict_obj.
In this case, vict_obj must point at a character rather than an object.

TO_NOTVICT: In another case where vict_obj must point to a character. This
sends the output to everybody in the room except ch and vict_obj.

TO_CHAR: Finally, this option sends the output to the ch.

TO_SLEEP: This is a special option that must be combined with one of the above
options. It tells act() that the output is to be sent even to characters that
are sleeping. It is combined with a bitwise ‘or’. i.e. TO_VICT | TO_SLEEP.

When the string has been parsed, it is capitalized and a newline is added.
...


Now, when you've read the above a couple of times, you'll probably ask yourself (and us :) , "...but what does it mean when the parameter ch is passed a reference to the victim?". It means, as it says in the act.txt file right above here, that ch: The “performing character”. This is the character that the output string
is associated with. The character is used to determine the room for the output
of the action in question.


Consider a hypothetical scenario, where YourName is fighting HerName, and we're sending a genering "hurts" message.

So, what does this do?
Code:
act("You hurt $M", TRUE, ch, 0, vict, TO_CHAR); act("$n hurts $N", TRUE, ch, 0, vict, TO_NOTVICT); act("$n hurts you!", TRUE, ch, 0, vict, TO_VICT);
It sends "You hurt her" to the char causing the hurting, "YourName hurts HerName" to onlookers in the same room as YourName and "YourName hurts you!" to the victim.

So, what if we switch the order of the passed variables?
Code:
act("You hurt $m", TRUE, vict, 0, ch, TO_VICT); act("$N hurts $n", TRUE, vict, 0, ch, TO_NOTVICT); act("$m hurts you!", TRUE, vict, 0, ch, TO_CHAR);
As you see, we need to switch the flags and the control characters in the strings to get the same results. Also note that now, the second line works corectly if YourName happened to hurt HerName from another room. The victims room is used to find the TO_ROOM room, because it is sent as the 'ch' parameter.

I think much of your confusion stems from the fact that we have two different concepts here with the same name. 'ch' refers to both a variable (in the calling code) and a parameter (in the act() prototype). But even though the parameter is called 'ch', any char_data pointer will work there, including 'vict'.
The following user(s) said Thank You: Chime, lacrc

Please Log in or Create an account to join the conversation.

More
30 Mar 2018 05:57 #7854 by JTP
Replied by JTP on topic Skill question
Thank you for giving detailed explanation to both ways that helped.

Please Log in or Create an account to join the conversation.

More
30 Mar 2018 16:44 - 30 Mar 2018 16:45 #7855 by JTP
Replied by JTP on topic Skill question
Ok i knew i would run into trouble haha...the skill im making is an AOE skill and has:
Code:
act("You ...!", FALSE, ch, 0, tch, TO_CHAR); act("$n ...!", FALSE, ch, 0, tch, TO_ROOM); */ also tried VICT /* GET_MANA(ch) = (GET_MANA(ch) - 60); damage(ch, tch, dam, TYPE_UNDEFINED);

BUT if the skill instantly kills the target, all they see is You die R.I.P. and then the login menu.
Other then that it looks ok.

Any idea ? I also tried using 0 instead of tch and TRUE instead of FALSE, still the same.
Last edit: 30 Mar 2018 16:45 by JTP.

Please Log in or Create an account to join the conversation.

More
31 Mar 2018 12:13 #7859 by JTP
Replied by JTP on topic Skill question
Solved

Please Log in or Create an account to join the conversation.

Time to create page: 0.306 seconds