Adde Posted June 24, 2013 Share Posted June 24, 2013 Hey guys, I have been tried to understand how to stop the damage from weapon id 41 if the player is in team Emergency. If I understand this right it should be something with: function cancel () if getTeamName ( getTeamFromName ( "Emergency" )) then if ( attackerWeapon == 41 ) then cancelEvent() addEventHandler ( "onPlayerDamage", getRootElement, cancel ) right? My script looks like this function medicJob (healer, healerweapon, bodypart, loss) theHealth = getElementHealth (source) theSkin = getPedSkin ( healer ) if (healerweapon == 41) and (loss > 1) and ( theHealth < 80 ) and ( theSkin == 276 ) then setElementHealth ( source, getElementHealth(source) + 20 ) givePlayerMoney (healer, 30) end end addEventHandler ("onPlayerDamage", getRootElement(), medicJob ) Link to comment
DiSaMe Posted June 24, 2013 Share Posted June 24, 2013 Cancelling onPlayerDamage has no effect. Use onClientPlayerDamage in a client-side script instead. Link to comment
Adde Posted June 24, 2013 Author Share Posted June 24, 2013 soooo.. function cancel ( attackerWeapon ) if getTeamName ( getPlayerTeam ( getLocalPlayer() ) ) == "Emergency" then if ( attackerWeapon == 41 ) then cancelEvent() end end end addEventHandler ( "onClientPlayerDamage", getLocalPlayer(), cancel ) ?? Link to comment
iMr.3a[Z]eF Posted June 24, 2013 Share Posted June 24, 2013 function cancel ( attackerWeapon, player ) if getElementType( player ) == "player" then if getTeamName ( getPlayerTeam ( player ) ) == "Emergency" then if ( attackerWeapon == 41 ) then cancelEvent() end end end end addEventHandler ( "onPlayerDamage", getLocalPlayer(), cancel ) Link to comment
Vision Posted June 24, 2013 Share Posted June 24, 2013 Is that what you wanted to? function cancel ( attacker, attackerWeapon ) if ( getTeamName ( getPlayerTeam ( attacker ) ) == "Emergency" ) then if ( attackerWeapon == 41 ) then cancelEvent ( ) end end end addEventHandler ( "onClientPlayerDamage", root, cancel ) Link to comment
Sasu Posted June 24, 2013 Share Posted June 24, 2013 Is that what you wanted to? function cancel ( attacker, attackerWeapon ) if ( getTeamName ( getPlayerTeam ( attacker ) ) == "Emergency" ) then if ( attackerWeapon == 41 ) then cancelEvent ( ) end end end addEventHandler ( "onClientPlayerDamage", root, cancel ) You should use getElementType(attacker) to check if is a player instead of vehicle, object, etc.. Link to comment
iMr.3a[Z]eF Posted June 24, 2013 Share Posted June 24, 2013 Is that what you wanted to? function cancel ( attacker, attackerWeapon ) if ( getTeamName ( getPlayerTeam ( attacker ) ) == "Emergency" ) then if ( attackerWeapon == 41 ) then cancelEvent ( ) end end end addEventHandler ( "onClientPlayerDamage", root, cancel ) You should use getElementType(attacker) to check if is a player instead of vehicle, object, etc.. as i did lol function cancel ( attackerWeapon, player ) if getElementType( player ) == "player" then if getTeamName ( getPlayerTeam ( player ) ) == "Emergency" then if ( attackerWeapon == 41 ) then cancelEvent() end end end end addEventHandler ( "onPlayerDamage", getLocalPlayer(), cancel ) Link to comment
Sasu Posted June 24, 2013 Share Posted June 24, 2013 Is that what you wanted to? function cancel ( attacker, attackerWeapon ) if ( getTeamName ( getPlayerTeam ( attacker ) ) == "Emergency" ) then if ( attackerWeapon == 41 ) then cancelEvent ( ) end end end addEventHandler ( "onClientPlayerDamage", root, cancel ) You should use getElementType(attacker) to check if is a player instead of vehicle, object, etc.. as i did lol function cancel ( attackerWeapon, player ) if getElementType( player ) == "player" then if getTeamName ( getPlayerTeam ( player ) ) == "Emergency" then if ( attackerWeapon == 41 ) then cancelEvent() end end end end addEventHandler ( "onPlayerDamage", getLocalPlayer(), cancel ) But the event and parameters is wrong. "onClientPlayerDamage" --[[ attacker: A player element representing the attacker or vehicle element (when being run over or falling off a bike). weapon: An integer representing the weapon ID the attacker used ]] Should be: function cancel ( player, attackerWeapon ) if getElementType( player ) == "player" then if getTeamName ( getPlayerTeam ( player ) ) == "Emergency" then if ( attackerWeapon == 41 ) then cancelEvent() end end end end addEventHandler ( "onClientPlayerDamage", root, cancel ) Link to comment
iMr.3a[Z]eF Posted June 24, 2013 Share Posted June 24, 2013 that is mean the script have to be client Link to comment
iPrestege Posted June 25, 2013 Share Posted June 25, 2013 No it's not just change localPlayer > root as Sasuke* did . Link to comment
Adde Posted June 25, 2013 Author Share Posted June 25, 2013 Now my heal system don´t work I stop damage but wont heal Link to comment
Adde Posted June 25, 2013 Author Share Posted June 25, 2013 Post the script. Ok Server function medicJob (healer, healerweapon, bodypart, loss) theHealth = getElementHealth (source) theSkin = getPedSkin ( healer ) if (healerweapon == 41) and (loss > 1) and ( theHealth < 80 ) and ( theSkin == 276 ) then setElementHealth ( source, getElementHealth(source) + 20 ) givePlayerMoney (healer, 30) end end addEventHandler ("onPlayerDamage", getRootElement(), medicJob ) Client function cancel ( attacker, attackerWeapon ) if ( getTeamName ( getPlayerTeam ( attacker ) ) == "Emergency" ) then if ( attackerWeapon == 41 ) then cancelEvent ( ) end end end addEventHandler ( "onClientPlayerDamage", root, cancel ) Link to comment
Castillo Posted June 25, 2013 Share Posted June 25, 2013 -- client side: function cancel ( attacker, attackerWeapon, bodypart, loss ) if ( getTeamName ( getPlayerTeam ( attacker ) ) == "Emergency" ) then if ( attackerWeapon == 41 ) then local theSkin = getElementModel ( attacker ) local theHealth = getElementHealth ( localPlayer ) if ( loss > 1 ) and ( theHealth < 80 ) and ( theSkin == 276 ) then triggerServerEvent ( "healPlayer", localPlayer, attacker ) cancelEvent ( ) end end end end addEventHandler ( "onClientPlayerDamage", root, cancel ) -- server side: function medicJob ( healer ) setElementHealth ( source, getElementHealth ( source ) + 20 ) givePlayerMoney ( healer, 30 ) end addEvent ( "healPlayer", true ) addEventHandler ( "healPlayer", getRootElement(), medicJob ) Link to comment
Adde Posted June 25, 2013 Author Share Posted June 25, 2013 Oh, I thought of something like that also, but didn´t test because I didn´t know how to do it. I will test this and tell if it works As it should Link to comment
Adde Posted June 26, 2013 Author Share Posted June 26, 2013 It didn´t work It only stop the damage it doesn´t heal. 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