Jump to content
Sign in to follow this  

Question about the OnWeaponHitCharacter event

Recommended Posts

Hi! does this mean when you hit a different player, or a hit a zombie? Also, How do I satisfy the Float parameter called damageSplit? Can I just fill in any number with my own variable or do I have to call a specific method that returns the value? I'm defintely new to LUA coding, so thanks for your time replying to this!

Share this post

Link to post
Share on other sites
Posted (edited)

After doing some of my own tests I can confirm that it includes hitting other players and zombies.


OnWeaponHitCharacter calls functions added to it when triggered. You must name the 4 parameters in the function you give to the OnWeaponHitCharacter Event.

You can call those parameters any variable name you want in your lua functions.


Here's a simple example lua code that prints out the attacker's name, target's name, weapon name, and the damageSplit variable.

Feel free to modify/use this code.

    Triggered when a "IsoGameCharacter" has been hit by a "HandWeapon".
        IsoGameCharacter attacker
        IsoGameCharacter target
        HandWeapon weapon
        Float damageSplit
local function onWeaponHit(attacker, target, weapon, damageSplit)
    local attackerName = tostring( attacker:getFullName() )
    local targetName = tostring( target:getFullName() )
    local weaponName = tostring( weapon:getName() )
    -- Print out the attacker's name, target's name, weapon name, and the damageSplit variable.
    print(string.format("%s | %s | %s | %f", attackerName, targetName, weaponName, damageSplit))

    --print(attackerName.." | "..targetName.." | "..weaponName.." | "..damageSplit)

-- Add the function named "onWeaponHit" to the OnWeaponHitCharacter Event.


It prints out this on the Build 40 console. (I am hitting super survivors and zombies with a hammer. Apparently zombies have names.)


Edited by ATPHHe

Share this post

Link to post
Share on other sites

You’ll want to use getType() to check if it’s an IsoZombie or an IsoPlayer, iirc.  So, attacker.getType() should return a string with the class name that you can compare.

IsoGameCharacter is the just patent class these two inherit from, rather than what’s actually passed to the function.


Zombies have full player descriptions, but they’re not used for much (if anything) in practice. It’s inherited from IsoGameCharacter.

I’ve not touched this stuff in a long time though, personally. I might well have it confused with getClass() or toString(). There should be examples of this in the game code regardless.



Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...