I am clueless as to why this will not work, I get no errors what so ever in console, just nothing happens when it should be.
[lua]
//Adjustable Vars
duration = 20 -- duration in seconds
color = Color(0, 0, 255, 100)
health = 200
frags = 1337
text = "!rtd"
dice = {}
function dice:outcomeIgnite(ply)
ply:PrintMessage(HUD_PRINTTALK, "You have been ignited for "..duration)
PrintMessage(HUD_PRINTTALK, ply:Nick().." has been ignited for "..duration)
ply:Ignite(duration, 0)
end
function dice:outcomeKill(ply)
ply:PrintMessage(HUD_PRINTTALK, "You have been killed")
PrintMessage(HUD_PRINTTALK, ply:Nick().." has been killed")
ply:Kill()
end
function dice:outcomeColor(ply)
ply:PrintMessage(HUD_PRINTTALK, "You got your color changed")
PrintMessage(HUD_PRINTTALK, ply:Nick().." got their color changed")
ply:SetColor(color)
end
function dice:outcomeNothing(ply)
ply:PrintMessage(HUD_PRINTTALK, "You got nothing")
PrintMessage(HUD_PRINTTALK, ply:Nick().." got nothing")
end
function dice:outcomeHealth(ply)
ply:PrintMessage(HUD_PRINTTALK, "You got your health set to: "..health)
PrintMessage(HUD_PRINTTALK, ply:Nick().." got their health set to "..health)
ply:SetHealth(health)
end
function dice:outcomeFrags(ply)
ply:PrintMessage(HUD_PRINTTALK, "You got your frags set to "..frags)
PrintMessage(HUD_PRINTTALK, ply:Nick().." got their frags set to "..frags)
ply:SetFrags(frags)
end
function diceRoll()
dice = math.Rand(1, 6)
if dice == 1 then
dice:outcomeColor(ply)
elseif dice == 2 then
dice:outcomeFrags(ply)
elseif dice == 3 then
dice:outcomeHealth(ply)
elseif dice == 4 then
dice:outcomeNothing(ply)
elseif dice == 5 then
dice:outcomeKill(ply)
elseif dice == 6 then
dice:outcomeIgnite(ply)
end
end
function dicePlayerSay()
if string.find(text) then
dice:Roll()
end
end
hook.Add("PlayerSay", "rtdcmd", dicePlayerSay)
concommand.Add("rtd", diceRoll)
[/lua]
any help would be great.
You aren't passing parameters to the PlayerSay hook. I'll fix it up, one second.
In you diceroll function you are setting the dice variable to a random number, overwriting the table that was previously stored in dice. You need to name that variable differently.
Also, you should use local variables.
[editline]02:36PM[/editline]
You are calling dice:Roll but the function is diceRoll.
[lua]//Adjustable Vars
local duration = 20 -- duration in seconds
local color = Color(0, 0, 255, 100)
local health = 200
local frags = 1337
local chatcommand = "!rtd"
local dice = {}
dice.outcomes = {
Ignite = function(pl)
pl:PrintMessage(HUD_PRINTTALK, "You have been ignited for "..duration)
PrintMessage(HUD_PRINTTALK, pl:Nick().." has been ignited for "..duration)
pl:Ignite(duration, 0)
end ,
Kill = function(pl)
pl:PrintMessage(HUD_PRINTTALK, "You have been killed")
PrintMessage(HUD_PRINTTALK, pl:Nick().." has been killed")
pl:Kill()
end ,
Color = function(pl)
pl:PrintMessage(HUD_PRINTTALK, "You got your color changed")
PrintMessage(HUD_PRINTTALK, pl:Nick().." got their color changed")
pl:SetColor(color)
end ,
Nothing = function(pl)
pl:PrintMessage(HUD_PRINTTALK, "You got nothing")
PrintMessage(HUD_PRINTTALK, pl:Nick().." got nothing")
end ,
Health = function(pl)
pl:PrintMessage(HUD_PRINTTALK, "You got your health set to: "..health)
PrintMessage(HUD_PRINTTALK, pl:Nick().." got their health set to "..health)
pl:SetHealth(health)
end ,
Frags = function(pl)
pl:PrintMessage(HUD_PRINTTALK, "You got your frags set to "..frags)
PrintMessage(HUD_PRINTTALK, pl:Nick().." got their frags set to "..frags)
pl:SetFrags(frags)
end ,
}
function dice:Roll(pl)
table.Random(dice.outcomes)(pl)
end
local function dicePlayerSay(pl , text , teamonly , dead)
if text == "rtd" then -- Ran the command, not from the chat hook.
dice:Roll(pl)
elseif string.find(chatcommand , string.lower(text)) then
dice:Roll(pl)
end
end
hook.Add("PlayerSay", "rtdcmd", dicePlayerSay)
concommand.Add("rtd", dicePlayerSay)
[/lua]
I see what I did wrong and thanks for the quick response, very much appreciated guys, thanks :)
|FlapJack|, your code still has a nil value being passed to concommand.Add at the bottom.
Also, the dice variable can be made local.
[QUOTE=MakeR;22061955]|FlapJack|, your code still has a nil value being passed to concommand.Add at the bottom.
Also, the dice variable can be made local.[/QUOTE]
Only if the methods are changed to regular functions.
[QUOTE=|FlapJack|;22061963]Only if the methods are changed to regular functions.[/QUOTE]
Since when did having a method in the table prevent it from being local?
[editline]02:49PM[/editline]
I never remember that being the case.
Last time I looked, it caused an error. I'll test it now.
[editline]02:51PM[/editline]
Seems it doesn't error. Pretty weird, I was sure it did.
Thought so.
if you dont mind me asking, at table.Random(dice.outcomes)(pl), whats the extra (pl) do?
It calls the function returned by table.Random, passing the player as the first argument.
:ninja:
I understand now, thank you.
Sorry to bump but I'm having some more problems. Im wanting to make a freeze roll but having a little trouble.
It just instantly turns the freeze off after the roll.
[lua]
Freeze = function(pl)
local Timer = CurTime()+0.1
pl:PrintMessage(HUD_PRINTTALK, "[RTD]You got frozen for "..duration_freeze.." seconds")
PrintMessage(HUD_PRINTTALK, "[RTD]"..pl:Nick().." got frozen for "..duration_freeze.." seconds")
pl:Freeze(true)
pl:Lock()
if Timer >= duration_freeze then
pl:Freeze(false)
pl:UnLock()
pl:PrintMessage(HUD_PRINTTALK, "[RTD]You got unfrozen")
PrintMessage(HUD_PRINTTALK, "[RTD]"..pl:Nick().." got unfrozen")
end
end,
[/lua]
and also my color roll doesnt seem to work either.
[lua]
Color = function(pl)
pl:PrintMessage(HUD_PRINTTALK, "[RTD]You got your color changed")
PrintMessage(HUD_PRINTTALK, "[RTD]"..pl:Nick().." got their color changed")
pl:SetColor(color)
end ,
[/lua]
local color = Color(0, 0, 255, 200) is at the top of the script
as well as the duration_freeze