Jump to content

elementData con tablas


-Rex-

Recommended Posts

Posted (edited)
--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-
Posted

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.

Posted
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

Posted
13 hours ago, -Rex- said:

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

Como ya te dije usando setElementData(source, index, value, false) es decir apagando la syncronizacion no se usa mucha CPU

  • 4 months later...
Posted
20 hours ago, RekZ said:

Podria servir esto para poder dar uso a una misma tabla tanto en client como en server ?

No. Tendrías que hacer una tabla independientemente para ambos lados.

Posted

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.

  • 1 month later...
Posted
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.

  • Recently Browsing   0 members

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