How to make Player model invisible?

Please post any questions about developing your plugin here. Please use the search function before posting!
v1k1r
Junior Member
Posts: 6
Joined: Sat Jul 04, 2020 5:16 pm

How to make Player model invisible?

Postby v1k1r » Sat Jul 04, 2020 5:21 pm

Syntax: Select all

from messages import SayText2
from events import Event
from players.entity import Player
from players.helpers import index_from_userid


def load():
SayText2('Plugin Predator has been loaded successfully!').send()


def unload():
SayText2('Plugin Predator has been unloaded successfully!').send()


@Event('player_team')
def on_player_team(game_event):
# Retrieve the user ID of the victim
userid = game_event['userid']
index = index_from_userid(userid)
player = Player(index)
# Retrieve the user ID of the attacker
team = game_event['team']
if team == 3: # CT
SayText2(f'{player.name} Is now Hunter!').send()
player.name = 'Hunter'
else: # T
SayText2(f'{player.name} Is now Predator!').send()
player.name = 'Predator'
# HERE DO SOMETHING TO MAKE PLAYER MODEL INVISIBLE FOR CT


On last row i need to make player model invisible for CT
Last edited by L'In20Cible on Sun Jul 05, 2020 9:09 am, edited 1 time in total.
Reason: [code] → [python]
My English is not perfect, but i try :D
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

Re: How to make Player model invisible?

Postby VinciT » Sun Jul 05, 2020 1:29 am

If you want all the terrorists to be invisible, use this:

Syntax: Select all

# ../invis/invis.py

# Source.Python
from colors import Color
from events import Event
from players.entity import Player


INVISIBLE = Color(255, 255, 255, 0)


@Event('player_spawn')
def player_spawn(event):
player = Player.from_userid(event['userid'])

# Is this a terrorist?
if player.team == 2:
player.color = INVISIBLE

If, however, you want the terrorists to be visible to each other but invisible to counter-terrorists, you'd have to hook the SetTransmit function.
ImageImageImageImageImage
v1k1r
Junior Member
Posts: 6
Joined: Sat Jul 04, 2020 5:16 pm

Re: How to make Player model invisible?

Postby v1k1r » Sun Jul 05, 2020 6:38 am

VinciT wrote:If you want all the terrorists to be invisible, use this:

Syntax: Select all

# ../invis/invis.py

# Source.Python
from colors import Color
from events import Event
from players.entity import Player


INVISIBLE = Color(255, 255, 255, 0)


@Event('player_spawn')
def player_spawn(event):
player = Player.from_userid(event['userid'])

# Is this a terrorist?
if player.team == 2:
player.color = INVISIBLE

If, however, you want the terrorists to be visible to each other but invisible to counter-terrorists, you'd have to hook the SetTransmit function.

It works like a charm TY!
My English is not perfect, but i try :D
v1k1r
Junior Member
Posts: 6
Joined: Sat Jul 04, 2020 5:16 pm

Re: How to make Player model invisible?

Postby v1k1r » Sun Jul 05, 2020 8:18 am

But there is still shadow :D
My English is not perfect, but i try :D
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: How to make Player model invisible?

Postby L'In20Cible » Sun Jul 05, 2020 9:07 am

Syntax: Select all

from entities.constants import EntityEffects

player.effects |= EntityEffects.NODRAW
v1k1r
Junior Member
Posts: 6
Joined: Sat Jul 04, 2020 5:16 pm

Re: How to make Player model invisible?

Postby v1k1r » Mon Jul 06, 2020 6:40 pm

Syntax: Select all

from messages import SayText2
from events import Event
from colors import Color
from players.entity import Player
from players.helpers import index_from_userid
from entities.constants import EntityEffects


def load():
SayText2('Plugin Predator has been loaded successfully!').send()


def unload():
SayText2('Plugin Predator has been unloaded successfully!').send()


INVISIBLE = Color(255, 255, 255, 0)
FLASHED = Color(128, 255, 128, 255)


@Event('player_team')
def on_player_team(game_event):
# Retrieve the user ID of the victim
userid = game_event['userid']
index = index_from_userid(userid)
player = Player(index)
# Retrieve the user ID of the attacker
team = game_event['team']
if team == 3: # CT
SayText2(f'{player.name} Is now Hunter!').send()
player.cash = 16000
else: # T
SayText2(f'{player.name} Is now Predator!').send()


@Event('player_spawn')
def player_spawn(event):
player = Player.from_userid(event['userid'])

# Is this a terrorist?
if player.team == 2:
player.color = INVISIBLE
player.effects |= EntityEffects.NODRAW
SayText2(f'{player.name} Is now Invisible!').send()
elif player.team == 3: # CT Player
player.cash = 16000


@Event('player_death')
def player_died(event):
player = Player.from_userid(event['userid'])
attacker = Player.from_userid(event['attacker'])

if attacker.team == 3 and player.team == 2:
player.team = 3
attacker.team = 2


@Event('player_blind')
def player_blinded(event):
player = Player.from_userid(event['userid'])
attacker = Player.from_userid(event['attacker'])
duration = event['blind_duration']
if player.team == 2 and attacker.team == 3:
SayText2(f'{player.name} Is now Flashed by {attacker.name}!').send()
player.color = FLASHED
player.effects = EntityEffects.ITEM_BLINK
while duration > 0.1:
duration -= 0.05
if duration < 0.2 and player.team == 2 and attacker.team == 3:
break
if player.team == 2 and attacker.team == 3:
SayText2(f'{duration}').send()
if player.team == 2 and attacker.team == 3:
SayText2(f'Broke OUT!').send()
player.color = INVISIBLE
player.effects |= EntityEffects.NODRAW


Well problem with last part, is that it's not showing player model while player is flashed, what am trying to do is While player is flashed hes model is visible, and when blind over it's invisible again
My English is not perfect, but i try :D
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

Re: How to make Player model invisible?

Postby VinciT » Thu Jul 09, 2020 3:15 am

Give this a try:

Syntax: Select all

# ../invis/invis.py

# Python
from time import time

# Source.Python
from events import Event
from players.entity import Player
from entities.constants import EntityEffects
from messages import HintText, SayText2


class PlayerInvis(Player):
"""Custom Player class.

Args:
index (int): A valid player index.
caching (bool): Check for a cached instance?

Attributes:
disabled_delay (Delay): Instance of Delay() used for resetting the
player's invisiblity.
disabled_duration (float): For how long should the player stay visible?
count_think (Repeat): Instance of Repeat() used for looping the
`_count_think()` function.
"""

def __init__(self, index, caching=True):
super().__init__(index, caching)

self.disabled_delay = None
self.disabled_duration = 0
self.count_think = self.repeat(self._count_think)

def disable_invisiblity(self, duration):
self.disabled_duration = duration

try:
already_running = self.disabled_delay.running
except AttributeError:
already_running = False

# Check if there's already a Delay instance that hasn't been called.
# (in case the player got flashed multiple times in a short timespan)
if already_running:
# Push the delay to be called a bit later.
self.disabled_delay.exec_time = time() + duration
return

# Strip the NODRAW flag from the player to make them visible again.
self.effects &= ~EntityEffects.NODRAW
# Reapply the NODRAW flag after the given `duration`.
self.disabled_delay = self.delay(duration, setattr, (
self, 'effects', self.effects | EntityEffects.NODRAW))
# Show the player a countdown until they become invisible again.
# (start looping the `_count_think()` function)
self.count_think.start(0.1, execute_on_start=True)

def _count_think(self):
# Is the player still visible?
if self.disabled_duration > 0:
# Show the player for how long they'll be visible.
HintText(
f'You are visible for {self.disabled_duration:.1f} seconds.'
).send(self.index)

self.disabled_duration -= 0.1
return

# The disabled duration has reached its end - stop the looping of the
# `_count_think()` function.
self.count_think.stop()
HintText(f'You are invisible again!').send(self.index)
SayText2(f'{self.name} is no longer visible!').send()


@Event('player_spawn')
def player_spawn(event):
player = PlayerInvis.from_userid(event['userid'])

# Is this a terrorist?
if player.team == 2:
# Add the NODRAW flag to the player to make them completely invisible.
player.effects |= EntityEffects.NODRAW


@Event('player_blind')
def player_blind(event):
player_v = PlayerInvis.from_userid(event['userid'])
player_a = PlayerInvis.from_userid(event['attacker'])
blind_duration = event['blind_duration']

# Is the player who got flashed a terrorist?
if player_v.team == 2:
# Is the player who threw the flash not a counter-terrorist?
if player_a.team != 3:
# No need to go further.
return

# Disable the player's invisiblity for 90% of the blind duration.
player_v.disable_invisiblity(blind_duration * 0.9)
# Notify the players on the server who flashed whom.
SayText2(
f'{player_v.name} has been flashed by {player_a.name}!').send()
ImageImageImageImageImage
v1k1r
Junior Member
Posts: 6
Joined: Sat Jul 04, 2020 5:16 pm

Re: How to make Player model invisible?

Postby v1k1r » Fri Jul 10, 2020 10:05 am

Ty i'll try
My English is not perfect, but i try :D

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 25 guests