Jump to content

start script/resource for 1 player only


Recommended Posts

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

@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

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

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
@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
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...