Jump to content

Make player a zombie problem


marty000123

Recommended Posts

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 by marty000123
Link to comment

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
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 by marty000123
Link to comment
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 by Dimos7
  • Like 1
Link to comment

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

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