marty000123 Posted July 24, 2017 Share Posted July 24, 2017 (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 July 24, 2017 by marty000123 Link to comment
Simple0x47 Posted July 24, 2017 Share Posted July 24, 2017 Cool you're talking about zombies, but what about showing us the code of the attack function? Link to comment
iMr.WiFi..! Posted July 24, 2017 Share Posted July 24, 2017 Try to use : setElementData ( thePlayer, "zombieProof", true ) -- this will make the zombie not attack you Im not sure about this but try it : ) Link to comment
Dimos7 Posted July 24, 2017 Share Posted July 24, 2017 (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 July 24, 2017 by Dimos7 Link to comment
marty000123 Posted July 25, 2017 Author Share Posted July 25, 2017 https://pastebin.com/eruNwKBD Link to comment
Dimos7 Posted July 25, 2017 Share Posted July 25, 2017 what is there errors also post the code with code button Link to comment
Zorgman Posted July 25, 2017 Share Posted July 25, 2017 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 Link to comment
marty000123 Posted July 26, 2017 Author Share Posted July 26, 2017 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. Link to comment
Zorgman Posted July 26, 2017 Share Posted July 26, 2017 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 Link to comment
marty000123 Posted July 26, 2017 Author Share Posted July 26, 2017 (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 July 26, 2017 by marty000123 Link to comment
Zorgman Posted July 26, 2017 Share Posted July 26, 2017 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. Link to comment
marty000123 Posted July 26, 2017 Author Share Posted July 26, 2017 The point is not to create a new kind of zombie. The Katana part will be the player that's spawned in the zombie class. I'll try it out, thanks. Link to comment
iMr.WiFi..! Posted July 26, 2017 Share Posted July 26, 2017 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 : ) ^^ Link to comment
Anubhav Posted July 30, 2017 Share Posted July 30, 2017 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) 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