Welcome to the Builder Academy

Question skill stun / wierd problem

More
19 Nov 2016 14:21 - 19 Nov 2016 22:10 #6279 by JTP
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 ?

Code:
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
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:
Code:
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: 19 Nov 2016 22:10 by JTP.

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

More
19 Nov 2016 22:56 - 19 Nov 2016 23:21 #6281 by JTP
Replied by JTP on 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: 19 Nov 2016 23:21 by JTP.

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

More
19 Nov 2016 23:22 #6283 by thomas
Replied by thomas on 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 ):
Code:
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.

Code:
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.

More
20 Nov 2016 01:38 #6284 by JTP
Replied by JTP on 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
20 Nov 2016 09:36 #6285 by thomas
Replied by thomas on topic skill stun / wierd problem
just add another check in the list, if it's going to have a new effect.
Code:
} 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:
Code:
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.

More
27 Nov 2016 13:29 - 27 Nov 2016 15:43 #6318 by JTP
Replied by JTP on 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: 27 Nov 2016 15:43 by JTP.

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

Time to create page: 0.232 seconds