toxicsmoke11 Posted August 15, 2014 Share Posted August 15, 2014 is it possible to start a resource/script for just one player only ? i have seen that multigamemode servers have something like that i believe so i was just wondering how they done it does anyone know how to do that? Link to comment
Castillo Posted August 15, 2014 Share Posted August 15, 2014 They use loadstring function to load the Lua code. Link to comment
toxicsmoke11 Posted August 15, 2014 Author Share Posted August 15, 2014 okay,but can you give me an example? i saw loadstring on wiki only at useful functions section, but it seems pretty complicated to me what if i had 10 players on my server and i wanted to start map resource just for 1 player who used a command? Link to comment
Bonsai Posted August 15, 2014 Share Posted August 15, 2014 The loadstring function is the easiest part of this stuff. You have to do a lot more. So, better try something else. Btw, is there a way to "block" debug warnings/errors that are e.g. caused by map scripts when doing it this way? Link to comment
DiSaMe Posted August 15, 2014 Share Posted August 15, 2014 Resource cannot "run for 1 player" because resources don't "run for players". Resources run globally, and it's not clear what "running for player" is supposed to mean. For example, if chatbox message appears for one player and not for others, it means outputChatBox was called with that player as argument. It was not called "for player", it was just called, and player was passed a an argument. As you can see, there's no magic, just logic. Link to comment
toxicsmoke11 Posted August 15, 2014 Author Share Posted August 15, 2014 @Bonsai, what could be "something else" ? any suggestions? @CrystalMV how could i make then map objects clientsided so they load for only 1 player?what are arguments for that? i dont see anything about client side on createObject page except blue text 'Client' indicating that its possible to make it clientsided Link to comment
Bonsai Posted August 15, 2014 Share Posted August 15, 2014 Uh, by something else I meant something that isn't related to what this topic is about. Its just a hard thing to do. If its about loading maps for one player only, its more or less easy as long as no scripts are involved. You are pretty alone with this stuff, since MTA doesn't deliver anything actual helpful. (besides from functions to create objects, setting dimensions etc.) Link to comment
WASSIm. Posted August 15, 2014 Share Posted August 15, 2014 you can use this function function loadScript(file) local file = fileOpen(file) if (file) then local content = fileRead(file, fileGetSize(script)) local loaded = loadstring(content) fileClose(file) if (loaded) then return true end end return false end Link to comment
DiSaMe Posted August 16, 2014 Share Posted August 16, 2014 @CrystalMV how could i make then map objects clientsided so they load for only 1 player?what are arguments for that?i dont see anything about client side on createObject page except blue text 'Client' indicating that its possible to make it clientsided Call the function from client-side script and the object will be created for the client. But I think it's better to create server-side objects in different dimensions and put the player in dimension depending on gamemode choice. Link to comment
ixjf Posted August 16, 2014 Share Posted August 16, 2014 you can use this function function loadScript(file) local file = fileOpen(file) if (file) then local content = fileRead(file, fileGetSize(script)) local loaded = loadstring(content) fileClose(file) if (loaded) then return true end end return false end No, you can't. I believe that function was already moved away from "Useful Functions" on the wiki. It's not useful and it has a number of errors: 1. fileGetSize(script) - what is script? 2. loadstring(content) - That's not how the function works. The function takes a string with the decompiled data (loading bytecode is no longer possible in MTA) and then returns a new chunk, this is what you'll call to actually load the script. 3. This is not an error but it should be very useful: if there is a syntax error, loadstring will return nil as the first return value and the error message as the second return value. You probably should output this message just in case. When calling the chunk returned by loadstring you might also want to use pcall instead to output the error message with important information like where does it come from. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now