Jump to content

setTimer function with OOP


Recommended Posts

player_tbl = {
	index = {
		in_zone = false,
		
		zombie_proof = false,
		
		zombies = {},
		zombie_limit = 60,
		
		create_zombie = function(player)
			outputChatBox("test")
			if player.zombie_proof or not player.in_zone or isPedDead(player.element) then
				return
			end
			
			local zombie_count = 0
			while zombie_count < 3 do
				triggerClientEvent ("find_spawn_location", player.element)
				zombie_count = zombie_count + 1
			end
		end
	},
	
	players = {}
}

addEventHandler("onResourceStart", resourceRoot, function()
	for i, player in ipairs(getElementsByType("player")) do
		local self = setmetatable({
			element = player
		},
		{
			__index = player_tbl.index
		})
		
		table.insert(player_tbl.players, self)
		
		Timer(function(self)
			self:create_zombie() -- this line
			--self.create_zombie(self) -- or this line
		end, 10000, 0, self)
	end
end)

OD3L3z.png

 

What is the cause of the mistake?

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