[Cs:s] Drug Command

Please post any questions about developing your plugin here. Please use the search function before posting!
cssbestrpg
Senior Member
Posts: 287
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

[Cs:s] Drug Command

Postby cssbestrpg » Fri Aug 06, 2021 10:32 pm

Hi guys, i have a issue with drug i can't get it work properly.
I tried make old eventscripts code in Source.Python.

Eventscripts part

Syntax: Select all

def drug(user, times=8, count=0):
if isAlive(user):
count += 1

r = random.randint(0, 255)
g = random.randint(0, 255)
b = random.randint(0, 255)
a = random.randint(175, 215)

angle = random.randint(15, 50)
if random.randint(0,1) == 1:
angle = random.randint(-50, -15)

_angle1 = es.getplayerprop(user, 'CCSPlayer.m_angEyeAngles[0]')
_angle2 = es.getplayerprop(user, 'CCSPlayer.m_angEyeAngles[1]')

usermsg.fade(user, 1, 1450, 650, r, g, b, a)
es.server.queuecmd('es_xsetang %s %s %s %s' % (user, _angle1, _angle2, angle))

if count < times:
gamethread.delayed(2.45, drug, (user, times, count))
else:
es.server.queuecmd('es_xsetang %s %s %s 0' % (user, _angle1, _angle2))


Source.Python

Syntax: Select all

import rpglib, random
from colors import Color
from players.entity import Player

def drug(user, times=8, count=0):
if rpglib.isAlive(user):
count += 1
r = random.randint(0, 255)
g = random.randint(0, 255)
b = random.randint(0, 255)
a = random.randint(175, 215)
color = Color(r,g,b,a)
rpglib.fade(user, 1, 1, color)
player = Player.from_userid(user)
angle = random.randint(15, 50)
if random.randint(0,1) == 1:
angle = random.randint(-50, -15)

_angle1 = player.get_network_property_vector('m_angEyeAngles[0]')
_angle2 = player.get_network_property_vector('m_angEyeAngles[1]')
player.client_command('setang %s %s %s' % (_angle1, _angle2, angle), True)
if count < times:
player.delay(2.45, drug, (user, times, count))
else:
player.client_command('setang %s %s 0' % (_angle1, _angle2), True)

The setang part doesn't work, player screen angle doesn't change
User avatar
Kami
Global Moderator
Posts: 263
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Re: [Cs:s] Drug Command

Postby Kami » Sat Aug 07, 2021 8:45 am

You could try to set the angle using http://wiki.sourcepython.com/developing/modules/entities.entity.html?highlight=teleport#entities.entity.Entity.teleport

I did not test this, but you might get the idea:

Syntax: Select all

from mathlib import QAngle
import rpglib, random
from colors import Color
from players.entity import Player

def drug(user, times=8, count=0):
if rpglib.isAlive(user):
count += 1
r = random.randint(0, 255)
g = random.randint(0, 255)
b = random.randint(0, 255)
a = random.randint(175, 215)
color = Color(r,g,b,a)
rpglib.fade(user, 1, 1, color)
player = Player.from_userid(user)
angle = random.randint(15, 50)
if random.randint(0,1) == 1:
angle = random.randint(-50, -15)

_angle1 = player.get_network_property_vector('m_angEyeAngles[0]')
_angle2 = player.get_network_property_vector('m_angEyeAngles[1]')
#player.client_command('setang %s %s %s' % (_angle1, _angle2, angle), True)
player.teleport(None, QAngle(_angle1,_angle2,angle),None)
if count < times:
player.delay(2.45, drug, (user, times, count))
else:
player.teleport(None, QAngle(_angle1,_angle2,0.0),None)
#player.client_command('setang %s %s 0' % (_angle1, _angle2), True)
cssbestrpg
Senior Member
Posts: 287
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: [Cs:s] Drug Command

Postby cssbestrpg » Sat Aug 07, 2021 9:08 am

Thanks for your help, i made small code changes to get it work properly

Got it work with this:

Syntax: Select all

def drug(user, times=8, count=0):
if rpglib.isAlive(user):
count += 1
r = random.randint(0, 255)
g = random.randint(0, 255)
b = random.randint(0, 255)
a = random.randint(175, 215)
color = Color(r,g,b,a)
rpglib.fade(user, 1, 1, color)
player = Player.from_userid(user)
angle = random.randint(15, 50)
if random.randint(0,1) == 1:
angle = random.randint(-50, -15)

_angle1 = player.get_property_float('m_angEyeAngles[0]')
_angle2 = player.get_property_float('m_angEyeAngles[1]')
player.teleport(None, QAngle(_angle1,_angle2, float(angle)),None)
if count < times:
player.delay(2.45, drug, (user, times, count))
else:
player.teleport(None, QAngle(_angle1,_angle2,0.0),None)
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: [Cs:s] Drug Command

Postby Ayuto » Sun Aug 08, 2021 12:35 pm

Just two small hints:
  1. You can use player.dead to check whether a player is dead or alive.
  2. To get the eye angles you can simply use player.eye_angle (it will return a QAngle) which you can treat like a list (angle[2] = <random value>).
Both calls are much faster than using get_property_float/bool.
cssbestrpg
Senior Member
Posts: 287
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: [Cs:s] Drug Command

Postby cssbestrpg » Sun Aug 08, 2021 2:30 pm

Thanks for the hints, i have updated the code include them.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 18 guests