Spinning an object

Please post any questions about developing your plugin here. Please use the search function before posting!
battleweaver
Member
Posts: 43
Joined: Mon Oct 02, 2017 7:57 am
Location: Moscow
Contact:

Spinning an object

Postby battleweaver » Wed Apr 11, 2018 12:40 pm

CS:GO
I try to spin an object around Y axis.
I did not figure out how to spin an entity after spawning using SourcePython commands, so my approach was to activate a spinning animation of a model. My thought was to use entity.call_input().

Syntax: Select all

from engines.precache import Model
from entities._base import Entity
from events import Event
from players._base import Player
from entities.constants import SolidType

@Event('player_say')
def player_say(game_event):
skin = Entity.create('prop_dynamic_override')
player = Player(game_event.index)
skin.model = Model('models/coop/challenge_coin.mdl')
skin.origin = player.origin
skin.set_property_ushort('m_Collision.m_usSolidFlags', 12) # 8 - not solid, 4 - trigger
skin.solid_type = SolidType.BBOX
skin.spawn()
skin.call_input('SetDefaultAnimation', "challenge_coin_idle")

It spawns and it does not spin. I tried to place skin.call_input() before spawn, same result.

Any thoughts where is an error or other approaches?
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Spinning an object

Postby Ayuto » Wed Apr 11, 2018 3:15 pm

You can spin an entity by modifying the angle attribute (or maybe it's called angles. Can't remember...).
User avatar
Kami
Global Moderator
Posts: 263
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Re: Spinning an object

Postby Kami » Wed Apr 11, 2018 3:48 pm

Hey,

this is a quick test I did and should show you how you can use angles to spin your coin :)
I tested this in CS:S but I think CS:GO should be the same

Syntax: Select all

from events import Event
from players.entity import Player
from mathlib import Vector
from engines.precache import Model
from entities.entity import Entity
from listeners.tick import Repeat

global x
x = 0

spin_speed = 10

ent_model = Model('models/props_c17/oildrum001.mdl')


@Event('player_say')
def say(ev):
player = Player.from_userid(ev['userid'])
ent = Entity.create('prop_dynamic_override')
ent.model = ent_model
ent.origin = Vector(*player.view_coordinates)
ent.spawn()
repeat = Repeat(spin_drum,(ent.index,))
repeat.start(0.1)

def spin_drum(index):
global x
x += spin_speed
ent = Entity(index)
ent.angles = Vector(ent.angles[0],x,ent.angles[2])


You can just replace 'models/props_c17/oildrum001.mdl' with your model :)
battleweaver
Member
Posts: 43
Joined: Mon Oct 02, 2017 7:57 am
Location: Moscow
Contact:

Re: Spinning an object

Postby battleweaver » Thu Apr 12, 2018 12:32 pm

Thank you for help.
Here is my version.

Syntax: Select all

from engines.precache import Model
from entities._base import Entity
from events import Event
from mathlib import Vector, QAngle
from players._base import Player
from entities.constants import SolidType

class Skin():
def __init__(self):
self.all_skins = []
self.spin_repeat = Repeat(self.spin_all_skins)

def create_model_prop(self, spawn_coords, item_model):
skin = Entity.create('prop_dynamic_glow')
skin.model = item_model
skin.origin = spawn_coords
skin.set_property_ushort('m_Collision.m_usSolidFlags', 12) # 8 - not solid, 4 - trigger
skin.solid_type = SolidType.BBOX
skin.spawn()
self.all_skins.append(skin)

def spin_all_skins(self):
for skin in self.all_skins:
self._spin_skin(skin)

def _spin_skin(self, skin):
new_angle = skin.angles.y + 10 if skin.angles.y + 10 < 360 else skin.angles.y - 350
skin.angles = QAngle(skin.angles.x, new_angle, skin.angles.z)
my_skin = Skin()
my_skin.spin_repeat.start(0.1)
@Event('player_say')
def say(ev):
player = Player.from_userid(ev['userid'])
my_skin.create_glow(Vector(*player.view_coordinates), Model('models/coop/challenge_coin.mdl'))

self.spin_repeat = Repeat(self.spin_all_skins) - this was made because my objects are pickable. So, when they are picked up and removed, server tries addressing to them for spinning and crashes. In my case I address to them indirectly.
skin.angles = QAngle(skin.angles.x, new_angle, skin.angles.z) - entity.angles returns QAngle, not Vector and both of them have x,y,z attributes

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 26 guests