marty000123 Posted December 28, 2016 Share Posted December 28, 2016 (edited) I use this script to make the player who spawns as the ''Infected'' team a zombie. --serverside????? function makePlayerZombie() if getPlayerTeam == Infected then setElementData (player,'zombie',true) else return false end end addEventHandler('onPlayerSpawn', getRootElement(), makePlayerZombie) function removePlayerZombie() if getElementData (player,'zombie',true) then setElementData (player,'zombie',false) end end addEventHandler('onPlayerWasted', getRootElement(), removePlayerZombie) But zombies still attack the players. I have tried doing this on a ped with setElementData(ped,'zombie',true), and he acted like a zombie and zombies didn't attack him. This should work, but why doesn't it work? Also, this error has been given. It shows when a player in the ''Infected'' team dies. Error: WARNING: playerzombie\server.lua:10: Bad argument @ 'getElementData' [Expected element at argument 1, got nil] Any solution? Edited December 28, 2016 by marty000123 Link to comment
4O4 Posted December 28, 2016 Share Posted December 28, 2016 Hi, please use Code button next time you are pasting Lua code if getPlayerTeam == Infected then This condition looks bad and it is probably never true. getPlayerTeam is a function so it should be called - check wiki for examples. Also, Infected should probably be quoted if it is team name literal. function removePlayerZombie() if getElementData (player,'zombie',true) It is throwing warning, because you haven't defined "player" anywhere. It should probably be "source" in your case instead. Link to comment
marty000123 Posted December 28, 2016 Author Share Posted December 28, 2016 (edited) function makePlayerZombie() if isPlayerInTeam(player, "Infected") then outputChatBox("You spawned as a zombie, so you do not have to be afraid for other zombies anymore!", player, 255, 0, 0) setElementData (player,'zombie',true) else return false end end addEventHandler('onPlayerSpawn', getRootElement(), makePlayerZombie) function removePlayerZombie() if getElementData (source,'zombie',true) then setElementData (player,'zombie',false) end end addEventHandler('onPlayerWasted', getRootElement(), removePlayerZombie) [2016-12-28 08:46:58] ERROR: playerzombie\server.lua:2: attempt to call global 'isPlayerInTeam' (a nil value)[code] I have no idea how to call since I've never done it before and the wiki isn't really making it clear for me.. And uh, I don't know how to properly make that LUA code on the forum. Edited December 28, 2016 by marty000123 Link to comment
Dimos7 Posted December 28, 2016 Share Posted December 28, 2016 (edited) function makePlayerZombie() if getTeamName(getPlayerTeam(source))== "Infected" then outputChatBox("You spawned as a zombie, so you do not have to be afraid for other zombies anymore!", player, 255, 0, 0) setElementData (source,'zombie',true) else return false end end addEventHandler('onPlayerSpawn', getRootElement(), makePlayerZombie) function removePlayerZombie() if getElementData (source,'zombie',true) then setElementData (source,'zombie',false) end end addEventHandler('onPlayerWasted', getRootElement(), removePlayerZombie) Edited December 28, 2016 by Dimos7 1 Link to comment
marty000123 Posted December 29, 2016 Author Share Posted December 29, 2016 That worked man, thanks alot. But why does it need to be ''source'' instead of ''player''? Like, the getElementData and setElementData needs to refer to the player, right? And when is source/player used? Link to comment
4O4 Posted December 29, 2016 Share Posted December 29, 2016 It must be Player, but not necessarily a variable named "player" (which was nil in your case, because you never told your script what it is). Both of your functions are executed by some events, and all events have a source (which is also a special variable available in scope of the function that gets executed by event). If you open the documentation page on wiki for onPlayerWasted you can see that in this case the source of event is some Player. Quote The source of this event is the player that died or got killed. There is plenty of information on wiki, so you just need to learn how to use it properly. Follow the links and read everything which is related to the functions or events you want to use. Start by clicking on "source" link and you will see all information about event system Then check some Lua tutorials to learn about variables, scopes, functions etc., there are links on main wiki page too (https://wiki.multitheftauto.com/wiki/Main_Page, General Lua Help section). 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