Revision Difference
Entity:GetSaveTable#528862
<function name="GetSaveTable" parent="Entity" type="classfunc">
<description>
Returns a table of save values for an entity.
These tables are not the same between the client and the server, and different entities may have different fields.
You can get the list different fields an entity has by looking at it's source code ( the 2013 SDK can be found online, https://github.com/ValveSoftware/source-sdk-2013 ). Accessible fields are defined by each DEFINE_FIELD and DEFINE_KEYFIELD inside the DATADESC block.
You can get the list different fields an entity has by looking at it's source code (the 2013 SDK can be found [online](https://github.com/ValveSoftware/source-sdk-2013)). Accessible fields are defined by each `DEFINE_FIELD` and `DEFINE_KEYFIELD` inside the `DATADESC` block.
Take the headcrab, for example:
```
BEGIN_DATADESC( CBaseHeadcrab )
// m_nGibCount - don't save
DEFINE_FIELD( m_bHidden, FIELD_BOOLEAN ),
DEFINE_FIELD( m_flTimeDrown, FIELD_TIME ),
DEFINE_FIELD( m_bCommittedToJump, FIELD_BOOLEAN ),
DEFINE_FIELD( m_vecCommittedJumpPos, FIELD_POSITION_VECTOR ),
DEFINE_FIELD( m_flNextNPCThink, FIELD_TIME ),
DEFINE_FIELD( m_flIgnoreWorldCollisionTime, FIELD_TIME ),
DEFINE_KEYFIELD( m_bStartBurrowed, FIELD_BOOLEAN, "startburrowed" ),
DEFINE_FIELD( m_bBurrowed, FIELD_BOOLEAN ),
DEFINE_FIELD( m_flBurrowTime, FIELD_TIME ),
DEFINE_FIELD( m_nContext, FIELD_INTEGER ),
DEFINE_FIELD( m_bCrawlFromCanister, FIELD_BOOLEAN ),
DEFINE_FIELD( m_bMidJump, FIELD_BOOLEAN ),
DEFINE_FIELD( m_nJumpFromCanisterDir, FIELD_INTEGER ),
DEFINE_FIELD( m_bHangingFromCeiling, FIELD_BOOLEAN ),
DEFINE_FIELD( m_flIlluminatedTime, FIELD_TIME ),
DEFINE_INPUTFUNC( FIELD_VOID, "Burrow", InputBurrow ),
DEFINE_INPUTFUNC( FIELD_VOID, "BurrowImmediate", InputBurrowImmediate ),
DEFINE_INPUTFUNC( FIELD_VOID, "Unburrow", InputUnburrow ),
DEFINE_INPUTFUNC( FIELD_VOID, "StartHangingFromCeiling", InputStartHangingFromCeiling ),
DEFINE_INPUTFUNC( FIELD_VOID, "DropFromCeiling", InputDropFromCeiling ),
// Function Pointers
DEFINE_THINKFUNC( EliminateRollAndPitch ),
DEFINE_THINKFUNC( ThrowThink ),
DEFINE_ENTITYFUNC( LeapTouch ),
END_DATADESC()
```
⤶
⤶
For each **DEFINE_FIELD**, the save table will have a key with name of **first** argument.
⤶
For each **DEFINE_KEYFIELD**, the save table will have a key with name of the **third** argument.⤶
⤶
* For each **DEFINE_FIELD**, the save table will have a key with name of **first** argument.⤶
* For each **DEFINE_KEYFIELD**, the save table will have a key with name of the **third** argument.
See <page>Entity:GetInternalVariable</page> for only retrieving one key of the save table.
</description>
<realm>Shared</realm>
<args>
<arg name="showAll" type="boolean">If set, shows all variables, not just the ones for save.</arg>
</args>
<rets>
<ret name="" type="table">A table containing all save values in key/value format.
The value may be a sequential table (starting with 1) if the field in question is an array in engine.</ret>
The value may be a sequential table (starting to **1**) if the field in question is an array in engine.</ret>
</rets>
</function>⤶
⤶
<example>⤶
<description>Get how long it has been since the player was damaged</description>⤶
<code>⤶
local meta = FindMetaTable( "Player" )⤶
⤶
function meta:GetLastDamageTime()⤶
return self:GetSaveTable().m_flLastDamageTime⤶
end⤶
⤶
print( Entity( 1 ):GetLastDamageTime() )⤶
</code>⤶
<output>-31.965000152588</output>⤶
⤶
</example>⤶
⤶
⤶
<example>⤶
<description>Determine if a door is locked (only works on server side otherwise returns nil)</description>⤶
<code>⤶
function IsDoorLocked(ent)⤶
return ent:GetSaveTable().m_bLocked⤶
end⤶
</code>⤶
<output>returns true if the door is locked</output>⤶
⤶
</example>⤶
⤶
⤶
<example>⤶
<description>Function `DoorIsOpen( door )` that returns whether a door is open or not, for different door classes</description>⤶
<code>⤶
local TestingFunctions = {⤶
["func_door"] = function( self )⤶
return ( self:GetSaveTable().m_toggle_state == 0 )⤶
end,⤶
["func_door_rotating"] = function( self )⤶
return ( self:GetSaveTable().m_toggle_state == 0 )⤶
end,⤶
["prop_door_rotating"] = function( self )⤶
return ( self:GetSaveTable().m_eDoorState ~= 0 )⤶
end,⤶
}⤶
function DoorIsOpen( door )⤶
local func = TestingFunctions[door:GetClass()]⤶
if func then⤶
return func( door )⤶
end⤶
end⤶
</code>⤶
⤶
</example></function>