Players transparency

Please post any questions about developing your plugin here. Please use the search function before posting!
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Players transparency

Postby Tuck » Sun Dec 02, 2012 9:36 pm

Okay so back on the "old" forums i posted a request for this to be fixed/discovered

I cannot set players transparency in csgo the way css does it, i think it has something to do with we have to set RenderMode
but i cannot seem to find any information about rendermode, tried to debug it but everytime i changeteam the rendermode changes to some random weird number fx -630239

if i try to set it to something between 1-10 sometimes players goes 100% invisible even transparency set to 255, and players that see the player with a different rendermod crashes.

Syntax: Select all

def setColor(user, red, green, blue, alpha = None):
renderColor = red
renderColor += green << 8
renderColor += blue << 16
if alpha is None:
renderColor += getColor(user)[3] << 24
else:
renderColor += alpha << 24
if renderColor >= 2**31:
renderColor -= 2**32
user.entity.SetPropInt('CBaseEntity.m_nRenderMode', user.entity.GetPropInt('CBaseEntity.m_nRenderMode') | 1)
user.entity.SetPropInt('CBaseEntity.m_nRenderFX', user.entity.GetPropInt('CBaseEntity.m_nRenderFX') | 256)
user.entity.SetPropInt('CBaseEntity.m_clrRender', renderColor)


It would help me and a lot of other people if this can be fixed/discovered

I don't know where to start to figure this out my self.

Thanks in advance.
-Tuck
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Tue Dec 04, 2012 10:59 pm

Hey Tuck,

Can you post your entire code please? It's hard to help you when we need to rewrite your functions (cf: getColor) and/or "guessing" the type of the arguments you are using (cf: user)...

Thanks,

L'In20Cible
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Tue Dec 04, 2012 11:06 pm

You can try with the BaseEntity property "color". I haven't figured out why it isn't working, yet, as I haven't had a lot of time to work on it.

Syntax: Select all

from events import Event
from filters.players import PlayerIter
from players.entity import PlayerEntity


@Event
def player_say(GameEvent):
for index in PlayerIter():
player = PlayerEntity(index)
if player.team == 2:
player.color = (255, 0, 0, 125)
elif player.team == 3:
player.color = (0, 0, 255, 125)
Though, doing this would require you to restart your server each time you modify the BaseEntity get_color or set_color methods.

Satoon
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Wed Dec 05, 2012 4:06 am

Syntax: Select all

def getColor(user):
if not user.entity:
user.entity = Player.EdictOfPlayer(user.IPlayerInfo)
color = user.entity.GetPropInt('CBaseEntity.m_clrRender')
return tuple(int(x) for x in (color & 0xff, (color & 0xff00) >> 8, (color & 0xff0000) >> 16, (color & 0xff000000) >> 24))


my "user" is basicly just a class with diferent source python types such as IPlayerInfo and edict_t

I coded it just like playerlib in ES and talking to you satoon in previus posts about this u said you used the methods from playerlib im doing the same thing, so if you have not changed your way of doing this your's wont work either.
-Tuck
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Wed Dec 05, 2012 4:12 am

I hope you realize that PlayerEntity is essentially the same thing as your player class. Instead of "entity", we use "edict", since it is the player's edict. Also, in __getattr__, we utilize both the edict and IPlayerInfo instances to see if the attribute is a method of either of those two object:
  • From ../_libs/entities/entity.py lines 62-72:

    Syntax: Select all

    def __getattr__(self, attr):
    '''Finds if the attribute is valid and returns the appropriate value'''

    # Loop through all instances (used to get edict/IPlayerInfo attributes)
    for instance in self.instances:

    # Does the current instance contain the given attribute?
    if hasattr(instance, attr):

    # Return the instance's value for the given attribute
    return getattr(instance, attr)
  • From ../_libs/players/entity.py lines 58 - 64:

    Syntax: Select all

    @property
    def instances(self):
    '''Yields the player's IPlayerInfo and Edict instances'''

    # Yield the instances
    yield self.info
    yield self.edict
So, you are basically reinventing the wheel for no real purpose.

Satoon
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Wed Dec 05, 2012 4:15 am

I have tried a few changes to get this working, but no matter what I try, I cannot seem to get the alpha value to matter. I will continue to research this myself, but if someone figures it out, please post here so we all know.

Satoon
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Wed Dec 05, 2012 4:16 am

basicly i only use IPlayerInfo in almost all the cases so basicly i have edict_t as None i only retrieve edict_t if i need it, i'm also storing cached sql database information about user inside it

Basicly i felt it was cleaner to take the "engine/source-python" types and only retrieving them if i needed to use them :)
-Tuck
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Wed Dec 05, 2012 4:23 am

The issue with that is that if you need them multiple times, you end up wasting the time to retrieve them. If you are not worried about any minimal speed difference, then I really don't see what the issue would be with storing those values on instanciation.

Also, we require the index to get an instance, but get the entity's edict in order to verify that the entity is of the proper type for the given class (as in for PlayerEntity, the classname "must" be "player" in order to retrieve an instance). Since we already get the edict, we just go ahead and store it.

We "could" forgo getting the IPlayerInfo instance until it is first needed, but that would require a lot of messy code, and again, there really is no harm in storing that information whether it is used later or not.

You could also have a class that inherits from PlayerEntity that stores the sql database, if you wanted to.

Satoon
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Wed Dec 05, 2012 4:31 am

satoon101 wrote:The issue with that is that if you need them multiple times, you end up wasting the time to retrieve them. If you are not worried about any minimal speed difference, then I really don't see what the issue would be with storing those values on instanciation.

Also, we require the index to get an instance, but get the entity's edict in order to verify that the entity is of the proper type for the given class (as in for PlayerEntity, the classname "must" be "player" in order to retrieve an instance). Since we already get the edict, we just go ahead and store it.

We "could" forgo getting the IPlayerInfo instance until it is first needed, but that would require a lot of messy code, and again, there really is no harm in storing that information whether it is used later or not.

You could also have a class that inherits from PlayerEntity that stores the sql database, if you wanted to.

Satoon


i made it possible to use them multiple times, only be retrieving them once, but yea i was more thinking into memory lane storing it there

On the player instance related im pretty sure the problems lays within

Syntax: Select all

SetPropInt('CBaseEntity.m_nRenderMode', user.entity.GetPropInt('CBaseEntity.m_nRenderMode') | 1)


The renderMode of the model has to be set so its cabeable to be transparent however csgo redefined the values of rendermode so it looks random as i stated in first post

However i never work with reading Bits in python so i wouldnt know how to check, if basicly they store more information in the rendermode variable, so for example we only have to set 1 bit to allow this? however setting it to 1-10 some of these makes the player go invisible (and crash people who view it) just my idea about the problem :/
-Tuck
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Wed Dec 05, 2012 3:24 pm

Hey guys,
Tuck wrote: however setting it to 1-10 some of these makes the player go invisible
This is normal since some render modes doesn't render at all (such as environmental and none):

Syntax: Select all

// Rendering constants
// if this is changed, update common/MaterialSystem/Sprite.cpp
enum RenderMode_t
{
kRenderNormal = 0, // src
kRenderTransColor, // c*a+dest*(1-a)
kRenderTransTexture, // src*a+dest*(1-a)
kRenderGlow, // src*a+dest -- No Z buffer checks -- Fixed size in screen space
kRenderTransAlpha, // src*srca+dest*(1-srca)
kRenderTransAdd, // src*a+dest
kRenderEnvironmental, // not drawn, used for environmental effects
kRenderTransAddFrameBlend, // use a fractional frame value to blend between animation frames
kRenderTransAlphaAdd, // src + dest*(1-a)
kRenderWorldGlow, // Same as kRenderGlow but not fixed size in screen space
kRenderNone, // Don't render.

kRenderModeCount, // must be last
};

I didn't test it yet but I wonder if the following may fix the problem:

Syntax: Select all

from events import Event
from filters.players import PlayerIter
from players.entity import PlayerEntity
from Entity import FL_EDICT_CHANGED

@Event
def player_say(GameEvent):
for index in PlayerIter():
player = PlayerEntity(index)
if player.team == 2:
player.color = (255, 0, 0, 125)
elif player.team == 3:
player.color = (0, 0, 255, 125)
player.edict.m_fStateFlags |= FL_EDICT_CHANGED


L'In20Cible
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Wed Dec 05, 2012 4:07 pm

did not work @L'In20Cible
-Tuck
DJiSer
Junior Member
Posts: 20
Joined: Sat May 10, 2014 2:44 pm

Postby DJiSer » Mon Aug 18, 2014 10:06 am

It's possible to change player alpha in csgo?
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Tue Aug 19, 2014 12:11 am

I'm sure it is possible, just not sure how to do it, yet. I have a few ideas that I will test myself once I have finished the BaseEntity updates. I hope to have those done within the next two weeks, but no promises.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 111 guests