[Cs:s] Effects showing certain user

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

[Cs:s] Effects showing certain user

Postby cssbestrpg » Sun Jul 25, 2021 6:28 pm

Hi guys i have a issue of my code when i try make show effect for certain users.
When in rpg set effects to off, it works fine that doesn't show effects when is alone, but when other player is and have effects on, i still see the effects even suppose not.

Here is the effect code

Syntax: Select all

def beam(users, _start, _end, lifeTime, startWidth, endWidth, amplitude, r, g, b, a=255, vmt='sprites/laserbeam.vmt'):
modelIndex = engine_server.precache_model(vmt)
tempEnt = TempEntity('BeamPoints')
tempEnt.red = r
tempEnt.green = g
tempEnt.blue = b
tempEnt.alpha = a

tempEnt.start_point = _start
tempEnt.end_point = _end

tempEnt.life_time = lifeTime
tempEnt.start_width = startWidth
tempEnt.end_width = endWidth
tempEnt.amplitude = amplitude

tempEnt.halo_index = modelIndex
tempEnt.model_index = modelIndex
tempEnt.create(RecipientFilter(*users))

beam(rpg.getEffectUsers(), _start, _end, 0.2, 30, 1, 2, color[0], color[1], color[2], 255, 'sprites/laser.vmt')

RPG effect:

Syntax: Select all

def getEffectUsers():
return filter(lambda x: not rpglib.is_bot(x) and players[x]['effects'] == 1, rpglib.getUseridList())

Here is getUseridList() defined:

Syntax: Select all

def getUseridList():
for i in PlayerIter.iterator():
yield i.userid
User avatar
L'In20Cible
Project Leader
Posts: 1446
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [Cs:s] Effects showing certain user

Postby L'In20Cible » Mon Jul 26, 2021 2:32 am

Your problem is that you are passing their userid while it should be their index.
cssbestrpg
Senior Member
Posts: 168
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: [Cs:s] Effects showing certain user

Postby cssbestrpg » Mon Jul 26, 2021 6:15 am

L'In20Cible wrote:Your problem is that you are passing their userid while it should be their index.

Which of my code line i need to passing their index and how to do it properly?
User avatar
Kami
Global Moderator
Posts: 250
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Re: [Cs:s] Effects showing certain user

Postby Kami » Mon Jul 26, 2021 4:20 pm

I guess you could just try and change

Syntax: Select all

yield i.userid


to

Syntax: Select all

yield i.index
cssbestrpg
Senior Member
Posts: 168
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: [Cs:s] Effects showing certain user

Postby cssbestrpg » Mon Jul 26, 2021 4:41 pm

Kami wrote:I guess you could just try and change

Syntax: Select all

yield i.userid


to

Syntax: Select all

yield i.index

Well i changed to that, now i get errors:

Code: Select all

[SP] Caught an Exception:
Traceback (most recent call last):
  File "..\addons\source-python\packages\source-python\events\listener.py", line 92, in fire_game_event
    callback(game_event)
  File "..\addons\source-python\plugins\rpg\skills\armoredemption.py", line 37, in player_death
    for i in rpg.getEffectUsers():
  File "..\addons\source-python\plugins\rpg\rpg.py", line 1004, in <lambda>
    return filter(lambda x: not rpglib.is_bot(x) and players[x]['effects'] == 1, rpglib.geUseridList())
  File "..\addons\source-python\packages\custom\rpglib\__init__.py", line 341, in is_bot
    return get_steamid(userid).startswith('BOT')
  File "..\addons\source-python\packages\custom\rpglib\__init__.py", line 631, in get_steamid
    pEnt        = Player(index_from_userid(userid))

ValueError: Conversion from "Userid" (1) to "Index" failed.

User avatar
Kami
Global Moderator
Posts: 250
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Re: [Cs:s] Effects showing certain user

Postby Kami » Mon Jul 26, 2021 5:30 pm

Yeah, that's because you use the same function somewhere else in your code too. Didn't think about that.

You could instead revert your getUseridList and simply create a new function:

Syntax: Select all

def getIndexList():
for i in PlayerIter.iterator():
yield i.index


then you do

Syntax: Select all

def getEffectUsers():
return filter(lambda x: not rpglib.is_bot(x) and players[x]['effects'] == 1, rpglib.getIndexList())


I'm not sure if your is_bot function and players dict work with an index or a userid, so that might give you an error then.
cssbestrpg
Senior Member
Posts: 168
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: [Cs:s] Effects showing certain user

Postby cssbestrpg » Mon Jul 26, 2021 5:35 pm

It uses this:

Syntax: Select all

def get_steamid(userid):
pEnt = Player(index_from_userid(userid))
steamid = pEnt.steamid

if steamid == 'BOT':
steamid = 'BOT_%s' % pEnt.name

return steamid

Syntax: Select all

def is_bot(userid):
return get_steamid(userid).startswith('BOT')
User avatar
Kami
Global Moderator
Posts: 250
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Re: [Cs:s] Effects showing certain user

Postby Kami » Mon Jul 26, 2021 6:35 pm

Okay, so I tried to think of a quick fix and this is what I came up with. You can add this new function that will either create a new list of indexes or use an existing list of userids to create a list of corresponding indexes.

Syntax: Select all

def getIndexList(list=None):
if list == None:
for i in PlayerIter.iterator():
yield i.index
else:
for i in list:
yield index_from_userid(i)


If you add this function to the same place where your getEffectUsers() is you can change your effect code to:

Syntax: Select all

def beam(users, _start, _end, lifeTime, startWidth, endWidth, amplitude, r, g, b, a=255, vmt='sprites/laserbeam.vmt'):
modelIndex = engine_server.precache_model(vmt)
tempEnt = TempEntity('BeamPoints')
tempEnt.red = r
tempEnt.green = g
tempEnt.blue = b
tempEnt.alpha = a

tempEnt.start_point = _start
tempEnt.end_point = _end

tempEnt.life_time = lifeTime
tempEnt.start_width = startWidth
tempEnt.end_width = endWidth
tempEnt.amplitude = amplitude

tempEnt.halo_index = modelIndex
tempEnt.model_index = modelIndex
tempEnt.create(RecipientFilter(*users))

beam(rpg.getIndexList(rpg.getEffectUsers()), _start, _end, 0.2, 30, 1, 2, color[0], color[1], color[2], 255, 'sprites/laser.vmt')
cssbestrpg
Senior Member
Posts: 168
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: [Cs:s] Effects showing certain user

Postby cssbestrpg » Mon Jul 26, 2021 7:11 pm

Edit:

Got it working with this:

Syntax: Select all

for es in rpg.getEffectUsers():
rpglib.beam(RecipientFilter(es and index_from_userid(es)), _start, _end, 0.2, 30, 1, 2, color[0], color[1], color[2], 255, 'sprites/laser.vmt')


Didn't need to change def beam code and

Syntax: Select all

def getEffectUsers():
return filter(lambda x: not rpglib.is_bot(x) and players[x]['effects'] == 1, rpglib.getUseridList())
User avatar
Kami
Global Moderator
Posts: 250
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Re: [Cs:s] Effects showing certain user

Postby Kami » Tue Jul 27, 2021 6:50 pm

Glad you got it working! This way could potentialy be more stressful on the server as you are now creating a new beam for every person that has effects enabled. If you got 10 players on the server that have effects enabled that would make 10 beams instead of just one beam that shows to all players that have effects enabled.
cssbestrpg
Senior Member
Posts: 168
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: [Cs:s] Effects showing certain user

Postby cssbestrpg » Tue Jul 27, 2021 7:13 pm

It wasn't easy to get it working, i did spend few hours and searching some effect code from forum, one effect code i found one post that gave me idea to solve it. I don't think it makes perfomance issue for server, even if all players have enabled effects.
One thing still i don't get it, if i would have code rpg.getEffectUsers(), it wouldn't show effect when have enabled effects, when would have disabled effects, it would then show the effect. But some reason it works properly when did use this code:

Syntax: Select all

for in es rpg.getEffectUsers():

then the effect code, then if have enabled effects, it would show effect properly, when disabled then wouldn't show

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 1 guest