Hi, i'm learning on lua, i have a projet for my server deathrun with a friend. I create with my friend a RTD for deathrun. I'm stuck for create a timer for restrict the command RTD.
We would need help on this script, there must be mistakes, but it does not work , or rather it is not complete.. Someone can help us here please?
[CODE]function StartSRTD(ply)
if ply:IsValid() then return end
if ply:Alive() then
if timer.Exists(ply:SteamID().."_Delay") then
local timeleft = math.Round(timer.TimeLeft(ply:SteamID().."_Delay"))
ply:ChatPrint("Test1")
return
end
timer.Simple(0.05, function()
table.Random(Effects)(ply)
timer.Create(ply:SteamID().."_Delay", SRTDTimer, 1, function() timer.Destroy(ply:SteamID().."_Delay") end)
end)
else
ply:ChatPrint("Test2")
end
end[/CODE]
[CODE]
if ply:IsValid() then return end
[/CODE]
Why do you want to run the script only when the player is invalid?
I have modified my script, i connect on my server, i type "rtd" in console, is write : "unknown command: rtd"
[CODE]function Randomeff()
ply:ChatPrint("Fonction")
if ply:Alive() then
ply:ChatPrint("Alive")
if ply:Team() == TEAM_RUNNER then
ply:ChatPrint("Team Runner")
if timer.Exists(self:SteamID().."_Delay") then
ply:ChatPrint("Timer existant")
local tempsrestant = math.Round( timer.TimeLeft(self:SteamID().."_Delay"))
ply:ChatPrint("Temps Restant = "..tempsrestant..)
return ""
end
table.random(Effects)(ply)
timer.Create( self:SteamID().."_Delay", SRTDTime, 1, function() timer.Remove( self:SteamID().."_Delay") end)
else
ply:ChatPrint("Que en Runner")
end
else
ply:ChatPrint("Que si tes en vie")
end
end
concommand.Add("rtd", Randomeff) -- Command in the console "rtd"
function RollTheDice(ply,cmd,args)
if not (ply:IsValid()) then return end
RollTheDice(ply)
end
hook.Add( "PlayerSay", "RollTheDice", function( ply, text, public)
text = string.lower( text )
if ( text == "/rtd" ) then -- Command /rtd
Randomeff()
return ""
end
end)[/CODE]
[QUOTE=AkiraEU;50722301]I have modified my script, i connect on my server, i type "rtd" in console, is write : "unknown command: rtd"
[CODE]function Randomeff()
ply:ChatPrint("Fonction")
if ply:Alive() then
ply:ChatPrint("Alive")
if ply:Team() == TEAM_RUNNER then
ply:ChatPrint("Team Runner")
if timer.Exists(self:SteamID().."_Delay") then
ply:ChatPrint("Timer existant")
local tempsrestant = math.Round( timer.TimeLeft(self:SteamID().."_Delay"))
ply:ChatPrint("Temps Restant = "..tempsrestant..)
return ""
end
table.random(Effects)(ply)
timer.Create( self:SteamID().."_Delay", SRTDTime, 1, function() timer.Remove( self:SteamID().."_Delay") end)
else
ply:ChatPrint("Que en Runner")
end
else
ply:ChatPrint("Que si tes en vie")
end
end
concommand.Add("rtd", Randomeff) -- Command in the console "rtd"
function RollTheDice(ply,cmd,args)
if not (ply:IsValid()) then return end
RollTheDice(ply)
end
hook.Add( "PlayerSay", "RollTheDice", function( ply, text, public)
text = string.lower( text )
if ( text == "/rtd" ) then -- Command /rtd
Randomeff()
return ""
end
end)[/CODE][/QUOTE]
First of all, you use a "ply" variable in the "Randomeff" function, but you haven't passed it as a parameter to the function. So, it should look like:
[CODE]
function Randomeff(ply, cmd, args)
//Contents of your function
end
[/CODE]
Also, there are some other mistakes in your code. For example, this line:
[CODE]
ply:ChatPrint("Temps Restant = "..tempsrestant..)
[/CODE]
You have an extra concatenation operator after the "tempsrestant" variable.
Thanks ^^'
I have a problem with my script, my srtd.lua not load at server start, i created the file init.lua, putting an include to load srtd.lua but says he is not srtd.lua. I have no solution, i do not understand why it does not load, i do not have a lot of addons on my server..
It's solved, thanks !
[CODE]if SERVER then
-- Script here.
end[/CODE]
Also, all of your fucking functions are global. Make them local.
Sorry, you need to Log In to post a reply to this thread.