Actually you put the code in the wrong place
Code:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
if (not attacker:isPlayer()) then return end
local weapontype = nil
local slotItem = attacker:getSlotItem(CONST_SLOT_LEFT)
if slotItem then
weaponType = slotItem:getType():getWeaponType()
end
local skill = SKILL_FIST
if weaponType == WEAPON_DISTANCE then
skill = SKILL_DISTANCE
elseif weaponType == WEAPON_SWORD then
skill = SKILL_SWORD
elseif weaponType == WEAPON_CLUB then
skill = SKILL_CLUB
elseif weaponType == WEAPON_AXE then
skill = SKILL_AXE
end
local skilllvl = attacker:getEffectiveSkillLevel(skill)
if math.random(0,99) < skillLvl/10 then
if origin == ORIGIN_MELEE then
creature:say("SKULLBASH!", TALKTYPE_MONSTER_SAY)
elseif origin == ORIGIN_RANGED then
creature:say("HEADSHOT!", TALKTYPE_MONSTER_SAY)
end
return primaryDamage * 10, primaryType, secondaryDamage, secondaryType
end
return primaryDamage, primaryType, secondaryDamage, secondaryType
end
I can't test (I'm without any ot on my laptop, and I'm writing this on my phone now)
How it should work:the first if check if the attacker is a player.
The second if checks if you have an item equipped in the left hand slot, and then, reserves the type of weapon in a variable.
The other if/elseifs check if you are using sword, to count sword fighting, if you use club, to count club fighting, etc.. (haven't done for magic level, do some research and do yourself)
After that, I checked the skill lvl of the weapon type that the player is using (sword fighting to sword, club fighting to club, etc)
After that, I get a random number between 0 and 99 (including both) . The number generated is compared to the number of the player skill divided by 10 (so, skill 10 = 1%, it means that the random should be 0 to work, and skill 100 = 10%, so the random must be between 0 and 9 to work . Etc
And the rest is a copy of the script you found