Adding Togglemurder, getting errors :(

Posted by Mopop on Thu 24 Nov 2005 03:12 AM — 22 posts, 76,354 views.

#0
Trying to add a togglemurder function so players do not kill if they dont want to, for free pk fights or player events. Its been giving me a little problem but here is what I got.

the code.

void toggle_murder(CHAR_DATA *ch, char *argument)
{
   char *victim;

   set_char_color( AT_RED, ch );
   ch_printf( ch, "You are set to %s.\n\are.", xIS_SET( ch->act, PLR_MURDER ) ? "stun" : "murder" );
   if( !xIS_SET( ch->act, PLR_MURDER )
    2053->  xSET_BIT( ch->act, PLR_MURDER );
   else 
      xREMOVE_BIT( ch->act, PLR_MURDER );
   if( !IS_NPC( victim ) && xIS_SET( ch->act, PLR_MURDER ) && victim->hit < 1 )
  {
      victim->hit = 0;
      ch_printf( ch, "You spare your victim!" );
      act( AT_RED, "$n's life has been spared!", victim, NULL, NULL, TO_ROOM );
      act( AT_RED, "Your life has been spared, this time.", victim, NULL, NULL, TO_CHAR );
   }
   return;
}


the errors

player.c: In function `toggle_murder':
player.c:2053: called object is not a function
player.c:2053: parse error before ';' token
player.c:2056: request for member `act' in something not a structure or union
player.c:2056: request for member `hit' in something not a structure or union
player.c:2058: request for member `hit' in something not a structure or union
cc1: warnings being treated as errors
player.c:2060: warning: passing arg 3 of `act' from incompatible pointer type
player.c:2061: warning: passing arg 3 of `act' from incompatible pointer type
Amended on Thu 24 Nov 2005 05:15 AM by Nick Gammon
USA #1
 char *victim;

That's the problem. Needs to be:
 CHAR_DATA *victim;
#2
Awesome! now I only got these 2 errors

player.c: In function `toggle_murder':
player.c:2053: called object is not a function
player.c:2053: parse error before ';' token

gettin' close :-D
USA #3
Could you edit the first post and point out what those lines are? Also, remember to use the code tag.

[EDIT] Okay wait, this function seems odd. victim isn't even initialized. It's just declared. Unless I'm missing something.
Amended on Thu 24 Nov 2005 03:58 AM by Zeno
Australia Forum Administrator #4

if( !xIS_SET( ch->act, PLR_MURDER )


You are missing a bracket. You have 2 LH brackets, and 1 RH bracket.
#5
Eh? Come again? Sorry still new at this :P
Australia Forum Administrator #6
Putting aside other possible problems, like the fact that you are using "victim" without initialising it, the syntax error is because you are a bracket short. It should read:

if( !xIS_SET( ch->act, PLR_MURDER ) )
#7
Ah thanks, So I heard I wasnt quite sure how to intialize it :( I got a little help making this...

I compiled fixing what you said and got these errors.

o/tables.o(.text+0x4670): In function `skill_function':
//tables.c:1115: undefined reference to `do_toggle_murder'
o/tables.o(.text+0x75b3): In function `skill_name':
//tables.c:2237: undefined reference to `do_toggle_murder'
collect2: ld returned 1 exit status
smaug: No such file or directory
smaug: No such file or directory
Done compiling mud.
Amended on Thu 24 Nov 2005 05:47 AM by Mopop
USA #8
Just a typo.
void toggle_murder(CHAR_DATA *ch, char *argument)

There's no "do_" in there.
#9
Sweet that works now if I only knew why It was crashing the mud when I use it.
USA #10
Like we said, victim isn't initialized. Basically this means that you declared space for it be defined, you use it (such as the !IS_NPC check) but it's never actually defined. It's still null.
#11
isnt that what CHAR_DATA victim* is doing?

Here is the current code


void do_toggle_murder(CHAR_DATA *ch, char *argument)
{
   CHAR_DATA *victim;

   set_char_color( AT_RED, ch );
   ch_printf( ch, "You are set to %s.\n\r", xIS_SET( ch->act, PLR_MURDER ) ? "stun" : "murder" );
   if( !xIS_SET( ch->act, PLR_MURDER ))
      xSET_BIT( ch->act, PLR_MURDER );
   else
      xREMOVE_BIT( ch->act, PLR_MURDER );
   if( !IS_NPC( victim ) && xIS_SET( ch->act, PLR_MURDER ) && victim->hit < 1 )
  {
      victim->hit = 0;
      ch_printf( ch, "You spare your victim!" );
      act( AT_RED, "$n's life has been spared!", victim, NULL, NULL, TO_ROOM );
      act( AT_RED, "Your life has been spared, this time.", victim, NULL, NULL, TO_CHAR );
   }
   return;
}


and this is what my core file is saying when I check it.

#0 0x08148d2f in do_toggle_murder (ch=0x85c5fb0, argument=0xb54b4a4c "") at player.c:2056
#1 0x0810d05d in interpret (ch=0x85c5fb0, argument=0xb54b4a4c "") at interp.c:543
#2 0x080d2840 in game_loop () at comm.c:881
#3 0x080d1e67 in main (argc=5, argv=0xb54b4ed4) at comm.c:551
#4 0x4b9ced06 in __libc_start_main () from /lib/libc.so.6
(gdb) frame 0
#0 0x08148d2f in do_toggle_murder (ch=0x85c5fb0, argument=0xb54b4a4c "") at player.c:2056
2056 in player.c
(gdb) list
2051 in player.c

maybe you guys can get an understaning of it better than I can :P
USA #12
No, CHAR_DATA is declaring it, and that's it.
#13
Well like I said earlier excuse my ignorance how would I define it, I tried looking for examples in other code and kinda drew blank, this is one of the first things I (kinda) wrote on my own. So sorry for the newbness.
USA #14
Well my question is why is there a victim in the first place? Isn't that command only meant to toggle the setting?
#15
I put victim there so it doesnt kill them when they go below 0 life, it needs to know who not to kill right?
Australia Forum Administrator #16
How are you planning to use this command?

toggle_murder

or

toggle_murder nick


If the first case, then you don't know the victim, so you can hardly say:

$n's life has been spared!

can you? Who is $n?

If you are doing "toggle_murder nick" (which doesn't make a huge amount of sense to me) then you need to look up "nick" and get his pointer into victim. Look at any skill that has a victim for how to do this (eg. murder).
#17
Well it was just going to be the command "Togglemurder"
then it will say if you are going to kill or stun.
So all I will need to do is remove the $n or just change it to something more generic?
USA #18
I think what Nick's saying here is that the portions of your function that are meant to tell the code what to do if someone is flagged (set to stun) should be a modification to the combatcode and that this function by itself should just do the actual toggling of the flag and output your message to let them know their current status. Personally I still think that you are better off (the easier way) to just make the toggle portion a new option under the config command (do_config) and the add your flag defination to fight.c, but it's your mud. ;)
USA #19
Right. Like I said, that command is only to toggle the flag right? That's what I was asking.
#20
Oh no it is suppose to be the whole command, I didnt realize I had it done wrong. So what you are sayin is, this doesnt do a thing except gives the player the flag? So I need to add the stunning somewhere else? If so where should I add it?
USA #21
Well I'm not sure how you want it. I figured it was something like this. The command is to toggle the flag. And the flag is to decide if you spare a victim in combat or not. If that's right, then that function does too much. It just needs to toggle the flag like I said.