Ayuto

custom_types example3 (es.entitygetvalue)

Dec 27th, 2013
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.53 KB | None | 0 0
  1. # =============================================================================
  2. # >> IMPORTS
  3. # =============================================================================
  4. # binutils
  5. import binutils
  6.  
  7. from custom_types import Interfaces
  8.  
  9.  
  10. # =============================================================================
  11. # >> TESTS
  12. # =============================================================================
  13. # Get the IServerTools interface
  14. server_tools = Interfaces.server_tools
  15.  
  16. # Get the first entity
  17. entity = server_tools.FirstEntity()
  18.  
  19. def entitygetvalue(entity, field, string_t=False, buffer_size=1024):
  20.     # Create a buffer
  21.     buffer = binutils.alloc(buffer_size)
  22.  
  23.     # Call the function, which fills <buffer>
  24.     if not server_tools.GetKeyValue(entity, field, buffer, buffer_size) % 2:
  25.         # The key does not exist
  26.         buffer.dealloc()
  27.         return None
  28.  
  29.     # Save the result
  30.     result = buffer.get_string() if string_t else buffer.get_string_array()
  31.  
  32.     # Deallocate the buffer
  33.     buffer.dealloc()
  34.    
  35.     # Return the result
  36.     return result
  37.    
  38. # Loop through all entities on the current map
  39. while entity:
  40.     # The key "model" is a string_t as it accesses this attribute:
  41.     # string_t m_ModelName;
  42.     # That's why we need to handle it differently. It's obviously a bug in the
  43.     # engine itself. But that's the reason why
  44.     # es.entitygetvalue(<index>, <field>) fails on the key "model".
  45.     print entitygetvalue(entity, 'model', True)
  46.     entity = server_tools.NextEntity(entity)
Advertisement
Add Comment
Please, Sign In to add comment