Jump to content

Anti-zombie player


Recommended Posts

Posted (edited)

Hi community.

I made a script that makes the player immune to zombies. It gives them the elementdata, causing zombies to not attack the player. But it doesn't work, the zombies still attack the player. I've made sure the team was correct. Any help would be nice.

This is the script I'm using:

	function makeZombie()
if getPlayerTeam(source) == "Infected" then
setElementData(source, "zombie", true)
end
end
addEventHandler("onPlayerSpawn", getRootElement(), makeZombie)
	function removeZombie()
if getElementData(source, "zombie", true) then
removeElementData(source, "zombie")
end
end
addEventHandler("onPlayerWasted", getRootElement(), removeZombie)
Edited by marty000123
Posted (edited)
	function makeZombie()
if getPlayerTeam(source) == "Infected" then
setElementData(source, "zombie", true)
end
end
addEventHandler("onPlayerSpawn", getRootElement(), makeZombie)
	function removeZombie()
if getElementData(source, "zombie") == true then
removeElementData(source, "zombie")
end
end
addEventHandler("onPlayerWasted", getRootElement(), removeZombie)

 

Edited by Dimos7
Posted

Hi,

The 'attack code' is not necessary here. The "zombie" element data filters out non-valid targets, assuming you use a derivate of Slothman's zombies.

I banged my head hard against a similar team problem with my own project a while ago. getPlayerTeam returns the team element so it will never be equal with the "Infected" string and your char never gets zombiefied. Use getPlayerTeam in conjunction with getTeamName in order to do your check. Let me know how it went if you'll find the time.

Cheers

Posted

Thanks for the reply,

function makeZombie(thePlayer)
if getTeamName(getPlayerTeam(thePlayer)) == "Infected"then
setElementData(thePlayer, "zombie", true)
end
end
addEventHandler("onPlayerSpawn", getRootElement(), makeZombie)

This is what I have now. Still no luck, and no errors/warnings.

Posted

Hi,

Check the wiki for the parameters for onPlayerSpawn: player team is the fifth, so we have:

function makeZombie(x,y,z,rot,team)
  if getTeamName(team) == "Infected" then
  	setElementData(source, "zombie", true)
  end
end
addEventHandler("onPlayerSpawn", getRootElement(), makeZombie)

Also make sure this script is server side.

Cheers

Posted (edited)

It's not working too well. It gives a warning. My scripter is on it at the moment. Thanks a lot though, pushed me into the right direction!

But now I have another problem. It's with another part of the same script. The point of the bit is to make players lose 40hp when they're hit by a zombie player. But it doesn't seem to work, and it gives 0 warnings and 0 errors. Help would be nice.

function katana(attacker, weapon, bodypart, loss)
if getElementData(getRootElement(), "zombie", true) then
    if getPedWeapon (getRootElement()) == 8 then
        setElementHealth ( attacker, getElementHealth(attacker) - 40 )
    end
end
end
addEventHandler("onPlayerDamage", getRootElement(), katana)

Edited by marty000123
Posted

Looks like you're checking the root element for the 'zombie' attribute and weapon. You should instead check the attacker and alter the health of the source (that's the damaged player). Is this a special type of zombie that you try to set up? Because otherwise the 'zombie' resource has a function to amplify the zed damage, you only need to change the value there.

Posted
On ٢٤‏/٧‏/٢٠١٧ at 20:56, iMr.WiFi..! said:

Try to use :
 


setElementData ( thePlayer, "zombieProof", true ) -- this will make the zombie not attack you

Im not sure about this but try it : )

^^

Posted
function katana(attacker, weapon, bodypart, loss)
	if getElementData(attacker, "zombie", true) then
    	if getPedWeapon(attacker) == 8 then
        	setElementHealth(source, getElementHealth(source) - 40)
    	end
	end
end
addEventHandler("onPlayerDamage", getRootElement(), katana)

 

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...