capitanazop Posted October 23, 2008 Share Posted October 23, 2008 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 Link to comment
tma Posted October 23, 2008 Share Posted October 23, 2008 Your variable 'Player' isn't defined so use something like: Player = getLocalPlayer() before your setElementHealth() call. Link to comment
capitanazop Posted October 23, 2008 Author Share Posted October 23, 2008 i have the same problem 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
XetaQuake Posted October 23, 2008 Share Posted October 23, 2008 And maybe you add a else, not sure but i think that can prevent warnings. XetaQuake //EDIT: add a local befor Player = getLocalPlayer() Link to comment
Mr.Hankey Posted October 23, 2008 Share Posted October 23, 2008 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
Gamesnert Posted October 23, 2008 Share Posted October 23, 2008 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
DiSaMe Posted October 23, 2008 Share Posted October 23, 2008 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now