### [Fixed] Bug with npc.ar !

Posted:

**Fri Feb 27, 2009 2:52 pm**Hello,

I tried to use the value npc.ar, which was fixed by Austin (corechanges 10-29). I am talking about NPCs without any armor equipped, so this value reflects the intrinsic armor from the configuration. (Up to now our combat scripts look into the NPC template in the configuration for the intrinsic armor). Npc.ar works, but ...

But if a script sets npc.ar_mod to any positive value, both npc.ar and npc.ar_mod take on this new value!

If a script sets npc.ar_mod to any negative value, npc.ar takes on the correct value from the configuration (but not the new value reduced by the negative value), and ar_mod contains the negative value just written.

If a script sets npc.ar_mod to zero, the npc.ar is set to the correct value from the configuration and npc.ar_mod is zero. That means, we can correct the intrinsic value again by writing zero to npc.ar_mod, but as long npc.ar_mod has a value greater than zero the same value is in npc.ar. If the value in npc.ar_mod is lower than zero, it is ignored.

With items and player characters it works this way:

Set item.ar_mod to any positive or negative value or to zero, the item.ar_mod has the value just written, and item.ar has the old value plus (or minus) the value in item.ar_mod.

Example: A shield has intrinsic AR = 28. I.e. item.ar = 28, and item.ar_mod = 0 initially.

If i write:

item.ar_mod => 5 then item.ar = (28+5) = 33 and item.ar_mod = 5.

item.ar_mod => -15 then item.ar = (28-5) = 23 and item.ar_mod = -5.

item.ar_mod => 0 then item.ar = 28 again and item.ar_mod = 0.

So the initial value of npc.ar is lost, if a NPC uses a spell which changes its AR. It is possible to regain it by writing zero to npc.ar_mod, but while npc.ar_mod is different from zero npc.ar is wrong (i.e. the same value as in npc.ar_mod).

How to repeat:

Create a NPC, without equipment (i.e. no armor or shields):

Then by script do this: (Assume the NPC has intrinsic armor 10 from the configuration)

1) Set npc.ar_mod := 5 (NPC should now have ar=15)

2) Read npc.ar -> it is now 5!

3) Read npc.ar_mod -> it is 5

4) Set npc.ar_mod := 0

5) Read npc.ar -> it is now 10 again!

6) Read npc.ar_mod -> it is 0

7) Set npc.ar_mod := -5

8) Read npc.ar -> it is still 10

9) Read npc.ar_mod -> it is -5

10) Set npc.ar_mod := 0

11) Read npc.ar -> it is now 10 again!

12) Read npc.ar_mod -> it is 0

So if a NPC uses a protection spell, which sets npc.ar_mod to a positive value, it sets its entire armor to the new value which actually should be an increment instead.

As it is, npc.ar cannot be used, except with workarounds for NPCs, but it works for items and player characters.

This was found and verified with the pol-core-097.2-2009-01-13-Coregina core, which we are using.

But the same behavior exists with the newest 0.98 beta core (pol-core-098-2009-02-18).

OWHorus

I tried to use the value npc.ar, which was fixed by Austin (corechanges 10-29). I am talking about NPCs without any armor equipped, so this value reflects the intrinsic armor from the configuration. (Up to now our combat scripts look into the NPC template in the configuration for the intrinsic armor). Npc.ar works, but ...

But if a script sets npc.ar_mod to any positive value, both npc.ar and npc.ar_mod take on this new value!

If a script sets npc.ar_mod to any negative value, npc.ar takes on the correct value from the configuration (but not the new value reduced by the negative value), and ar_mod contains the negative value just written.

If a script sets npc.ar_mod to zero, the npc.ar is set to the correct value from the configuration and npc.ar_mod is zero. That means, we can correct the intrinsic value again by writing zero to npc.ar_mod, but as long npc.ar_mod has a value greater than zero the same value is in npc.ar. If the value in npc.ar_mod is lower than zero, it is ignored.

With items and player characters it works this way:

Set item.ar_mod to any positive or negative value or to zero, the item.ar_mod has the value just written, and item.ar has the old value plus (or minus) the value in item.ar_mod.

Example: A shield has intrinsic AR = 28. I.e. item.ar = 28, and item.ar_mod = 0 initially.

If i write:

item.ar_mod => 5 then item.ar = (28+5) = 33 and item.ar_mod = 5.

item.ar_mod => -15 then item.ar = (28-5) = 23 and item.ar_mod = -5.

item.ar_mod => 0 then item.ar = 28 again and item.ar_mod = 0.

So the initial value of npc.ar is lost, if a NPC uses a spell which changes its AR. It is possible to regain it by writing zero to npc.ar_mod, but while npc.ar_mod is different from zero npc.ar is wrong (i.e. the same value as in npc.ar_mod).

How to repeat:

Create a NPC, without equipment (i.e. no armor or shields):

Then by script do this: (Assume the NPC has intrinsic armor 10 from the configuration)

1) Set npc.ar_mod := 5 (NPC should now have ar=15)

2) Read npc.ar -> it is now 5!

3) Read npc.ar_mod -> it is 5

4) Set npc.ar_mod := 0

5) Read npc.ar -> it is now 10 again!

6) Read npc.ar_mod -> it is 0

7) Set npc.ar_mod := -5

8) Read npc.ar -> it is still 10

9) Read npc.ar_mod -> it is -5

10) Set npc.ar_mod := 0

11) Read npc.ar -> it is now 10 again!

12) Read npc.ar_mod -> it is 0

So if a NPC uses a protection spell, which sets npc.ar_mod to a positive value, it sets its entire armor to the new value which actually should be an increment instead.

As it is, npc.ar cannot be used, except with workarounds for NPCs, but it works for items and player characters.

This was found and verified with the pol-core-097.2-2009-01-13-Coregina core, which we are using.

But the same behavior exists with the newest 0.98 beta core (pol-core-098-2009-02-18).

OWHorus