I use the following on my fretta server, which used to work quite nicely, but now, after I added outcomes for some specific gamemodes, it errors out with the following:
Lua Error: Hook 'rtdcmd' Failed: [lua\autorun\server\rtd.lua:434] attempt to call local 'outcome' (a table value)
It also won't load automatically, as gmod.GetGamemode.Name() is nil before the gamemode loads. Could I simply fix that with a few seconds timer?
[lua]
AddCSLuaFile("./client/cl_rtd.lua")
AddCSLuaFile("../client/cl_rtd.lua") -- No idea which of these two work :D
local duration = CreateConVar("rtd_roll_duration", 20)
local health = CreateConVar("rtd_roll_health", 200)
local frags = CreateConVar("rtd_roll_frags", 1337)
local armor = CreateConVar("rtd_roll_armor", 100)
local maxrolls = CreateConVar("rtd_rolls_max", 2)
local rollinterval = CreateConVar("rtd_rolls_interval", 180)
local chatcommand = CreateConVar("rtd_roll_saycommand", "!rtd")
local dice = {}
local health = health:GetInt()
local frags = frags:GetInt()
local duration = duration:GetInt()
local armor = armor:GetInt()
dice.outcomes = {
Ignite = function(ply)
-- PrintMessage(HUD_PRINTTALK, "[RTD]"..ply:Nick().." has been ignited for "..duration.." seconds")
for k, v in pairs(player.GetAll()) do
chat.AddText(v,Color(255,255,0),"[RTD]",Color(0,255,0),ply:Nick(),Color(0,255,255)," has been ignited for "..duration.." seconds")
end
ply:Ignite(duration, 0)
ply:SetColor(255, 0, 0, 255)
timer.Simple(duration, function(ply)
ply:SetColor(255, 255, 255, 255)
end, ply)
end ,
Kill = function(ply)
--PrintMessage(HUD_PRINTTALK, "[RTD]"..ply:Nick().." has been killed")
for k, v in pairs(player.GetAll()) do
chat.AddText(v,Color(255,255,0),"[RTD]",Color(0,255,0),ply:Nick(),Color(0,255,255)," has been killed")
end
ply:Kill()
end ,
Colors = function(ply)
--PrintMessage(HUD_PRINTTALK, "[RTD]"..ply:Nick().." got their color changed")
for k, v in pairs(player.GetAll()) do
chat.AddText(v,Color(255,255,0),"[RTD]",Color(0,255,0),ply:Nick(),Color(0,255,255)," got their colour changed")
end
ply:SetColor(math.Rand(0, 255), math.Rand(0, 255), math.Rand(0, 255), 255)
end ,
Nothing = function(ply)
--PrintMessage(HUD_PRINTTALK, "[RTD]"..ply:Nick().." got nothing")
for k, v in pairs(player.GetAll()) do
chat.AddText(v,Color(255,255,0),"[RTD]",Color(0,255,0),ply:Nick(),Color(0,255,255)," got nothing")
end
end ,
Health = function(ply)
--PrintMessage(HUD_PRINTTALK, "[RTD]"..ply:Nick().." got their health added by "..health)
for k, v in pairs(player.GetAll()) do
chat.AddText(v,Color(255,255,0),"[RTD]",Color(0,255,0),ply:Nick(),Color(0,255,255)," got their health added by "..health)
end
ply:SetHealth(ply:Health()+health)
end ,
Frags = function(ply)
--PrintMessage(HUD_PRINTTALK, "[RTD]"..ply:Nick().." got their frags set to "..frags)
for k, v in pairs(player.GetAll()) do
chat.AddText(v,Color(255,255,0),"[RTD]",Color(0,255,0),ply:Nick(),Color(0,255,255)," got their frags set to ".. frags)
end
ply:SetFrags(frags)
end ,
Freeze = function(ply)
--PrintMessage(HUD_PRINTTALK, "[RTD]"..ply:Nick().." got frozen for "..duration.." seconds")
for k, v in pairs(player.GetAll()) do
chat.AddText(v,Color(255,255,0),"[RTD]",Color(0,255,0),ply:Nick(),Color(0,255,255)," got frozen for "..duration.." seconds")
end
ply:Freeze(true)
ply:SetColor(0, 0, 255, 255)
ply:EmitSound("physics/glass/glass_sheet_break1.wav")
timer.Simple(duration, function(ply)
ply:Freeze(false)
--ply:PrintMessage(HUD_PRINTTALK, "[RTD]You got unfrozen")
chat.AddText(ply, Color(255,255,0),"[RTD]",Color(0,255,0),"You",Color(0,255,255)," got unfrozen")
--PrintMessage(HUD_PRINTTALK, "[RTD]"..ply:Nick().." just got unfrozen")
for k, v in pairs(player.GetAll()) do
chat.AddText(v, Color(255,255,0),"[RTD]",Color(0,255,0),ply:Nick(),Color(0,255,255)," just got unfrozen")
end
ply:SetColor(255, 255, 255, 255)
end, ply)
end,
Strip = function(ply)
--PrintMessage(HUD_PRINTTALK, "[RTD]"..ply:Nick().." got stripped of all weapons, except a lousy crowbar")
for k, v in pairs(player.GetAll()) do
chat.AddText(v,Color(255,255,0),"[RTD]",Color(0,255,0),ply:Nick(),Color(0,255,255)," got stripped of everything except a lousy crowbar")
end
ply:StripWeapons()
ply:Give("weapon_crowbar")
ply:Give("weapon_zm_improvised")
end,
Ragdoll = function(ply)
--PrintMessage(HUD_PRINTTALK, "[RTD]"..ply:Nick().." got ragdoll'd for "..duration.." seconds")
for k, v in pairs(player.GetAll()) do
chat.AddText(v,Color(255,255,0),"[RTD]",Color(0,255,0),ply:Nick(),Color(0,255,255)," got ragdolled for "..duration.." seconds")
end
local ent = ents.Create("prop_ragdoll")
ent:SetPos(ply:GetPos())
ent:SetAngles(ply:GetAngles())
ent:SetModel(ply:GetModel())
ent:Spawn()
ent:Activate()
ent:SetColor(255, 255, 25, 255)
ply:SetParent(ent)
ply:Spectate(OBS_MODE_CHASE)
ply:SpectateEntity(ent)
ply:StripWeapons()
timer.Simple(duration, function(ply)
--PrintMessage(HUD_PRINTTALK, "[RTD]"..ply:Nick().." got unragdoll'd")
for k, v in pairs(player.GetAll()) do
chat.AddText(v,Color(255,255,0),"[RTD]",Color(0,255,0),ply:Nick(),Color(0,255,255)," got unragdolled")
end
ply:SetParent()
ply:Spawn()
entpos = ent:GetPos()
entpos.z = entpos.z + 75
ply:SetPos(entpos)
ent:Remove()
end, ply)
end,
Rocket = function(ply)
--PrintMessage(HUD_PRINTTALK, "[RTD]"..ply:Nick().." got shot the fuck up and got exploded")
for k, v in pairs(player.GetAll()) do
chat.AddText(v,Color(255,255,0),"[RTD]",Color(0,255,0),ply:Nick(),Color(0,255,255)," got shot the fuck up and asploded!")
end
if ply:GetMoveType() == MOVETYPE_NOCLIP then
ply:SetMoveType(MOVETYPE_WALK)
end
ply:SetVelocity(Vector(0, 0, 9999))
timer.Simple(3, function(ply)
local exp = ents.Create("env_explosion")
exp:SetPos(ply:GetPos())
exp:Spawn()
exp:Fire("Explode", 0, 0)
ply:KillSilent()
ply:Kill()
//ply:KillSilent()
end, ply)
end ,
Crush = function(ply)
if ply:GetMoveType() == MOVETYPE_NOCLIP then
ply:SetMoveType(MOVETYPE_WALK)
end
ply:Freeze(true)
ply:GodDisable()
--PrintMessage(HUD_PRINTTALK, "[RTD]"..ply:Nick().." got fucking crushed!")
for k, v in pairs(player.GetAll()) do
chat.AddText(v,Color(255,255,0),"[RTD]",Color(0,255,0),ply:Nick(),Color(0,255,255)," got crushzored!")
end
local models = {
"models/props_c17/FurnitureWashingmachine001a.mdl",
"models/Cliffs/rockcluster02.mdl",
"models/props_wasteland/rockcliff_cluster02a.mdl",
"models/props_wasteland/rockcliff05f.mdl",
"models/props_wasteland/rockcliff_cluster03c.mdl",
"models/props_foliage/rock_coast02h.mdl",
"models/props_junk/TrashDumpster02.mdl",
"models/props_wasteland/cargo_container01.mdl",
"models/props_wasteland/laundry_dryer002.mdl",
"models/props_foliage/rock_coast02h.mdl"}
local entc = ents.Create("prop_physics")
entc:SetModel(table.Random(models))
entc:SetPos(ply:GetPos()+Vector(0, 0, 500))
entc:Spawn()
phys = entc:GetPhysicsObject()
phys:SetMass(999)
entc:SetVelocity(Vector(0, 0, -999))
timer.Simple(6, function(ply)
entc:Remove()
if ply:Alive() then
ply:Kill()
end
ply:Freeze(false)
end, ply)
end,
Invis = function(ply)
--PrintMessage(HUD_PRINTTALK, "[RTD]"..ply:Nick().." got invisible for "..duration.." seconds")
for k, v in pairs(player.GetAll()) do
chat.AddText(v,Color(255,255,0),"[RTD]",Color(0,255,0),ply:Nick(),Color(0,255,255)," turned invisible for "..duration.." seconds")
end
ply:SetColor(0, 0, 0, 0)
timer.Simple(duration, function(ply)
--PrintMessage(HUD_PRINTTALK, "[RTD]"..ply:Nick().." got uninvis'd")
for k, v in pairs(player.GetAll()) do
chat.AddText(v,Color(255,255,0),"[RTD]",Color(0,255,0),ply:Nick(),Color(0,255,255)," lost invisibility")
end
ply:SetColor(255, 255, 255, 255)
end, ply)
end,
Godmode = function(ply)
--PrintMessage(HU
You are adding tables that contain the function to run to your outcome table, you don't need to use table.insert because the key is the function name, eg
[lua]function dice.outcomes.Speed(ply)
for k, v in pairs(player.GetAll()) do
chat.AddText(v,Color(255,255,0),"[RTD]",Color(0,255,0),ply:Nick(),Color(0,255,255)," got 2x speed for "..duration.." seconds")
end
ply:SetWalkSpeed(500)
ply:SetCrouchedWalkSpeed(2)
timer.Simple(duration, function(ply)
for k, v in pairs(player.GetAll()) do
chat.AddText(v,Color(255,255,0),"[RTD]",Color(0,255,0),ply:Nick(),Color(0,255,255)," no longer has 2x speed")
end
ply:SetGravity(250)
ply:SetCrouchedWalkSpeed(1)
end, ply)
end[/lua]
Oh I see, thanks very much.
I would still use table.insert for the "dice.notimers" array, right? And for line 350, would I be correct in saying that adding a simple timer, so the gamemode name is retrieved after the lua file is run would work?
You need to remove the '{' and '}' around the strings you are adding to notimers with table.insert.
I'm not sure about the second question.
Thanks for the help. Putting the gamemode check into a timer seemed to have work fine.
I have another question now though, regarding the creating and removing of different entities. When someone get's jailed, "jail" is spawned. If another player then also get's jailed, another "jail" is spawned, and then that one is removed after the timer, rather than the first one.
Basically, how can I check if that entity already exists, and if so, change the name of the new entity?
Make the jail variable local, this will cause each call to the Jail function to handle a separate jail entity.
Sorry, you need to Log In to post a reply to this thread.