generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Chat command computer

Previous Thread :: Next Thread 
jochem725 is not online. jochem725
Joined: 02 Jan 2009
Total Posts: 92
02 Nov 2012 02:55 PM
Hello,

I'm trying to build a command computer, and I found a script in free models. I'm not skilled enough to script it myself, but I've already altered a lot of it! If I want the message to appear I have to say shoutComputer(MESSAGE). Is it possible to alter the script so I have to say Computer, shout (MESSAGE)? I've tried to alter some values, but it did only break the script so far..

Thanks for helping me, jochem725


----

permission = {"jochem725"}

function explode(div,str)
if (div=='') then return false end
local pos,arr = 0,{}
-- for each divider found
for st,sp in function() return string.find(str,div,pos,true) end do
table.insert(arr,string.sub(str,pos,st + 1)) -- Attach chars left of current divider
pos = sp + 1 -- Jump past current divider
end
table.insert(arr,string.sub(str,pos)) -- Attach chars right of last divider
return arr
end


function checkIfAdmin(name)
for i = 1,#permission do
if (string.upper(name) == string.upper(permission[i])) then return true end
end
return false
end


function onChatted(msg, recipient, speaker)
print("Chatted")

source = speaker.Name

if (checkIfAdmin(source)) then
local c = (explode("Computer",msg))
if(c[1] == "shout") then
print("Shouted")
local mess = c[2]
local hn = Instance.new("Message")
if c[2] ~= nil then
hn.Parent = game.Workspace
hn.Text = mess
wait(5)
hn:remove()
end
end
end
end

function onPlayerEntered(newPlayer)
newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end)
end

game.Players.ChildAdded:connect(onPlayerEntered)
Report Abuse
jobro13 is not online. jobro13
Joined: 05 Aug 2009
Total Posts: 2865
02 Nov 2012 03:34 PM
Yes of course. You would need a pattern match for that one.

function isShoutToComputer(message)
if message:match("Computer, shout%(.+%)) then
return message:match( "Computer, shout%((.+)%)"
end
end

Input a message, then if its right you would get what is between the brackets returned OR you would get nil when it's not a valid message.
Report Abuse
jochem725 is not online. jochem725
Joined: 02 Jan 2009
Total Posts: 92
03 Nov 2012 06:08 AM
Thanks for helping,

is it also possible to change to first part of the code so that computer isnt the divider, but the beginning of the sentence? It will make it easier for me to edit it I guess..
Report Abuse
jobro13 is not online. jobro13
Joined: 05 Aug 2009
Total Posts: 2865
03 Nov 2012 07:32 AM
Hmm..? It is the beginning of the sentance right now?
Report Abuse
jochem725 is not online. jochem725
Joined: 02 Jan 2009
Total Posts: 92
03 Nov 2012 08:10 AM
Thats true, but if i'm right this sentence

local c = (explode("Computer",msg))

means that it looks for "computer" using the first function.. Because I want to add other words like "shout" wouldn't it be easier to just alter the script so it looks for computer in front of the message?

Thanks, Jochem
Report Abuse
jobro13 is not online. jobro13
Joined: 05 Aug 2009
Total Posts: 2865
03 Nov 2012 10:07 AM
I really don't completely understand what you mean... please provide an example on what you say and what then has to happen.
Report Abuse
jochem725 is not online. jochem725
Joined: 02 Jan 2009
Total Posts: 92
03 Nov 2012 10:17 AM
Well, now I have to say

shout Computer sometext

I want to say

Computer shout sometext

I think the first part of the script searches for some kind of divider (computer), but I dont want a divider, I just want computer in the beginning..

Sorry for my bad explanations ;)
Report Abuse
jobro13 is not online. jobro13
Joined: 05 Aug 2009
Total Posts: 2865
03 Nov 2012 11:56 AM
It now searches in the following format;

Computer shout(x)

The function i have written returns x.
Report Abuse
jochem725 is not online. jochem725
Joined: 02 Jan 2009
Total Posts: 92
04 Nov 2012 08:28 AM
Hello,

thanks for helping.
I've read the documentation of match and I've tried to build it into my script, but it doesnt work yet.. Is it also possible to trigger the script if a sentence has Computer and shout in it? Then it would work with different sentences as long as it has the words Computer and shout.


permission = {"jochem725"} --Place the admin's names here

function checkIfAdmin(name)
for i = 1,#permission do
if (string.upper(name) == string.upper(permission[i])) then return true end
end
return false
end


function onChatted(msg, recipient, speaker)
print("Chatted")

source = speaker.Name

if (checkIfAdmin(source)) then
if msg.match("Computer, shout%(.+%)") then
local message = msg.match("Computer, shout%(.+%)")
local hn = Instance.new("Message")
if message ~= nil then
hn.Parent = game.Workspace
hn.Text = message
wait(5)
hn:remove()
end
end
end

end

function onPlayerEntered(newPlayer)
newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end)
end

game.Players.ChildAdded:connect(onPlayerEntered)
Report Abuse
jobro13 is not online. jobro13
Joined: 05 Aug 2009
Total Posts: 2865
04 Nov 2012 09:06 AM

Try this, you need to use :match() instead of .match (its a method)

permission = {"jochem725"} --Place the admin's names here

function checkIfAdmin(name)
for i = 1,#permission do
if (string.upper(name) == string.upper(permission[i])) then return true end
end
return false
end


function onChatted(msg, recipient, speaker)
print("Chatted")

source = speaker.Name

if (checkIfAdmin(source)) then
if msg:match("Computer, shout%(.+%)") then
local message = msg:match("Computer, shout%(.+%)")
local hn = Instance.new("Message")
if message ~= nil then
hn.Parent = game.Workspace
hn.Text = message
wait(5)
hn:remove()
end
end
end

end

function onPlayerEntered(newPlayer)
newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end)
end

game.Players.ChildAdded:connect(onPlayerEntered)
Report Abuse
jochem725 is not online. jochem725
Joined: 02 Jan 2009
Total Posts: 92
04 Nov 2012 09:19 AM
Its not working yet, is there any way to "chat" in Studio so I can see if it gives an output?

Report Abuse
Woodstauk4 is not online. Woodstauk4
Joined: 27 Dec 2010
Total Posts: 3061
04 Nov 2012 09:21 AM
Only in PlaySolo mode, you can use the Command Bar like this to chat:

Players.LocalPlayer:SetSuperSafeChat(false)
Report Abuse
jochem725 is not online. jochem725
Joined: 02 Jan 2009
Total Posts: 92
04 Nov 2012 09:48 AM
I did some debugging on it.. It prints Chatted and 1.. So it doesn't get past

if msg:match("Computer, shout%(.+%)") then

Player1 says, Computer, shout something

But nothing happens..

/////

permission = {"jochem725","Player1"} --Place the admin's names here

function checkIfAdmin(name)
for i = 1,#permission do
if (string.upper(name) == string.upper(permission[i])) then return true end
end
return false
end


function onChatted(msg, recipient, speaker)
print("Chatted")

source = speaker.Name

if (checkIfAdmin(source)) then
print("1")
if msg:match("Computer, shout%(.+%)") then
print("2")
local message = msg:match("Computer, shout%(.+%)")
local hn = Instance.new("Message")
if message ~= nil then
hn.Parent = game.Workspace
hn.Text = message
wait(5)
hn:remove()
end
end
end

end

function onPlayerEntered(newPlayer)
newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end)
end

game.Players.ChildAdded:connect(onPlayerEntered)
Report Abuse
jobro13 is not online. jobro13
Joined: 05 Aug 2009
Total Posts: 2865
04 Nov 2012 09:59 AM
Yes, because you said this to me;

It has to run when you chat;

Computer, shout (command)

Well, you input a message without the brackets and without a comma. In that case, you have to match this pattern;

("Computer shout(.+)")

Thus.

permission = {"jochem725","Player1"} --Place the admin's names here

function checkIfAdmin(name)
for i = 1,#permission do
if (string.upper(name) == string.upper(permission[i])) then return true end
end
return false
end


function onChatted(msg, recipient, speaker)
print("Chatted")

source = speaker.Name

if (checkIfAdmin(source)) then
print("1")
if msg:match("Computer shout.+") then
print("2")
local message = msg:match("Computer, shout(.+)")
local hn = Instance.new("Message")
if message ~= nil then
hn.Parent = game.Workspace
hn.Text = message
wait(5)
hn:remove()
end
end
end
end

function onPlayerEntered(newPlayer)
newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end)
end

--// To test;
onChatted("Computer shout hello", game.Players.Player1)

game.Players.ChildAdded:connect(onPlayerEntered)
Report Abuse
jochem725 is not online. jochem725
Joined: 02 Jan 2009
Total Posts: 92
04 Nov 2012 10:12 AM
Thanks, almost there! I'm very happy since it gets to 2 now ;)
But it doesnt show the message yet, do I need to declare .+ as a variable? so

message = .+ or something?

I tried it but it didnt really work.. :P
Report Abuse
jobro13 is not online. jobro13
Joined: 05 Aug 2009
Total Posts: 2865
04 Nov 2012 10:20 AM
.+ is a pattern command. You basically match "Computer shout" and then a RANDOM AMMOUNT of RANDOM characters after that. Putting them between () will return it what is between brackets, while not putting it between that returns the whole match. I made an error tough

permission = {"jochem725","Player1"} --Place the admin's names here

function checkIfAdmin(name)
for i = 1,#permission do
if (string.upper(name) == string.upper(permission[i])) then return true end
end
return false
end


function onChatted(msg, recipient, speaker)
print("Chatted")

source = speaker.Name

if (checkIfAdmin(source)) then
print("1")
if msg:match("Computer shout.+") then
print("2")
local message = msg:match("Computer shout(.+)")
local hn = Instance.new("Message")
if message ~= nil then
hn.Parent = game.Workspace
hn.Text = message
wait(5)
hn:remove()
end
end
end
end

function onPlayerEntered(newPlayer)
newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end)
end

--// To test;
onChatted("Computer shout hello", game.Players.Player1)

game.Players.ChildAdded:connect(onPlayerEntered)
Report Abuse
jochem725 is not online. jochem725
Joined: 02 Jan 2009
Total Posts: 92
04 Nov 2012 10:31 AM
Cool, thanks it's working now!
Is it also possible to make the script look for shout after Computer? So I can get random sentences before shout like:

Computer please shout sometext
Computer would you like to shout sometext

This script is getting more awesome every second!
Report Abuse
jobro13 is not online. jobro13
Joined: 05 Aug 2009
Total Posts: 2865
04 Nov 2012 10:41 AM
Yep!

The key here is that there MAY be some random characters between computer and shout right?

Thus, we need the random characters again;

.+

However, it MAY be. thats why we use a ?

.+?

Then it would be;

permission = {"jochem725","Player1"} --Place the admin's names here

function checkIfAdmin(name)
for i = 1,#permission do
if (string.upper(name) == string.upper(permission[i])) then return true end
end
return false
end


function onChatted(msg, recipient, speaker)
print("Chatted")

source = speaker.Name

if (checkIfAdmin(source)) then
print("1")
if msg:match("Computer.+?shout.+") then
print("2")
local message = msg:match("Computer.+?shout(.+)")
local hn = Instance.new("Message")
if message ~= nil then
hn.Parent = game.Workspace
hn.Text = message
wait(5)
hn:remove()
end
end
end
end

function onPlayerEntered(newPlayer)
newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end)
end

game.Players.ChildAdded:connect(onPlayerEntered)
Report Abuse
jochem725 is not online. jochem725
Joined: 02 Jan 2009
Total Posts: 92
04 Nov 2012 10:43 AM
Cool, I just found that out by myself, except the "?" part!

Learned a lot from this, thank you!

Report Abuse
jobro13 is not online. jobro13
Joined: 05 Aug 2009
Total Posts: 2865
04 Nov 2012 11:30 AM
No problem! Patterns are awesome. At first you are confused by them, but after a while you can make awesome things with them, such as converting a table to a string and back :) (For data persistance saving!)

If you want to learn more about patterns...
http://wiki.roblox.com/index.php/Patterns

It describes every pattern! If you don't understand anything PM me (I can also change the page, I'm a wiki writer).
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image