skill stun / wierd problem

  • JTP
  • JTP's Avatar Topic Author
  • Offline
  • Platinum Boarder
  • Platinum Boarder
More
1 year 6 months ago - 1 year 6 months ago #6279 by JTP
JTP created the topic: skill stun / wierd problem
Just had a wierd thing happend, from a player using stun skill, and he failed and stunned himself.
His respons of what happened after he stunned himself was, that he was suddently affected by ALOT of spells he has no access to, sanc, fireshield, etc.


Any ideas why the log shows what it does, or ideas to improve stun the code or what in the stun code is causing the problems ?

In file crash i see:
Nov 19 03:46:48 :: SYSERR: Unknown apply adjust -67 attempt (handler.c,
affect_modify).
Nov 19 03:46:48 :: SYSERR: Unknown apply adjust -67 attempt (handler.c,
affect_modify).
Nov 19 03:46:48 :: SYSERR: Unknown apply adjust -67 attempt (handler.c,
affect_modify).
Nov 19 03:47:06 :: SYSERR: Unknown apply adjust -67 attempt (handler.c,
affect_modify).

The code
ACMD(do_stun)
{
  char arg[MAX_INPUT_LENGTH];
  struct char_data *vict;
  struct affected_type af;
  int diff_lev, percent, prob;
  int chance;

  if (IS_NPC(ch) || !GET_SKILL(ch, SKILL_STUN)) {
    send_to_char(ch, "You have no idea how.\r\n");
    return;
  }

  one_argument(argument, arg);

  if (!GET_SKILL(ch, SKILL_STUN) ) {
    send_to_char(ch, "You do not know this skill.\r\n");
  } else  if (!*arg) {
    send_to_char(ch, "Stun who?\r\n");
  } else if (!(vict = get_char_room_vis(ch, arg, NULL))) {
    send_to_char(ch, "They don't seem to be here.\r\n");
  } else if ( ! IS_NPC(vict) ){
    send_to_char(ch, "You can not attack another PC.\r\n");
  } else if (vict == ch) {
    send_to_char(ch, "You Stun yourself...OUCH!.\r\n");
    act("$n tries to stun $mself, and says OUCH!", FALSE, ch, 0, vict, TO_ROOM);
  } else if (IS_AFFECTED(ch, AFF_CHARM) && (ch->master == vict)) {
    act("$N is just such a good friend, you simply can't stun $M.", FALSE, ch, 0, vict, TO_CHAR);
  } else if (ROOM_FLAGGED(ch->in_room, ROOM_PEACEFUL)) {
    send_to_char(ch, "This room just has such a peaceful, easy feeling...\r\n");
  } else if ( ! (GET_MOVE(ch) >= 10) ) {
    send_to_char(ch, "I am sorry, but you seem to tired to try to do that.\r\n");
  } else {
    percent = rand_number(1, 105);   /* 101% is a complete failure */
    prob = GET_SKILL(ch, SKILL_STUN);

    if ( percent < prob ) {
      GET_MOVE(ch) -= 10;
      diff_lev = GET_LEVEL(vict) - GET_LEVEL(ch);

      chance = 33 - (diff_lev ) ;

      if (chance > 100)
        chance = 100;

      chance -= GET_DEX(vict);
      percent = rand_number(1, 105);

      if ( chance > percent ) {
        new_affect(&af);
        af.duration = 0;
        af.spell = SKILL_STUN;
        SET_BIT_AR(af.bitvector, AFF_STUN);
        affect_to_char(vict, &af);

        stop_fighting(vict);
        GET_POS(vict) = POS_STUNNED;

        act("You stun $N.", FALSE, ch, 0, vict, TO_CHAR);
        act("$n stuns $N.", TRUE, ch, 0, vict, TO_NOTVICT);
        act("$n stuns you.", TRUE, ch, 0, ch->master, TO_VICT);
	improve_skill(ch, SKILL_STUN);

      } else {
        send_to_char(ch, "You failed to stun.\r\n");
        if ( rand_number(1,105) <= 1) {
          if (GET_LEVEL(ch) < LVL_IMMORT) {
            send_to_char(ch, "Oops, You stunned yourself!\r\n");
            SET_BIT_AR(af.bitvector, AFF_STUN);
            af.duration = 0;
            affect_to_char(ch, &af);
            GET_POS(ch) = POS_STUNNED;
          }
        }
      }

    } else {
      send_to_char(ch, "You failed to stun him.\r\n");
      if ( rand_number(1,105) <= 1) {
        if (GET_LEVEL(ch) < LVL_IMMORT) {
          send_to_char(ch, "Oops, You stunned your self.\r\n");
          SET_BIT_AR(af.bitvector, AFF_STUN);
          af.duration = 0;
          affect_to_char(ch, &af);
          GET_POS(ch) = POS_STUNNED;
        }
      }
    }
    hit(ch, vict, TYPE_UNDEFINED);
    WAIT_STATE(ch, PULSE_VIOLENCE * 4);
  }
}






While character is stunned he is affected by: detect invis, steel skin, stone skin, barkskin, sanc,
fireshield, prot fro evil, poison

And when stun is gone, so are the spells.


Another time char stunned himself:
Nov 19 08:43:14 :: SYSERR: Unknown apply adjust 122 attempt (handler.c,
affect_modify).
Nov 19 08:43:14 :: SYSERR: Unknown apply adjust 122 attempt (handler.c,
affect_modify).
Nov 19 08:43:14 :: SYSERR: Unknown apply adjust 122 attempt (handler.c,
affect_modify).
Nov 19 08:43:56 :: SYSERR: Unknown apply adjust 122 attempt (handler.c,
affect_modify).
So every time a char stuns himself, he is for the duration affected by spells he shouldnt be, AND those affect_modify appear in log.
Last Edit: 1 year 6 months ago by JTP.

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

  • JTP
  • JTP's Avatar Topic Author
  • Offline
  • Platinum Boarder
  • Platinum Boarder
More
1 year 6 months ago - 1 year 6 months ago #6281 by JTP
JTP replied the topic: skill stun / wierd problem
Just noticed missing new_affect(&af); in the part with the two places of stunning yourself, anything else missing or is that just what caused it to work strange ?

Or any ideas to improve it ?
Maybe a way to not be able to stun targets level 60 and above ?
How can i do that ?
Last Edit: 1 year 6 months ago by JTP.

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

More
1 year 6 months ago #6283 by thomas
thomas replied the topic: skill stun / wierd problem
you need both new_affect(&af); and af.spell=SKILL_STUN; everywhere you use the "af" variable.

What you're experiencing is called "uninitialized memory". When you enter the function, the variables are set up on the stack. I'll try to illustrate it:

Sometime before this function is called, the memory wher ethe stack is situated contains some data. It looks like this, more or less (it's pseudo-explanation-detailed-description-time. It does not actually look like this, but I hope it works as an explanation - the real deal is somewhat more complicated gribblelab.org/CBootcamp/7_Memory_Stack_vs_Heap.html ):
a1
f4
23
...
54
d6
d7
45
65
00
43 <- above here is garbage from earlier uses
f2 <- current stack top
b3 <- here, variables in the function calling your function have room

So, we call this function, and the stack top is moved up, making space for all the variables declared at the top of the function.

a1
f4 <- current stack top 
23 <- here, parameters are stored
...
54 <- ignoring all other variables than af. They're in this memory, above this arrow.
d6 <- the af variable starts here. 
d7
45
65
00 <- and ends here
43 
f2 
b3 <- here, variables in the function calling your function have room

At this point in time, the af object is allocated on the stack (this happens when the function is entered) but it contains the garbage data from some former call to another function - after all, the stack pointer goes up and down a lot during execution.
So, if you now use the af object, you get som very strange results - you might get crashes, or strange values assigned.

The call to new_affect(&af) sets some needed defaults, and the object is now sane. The strange &af syntax is a way of telling the new_affect code where to find our af object - in C a function can not get at other stack variables without such a solution. Calling new_affect(&af) basically means "I want the memory at THIS location to be used in new_affect".
The following user(s) said Thank You: WhiskyTest

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

  • JTP
  • JTP's Avatar Topic Author
  • Offline
  • Platinum Boarder
  • Platinum Boarder
More
1 year 6 months ago #6284 by JTP
JTP replied the topic: skill stun / wierd problem
Love those explanations...seems to work now, but will test more.

Any idea how i can prevent players from stunning a level 59+ mob ?

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

More
1 year 6 months ago #6285 by thomas
thomas replied the topic: skill stun / wierd problem
just add another check in the list, if it's going to have a new effect.
  } else if (IS_AFFECTED(ch, AFF_CHARM) && (ch->master == vict)) {
    act("$N is just such a good friend, you simply can't stun $M.", FALSE, ch, 0, vict, TO_CHAR);
+  } else if (GET_LEVEL(vict) > 59) {
+    act("$N is is immune to your stun!.", FALSE, ch, 0, vict, TO_CHAR);
  } else if (ROOM_FLAGGED(ch->in_room, ROOM_PEACEFUL)) {

Otherwise, if you want it to always result in a self-stun, alter your calculations:
      chance -= GET_DEX(vict);
      percent = rand_number(1, 105);

+      if (GET_LEVEL(vict) > 59) {
+        chance = 0;
+      }

      if ( chance > percent ) {

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

  • JTP
  • JTP's Avatar Topic Author
  • Offline
  • Platinum Boarder
  • Platinum Boarder
More
1 year 5 months ago - 1 year 5 months ago #6318 by JTP
JTP replied the topic: skill stun / wierd problem
Ok, stun no longer gives all sorts of spells when stunning yourself.

I have had a player test it for a few days, he used the skill ALOT, but one time it crashed the mud with this line in file crash, at the same time of the crash:


Nov 26 04:27:17 :: SYSERR: no valid target to act()!

Backtrace showed:
#0 0x080bd49d in script_damage (vict=0x955aa48, dam=3) at dg_misc.c:308
308 mudlog( BRF, 0, TRUE, "%s killed by script at %s",



Any ideas with a sulution to prevent that happening again ?
Last Edit: 1 year 5 months ago by JTP.

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

More
1 year 5 months ago #6319 by thomas
thomas replied the topic: skill stun / wierd problem
Do you have the full backtrace?

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

  • JTP
  • JTP's Avatar Topic Author
  • Offline
  • Platinum Boarder
  • Platinum Boarder
More
1 year 5 months ago #6320 by JTP
JTP replied the topic: skill stun / wierd problem
It was the only info in it

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

More
1 year 5 months ago #6321 by thomas
thomas replied the topic: skill stun / wierd problem
It doesn't seem like the problem is near the act() call.

There's a potential array-index-out-of-bounds in script_damage() in dg_misc.c:
  if (GET_POS(vict) == POS_DEAD) {
    if (!IS_NPC(vict))
      mudlog( BRF, 0, TRUE, "%s killed by script at %s",
          GET_NAME(vict), world[vict->in_room].name);  // <-- vict->in_room may be NOWHERE
    die(vict, NULL);
  }

The fix is adding a check for nowhere people:
  if (GET_POS(vict) == POS_DEAD) {
    if (!IS_NPC(vict))
      mudlog( BRF, 0, TRUE, "%s killed by script at %s",
          GET_NAME(vict), vict->in_room == NOWHERE ? "NOWHERE" : world[vict->in_room].name);
    die(vict, NULL);
  }

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

More
1 year 5 months ago #6322 by WhiskyTest
WhiskyTest replied the topic: skill stun / wierd problem
Thomas you pick up a lot of little bugs and fix them up in the forums, and I always add them into my local copy of tbaMUD.

Do these also get added into the next release?

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

More
1 year 5 months ago #6324 by thomas
thomas replied the topic: skill stun / wierd problem
these, and a couple of the more recent ones, will. I haven't really had an install locally for some time now. Installed the other night just to push up these and a couple of other changes:

github.com/tbamud/tbamud/commits/master

Feel free to submit a pull request for any other bugfixes ;)

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

More
1 year 5 months ago #6329 by Rumble
Rumble replied the topic: skill stun / wierd problem
I usually bookmark any fixes I notice in TBA's bug file. But I have not been as vigilant lately. I plan on putting together a release in January. I am making them annual for now unless someone else wants to take on development.

Rumble
The Builder Academy
tbamud.com 9091

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

More
1 year 5 months ago #6330 by WhiskyTest
WhiskyTest replied the topic: skill stun / wierd problem
Yep cool will do.. signing up to Github now :)

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

  • JTP
  • JTP's Avatar Topic Author
  • Offline
  • Platinum Boarder
  • Platinum Boarder
More
1 year 5 months ago #6332 by JTP
JTP replied the topic: skill stun / wierd problem
When i tried:

- if ((GET_OBJ_VAL(temp, 1) == 0) || (!GET_OBJ_VAL(temp, 0) == 1)) {
+ if ((GET_OBJ_VAL(temp, 1) == 0) || (GET_OBJ_VAL(temp, 0) != 1)) {


Then noone could drink, so had to set it back to (!GET_OBJ_VAL(temp, 0) == 1)) {

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

Time to create page: 2.043 seconds