Syntax: Select all
import time
from conversions_c import index_from_edict
from entity_c import EntityGenerator
from entities.entity import BaseEntity
from events import Event
from memory.hooks import PreHook
# Loop through all hostage_entity edicts
for edict in EntityGenerator('hostage_entity', True):
# Get the hostage's BaseEntity instance
hostage = BaseEntity(index_from_edict(edict)
# We only need to get the first hostage_entity edict
break
'''
Use the entity's OnRescueZoneTouch datamap attribute to prehook that function
The function is not directly a part of the entity itself, but instead
the entity is the first argument when the function is called.
'''
@PreHook(hostage.OnRescueZoneTouch.function)
def pre_hostage_rescue(arguments):
'''With a prehook, you can block the event from
happening by returning a value other than None.
None is automatically returned by a function if no value is explicitly returned
'''
# Has it been 2 minutes since the round started?
if time.time() - start_time < 120:
# Disallow rescuing hostages for the first 2 minutes of a round
return False
@Event
def round_freeze_end(game_event):
global start_time
start_time = time.time()
To get a list of all datamaps for a specific type of entity, make sure one is on the server and use the following code:
Syntax: Select all
from conversions_c import index_from_edict
from entity_c import EntityGenerator
from entities.entity import BaseEntity
# Set to the type of entity you wish to get the datamaps of
entity_type = 'player'
for edict in EntityGenerator(entity_type, True):
entity = BaseEntity(index_from_edict(edict))
break
def list_datamap(datamap, tablevel=0):
for x in sorted(datamap):
class_type = type(datamap[x]).__name__[1:]
print_string = '{0}{1} = Class: {2}'.format(
'\t' * tablevel, x, class_type)
if class_type == 'TypeObject':
print('{0} -> Type: {1}'.format(
print_string, datamap[x].type_object.__name__))
elif class_type == 'DataDesc':
print('{0} -> Type: {1}'.format(
print_string, datamap[x].get_attr.split('_', 1)[1]))
elif class_type in ('Input', 'FunctionTable'):
print('{0} -> Type: {1}'.format(print_string, datamap[x].type))
elif class_type == 'Embedded':
print(print_string)
list_datamap(datamap[x], tablevel + 1)
list_datamap(entity.datamaps)
Embedded ones provide further functionality, like:
Syntax: Select all
<PlayerEntity>.pl.deadflag
Inputs are functions, like my example above. Their "type" is the type of value you need to pass in if you want to call it. If the type is VOID, there is nothing to pass in. For example, InputSetTeam and SetTeam (which are actually the exact same thing) are of type INTEGER. So, you need to pass in an integer value:
Syntax: Select all
<PlayerEntity>.SetTeam(2)
Whereas Ignite is a VOID:
Syntax: Select all
<PlayerEntity>.Ignite()
# You can also specify a time to burn the entity with IgniteLifeTime
<PlayerEntity>.IgniteLifetime(2.0)
Notice in that last example that I used 2.0 (a float) and not just 2 (an integer). You must pass in the proper type, meaning that an integer is not allowed to be used when a float is required.