Jump to content

Amplified Knife Damage


capitanazop

Recommended Posts

function KnifeDamage( attacker, weapon, bodypart, targetPlayerName ) 
  
        if ( weapon == 4 ) then --the knife 
        setElementHealth ( Player, getElementHealth(Player) - 20 ) 
        end 
end 
addEventHandler ( "onClientPlayerDamage", getLocalPlayer(), KnifeDamage ) 

but this doesnt work

plz help me, bye n sorry for ma english :D

Link to comment

i have the same problem :S

function KnifeDamage( attacker, weapon, bodypart, targetPlayerName ) 
  
        if ( weapon == 4 ) then --the knife 
        Player = getLocalPlayer() 
        setElementHealth ( Player, getElementHealth(Player) - 20 ) 
        end 
end 
addEventHandler ( "onClientPlayerDamage", getLocalPlayer(), KnifeDamage ) 

[09:53:12] ERROR: ...er/mods/deathmatch/resources/diversion/diversion.lua:870: attempt to call global 'getLocalPlayer' (a nil value) 
[09:53:12] start: Resource 'diversion' started 

Link to comment

The error occurs because 'getLocalPlayer()' doesn't exist server side.

You need to make it as a client side script.

But you can also use the following code in your server side script:

function playerDamage ( attacker, weapon, bodypart, loss ) 
    if ( weapon == 4 ) then 
        setElementHealth ( source, getElementHealth(source) - 20 ) 
    end 
end 
  
addEventHandler ( "onPlayerDamage", getRootElement (), playerDamage ) 

Link to comment
The error occurs because 'getLocalPlayer()' doesn't exist server side.

The code you provided should work, but there's something strange with his piece of code... Let's take a look at the script.

function KnifeDamage( attacker, weapon, bodypart, targetPlayerName ) 
  
        if ( weapon == 4 ) then --the knife 
        Player = getLocalPlayer() 
        setElementHealth ( Player, getElementHealth(Player) - 20 ) 
        end 
end 
addEventHandler ( "onClientPlayerDamage", getLocalPlayer(), KnifeDamage ) 

How does getLocalPlayer() get called at all if it would be server side... Besides, you would get an error in the addEventHandler for bad argument. (2)

Have you set a variable with the same name to nil or something? Because it looks pretty weird... =/

Link to comment

It looks like the only problem is that you didn't make script work in client side, right? If you did, everything should be normal. And one more thing if it's client-side. All players around the attacked player will be hurt, won't they?

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...