|
| 19 Dec 2015 09:48 AM |
so, if I loadstring this
loadstring("while true do print(\"Hi!\")wait()end")()
Is there a way to intercept it later on, like save it as a variable and go loadstr:disconnect(), like this?
local loadstr = loadstring("while true do print(\"Hi!\")wait()end")() wait(5) loadstr:disconnect() |
|
|
| Report Abuse |
|
|
| |
|
|
| 19 Dec 2015 09:56 AM |
| There is not, you should know that. |
|
|
| Report Abuse |
|
|
|
| 19 Dec 2015 09:59 AM |
I didn't know of one, I was just asking. No need to be rude.
And I know there is, I just don't know how. Antiboomz0r did it. |
|
|
| Report Abuse |
|
|
|
| 19 Dec 2015 10:00 AM |
| I was not rude. I was saying that I thought you were smarter than this. |
|
|
| Report Abuse |
|
|
|
| 19 Dec 2015 10:01 AM |
Oh. It seemed like you were :/ hard to convey over the internet.
But anyways, any idea how he did it? |
|
|
| Report Abuse |
|
|
|
| 19 Dec 2015 10:01 AM |
There is not without implementing a custom wait function that yields your function and wrapping your loadstring in a coroutine.
woof |
|
|
| Report Abuse |
|
|
| |
|
| |
|
|
| 19 Dec 2015 10:10 AM |
| Lua Assembly Machine Instructions |
|
|
| Report Abuse |
|
|
|
| 19 Dec 2015 10:48 AM |
Okay okay okay okay, here's an intelligent answer. While I'm not entirely sure what you want :disconnect to do, I'm going to thoroughly explain what loadstring does, and how to utilize it.
First of all, loadstring takes a string, and turns it into a function, returning that function. Which is why you often see () right after. This is useful for if you only need the string to run once.
But what if you don't? What if you need this function in the future? Well it's quite simple really, because loadstring returns a function, simply assign the result of loadstring to a variable.
local loadstr = loadstring("print(\"Hi!\")")
loadstr() loadstr() loadstr()
But... You want a loop to run. And on :disconnect you want to break it... Hmm. Let's think.
Alright I got something.
So this plays on a multiple different concepts in Lua, but the basic idea is, make it a new thread, and break it when passed a specific argument (in this case, we'll use true).
local loadstr = loadstring("while not ({...})[1] do print(\"Hi!\")coroutine.yield()end")
loadstr = coroutine.create(loadstr) coroutine.resume(loadstr) coroutine.resume(loadstr, true) --We break it by passing true
Now what's the problem with this method? The simple fact that everytime we need to rerun the loop, we have to resume loadstr. Well this sucks.
But what if we used a global to break it instead...
finished = false local loadstr = loadstring("while not finished do print(\"Hi!\")wait()end")
loadstr = coroutine.create(loadstr) coroutine.resume(loadstr) print("Let's wait 2 seconds") wait(2) print("Let's put this loop out of it's misery") finished = true wait(2) print("It worked!")
Now let's wrap this up into a handy easy-to-use way of manipulating this:
Loops = {} function LoadLoop(str) local loadstr = coroutine.create(loadstring('print(Loops) print(coroutine.running()) while not Loops[coroutine.running()] do '..str..' wait()end')) return setmetatable({Thread=loadstr}, {__call=function(t)coroutine.resume(t.Thread)end}) end function EndLoop(loop) Loops[loop.Thread] = true end function CleanUp() for i,v in pairs(Loops) do Loops[i] = nil end end
local x = LoadLoop('print"hi"') x() wait(2) EndLoop(x)
Have fun (and thanks for the interesting use of my past 5-10 minutes.) |
|
|
| Report Abuse |
|
|
|
| 19 Dec 2015 10:52 AM |
| Dude omg I will lick your shoes clean. |
|
|
| Report Abuse |
|
|
| |
|
|
| 19 Dec 2015 11:08 AM |
if Roblox.Player.warspyking ~= Enum.GlobalConflicts.Illuminati then :Destroy(EverythingIHaveEverKnown) end |
|
|
| Report Abuse |
|
|
Waccsadac
|
  |
| Joined: 02 Jun 2012 |
| Total Posts: 2440 |
|
|
| 19 Dec 2015 11:10 AM |
Error in script: unexpected symbol near ':'
Waccsadac | Halosis Head of Innovation |
|
|
| Report Abuse |
|
|
|
| 19 Dec 2015 11:20 AM |
Okay, so I made this. How do I make it create the script? I already made the other functions I want, and sorta made the create function.
local Scripts = {}
local function CreateScript(Player, Name, Code) Scripts[Player.Name][Name] = {Thread = true, Code = Code} --Start it up?? end
local function StopAll(Player, Delete) for Key, Value in next, Scripts[Player.Name] do Value.Thread = true end if Delete then Scripts[Player.Name] = {} end end
local function LoadScript(Player, Script) local FoundScript = Scripts[Player.Name][Script] if FoundScript then FoundScript.Thread = false else SB:FireClient(Player, "Output", {Type = "Warn", Output = Script.." doesn't exist!"}) end end
local function StopScript(Player, Script) local FoundScript = Scripts[Player.Name][Script] if FoundScript then FoundScript.Thread = true else SB:FireClient(Player, "Output", {Type = "Warn", Output = Script.." doesn't exist!"}) end end |
|
|
| Report Abuse |
|
|
|
| 19 Dec 2015 11:22 AM |
| I'll let you figure this one out in an effort to help you to improve :) |
|
|
| Report Abuse |
|
|
|
| 19 Dec 2015 11:23 AM |
| But what if I can't get it.. |
|
|
| Report Abuse |
|
|
|
| 19 Dec 2015 11:25 AM |
Learn your crucial debugging skills.
If you look at my script it's really easy to see how it works. You can apply it in a script like yours with ease. |
|
|
| Report Abuse |
|
|
|
| 19 Dec 2015 11:28 AM |
Hmm, so I made this script. The problem is that I don't want them to have access to the global environment (It will be sandboxed), so I cannot give them access to Scripts to check if it is running. The other problem is that this loop-runs the code. I want the code to run, yes, but they have OPTIONAL looping. Like they have to add the loop if they want that.
so if I ran
s/print'hi'
It ideally wouldn't spam that unless I typed
s/while true do print'hi' end |
|
|
| Report Abuse |
|
|
|
| 19 Dec 2015 11:29 AM |
Oops, forgot the script. Here ya go.
local Scripts = {}
local function CreateScript(Player, Name, Code) local LoadString = coroutine.create(loadstring([[ while not Scripts[coroutine.running()] do ]]..Code..[[ wait() end ]])) return setmetatable({Thread = LoadString}, { __call = function(Script) coroutine.resume(Script.Thread) end, }) end
local function StopAll(Player, Delete) for Key, Value in next, Scripts[Player.Name] do Value.Thread = true end if Delete then Scripts[Player.Name] = {} end end
local function LoadScript(Player, Script) local FoundScript = Scripts[Player.Name][Script] if FoundScript then FoundScript.Thread = false else SB:FireClient(Player, "Output", {Type = "Warn", Output = Script.." doesn't exist!"}) end end
local function StopScript(Player, Script) local FoundScript = Scripts[Player.Name][Script] if FoundScript then FoundScript.Thread = true else SB:FireClient(Player, "Output", {Type = "Warn", Output = Script.." doesn't exist!"}) end end |
|
|
| Report Abuse |
|
|
|
| 19 Dec 2015 11:31 AM |
You're going to have to find some other way of optional looping then.
Not to mention learn how to use setfenv appropriately to place the Loops in a sandboxed environment.
Anyway like I said, you want to improve, work on this. If Scripters do it all for you, you're not going to learn anything. |
|
|
| Report Abuse |
|
|
|
| 19 Dec 2015 11:32 AM |
| Cmon bro. I literally have EVERYTHING else I need for this to work :/ |
|
|
| Report Abuse |
|
|
|
| 19 Dec 2015 12:28 PM |
Mfw unfortunately I saw this coming and warspyking didn't because he is human
dog 2 human 0
lick
|
|
|
| Report Abuse |
|
|
| |
|