Skip to content

Entities transmit alternative. #353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

CookStar
Copy link
Contributor

@CookStar CookStar commented Sep 23, 2020

This draft is derived from #332 & #332 (comment) & 14a38d4

Currently, there are ongoing discussions on how to implement the feature.
I've made a pull request as a draft for code review.

Example:

#Hide the teammates from each other.
@Event("player_spawn")
def on_player_spawn(game_event):
    player = Player.from_userid(game_event["userid"])
    for other in PlayerIter():
        if player.team_index == other.team_index:
            player.hide_entity(other.index)
            other.hide_entity(player.index)

#An optional reset, for spectating the game.
@Event("player_death")
def on_player_death(game_event):
    player = Player.from_userid(game_event["userid"])
    for other in PlayerIter():
        player.reset_entity(other.index)

Entity class

# =========================================================================
# >> ENTITY TRANSMIT FUNCTIONALITY
# =========================================================================
def hide(self):
"""Hide the entity from all players."""
transmit_manager.hide(self.index)
def hide_from(self, player_index):
"""Hide the entity from player.
:param int player_index:
The target player index to hide this entity.
"""
transmit_manager.hide_from(self.index, player_index)
def show(self):
"""Show the entity to all players."""
transmit_manager.show(self.index)
def show_from(self, player_index):
"""Show the entity to player.
:param int player_index:
The target player index to show this entity.
"""
transmit_manager.show_from(self.index, player_index)
def reset(self):
"""Reset the entity's hidden/shown state."""
transmit_manager.reset(self.index)
def reset_from(self, player_index):
"""Reset the player's entity hidden/shown state.
:param int player_index:
The target player index to reset the player's hidden/shown state.
"""
transmit_manager.reset_from(self.index, player_index)
def is_hidden(self):
"""Return True if the entity is hidden from any player.
:rtype: bool
"""
return transmit_manager.is_hidden(self.index)
def is_hidden_from(self, player_index):
"""Return True if the entity is hidden from the player.
:param int player_index:
The target player index to check if the entity is hidden.
:rtype: bool
"""
return transmit_manager.is_hidden_from(self.index, player_index)
def get_hidden_player(self):
"""Get the players where the entity is hidden.
:return:
A tuple containing :class:`players.entity.Player` instances
in which the entity is hidden.
:rtype: tuple
"""
return transmit_manager.get_hidden_player(self.index)

Player class

# =========================================================================
# >> PLAYER TRANSMIT FUNCTIONALITY
# =========================================================================
def hide_entity(self, entity_index):
"""Hide the entity from player.
:param int entity_index:
The target entity index to hide from the player.
"""
transmit_manager.hide_from(entity_index, self.index)
def show_entity(self, entity_index):
"""Show the entity to player.
:param int entity_index:
The target entity index to show the entity to player.
"""
transmit_manager.show_from(entity_index, self.index)
def reset_entity(self, entity_index):
"""Reset the player's entity hidden/shown state.
:param int entity_index:
The target entity_index to reset the player's hidden/shown state.
"""
transmit_manager.reset_from(entity_index, self.index)
def reset_all_entity(self):
"""Reset the player's hidden/shown state on all entities."""
transmit_manager.reset_player(self.index)
def is_entity_hidden(self, entity_index):
"""Return True if the entity is hidden from the player.
:param int entity_index:
The target entity index to check if the entity is hidden.
:rtype: bool
"""
return transmit_manager.is_hidden_from(entity_index, self.index)
def get_hidden_entity(self):
"""Get the entities that are hidden from the player.
:return:
A tuple containing :class:`entities.entity.Entity` instances
that are hidden from the player.
:rtype: tuple
"""
return transmit_manager.get_hidden_entity(self.index)

Other Function

# =============================================================================
# >> FUNCTIONS
# =============================================================================
def reset_hidden_state():
"""Reset all entities' hidden/shown state."""
transmit_manager.reset_all()

@CookStar CookStar marked this pull request as draft September 23, 2020 12:42
@CookStar CookStar changed the title Entities transmit alternative(draft). Entities transmit alternative. Sep 23, 2020
@CookStar
Copy link
Contributor Author

Here's my opinion on the Entities transmit (hidden/shown state) feature. #332 (comment)

@ArtichaTM
Copy link

ArtichaTM commented Sep 19, 2021

Hmm, something wrong

from _entities._transmit import transmit_manager

@ClientCommand('test')
def test(_, index):
    player = Player(index)
    print(transmit_manager.get_hidden_entity(player.index))

gives me:

1

[SP] Caught an Exception:
Traceback (most recent call last):
  File "..\addons\source-python\packages\source-python\commands\auth.py", line 44, in __call__
    return self.callback(*args)
  File "..\addons\source-python\plugins\WCSSkills\commands\commands.py", line 33, in test
    print(transmit_manager.get_hidden_entity(player.index))
  File "..\addons\source-python\packages\source-python\entities\_base.py", line 132, in __call__
    obj = super().__call__(index)
  File "..\addons\source-python\packages\source-python\entities\_base.py", line 199, in __init__
    super().__init__(index)

ValueError: Conversion from "Index" (351) to "BaseEntity" failed.

I found the reason. I don't why, but when I hide weapon_c4 from Terrorist (me, tried alone and with bots — all the same), suddenly he can't find this c4. Idk why xD

He can't find c4 when:
CT — when c4 on floor
T — nevermind, even if bomb in player

That's so weird. After several round restarts, bomb entity changed, but he show in tuple previous entity, and new (if I add to no_transmit). But If I hide new bomb and restarts round, everything going the same

@CookStar CookStar closed this Jul 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants