def getViewCoords(userid, mask=0xFFFFFFFF, collisiongroup=0): player = playerlib.getPlayer(userid) startvec = player.getEyeLocation() # Create start and end vector pointers pStart = createVector(*startvec) pEnd = createVector(*list(Vector(startvec) + Vector(player.viewvector) \ * MAX_COORD_RANGE)) # Allocate space for the CGameTrace object ptr = spe.alloc(SIZE_TRACE_T) # Call UTIL_TraceLine() spe.call('TraceLine', pStart, pEnd, mask, spe.getPlayer(int(userid)), collisiongroup, ptr) # Wrap the end vector... x = spe.makeObject('Vector', ptr + 12) # ... and save the result result = x.x, x.y, x.z # Deallocate reserved space spe.dealloc(pStart) spe.dealloc(pEnd) spe.dealloc(ptr) # Finally, return the result return result
def createVector(x, y, z): obj = spe.makeObject('Vector', spe.alloc(SIZE_VECTOR)) obj.x = x obj.y = y obj.z = z return obj.base
def __new__(cls, x=0, y=0, z=0): ''' Creates a pointer and sets the coordinates. ''' pointer = spe.alloc(12) spe.setLocVal('f', pointer, float(x)) spe.setLocVal('f', pointer + 4, float(y)) spe.setLocVal('f', pointer + 8, float(z)) return super(cls, cls).__new__(cls, pointer)
def __new__(cls, users): ''' Adds all given users to the new created pointer. ''' pointer = spe.alloc(40) spe.call('RecipientFilterConst', pointer) for userid in getUsers(users): player = spe.getPlayer(userid) spe.call('AddRecipient', pointer, player) return super(cls, cls).__new__(cls, pointer)