Critical Hit
Introduction[edit | edit source]
We are going to learn how to create a script with a variable critical-hit ratio based on the luck and sword skills of the player. (I used sword skills because I applied this script on a sword, but blunt or marksman is also a possibility.)
How do we create a Critical-Hit effect?[edit | edit source]
We’ll first create the script. Because we need variables we have to create a random number everytime the player hits an actor. The best way to do this is if we use the "getRandomPercent"-function and some skills. To be sure your chances on landing a critical-hit attack stay reasonable, the total amount of your Luck and Blade skill is divided by 40 (= *0.025) so your chances are (mostly) between 1% and 5%. You’ll be able to land a critical-hit attack if your RandomPercent is equal to or lower as your skill variable.
The Script[edit | edit source]
Scn CriticalHit Short RandomPercent Short SkillVar Ref Me Float LuckSkill Float BladeSkill Begin ScriptEffectStart If isEssential == 0 Set RandomPercent to getRandomPercent Set LuckSkill to player.getActorValue Luck Set BladeSkill to player.getActorValue Blade Set SkillVar to (LuckSkill + BladeSkill) * 0.025 If SkillVar < 1 Set SkillVar to 1 Endif If RandomPercent <= SkillVar Message "Critical Hit" ;Set Me to getself ;your functions (eg. Player.Pushactoraway Me 100) Endif Endif End