I want to add zombies to a special Rp gamemode but for some reason it cannot read the chat commands.
Here is code:
/*---------------------------------------------------------
Variables
---------------------------------------------------------*/
local timeLeft = 10
local timeLeft2 = 10
local stormOn = false
local zombieOn = false
local maxZombie = 70
/*---------------------------------------------------------
Zombie
---------------------------------------------------------*/
local ZombieStart, ZombieEnd
local function ControlZombie()
timeLeft2 = timeLeft2 - 1
if timeLeft2 < 1 then
if zombieOn then
timeLeft2 = math.random(5,10)
zombieOn = false
timer.Stop("start2")
ZombieEnd()
else
timeLeft2 = math.random(5,12)
zombieOn = true
timer.Start("start2")
DB.RetrieveZombies(function()
ZombieStart()
end)
end
end
end
ZombieStart = function()
for k, v in pairs(player.GetAll()) do
if v:Alive() then
v:PrintMessage(HUD_PRINTCENTER, LANGUAGE.zombie_approaching)
v:PrintMessage(HUD_PRINTTALK, LANGUAGE.zombie_approaching)
end
end
end
ZombieEnd = function()
for k, v in pairs(player.GetAll()) do
if v:Alive() then
v:PrintMessage(HUD_PRINTCENTER, LANGUAGE.zombie_leaving)
v:PrintMessage(HUD_PRINTTALK, LANGUAGE.zombie_leaving)
end
end
end
local function LoadTable(ply)
ply:SetSelfDarkRPVar("numPoints", table.getn(zombieSpawns))
for k, v in pairs(zombieSpawns) do
ply:SetSelfDarkRPVar("zPoints" .. k, v)
end
end
local function ReMoveZombie(ply, index)
if ply:HasPriv("rp_commands") then
if not index or zombieSpawns[tonumber(index)] == nil then
GAMEMODE:Notify(ply, 1, 4, string.format(LANGUAGE.zombie_spawn_not_exist, tostring(index)))
else
DB.RetrieveZombies(function()
GAMEMODE:Notify(ply, 0, 4, LANGUAGE.zombie_spawn_removed)
table.remove(zombieSpawns, index)
DB.StoreZombies()
if ply.DarkRPVars.zombieToggle then
LoadTable(ply)
end
end)
end
else
GAMEMODE:Notify(ply, 1, 4, string.format(LANGUAGE.need_admin, "/removezombie"))
end
return ""
end
AddChatCommand("/removezombie", ReMoveZombie)
local function AddZombie(ply)
if ply:HasPriv("rp_commands") then
DB.RetrieveZombies(function()
table.insert(zombieSpawns, ply:GetPos())
DB.StoreZombies()
if ply.DarkRPVars.zombieToggle then LoadTable(ply) end
GAMEMODE:Notify(ply, 0, 4, LANGUAGE.zombie_spawn_added)
end)
else
GAMEMODE:Notify(ply, 1, 6, string.format(LANGUAGE.need_admin, "/addzombie"))
end
return ""
end
AddChatCommand("/addzombie", AddZombie)
local function ToggleZombie(ply)
if ply:HasPriv("rp_commands") then
if not ply.DarkRPVars.zombieToggle then
DB.RetrieveZombies(function()
ply:SetSelfDarkRPVar("zombieToggle", true)
LoadTable(ply)
end)
else
ply:SetSelfDarkRPVar("zombieToggle", false)
end
else
GAMEMODE:Notify(ply, 1, 6, LANGUAGE.string.format(LANGUAGE.need_admin, "/showzombie"))
end
return ""
end
AddChatCommand("/showzombie", ToggleZombie)
local function GetAliveZombie()
local zombieCount = 0
local ZombieTypes = {"npc_zombie", "npc_fastzombie", "npc_headcrab_fast"}
for _, Type in pairs(ZombieTypes) do
zombieCount = zombieCount + #ents.FindByClass(Type)
end
return zombieCount
end
local function SpawnZombie()
timer.Start("move")
if GetAliveZombie() >= maxZombie then return end
if table.getn(zombieSpawns) <= 0 then return end
local ZombieTypes = {"npc_zombie", "npc_fastzombie", "npc_headcrab_fast"}
local zombieType = math.random(1, #ZombieTypes)
local Zombie = ents.Create(ZombieTypes[zombieType])
Zombie.nodupe = true
Zombie:Spawn()
Zombie:Activate()
Zombie:SetPos(DB.RetrieveRandomZombieSpawnPos())
end
local function ZombieMax(ply, args)
if ply:HasPriv("rp_commands") then
if not tonumber(args) then
GAMEMODE:Notify(ply, 1, 4, string.format(LANGUAGE.invalid_x, "argument", ""))
return ""
end
maxZombie = tonumber(args)
GAMEMODE:Notify(ply, 0, 4, string.format(LANGUAGE.zombie_maxset, args))
end
return ""
end
AddChatCommand("/zombiemax", ZombieMax)
AddChatCommand("/maxzombie", ZombieMax)
AddChatCommand("/maxzombies", ZombieMax)
local function StartZombie(ply)
if ply:HasPriv("rp_commands") then
timer.Start("zombieControl")
GAMEMODE:Notify(ply, 0, 4, LANGUAGE.zombie_enabled)
end
return ""
end
AddChatCommand("/enablezombie", StartZombie)
local function StopZombie(ply)
if ply:HasPriv("rp_commands") then
timer.Stop("zombieControl")
zombieOn = false
timer.Stop("start2")
ZombieEnd()
GAMEMODE:Notify(ply, 0, 4, LANGUAGE.zombie_disabled)
end
return ""
end
AddChatCommand("/disablezombie", StopZombie)
timer.Create("start2", 1, 0, SpawnZombie)
timer.Create("zombieControl", 1, 0, ControlZombie)
timer.Stop("start2")
timer.Stop("zombieControl")
And error is:
[ERROR] lua/autorun/server/zombies.lua:75: attempt to call global 'AddChatCommand' (a nil value)
1. unknown - lua/autorun/server/zombies.lua:75
If the base gamemode is DarkRP then check out [URL="http://wiki.darkrp.com/index.php?title=LUA:DarkRP_Chat_Command"]this[/URL] otherwise you could look into adding some hooks for PlayerSay, I don't know much else that could help.
[QUOTE=TheTechPony;49310399]If the base gamemode is DarkRP then check out [URL="http://wiki.darkrp.com/index.php?title=LUA:DarkRP_Chat_Command"]this[/URL] otherwise you could look into adding some hooks for PlayerSay, I don't know much else that could help.[/QUOTE]
thank you will give it a go!!!
Sorry, you need to Log In to post a reply to this thread.