Jump to content

elementData con tablas


-Rex-

Recommended Posts

--Funciones tipo Shared:



tablaAlmacenamiento = { } 
  
function setData( element, dataName, value ) 
     
    if not tablaAlmacenamiento[element] then 
        tablaAlmacenamiento[element] = { } 
    end 
  
    if not tablaAlmacenamiento[element][dataName] then 
        tablaAlmacenamiento[element][dataName] = value 
        return true 
    else 
        tablaAlmacenamiento[element][dataName] = value 
        return true 
    end 
  
    return false 
  
end 
  
function getData( element, dataName ) 
     
    if tablaAlmacenamiento[element] and tablaAlmacenamiento[element][dataName] then 
  
        return tablaAlmacenamiento[element][dataName] 
    end 
  
    return false 
  
end 
  
function clearTheElementData( element ) 
  
    if tablaAlmacenamiento[element] then 
        tablaAlmacenamiento[element] = false 
        tablaAlmacenamiento[element] = { } 
    end 
end 


--Funciones tipo Server:

  
local elements =  
{ 
    "player", 
    "ped", 
    "water", 
    "sound", 
    "vehicle", 
    "object", 
    "pickup", 
    "marker", 
    "colshape", 
    "blip", 
    "radararea", 
    "team", 
    "spawnpoint", 
    "projectile", 
    "effect", 
    "light", 
    "searchlight", 
    "shader", 
    "texture", 
} 
  
function onStop( resource ) 
  
    for _, element in ipairs( elements ) do 
  
        for _, object in ipairs( getElementsByType ( element, getResourceRootElement( resource ) ) ) do 
            clearTheElementData ( object ) 
        end 
  
    end 
  
end 
addEventHandler( "onResourceStop", getRootElement(  ), onStop ) 









--[[
funciones de prueba:

function dsa( source ) 
    setData( source, "pruebas", 0 ) 
    setData( source, "pruebas", ( getData ( source, "pruebas" ) or 0 ) + 1 ) 
    outputChatBox( tostring( getData ( source, "pruebas" ) ) ) 
end 
addCommandHandler( "lze", dsa ) 

]]--

 

Este es Un método mas optimizado para guardar datos

 

 

 

Edited by -Rex-
Link to comment

Esta bastante bien esto pero... no le veo mucha utilidad ya que esto hace la misma funcion que setElementData(source, index, value, false) que básicamente no sincroniza los datos entre server-client lo que no provoca uso excesivo de la red e CPU pero esta bastante bien que lo aportes.

Link to comment
10 hours ago, Arsilex said:

Esta bastante bien esto pero... no le veo mucha utilidad ya que esto hace la misma funcion que setElementData(source, index, value, false) que básicamente no sincroniza los datos entre server-client lo que no provoca uso excesivo de la red e CPU pero esta bastante bien que lo aportes.

Exacto Funciona igual, Solo que este método no usa mucha CPU, como lo hace la función de MTA

Link to comment
  • 4 months later...

Hay un problema con esta función:

function clearTheElementData( element ) 
  
    if tablaAlmacenamiento[element] then 
        tablaAlmacenamiento[element] = false 
        tablaAlmacenamiento[element] = { } 
    end 
end 

Eso puede causar un buffer overflow, lo mejor sería asignarle el valor "nil" para eliminarla.

Link to comment
  • 1 month later...
On 31/1/2017 at 11:46, Tomas said:

Hay un problema con esta función:


function clearTheElementData( element ) 
  
    if tablaAlmacenamiento[element] then 
        tablaAlmacenamiento[element] = false 
        tablaAlmacenamiento[element] = { } 
    end 
end 

Eso puede causar un buffer overflow, lo mejor sería asignarle el valor "nil" para eliminarla.

Lo tomare en cuenta.

Link to comment
  • Recently Browsing   0 members

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