if(ply.cache[id]==nil)then-- if this is the first time then create a cache record
ply.cache[id]={
cache=datatable
-- won't be defining the count here
}
end
if(ply.cache[id].count==nil)thenply.cache[id].count=1elseply.cache[id].count=ply.cache[id].count+1end-- keep count of how many times we have cached this datatable
if(ply.cache[id].count>1)then-- dont want to filter out data if this is the first time.
fork,vinpairs(datatable)do-- loop through the datatable
fork2,v2inpairs(table.GetKeys(ply.cache[id].cache))do-- check each key with each key from the record cache
if(tostring(k)==tostring(v2))then-- check if the keys are the same
if(v==ply.cache[id].cache[tostring(v2)])then-- check if the value/contents are the same
datatable[k]=nil-- if so then remove the key from the datatable
else-- if the key's value has changed we dont remove it since the client needs to know about it
ply.cache[id].cache[tostring(v2)]=v-- and then update the cache so we know about it next time
end
end
end
end
end
datatable.id=id-- give it the id so that the client side could handle it
-- Always give the id since it is highly "valuable".
-- Don't want the client mixing up the NPC, which this caching system could do if not handled correctly.