How do I add in commands?: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Master753
>Emess
double redirect fix
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{CatUp|Tutorials}}
#redirect[[Absolute beginner's guide to scripting]]
__TOC__
 
== Introduction ==
The Commands script is used to allow for voice commands for various things, such as making random explosions, or changing the time of day.Check out all of these versions from three friends
 
==Version one by Master753==
<pre>
function onChatted(msg, recipient, speaker)
 
-- convert to all lower case
 
local source = string.lower(speaker.Name)
msg = string.lower(msg)
 
if (msg == "day") then
game.Lighting.TimeOfDay = "16:32:00"
end
 
if (msg == "night") then
game.Lighting.TimeOfDay = "00:00:00"
end
 
-- Below is only for me
if (source ~= "lavamaster") then return end
 
if (msg == "deadly haze") then
local m = Instance.new("Message")
m.Text = "A mysterious haze is floating towards us..."
m.Parent = game.Workspace
wait(4)
local c = game.Players:GetChildren()
for i=1,#c do
if (string.lower(c[i].Name) ~= "lavamaster") then
if (c[i].Character ~= nil and c[i].Character.Humanoid ~= nil) then
c[i].Character.Humanoid.Health = 0
end
end
end
wait(2)
m.Parent = nil
end
 
if (msg == "boom!") then
local m = Instance.new("Message")
m.Text = "We're being bombed!"
m.Parent = game.Workspace
wait(4)
for i=1,100 do
local x = math.random(-200,200)
local z = math.random(-200,200)
local y = math.random(0,40)
 
local r = math.random(6,16)
 
local ex = Instance.new("Explosion")
ex.Position = Vector3.new(x,y,z)
ex.BlastRadius = r
ex.Parent = game.Workspace
wait(.05)
end
wait(2)
m.Parent = nil
end
 
 
end
 
function onPlayerEntered(newPlayer)
newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end)
end
 
game.Players.ChildAdded:connect(onPlayerEntered)
</pre>
 
==Version two by ram1000==
<pre>
function onChatted(msg, recipient, speaker)
 
-- convert to all lower case
 
local source = string.lower(speaker.Name)
msg = string.lower(msg)
 
if (msg == "day") then
game.Lighting.TimeOfDay = "14:00:00"
end
 
if (msg == "night") then
game.Lighting.TimeOfDay = "00:00:00"
end
 
if (msg == "normal") then
 
game.Lighting.TimeOfDay = "0:00:00"
game.Lighting.TopAmbientV9 = Color3.new(215,214,223)
game.Lighting.SpotLightV9 = Color3.new(197,197,197)
game.Lighting.BottomAmbientV9 = Color3.new(122,140,120)
game.Lighting.TimeOfDay = "14:00:00"
 
end
 
if (msg == "neon") then
 
game.Lighting.TopAmbientV9 = Color3.new(0,255,255)
game.Lighting.SpotLightV9 = Color3.new(0,255,255)
game.Lighting.BottomAmbientV9 = Color3.new(0,255,255)
 
end
 
if (msg == "red") then
 
game.Lighting.TopAmbientV9 = Color3.new(255,0,0)
game.Lighting.SpotLightV9 = Color3.new(255,0,0)
game.Lighting.BottomAmbientV9 = Color3.new(255,0,0)
 
end
 
if (msg == "yellow") then
 
game.Lighting.TopAmbientV9 = Color3.new(255,255,0)
game.Lighting.SpotLightV9 = Color3.new(255,255,0)
game.Lighting.BottomAmbientV9 = Color3.new(255,255,0)
 
end
 
if (msg == "green") then
 
game.Lighting.TopAmbientV9 = Color3.new(0,255,0)
game.Lighting.SpotLightV9 = Color3.new(0,255,0)
game.Lighting.BottomAmbientV9 = Color3.new(0,255,0)
 
end
 
if (msg == "darkblue") then
 
game.Lighting.TopAmbientV9 = Color3.new(0,0,255)
game.Lighting.SpotLightV9 = Color3.new(0,0,255)
game.Lighting.BottomAmbientV9 = Color3.new(0,0,255)
 
end
 
if (msg == "disco!") then
 
game.Lighting.TopAmbientV9 = Color3.new(0,0,255)
game.Lighting.SpotLightV9 = Color3.new(0,0,255)
game.Lighting.BottomAmbientV9 = Color3.new(0,0,255)
wait(0.5)
game.Lighting.TopAmbientV9 = Color3.new(0,255,0)
game.Lighting.SpotLightV9 = Color3.new(0,255,0)
game.Lighting.BottomAmbientV9 = Color3.new(0,255,0)
wait(0.5)
game.Lighting.TopAmbientV9 = Color3.new(255,0,0)
game.Lighting.SpotLightV9 = Color3.new(255,0,0)
game.Lighting.BottomAmbientV9 = Color3.new(255,0,0)
wait(0.5)
game.Lighting.TopAmbientV9 = Color3.new(255,255,0)
game.Lighting.SpotLightV9 = Color3.new(255,255,0)
game.Lighting.BottomAmbientV9 = Color3.new(255,255,0)
wait(0.5)
game.Lighting.TopAmbientV9 = Color3.new(0,255,255)
game.Lighting.SpotLightV9 = Color3.new(0,255,255)
game.Lighting.BottomAmbientV9 = Color3.new(0,255,255)
wait(0.5)
game.Lighting.TopAmbientV9 = Color3.new(0,0,255)
game.Lighting.SpotLightV9 = Color3.new(0,0,255)
game.Lighting.BottomAmbientV9 = Color3.new(0,0,255)
wait(0.5)
game.Lighting.TopAmbientV9 = Color3.new(0,255,0)
game.Lighting.SpotLightV9 = Color3.new(0,255,0)
game.Lighting.BottomAmbientV9 = Color3.new(0,255,0)
wait(0.5)
game.Lighting.TopAmbientV9 = Color3.new(255,0,0)
game.Lighting.SpotLightV9 = Color3.new(255,0,0)
game.Lighting.BottomAmbientV9 = Color3.new(255,0,0)
wait(0.5)
game.Lighting.TopAmbientV9 = Color3.new(255,255,0)
game.Lighting.SpotLightV9 = Color3.new(255,255,0)
game.Lighting.BottomAmbientV9 = Color3.new(255,255,0)
wait(0.5)
game.Lighting.TopAmbientV9 = Color3.new(0,255,255)
game.Lighting.SpotLightV9 = Color3.new(0,255,255)
game.Lighting.BottomAmbientV9 = Color3.new(0,255,255)
wait(0.5)
game.Lighting.TimeOfDay = "0:00:00"
game.Lighting.TopAmbientV9 = Color3.new(215,214,223)
game.Lighting.SpotLightV9 = Color3.new(197,197,197)
game.Lighting.BottomAmbientV9 = Color3.new(122,140,120)
game.Lighting.TimeOfDay = "14:00:00"
end
 
if (source ~= "username") then return end--Change this to your name.
 
if (msg == "die") then
local m = Instance.new("Message")
m.Text = "EVERYONE IS GONNA DIE!!!!!!!!!!"
m.Parent = game.Workspace
wait(4)
local c = game.Players:GetChildren()
for i=1,#c do
if (string.lower(c[i].Name) ~= "username") then
if (c[i].Character ~= nil and c[i].Character.Humanoid ~= nil) then
c[i].Character.Humanoid.Health = 0
end
end
end
wait(2)
m.Parent = nil
end
 
if (msg == "blackout") then
 
game.Lighting.TopAmbientV9 = Color3.new(0,0,0)
game.Lighting.SpotLightV9 = Color3.new(0,0,0)
game.Lighting.BottomAmbientV9 = Color3.new(0,0,0)
 
end
 
 
 
if (msg == "listen") then
 
local m = Instance.new("Message")
m.Text = "EVERYONE STOP TALKING!!!!"
m.Parent = game.Workspace
wait(4)
m.Parent = nil
 
end
 
 
 
end
 
function onPlayerEntered(newPlayer)
newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end)
end
 
game.Players.ChildAdded:connect(onPlayerEntered)
</pre>
 
==Version three by pross753==
<pre>
function onChatted(msg, recipient, speaker)
 
local source = string.lower(speaker.Name)
msg = string.lower(msg)
 
if (msg == "day") then
game.Lighting.TimeOfDay = "14:00:00"
end
 
if (msg == "night") then
game.Lighting.TimeOfDay = "00:00:00"
end
 
if (msg == "normal") then
 
game.Lighting.TimeOfDay = "0:00:00"
game.Lighting.TopAmbientV9 = Color3.new(215,214,223)
game.Lighting.SpotLightV9 = Color3.new(197,197,197)
game.Lighting.BottomAmbientV9 = Color3.new(122,140,120)
game.Lighting.TimeOfDay = "14:00:00"
 
end
 
if (msg == "neon") then
 
game.Lighting.TopAmbientV9 = Color3.new(0,255,255)
game.Lighting.SpotLightV9 = Color3.new(0,255,255)
game.Lighting.BottomAmbientV9 = Color3.new(0,255,255)
 
end
 
if (msg == "red") then
 
game.Lighting.TopAmbientV9 = Color3.new(255,0,0)
game.Lighting.SpotLightV9 = Color3.new(255,0,0)
game.Lighting.BottomAmbientV9 = Color3.new(255,0,0)
 
end
 
if (msg == "yellow") then
 
game.Lighting.TopAmbientV9 = Color3.new(255,255,0)
game.Lighting.SpotLightV9 = Color3.new(255,255,0)
game.Lighting.BottomAmbientV9 = Color3.new(255,255,0)
 
end
 
if (msg == "green") then
 
game.Lighting.TopAmbientV9 = Color3.new(0,255,0)
game.Lighting.SpotLightV9 = Color3.new(0,255,0)
game.Lighting.BottomAmbientV9 = Color3.new(0,255,0)
 
end
 
if (msg == "blue") then
 
game.Lighting.TopAmbientV9 = Color3.new(0,0,255)
game.Lighting.SpotLightV9 = Color3.new(0,0,255)
game.Lighting.BottomAmbientV9 = Color3.new(0,0,255)
 
end
 
if (msg == "black") then
 
game.Lighting.TimeOfDay = "00:00:00"
game.Lighting.TopAmbientV9 = Color3.new(0,0,0)
game.Lighting.SpotLightV9 = Color3.new(0,0,0)
game.Lighting.BottomAmbientV9 = Color3.new(0,0,0)
 
end
 
if (msg == "white") then
 
game.Lighting.TimeOfDay = "00:00:00"
game.Lighting.TopAmbientV9 = Color3.new(255,255,255)
game.Lighting.SpotLightV9 = Color3.new(255,255,255)
game.Lighting.BottomAmbientV9 = Color3.new(255,255,255)
 
end
 
-- Below is the admin commands.
if (source ~= "username") then return end --Change username to your name.
 
if (msg == "die") then --Change this if you want.
local m = Instance.new("Message")
m.Text = "Test message"--Change this if you want.
m.Parent = game.Workspace
wait(4)
local c = game.Players:GetChildren()
for i=1,#c do
if (string.lower(c[i].Name) ~= "username") then --change username to your name
if (c[i].Character ~= nil and c[i].Character.Humanoid ~= nil) then
c[i].Character.Humanoid.Health = 0
end
end
end
wait(2)
m.Parent = nil
end
 
if (msg == "peoplewhite") then
local c = game.Players:GetChildren()
for i=1,#c do
if (string.lower(c[i].Name) ~= username") then --Change username to your name.
if (c[i].Character ~= nil and c[i].Character.Humanoid ~= nil) then
c[i].Character:FindFirstChild("Head").BrickColor = BrickColor.new(1)
c[i].Character:FindFirstChild("Torso").BrickColor = BrickColor.new(1)
c[i].Character:FindFirstChild("Left Arm").BrickColor = BrickColor.new(1)
c[i].Character:FindFirstChild("Right Arm").BrickColor = BrickColor.new(1)
c[i].Character:FindFirstChild("Left Leg").BrickColor = BrickColor.new(1)
c[i].Character:FindFirstChild("Right Leg").BrickColor = BrickColor.new(1)
 
end
end
end
end
 
if (msg == "freeze") then
local c = game.Players:GetChildren()
for i=1,#c do
if (string.lower(c[i].Name) ~= "username") then --Change username to your name.
if (c[i].Character ~= nil and c[i].Character.Humanoid ~= nil) then
c[i].Character:GindFirstChild("Torso").Anchored = true
 
end
end
end
end
 
if (msg == "thaw") then
local c = game.Players:GetChildren()
for i=1,#c do
if (string.lower(c[i].Name) ~= "username") then --Change username to your name.
if (c[i].Character ~= nil and c[i].Character.Humanoid ~= nil) then
c[i].Character:FindFirstChild("Torso").Anchored = false
 
end
end
end
end
 
 
if (msg == "savagebeating") then --You may want to change this.
local m = Instance.new("Message")
m.Text = "Test message 1234"--Change this.
m.Parent = game.Workspace
wait(4)
local c = game.Players:Gethildren()
for i=1,#c do
if (string.lower(c[i].Name) ~= "username") then --Change username to your name.
if (c[i].Character ~= nil and c[i].Character.Humanoid ~= nil) then
c[i].Character.Humanoid.Health = 1
end
end
end
wait(2)
m.Parent = nil
end
 
if (msg == "zeekyboogydoog") then--Change this to boom! or somthing if you want too.
local m = Instance.new("Message")
m.Text = "Test Message 4567"--You may want to change this
m.Parent = game.Workspace
wait(4)
for i=1,100 do
local x = math.random(17.5,76.5)
local y = math.random(0,41.6)
local z = math.random(-115,101)
 
local r = math.random(6,16)
 
local ex = Instance.new("Explosion")
ex.Position = Vector3.new(x,y,z)
ex.BlastRadius = r
ex.Parent = game.Workspace
wait(.05)
end
wait(2)
m.Parent = nil
end
 
if (msg == "brandonwantbigboom") then
local m = Instance.new("Message")
m.Text = "Test Message 7890"
m.Parent = game.Workspace
wait(4)
 
 
local ex = Instance.new("Explosion")
ex.Position = Vector3.new(29.5,0.2,-7)--Change these numbers or the explosion might be somewhere unuseful.
ex.BlastRadius = 300
ex.Parent = game.Workspace
m.Parent = nil
end
 
if (msg == "listen") then
 
local m = Instance.new("Message")
m.Text = "EVERYONE STOP TALKING!!!!"
m.Parent = game.Workspace
game.Lighting.TopAmbientV9 = Color3.new(255,0,0)
game.Lighting.SpotLightV9 = Color3.new(255,0,0)
game.Lighting.BottomAmbientV9 = Color3.new(255,0,0)
wait(0.5)
game.Lighting.TopAmbientV9 = Color3.new(255,255,0)
game.Lighting.SpotLightV9 = Color3.new(255,255,0)
game.Lighting.BottomAmbientV9 = Color3.new(255,255,0)
wait(0.5)
game.Lighting.TopAmbientV9 = Color3.new(255,0,0)
game.Lighting.SpotLightV9 = Color3.new(255,0,0)
game.Lighting.BottomAmbientV9 = Color3.new(255,0,0)
wait(0.5)
game.Lighting.TopAmbientV9 = Color3.new(255,255,0)
game.Lighting.SpotLightV9 = Color3.new(255,255,0)
game.Lighting.BottomAmbientV9 = Color3.new(255,255,0)
wait(0.5)
game.Lighting.TopAmbientV9 = Color3.new(255,0,0)
game.Lighting.SpotLightV9 = Color3.new(255,0,0)
game.Lighting.BottomAmbientV9 = Color3.new(255,0,0)
wait(0.5)
game.Lighting.TopAmbientV9 = Color3.new(255,255,0)
game.Lighting.SpotLightV9 = Color3.new(255,255,0)
game.Lighting.BottomAmbientV9 = Color3.new(255,255,0)
wait(0.5)
game.Lighting.TopAmbientV9 = Color3.new(255,0,0)
game.Lighting.SpotLightV9 = Color3.new(255,0,0)
game.Lighting.BottomAmbientV9 = Color3.new(255,0,0)
wait(0.5)
game.Lighting.TopAmbientV9 = Color3.new(255,255,0)
game.Lighting.SpotLightV9 = Color3.new(255,255,0)
game.Lighting.BottomAmbientV9 = Color3.new(255,255,0)
wait(0.5)
game.Lighting.TimeOfDay = "0:00:00"
game.Lighting.TopAmbientV9 = Color3.new(215,214,223)
game.Lighting.SpotLightV9 = Color3.new(197,197,197)
game.Lighting.BottomAmbientV9 = Color3.new(122,140,120)
game.Lighting.TimeOfDay = "14:00:00"
m.Parent = nil
end
end
 
function onPlayerEntered(newPlayer)
newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end)
end
 
game.Players.ChildAdded:connect(onPlayerEntered)
</pre>
 
 
If you want to "learn" these commands, then here you go.
 
<pre>
if (msg == "freeze") then
local c = game.Players:GetChildren()
for i=1,#c do
if (string.lower(c[i].Name) ~= "username") then --Change username to your name.
if (c[i].Character ~= nil and c[i].Character.Humanoid ~= nil) then
c[i].Character:FindFirstChild("Torso").Anchored = true
 
</pre>
 
This "freezes" players, by anchoring the torso.
 
<pre>
 
if (string.lower(c[i].Name) ~= "username")
 
</pre>
 
This finds the name of the character.
 
<pre>
 
if (c[i].Character ~= nil and c[i].Character.Humanoid ~= nil) then
 
</pre>
 
This gets the character...
 
<pre>
 
c[i].Character:FindFirstChild("Torso").Anchored = true
 
</pre>
 
And this anchors that character's torso.
 
The "thaw" works the same, but instead, "Unanchors" the torso of the character.
 
[[Category:Scripting Tutorials]]

Latest revision as of 01:19, 30 January 2011