Page 1 of 1

[BM:S] Jet

Posted: Tue Feb 05, 2019 6:20 pm
by Painkiller
Ok i have delete biut new error.


Syntax: Select all

[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/jet/jet.py", line 39, in _jet_say_command
if has_jet[player.userid]:

KeyError: 2

Re: [BM:S] Jet

Posted: Wed Feb 06, 2019 1:42 pm
by Ayuto
Your plugin tries to lookup data by a user ID, but the user ID does not exist in the dict has_jet. I can't tell you more without seeing the code.

Re: [BM:S] Jet

Posted: Wed Feb 06, 2019 2:12 pm
by L'In20Cible
I believe he is using the code given in this thread: viewtopic.php?f=37&t=1358
And since that code relies on the player_activate event, my guess here is that he loaded the code without changing the map/restart his server.

Re: [BM:S] Jet

Posted: Thu Feb 07, 2019 7:02 pm
by Painkiller

Syntax: Select all

# =============================================================================
# >> IMPORTS
# =============================================================================
# Source.Python Imports
from cvars.public import PublicConVar
from events import Event
from messages import SayText2
from colors import WHITE
from commands.say import SayCommand
from entities.entity import Entity
from engines.sound import Sound
from listeners.tick import Delay
from players.entity import Player
from players.helpers import index_from_userid

# =============================================================================
# >> GLOBAL VARIABLES
# =============================================================================
has_jet = {}
jet_left = {}


# =============================================================================
# >> GAME EVENTS
# =============================================================================
@Event('player_activate')
def _player_activate(game_event):
player = Player.from_userid(game_event['userid'])
has_jet[player.userid] = False
jet_left[player.userid] = 3


# =============================================================================
# >> COMMANDS
# =============================================================================
@SayCommand('jet')
def _jet_say_command(command, index, team=None):
player = Player(index)
if has_jet[player.userid]:
SayText2("[Jetpack] Du benutzt bereits ein Jetpack!").send(index)
return

if not jet_left[player.userid]:
SayText2("[Jetpack] Du hast keine Jetpacks mehr!").send(index)
return

entity = Entity.create('env_smokestack')
entity.base_spread = 10
entity.end_size = 5
entity.jet_length = 180
entity.rate = 40
entity.color = WHITE
entity.set_key_value_string('SmokeMaterial', 'particle/SmokeStack.vmt')
entity.speed = 60
entity.spread_speed = 5
entity.start_size = 20
entity.initial_state = 1
entity.teleport(player.origin)
entity.spawn()
entity.set_parent(player, 'rfoot')

player.push(0, 200, True)
player.jetpack = True

has_jet[player.userid] = True
jet_left[player.userid] -= 1

Sound('/ambient/machines/thumper_startup1.wav').play(player.index)

if jet_left[userid] == 0:
SayText2("[Jetpack] Das war dein letztes Jetpack!").send(index)
else:
SayText2(
"[Jetpack] Du hast noch {jetpacks}/3 Jetpacks!".format(
jetpacks=jet_left[userid],
)
).send(index)

timer_trail = Delay(5, entity.remove)
timer_jet = Delay(5, player.set_jetpack, 0)
timer_data = Delay(5, remove_timer, userid)


# =============================================================================
# >> HELPER FUNCTIONS
# =============================================================================
def remove_timer(userid):
has_jet[userid] = False
index = index_from_userid(userid)
Sound('/ambient/machines/thumper_hit.wav').play(index)

Re: [BM:S] Jet

Posted: Sat Feb 09, 2019 12:47 am
by L'In20Cible
You need to relog, restart your server, or change the map for the values to be assigned to your userid. Either that, or you could simply add the following to your code:

Syntax: Select all

from players import PlayerGenerator
from players.helpers import userid_from_edict

def load():
for edict in PlayerGenerator():
player_activate({'userid': userid_from_edict(edict)})

Re: [BM:S] Jet

Posted: Mon Feb 11, 2019 8:38 am
by Painkiller
New Error:

Code: Select all

[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/jet/jet.py", line 50, in _jet_say_command
    entity.base_spread = 10
  File "../addons/source-python/packages/source-python/entities/_base.py", line 131, in __setattr__
    for server_class in self.server_classes:
  File "../addons/source-python/packages/source-python/entities/_base.py", line 244, in server_classes
    yield from server_classes.get_entity_server_classes(self)
  File "../addons/source-python/packages/source-python/entities/classes.py", line 143, in get_entity_server_classes
    entity_server_classes = [entity.server_class.name]

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbe in position 1: invalid start byte


[RocKsĀ³] |Painkiller_Overdose: jet
L 02/11/2019 - 09:37:11: "[RocKsĀ³] |Painkiller_Overdose<2><[U:1:43907303]><unassigned>" say "jet"

[SP] Caught an Exception:
Traceback (most recent call last):
  File "../addons/source-python/packages/source-python/listeners/tick.py", line 80, in _tick
    self.pop(0).execute()
  File "../addons/source-python/packages/source-python/listeners/tick.py", line 161, in execute
    return self.callback(*self.args, **self.kwargs)

TypeError: play_sound() takes 1 positional argument but 21 were given


here the plugin with your content @L'In20Cible

Syntax: Select all

# =============================================================================
# >> IMPORTS
# =============================================================================
# Source.Python Imports
from cvars.public import PublicConVar
from events import Event
from messages import SayText2
from colors import WHITE
from commands.say import SayCommand
from entities.entity import Entity
from engines.sound import Sound
from listeners.tick import Delay
from players.entity import Player
from players.helpers import index_from_userid
from players import PlayerGenerator
from players.helpers import userid_from_edict

# =============================================================================
# >> GLOBAL VARIABLES
# =============================================================================
has_jet = {}
jet_left = {}


# =============================================================================
# >> GAME EVENTS
# =============================================================================
@Event('player_activate')
def _player_activate(game_event):
player = Player.from_userid(game_event['userid'])
has_jet[player.userid] = False
jet_left[player.userid] = 3


# =============================================================================
# >> COMMANDS
# =============================================================================
@SayCommand('jet')
def _jet_say_command(command, index, team=None):
player = Player(index)
if has_jet[player.userid]:
SayText2("[Jetpack] Du benutzt bereits ein Jetpack!").send(index)
return

if not jet_left[player.userid]:
SayText2("[Jetpack] Du hast keine Jetpacks mehr!").send(index)
return

entity = Entity.create('env_smokestack')
entity.base_spread = 10
entity.end_size = 5
entity.jet_length = 180
entity.rate = 40
entity.color = WHITE
entity.set_key_value_string('SmokeMaterial', 'particle/SmokeStack.vmt')
entity.speed = 60
entity.spread_speed = 5
entity.start_size = 20
entity.initial_state = 1
entity.teleport(player.origin)
entity.spawn()
entity.set_parent(player, 'rfoot')

player.push(0, 200, True)
player.jetpack = True

has_jet[player.userid] = True
jet_left[player.userid] -= 1

Sound('/ambient/machines/thumper_startup1.wav').play(player.index)

if jet_left[userid] == 0:
SayText2("[Jetpack] Das war dein letztes Jetpack!").send(index)
else:
SayText2(
"[Jetpack] Du hast noch {jetpacks}/3 Jetpacks!".format(
jetpacks=jet_left[userid],
)
).send(index)

timer_trail = Delay(5, entity.remove)
timer_jet = Delay(5, player.set_jetpack, 0)
timer_data = Delay(5, remove_timer, userid)


# =============================================================================
# >> HELPER FUNCTIONS
# =============================================================================
def remove_timer(userid):
has_jet[userid] = False
index = index_from_userid(userid)
Sound('/ambient/machines/thumper_hit.wav').play(index)

def load():
for edict in PlayerGenerator():
player_activate({'userid': userid_from_edict(edict)})