player_attacks.lua

main 30 lines · 1.2 KB Raw
Alex Alex Commit Server upload 18/10/2026 23:38
1local playerAttack = CreatureEvent("playerAttackSound")
2
3
4function playerAttack.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
5 if attacker and attacker:isPlayer() then
6 local player = attacker
7 if origin == ORIGIN_MELEE or origin == ORIGIN_RANGED then
8 local weapon = player:getSlotItem(CONST_SLOT_LEFT)
9 if weapon then
10 local weaponType = weapon:getType():getWeaponType()
11
12 if weaponType == WEAPON_AXE or weaponType == WEAPON_SWORD or weaponType == WEAPON_CLUB then
13 playSound(player, "weapon_attack.ogg")
14 elseif weaponType == WEAPON_WAND then
15 playSound(player, "wand_attack.ogg")
16 elseif weaponType == WEAPON_DISTANCE then
17 playSound(player, "distance_attack.ogg")
18 elseif weaponType == WEAPON_NONE or weaponType == WEAPON_SHIELD then
19 playSound(player, "fist_attack.ogg")
20 end
21 else
22 playSound(player, "fist_attack.ogg")
23 end
24 end
25 end
26
27 return primaryDamage, primaryType, secondaryDamage, secondaryType
28end
29
30playerAttack:register()
Top