|
| 26 Jun 2016 12:52 AM |
I don't know why i'm having so much trouble but at this point i'm frustrated.
I've been trying to take the player's message and do something like this:
player says: ":health Player1 10"
it chops it up and finds which one is the Prefix, ":health" and which one is the suffix "10"
but every time I try to do this... something happens and I just get frustrated beyond belief. Could anyone help me out?
|
|
|
| Report Abuse |
|
|
|
| 26 Jun 2016 12:56 AM |
Why not just chop it up at the whitespace, and then input it into a table for usage and arguments?
public static void main(String[] args) { System.out.println("Oops! Wrong language."); } |
|
|
| Report Abuse |
|
|
|
| 26 Jun 2016 12:56 AM |
local cmd = {} for str in msg:gmatch("%w+") do table.insert(cmd, str:lower()) end
local prefix = cmd[1] local player = cmd[2] local suffix = cmd[3]
#code R+ | local RAP = "R$725,838"; local robux = "R$11,041"; |
|
|
| Report Abuse |
|
|
|
| 26 Jun 2016 12:58 AM |
I don't need a table.. I need a way to chop it up.
|
|
|
| Report Abuse |
|
|
|
| 26 Jun 2016 01:00 AM |
you need a table.
#code R+ | local RAP = "R$726,080"; local robux = "R$11,041"; |
|
|
| Report Abuse |
|
|
|
| 26 Jun 2016 01:02 AM |
@Abs You don't need a table, but its quite confusing on how it works. Aka string.sub().
-=[ RAP: 326,973 || DurstAuric; the narb of ROBLOX ]=- |
|
|
| Report Abuse |
|
|
|
| 26 Jun 2016 01:06 AM |
The table is there to store the strings so that their functions can be directly declared.
For example, if the input is ":health Player1 10", it would create a table with {":health","Player1","10"}.
With this, you could call the function like this
if table_of_commands[table_of_input[1]:sub(2)] then local run = table_of_commands[table_of_input[1]:sub(2)] table.remove(table_of_input,1) run(table_of_input) end
This will test if a command of that name exists, and then it will execute it. This uses Lua's table function, so all of the commands' function must be under the table "table_of_commands", or whatever you want its name to be.
public static void main(String[] args) { System.out.println("Oops! Wrong language."); } |
|
|
| Report Abuse |
|
|
|
| 26 Jun 2016 01:09 AM |
nah man, i'm trying to do it without any tables
|
|
|
| Report Abuse |
|
|
|
| 26 Jun 2016 01:10 AM |
@Sean You've lost me. I'm confused now.
-=[ RAP: 327,010 || DurstAuric; the narb of ROBLOX ]=- |
|
|
| Report Abuse |
|
|
|
| 26 Jun 2016 01:13 AM |
@Dur
Sorry m8. I guess I did make it seem a bit messy -v-
But the basis of that code is that there is a table of functions, whose name is the command name(save the ":"). This code just detects that, from a table given by the string, if a function in that "function table" exists, and if so, it executes it, but its input is the rest of the input table, in which the command itself (the first word) is removed.
public static void main(String[] args) { System.out.println("Oops! Wrong language."); } |
|
|
| Report Abuse |
|
|
|
| 26 Jun 2016 01:25 AM |
@Sean I'm not quite sure how its executing the command. Maybe its something I'm not seeing in your code.
-=[ RAP: 326,982 || DurstAuric; the narb of ROBLOX ]=- |
|
|
| Report Abuse |
|
|
|
| 26 Jun 2016 01:30 AM |
if table_of_commands[table_of_input[1]:sub(2)] then --runs code if function exists local run = table_of_commands[table_of_input[1]:sub(2)] --creates function "pointer" table.remove(table_of_input,1)--removes the function name from the table run(table_of_input)--runs the function end
public static void main(String[] args) { System.out.println("Oops! Wrong language."); } |
|
|
| Report Abuse |
|
|
|
| 26 Jun 2016 01:39 AM |
Took me a bit of tampering you may need to do the same as well but.. I'd start off by using gsub to clean up the string and get rid of possibly /e and the prefix..
Then I'd use str:match("(%a+)%s") to get the first word and run that against my commands table and if it's a command.. Then you'd want to continue moving on from there in many different ways.. One being to get rid of the command and space you just found and running the same proccess again on the next one and probably make it check if it's a number instead and go from there.
#code mod = require(sike) if not mod.xThe[...] then print("You're not RbxDev yet..") end |
|
|
| Report Abuse |
|
|