I have two problems :
Move linear doesn't work, it spawns heli in the sky but it doesn't move :
Syntax: Select all
import math
import random
from commands.say import SayCommand
from engines.precache import Model
from entities.entity import Entity
from mathlib import Vector
from messages import SayText2
from players.entity import Player
@SayCommand('test')
def on_test(command, index, team_only=None):
player = Player(index)
speed = 20.0
location = player.origin
start_pos = Vector(location.x, location.y, location.z+500)
end_pos = Vector(0, 0, 500)
entity = Entity.create('func_movelinear')
entity.set_key_value_vector('movedir', vec2angle(end_pos - start_pos))
entity.set_key_value_float('blockdamage', 0.0)
entity.set_key_value_float('startposition', 0.0)
entity.set_key_value_float('movedistance', (end_pos - start_pos).length)
entity.set_property_float('m_flSpeed', speed)
entity.spawnflags = 8 # "Not Solid"
entity.teleport(start_pos, None, None)
heli = Entity.create('prop_dynamic')
heli.origin = start_pos
heli.model = Model('models/props_vehicles/helicopter_rescue.mdl')
heli.solid_type = 6
heli.spawn()
heli.set_parent(entity)
SayText2(str(heli)).send()
SayText2(str(entity)).send()
entity.spawn()
def vec2angle(vec):
atan = math.degrees(math.atan(vec.y / vec.x))
if vec.x < 0:
y_angle = atan + 180
elif vec.y < 0:
y_angle = atan + 360
else:
y_angle = atan
# Calculate the x angle value
x_angle = 0 - math.degrees(math.atan(vec.z / math.sqrt(
vec.y ** 2 + vec.x ** 2)))
return Vector(x_angle, y_angle, 0)
Create the linear line :
I want that the helicopter travels the entire map passing by it center but by a random direction.
Sometimes i have an extremity of the map but not always whenever it would be necessary that each time the starting and ending point are an extremity of the map. if it's possible :x
Syntax: Select all
import math
import random
from commands.say import SayCommand
from engines.trace import engine_trace
from engines.trace import ContentMasks
from engines.trace import GameTrace
from engines.trace import MAX_TRACE_LENGTH, MAX_COORD_FLOAT, MIN_COORD_FLOAT, COORD_EXTENT, MAX_COORD_RANGE
from engines.trace import Ray
from engines.trace import TraceFilterSimple
from engines.precache import Model
from entities.entity import Entity
from filters.entities import EntityIter
from mathlib import Vector
from messages import SayText2
from events import Event
from players.entity import Player
from weapons.entity import Weapon
@SayCommand('test')
def on_test(command, index, team_only=None):
player = Player(index)
# origin_vector = player.origin
for worldspawn in EntityIter('worldspawn'):
origin_vector = (worldspawn.maxs - worldspawn.mins) / 2
SayText2(str(origin_vector)).send()
break
else:
raise NotImplementedError('No world on round start ~ wut?')
angle_one = random.randrange(360)
direction_one = Vector(math.cos(math.radians(angle_one)), math.sin(math.radians(angle_one)), 0)
direction_one_vector = origin_vector + direction_one * MAX_TRACE_LENGTH
trace = GameTrace()
engine_trace.trace_ray(
Ray(origin_vector, direction_one_vector), ContentMasks.ALL, None, trace
)
start_vector = trace.end_position
SayText2('Start vector :').send()
SayText2(str(start_vector)).send()
SayText2(str(trace.did_hit_world())).send()
angle_two = angle_one + 180
direction_two = Vector(math.cos(math.radians(angle_two)), math.sin(math.radians(angle_two)), 0)
direction_two_vector = origin_vector + direction_two * MAX_TRACE_LENGTH
trace = GameTrace()
engine_trace.trace_ray(
Ray(origin_vector, direction_two_vector), ContentMasks.ALL, None, trace
)
end_vector = trace.end_position
SayText2('End vector :').send()
SayText2(str(end_vector)).send()
SayText2(str(trace.did_hit_world())).send()
@TypedSayCommand('tp')
def teleport_command(
command_info, x:float, y:float, z:float):
player = Player(command_info.index)
origin = Vector(x, y, z)
player.origin = origin
Sincerly Existenz.
Ps : Sorry for my bad english :(