Strange results with JS combat scripting.

Need help with your JScripts? Got questions concerning the DFNs? Come forward, step inside :)
Post Reply
stranf
UOX3 Guru
Posts: 939
Joined: Wed Jan 04, 2006 3:59 pm
Has thanked: 0
Been thanked: 0

Strange results with JS combat scripting.

Post by stranf »

Here is a basic script which I added to my global.js to try and do some customizable damage calculations:

Code: Select all

function CalculateHitLoc( ) 
{ 
   var hitLoc = RandomNumber( 1, 100 ); // Determine area of Body Hit 
 
  if (hitLoc <4> 3 && hitLoc <13> 12 && hitLoc <29> 28 && hitLoc <33> 32 && hitLoc <39> 14)
     {armor.hp=armor.hp - RandomNumber(1,2);
    }

  }
  


var damage = baseDamage-block;
pAttacker.TextMessage(block);   

    
 if( damage <= 0 ) 
  {damage = RandomNumber( 1, 4 );} 


   return damage; 
} 


Basically it calculates a hit location, if the baseDamage of an enemy is greater than 15, it damages the armour at that location. The DEF value of that armor is divided by two and subtracted from the basedamage to give combat damage.


This is the idea, I would have fleshed it out (applied STR bonuses, etc) if I had gotten this simple portion done, but here is what I have noticed:


--Base damage of a weapon works (does between lodamage/hidamage) on monsters (which does not utilize their DEF value).

--PCs can not damage NPCs wearing armor. The debug text in my above code showing Def value pops above a character as "NaN". Even if the NPC is wearing an armor with a DEF value of 28, and the PC is attacking him with a 40-50 base damage weapon. Remove the armour from the NPC, and the NPC gets hurt.

--NPCs with armor can still atack and hurt PCs with armour, although their damage appears less than my calculation should reveal.


-- The minimum damage of 1-4 DOES not seem to applied to either the PC nor the NPC. Hit sounds are accompanied with no damage. Interesting.

-- No errors displayed in the console.

--The portion of my script that damages armor dosen't work. Interestingly enough, the C++ code fires a script that DOES damage the PCs armor. Since this is a new feature I have not noticed before, I will happily let the C++ code damage my armor instead of me coding it myself.

However, I would still like to apply the target area's DEF value and subtract it by the current damage.

Any ideas?

--Since it seems that the C++ code can damage armor and returns hit locations independent of my calculations, is their anyway to retrieve a hit-location from C++ and import that value into my JS script to use for defense calculations?
Post Reply