Page 1 of 1

[CSGO] Need help to spawn and move entity

Posted: Sun May 07, 2017 10:49 am
by existenz
Hey !

I want to spawn an entity at random one end of the map, after that i wan't to trace a ray for this entity and it must follow this vector.
But i don't know how to get the height and one end of the map and how to move an entity.

Entity :

Syntax: Select all

heli = Entity.create('prop_dynamic')
heli.origin = Vector(637.66650390625, 322.892578125, 256.03125)
heli.model = Model('models/props_vehicles/helicopter_rescue.mdl')
heli.solid_type = 6
heli.spawn()


Sincerly Existenz.

Re: [CSGO] Need help to spawn and move entity

Posted: Sun May 07, 2017 11:24 am
by Kill

Re: [CSGO] Need help to spawn and move entity

Posted: Sun May 07, 2017 12:29 pm
by iPlayer
Do you want your entity to move over time in some direction?

Re: [CSGO] Need help to spawn and move entity

Posted: Sun May 07, 2017 12:36 pm
by existenz
Thanks for your answer.

@Kill : I know about this function but i really want that the entity move in one direction.

@iPlayer : Yes, i want that entiry just crosses the map and despawn after arrive at the end of map. But the I want the trajectory to change every round.

Re: [CSGO] Need help to spawn and move entity

Posted: Sun May 07, 2017 2:31 pm
by PhantomDancer
i want that entiry just crosses the map

if you want to interact with your entity, i would (re)create multiple https://developer.valvesoftware.com/wiki/Path_track and apply https://developer.valvesoftware.com/wik ... tracktrain to it.

Re: [CSGO] Need help to spawn and move entity

Posted: Sun May 07, 2017 4:40 pm
by existenz
I just need 2 path_track no ? Point A and B, path_tracktrain start point A to point B.
But i don't know how to get location of point A and B.
They must to be in top of sky without obstruction and how create path_track and path_tracktrain.

I will search. Thanks :)

Re: [CSGO] Need help to spawn and move entity

Posted: Sun May 07, 2017 5:02 pm
by iPlayer
If you need a linear movement between two points, I'd recommend looking towards func_movelinear entity:

Syntax: Select all

import math
from entities.entity import Entity
from mathlib import Vector


def vec2angle(vec):
atan = math.degrees(math.atan(coord_eye_vec.y / coord_eye_vec.x))
if coord_eye_vec.x < 0:
y_angle = atan + 180
elif coord_eye_vec.y < 0:
y_angle = atan + 360
else:
y_angle = atan

# Calculate the x angle value
x_angle = 0 - math.degrees(math.atan(coord_eye_vec.z / math.sqrt(
coord_eye_vec.y ** 2 + coord_eye_vec.x ** 2)))

return Vector(x_angle, y_angle, 0)


speed = 48.0
start_pos = Vector(512, 0, 0)
end_pos = Vector(0, 0, 0)


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)
entity.spawn()


Then you can parent anything to this entity.

Re: [CSGO] Need help to spawn and move entity

Posted: Sun May 07, 2017 5:35 pm
by existenz
Thanks i will try !

Re: [CSGO] Need help to spawn and move entity

Posted: Mon May 08, 2017 12:51 pm
by existenz
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 :(

Re: [CSGO] Need help to spawn and move entity

Posted: Tue May 09, 2017 7:00 pm
by iPlayer
Add

Syntax: Select all

entity.call_input("Open")


when you want the heli to fly.

Re: [CSGO] Need help to spawn and move entity

Posted: Wed May 10, 2017 8:44 am
by existenz
Thanks iPlayer, it works ! I must just rotate my entity to be in good direction :)

No one has an idea why my code to create a linear line doesn't work well ?