On Prop +use from Player
Posted: Tue May 24, 2016 9:23 am
I am trying to hook onto the "use" function available when a player uses "+use" on a prop of any kind. The hook works perfectly however the arguments returned are of the Entity itself, and another that I cannot obtain info on. The returned arguments are (Pointer, Pointer), the first being the Entity, the second I hoped would be the Player. On my tests the server just crashes upon trying to obtain a index from said pointer. Code is beneath:
Syntax: Select all
from engines.precache import Model
from messages import SayText2
from players.entity import Player
from players.helpers import index_from_userid
from entities.entity import Entity
from entities.hooks import EntityPreHook
from entities.hooks import EntityCondition
from events import Event
from memory import make_object
model = Model('models/props/cs_militia/toilet.mdl')
global index
@Event('player_say')
def _on_say(event):
player = Player(index_from_userid(event['userid']))
origin = player.view_coordinates
entity = Entity.create('prop_physics_override')
entity.origin = origin
entity.model = model
entity.spawn_flags = 265
entity.spawn()
SayText2(str(entity.index)).send()
global index
index = entity.index
@EntityPreHook(EntityCondition.equals_entity_classname('prop_physics_override'), 'use')
def _on_start_touch(stack):
entity = make_object(Entity, stack[0])
# Retrieving index from stack[1] causes the crash.
# I know I am trying to create a Player object, but just retrieving the index_from_pointer causes it too.
player = make_object(Player, stack[1])