Creating Sprite does not work consistently
Posted: Wed Jan 24, 2018 9:56 am
So I am trying to create a Sprite in CS:S. This is my attempt:
Sometimes this work, sometimes it doesnt. That means, if I move around a idle bot und try so 'draw' a beam from my position to his, sometimes it gets drawn and sometimes not. I have no idea why. The distance does not seem to be the problem since it sometime works over 2000 Units and some times it dows not work over 100 Units. Maybe I did a very stupid mistake, I don't know.
Also the find_closest_enemy_player(player, radius) works as supposed, it finds the target and never runs into the 'error' in my scenario.
Syntax: Select all
from filters.players import PlayerIter
from mathlib import Vector
from engines.precache import Model
from players.entity import Player
from players.helpers import index_from_userid
def find_closest_enemy_player(player, radius):
alive_players = PlayerIter('alive')
cur_distance = 9999
i=0
for target in alive_players:
if target.team != player.team:
distance = player.origin.get_distance(target.origin)
SayText2('The distance: %s' %distance).send(player.index)
if distance <= radius:
if distance < cur_distance:
cur_distance = distance
return_target = target
i=1
if i != 0:
return return_target
else:
return 'error'
@Event('player_say')
def chat_based_trigger(game_event)
player = Player(index_from_userid(game_event['userid']))
target = find_closest_enemy_player(player, radius =9000)
if target != 'error':
laser_model = Model('sprites/lgtning.vmt')
effect1 = tempEntity('BeamPoints', alpha = 255, red =100, blue = 25, life_time =10.0, start_width = 10, end_width = 10, frame_rate =
255)
effect1.start_point = player.origin
effect1.end_point = target.origin
effect1.model = laser_model
effect1.create()
Sometimes this work, sometimes it doesnt. That means, if I move around a idle bot und try so 'draw' a beam from my position to his, sometimes it gets drawn and sometimes not. I have no idea why. The distance does not seem to be the problem since it sometime works over 2000 Units and some times it dows not work over 100 Units. Maybe I did a very stupid mistake, I don't know.
Also the find_closest_enemy_player(player, radius) works as supposed, it finds the target and never runs into the 'error' in my scenario.