Page 1 of 1

[Cs:s] Effects showing certain user

Posted: Sun Jul 25, 2021 6:28 pm
by cssbestrpg
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

Re: [Cs:s] Effects showing certain user

Posted: Mon Jul 26, 2021 2:32 am
by L'In20Cible
Your problem is that you are passing their userid while it should be their index.

Re: [Cs:s] Effects showing certain user

Posted: Mon Jul 26, 2021 6:15 am
by cssbestrpg
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?

Re: [Cs:s] Effects showing certain user

Posted: Mon Jul 26, 2021 4:20 pm
by Kami
I guess you could just try and change

Syntax: Select all

yield i.userid


to

Syntax: Select all

yield i.index

Re: [Cs:s] Effects showing certain user

Posted: Mon Jul 26, 2021 4:41 pm
by cssbestrpg
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.


Re: [Cs:s] Effects showing certain user

Posted: Mon Jul 26, 2021 5:30 pm
by Kami
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.

Re: [Cs:s] Effects showing certain user

Posted: Mon Jul 26, 2021 5:35 pm
by cssbestrpg
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')

Re: [Cs:s] Effects showing certain user

Posted: Mon Jul 26, 2021 6:35 pm
by Kami
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')

Re: [Cs:s] Effects showing certain user

Posted: Mon Jul 26, 2021 7:11 pm
by cssbestrpg
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())

Re: [Cs:s] Effects showing certain user

Posted: Tue Jul 27, 2021 6:50 pm
by Kami
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.

Re: [Cs:s] Effects showing certain user

Posted: Tue Jul 27, 2021 7:13 pm
by cssbestrpg
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