Adde Posted June 24, 2013 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 ) My ingame nickname is: Mr.Snus
DiSaMe Posted June 24, 2013 Posted June 24, 2013 Cancelling onPlayerDamage has no effect. Use onClientPlayerDamage in a client-side script instead. -
Adde Posted June 24, 2013 Author 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 ) ?? My ingame nickname is: Mr.Snus
iMr.3a[Z]eF Posted June 24, 2013 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 ) To Visit Us Press Here: mtasa://5.9.206.180:22002
Vision Posted June 24, 2013 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 )
Sasu Posted June 24, 2013 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.. State: Inactive
iMr.3a[Z]eF Posted June 24, 2013 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 ) To Visit Us Press Here: mtasa://5.9.206.180:22002
Sasu Posted June 24, 2013 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 ) State: Inactive
iMr.3a[Z]eF Posted June 24, 2013 Posted June 24, 2013 that is mean the script have to be client To Visit Us Press Here: mtasa://5.9.206.180:22002
iPrestege Posted June 25, 2013 Posted June 25, 2013 No it's not just change localPlayer > root as Sasuke* did .
Adde Posted June 25, 2013 Author Posted June 25, 2013 Now my heal system don´t work I stop damage but wont heal My ingame nickname is: Mr.Snus
Castillo Posted June 25, 2013 Posted June 25, 2013 Post the script. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Adde Posted June 25, 2013 Author 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 ) My ingame nickname is: Mr.Snus
Castillo Posted June 25, 2013 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 ) San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Adde Posted June 25, 2013 Author 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 My ingame nickname is: Mr.Snus
Adde Posted June 26, 2013 Author Posted June 26, 2013 It didn´t work It only stop the damage it doesn´t heal. My ingame nickname is: Mr.Snus
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