Jump to content

Loading Maps and Client side Scripts


Bonsai

Recommended Posts

Since more and more servers are switching over to some kind of arena system, there should be some built in function to support scripters. This could be e.g. a function to send map data to a certain element and it childs only.

There also should be a way to attach client side loaded scripts to an element or something, so it can easily be destroyed without having to catch every called function. MTA already has such a system which is attched to resource stops, this just gotta be possible without an actual resource being stopped.

Bons

Link to comment
You can do this already loadMapData

That function loads the map file for all players.

I don't get your question. Are you suggesting that the MTA team adds specific functionality to magically create a multi-arena system? No, that ain't going to happen. MTA provides you enough to do everything you just said on your own.

A lot of work for many Scripters, a little work for MTA Team.

Link to comment
No. Bonsai, no matter what happens MTA will not provide you this feature.

And to load it into a specific dimension you can just set the parent dimension.

Anyway, why isn't there an Event for Element Creation?

That would help alot.

I've only found https://wiki.multitheftauto.com/wiki/On ... entDestroy.

onClientElementCreation or something like that would offer you the possibility to store created Elements easily and destroy them as soon as they are not needed anymore.

Link to comment

I don't see the point of such an event. What would it be useful for? You can always wrap createElement to catch script-created elements and call your own event if you really need that.

A lot of work for many Scripters, a little work for MTA Team.

It's not going to happen, stop attempting to copy other servers.

Link to comment
I don't see the point of such an event. What would it be useful for? You can always wrap createElement to catch script-created elements and call your own event if you really need that.
A lot of work for many Scripters, a little work for MTA Team.

It's not going to happen, stop attempting to copy other servers.

Apparently you do not know what an element is.

https://wiki.multitheftauto.com/wiki/Element

I'm not attempting to copy anyone, why would I.

This Board exists so people can post SUGGESTIONS. That's what I did.

Why is everyone so hostile around here. Like people who search for more efficient solutions are completely insane.

Link to comment

If you're making objects, you can always wrap createObject, as ixjf said, like this:

  
objects = {} 
_createObject = createObject 
function createObject(...) 
    local ele = _createObject(...) 
    table.insert(objects, ele) 
    return ele 
end 

That clones the existing createObject function and overwrites the old createObject function with a "wrapper" which utilises the old object creation function.

Link to comment
If you're making objects, you can always wrap createObject, as ixjf said, like this:
  
objects = {} 
_createObject = createObject 
function createObject(...) 
    local ele = _createObject(...) 
    table.insert(objects, ele) 
    return ele 
end 

That clones the existing createObject function and overwrites the old createObject function with a "wrapper" which utilises the old object creation function.

I know that, thanks anyway.

But there are so many things that can be created by a script and you would have to create wrappers for any function.

Thats why I came up with that onElementCreation idea.

Also, an event that is triggered when something like time, gravity etc. is changed would be very useful.

That way you could load a clientside script, those two events detect all changes made and when you want to unload it, you just gotta destroy the elements and change world stuff back to normal.

Bonsai

Link to comment
  
addEventHandler("onResourceStart", resourceRoot, function() 
        -- Populate this function with all the element creation functions 
        local elementCreationFunctions = {"createObject", "createVehicle","createElement"} 
        addEvent("onElementCreated") 
        for i,v in ipairs(elementCreationFunctions) do 
            _G["_"..v],  _G[v] = _G[v], function(...) 
                local obj, err = pcall(_G[v], ...) 
                if not obj then 
                    return error(err, 2) 
                end 
                triggerEvent("onElementCreated", obj) 
                return obj 
            end 
        end 
) 
  

Link to comment
  
addEventHandler("onResourceStart", resourceRoot, function() 
        -- Populate this function with all the element creation functions 
        local elementCreationFunctions = {"createObject", "createVehicle","createElement"} 
        addEvent("onElementCreated") 
        for i,v in ipairs(elementCreationFunctions) do 
            _G["_"..v],  _G[v] = _G[v], function(...) 
                local obj, err = pcall(_G[v], ...) 
                if not obj then 
                    return error(err, 2) 
                end 
                triggerEvent("onElementCreated", obj) 
                return obj 
            end 
        end 
) 
  

Thanks Bro, I'll check that out.

Bonsai just stay at DDC if they ever finish it, lolololololo.

Suuure, I'm just interested :P

Link to comment

MTA is trying to keep unnecessary functions and events out of the application to keep MTA lightweight. It takes literally a couple lines of code to make an event for onElementCreation. You can use the below code for whatever you need, or the code that was provided above. Just saying, that MTA isn't necessarily looking at these suggestions that can be made with scripting, and that aren't necessary as a whole.

elements = { } 
  
addEvent( "onElementCreation", true ) 
addEventHandler( "onElementCreation", root, 
   function( tableID ) 
      outputServerLog( "Created a new element with type \"" .. getElementType( source ) .. "\" and ID " .. getElementID( source ) .. " (table index " .. tableID .. ")." ) 
      -- Whatever else you want to do with the element 
   end 
) 
  
local _createElement = createElement 
function createElement( elementType, elementID ) 
   if not elementType then 
      return false, "No element type was specified." 
   end 
    
   local element 
   if elementID then 
      element = _createElement( elementType, tostring( elementID ) ) 
   else 
      element = _createElement( elementType ) 
   end 
    
   if element then 
      table.insert( elements, element ) 
      triggerEvent( "onElementCreation", element, tostring( #elements ) ) 
      return element, tostring( #elements ) 
   else 
      return false, "Couldn't create the element for some reason. Check your arguments." 
   end 
end 

Link to comment
  • 2 weeks later...
  • Recently Browsing   0 members

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