Coder Social home page Coder Social logo

source-python-dev-team / source.python Goto Github PK

View Code? Open in Web Editor NEW
164.0 19.0 33.0 365.3 MB

This plugin aims to use boost::python and create an easily accessible wrapper around the Source Engine API for scripter use.

Home Page: http://forums.sourcepython.com

License: GNU General Public License v3.0

Python 87.39% Shell 0.03% CSS 0.26% PowerShell 0.01% C++ 6.66% C 0.18% CMake 0.18% Batchfile 0.02% HTML 0.23% TeX 0.40% JavaScript 4.64% Makefile 0.01%
source-python

source.python's Introduction

Source.Python

Introduction

Source.Python is an open-source project that uses boost::python to allow scripters to interact with Valve's Source-engine.

Directory Structure

  • addons/ - source-python binary and vdf load file
    • ../source-python/
      • ../bin/ - all other Source.Python related binaries
      • ../data/
        • ../custom/ - Custom Package data
        • ../plugins/ - plugin specific data
        • ../source-python/ - Source.Python specific data
      • ../docs/
        • ../custom/ - Custom Package documentation
        • ../plugins/ - plugin specific documentation
        • ../source-python/ - Source.Python documentation
      • ../packages/
        • ../custom/ - Custom Packages
        • ../site-packages/ - included site-packages
        • ../source-python/ - Source.Python Python API
      • ../plugins/ - plugins (use "sp plugin load " in server console to load)
      • ../Python3/ - Python3.x base
  • cfg/
    • ../source-python/ - configuration files
  • logs/
    • ../source-python/ - log files
  • resource/
    • ../source-python/
      • ../events/ - custom event files
      • ../translations/ - translation files
  • sound/
    • ../source-python/ - sound files
  • src/ - source code
    • ../core/ - core source code
    • ../hl2sdk/ - Source-engine SDKs (use the HL2SDK repository as a reference)
    • ../loader/ - source-python source code (the loader binary)
    • ../patches/ - SDK patches necessary for building
    • ../thirdparty/ - 3rd-party mods used by Source.Python

Useful links

source.python's People

Contributors

ayuto avatar cookstar avatar dronelektron avatar dsezen avatar ericentin avatar frag1337 avatar hackmastr avatar invincibleqc avatar ismael-git avatar jordanbriere avatar jsza avatar kamikazekuh avatar kirillmysnik avatar mahi avatar mrmalina avatar necavi avatar olegtsvetkov avatar omegak2 avatar roflmuffin avatar satoon101 avatar srpg avatar thapwned avatar thomasvieth avatar vinci6k avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

source.python's Issues

temp_entities.beam_points

Hi there SourcePython developing team!

First off I'd like to thank you all for all your effort and energy that you have put into this project and all the tools you have provided us with, it's very much appreciated.
That being said I think I have found a bug, whether it is the code for the temp entities, or the engine in CS:GO itself, I do not actually know.

The bug that I have encountered is when you are trying to use temp_entities.beam_points and setting the start and end width to be two different values.
I've previously worked with ES:S in CS:S and when defining 2 different kinds of width it worked just fine.

However I am now trying out the same thing in source python, in CS:GO and it does not seem to work as I intend it to.
It is supposed to make the line get bigger/wider in one of the ends, however that is not the case, no matter which values you put in the start and end width the line always stay the same as one of the values.

E.g. a start width of 5 and an end width of 20 will then be a straight line with no change, probably using the start and end width of either 5 or 20.
If you guys want a look at it for yourself here is the example I used when noticing this:

laser = model('sprites/laser.vmt')

    location1 = defender.origin
    location2 = defender.origin
    location1.z += 5
    location2.z += 140
    temp_entities.beam_points(self._recipients, 0, location1, location2, laser.index, laser.index, 10, 10, 1, 5, 50, 0, 0, 255, 150, 150, 170, 1)

I hope this information is detailed and explained well enough, I did my best to explain it in the best way I could.
I hope you guys will be able to fix this issue as it will open up for a lot more of opportunities when it comes to working with effects in SourcePython.

Sincerely

  • Manifest

Incorrect debug message level in CSourcePython::OnQueryCvarValueFinished

A debug message is printed to the console when OnQueryCvarValueFinished is called if you have level set to 1 or higher in core_settings.ini.

To reproduce:

from engines.server import engine_server
from events import Event
from players.helpers import edict_from_userid

@Event
def player_say(event):
    userid = event.get_int('userid')
    engine_server.start_query_cvar_value(edict_from_userid(userid), 'net_fakejitter')

Results in something like:
Cvar query (cookie: 143, status: 0) - name: net_fakejitter, value: 0

May 21st release.

Not working player.give_named_item

Please check the next code:

from events import Event
from players.entity import PlayerEntity
from players.helpers import index_from_userid

@Event('player_activate')
def player_activate(game_event):
    player = PlayerEntity(index_from_userid(game_event.get_int('userid')))
    player.give_named_item('weapon_shotgun', 0, None, False)

This code should give the player chosen weapon. But now it's not working.

env:
sourcepython: last edition from 23 september 2015
os: Ubuntu
game: CSGO

rendermode - int or str?

[SP] Caught an Exception:
Traceback (most recent call last):
File "..\addons\source-python\packages\custom\rpgz\listeners__init__.py", line 36, in call
callback(*args)
File "..\addons\source-python\plugins\rpg\skills\Stealth.py", line 82, in up
playerentity.color = r, g, b, a
File "..\addons\source-python\packages\source-python\entities\entity.py", line 241, in setattr
super(BaseEntity, self).setattr(attr, value)
File "..\addons\source-python\packages\source-python\entities\entity.py", line 312, in set_color
self.rendermode = self.rendermode | 1
File "..\addons\source-python\packages\source-python\entities\entity.py", line 235, in setattr
self.datamaps[attr]._set_value(value)
File "..\addons\source-python\packages\source-python\entities\datamaps.py", line 368, in _set_value
getattr(self.current_pointer, self.set_attr)(value, self.offset)

Boost.Python.ArgumentError: Python argument types in
Pointer.set_char(Pointer, int, int)
did not match C++ signature:
set_char(class CPointer {lvalue}, char, int offset=0)

ConfigManager.execute doesn't execute the config file

Assuming the config file is called 'testplugin.cfg' and I have a ConfigManager object referring to it like this somewhere:

config = ConfigManager(CFG_PATH.joinpath("testplugin"))

... and this in load():
config.write()
config.execute()

It writes the config file.
Everytime I try to execute it (from a script) the console echoes 'source-python doesn't exist, not executing'. But when I execute the config file manually using the server command "exec source-python/testplugin" it works and does't output any error. ConfigManager doesn't do anything else than what I do manually, so I don't have a clue lol.

CSS: Windows server crashes when sending a double quotation mark to chat.

Bare CSS server, map; de_dust2, only SourcePython is loaded, no plugins for SP are loaded, type anything which includes one or more of: " , send the message and the server crashes. Replicated on a live server and on a test server running on LAN only. With both the last Py3.3 commits and the newest released Py3.4 build from the zip download.
spcrash

Unable to add hardcoded keyvalues

Currently, only keyvalues are added, which are part of a datamap. But there are keyvalues, which are hardcoded in CBaseEntity::KeyValue(). E.g. renderamt: https://github.com/alliedmodders/hl2sdk/blob/28b43b06249837c1517db1468af14678080715f6/game/shared/baseentity_shared.cpp#L339

Should we loop through keyvalue_contents and add them regardless of the datamap?.

'Edict' object has no attribute 'get_team_index' in PlayerIter()

[SP] Caught an Exception:
Traceback (most recent call last):
  File '..\addons\source-python\packages\source-python\events\listener.py', line
 93, in fire_game_event
    callback(game_event)
  File '..\addons\source-python\plugins\hw\hw.py', line 400, in round_start
    for index in PlayerIter(is_filters=('ct', 't')):
  File '..\addons\source-python\packages\source-python\filters\iterator.py', lin
e 39, in __iter__
    if not self._is_valid(item):
  File '..\addons\source-python\packages\source-python\filters\iterator.py', lin
e 77, in _is_valid
    if not self.manager._filters[filter_name](item):
  File '..\addons\source-python\packages\source-python\filters\players.py', line
 103, in _player_is_on_team
    return playerinfo.get_team_index() == self.team

AttributeError: 'Edict' object has no attribute 'get_team_index'

get_color, set_color function throws an exception

[SP] Caught an Exception:
Traceback (most recent call last):
File '..\addons\source-python\packages\source-python\entities\entity.py', line289, in get_color
value & 0xff, (value & 0xff00) >> 8,
TypeError: unsupported operand type(s) for &: 'Color' and 'int'

I think this is due to that render_color is Color type and return object itself but not 4byte integer value as expected in code. Also set_color function throws a similar exception.

(CS:S) ShowMenu with lengthy message results in error

The following error appears in the server console when trying to send a menu that is longer than 240 bytes or so in length:

DLL_MessageEnd: Refusing to send user message ShowMenu of 256 bytes to client, user message size limit is 255 bytes

PagedMenu's top seperator can't be None, check missing

PagedMenu's attribute top_seperator raises an error if set to None due to a missing check in /packages/source-python/menus/radio.py on line 199 and 200:

buffer = (_translate_text(self.title or '', ply_index)).ljust(
    len(self.top_seperator) - len(info)) + info

<StringTable>.__iter__() causes infinite loop

When iterating over items in a StringTable instance, the items are iterated over infinitely. When testing for "item in", iter is used, causing an infinite loop if the item is not found in the StringTable.

from stringtables import StringTables

sounds = StringTables.soundprecache
for x in sounds:
    print(x)
from stringtables import StringTables

sounds = StringTables.soundprecache

sound_name = 'physics/plastic/plastic_box_impact_soft4.wav'
index = sounds[sound_name]
print(index)
print(sounds[index])
print(sound_name in sounds)

invalid_name = 'this/wont/work.wav'
index = sounds[invalid_name]
print(index)
print(sounds[index])
print(invalid_name in sounds)

Crash on server exit when calling entity input in unload()

To reproduce (TF2 Linux, May 21st release):

from entities.entity import Entity

entity = None

def load():
    global entity
    entity = Entity.create('trigger_multiple')
    entity.spawn()

def unload():
    global entity
    entity.call_input('Kill')

I've also tested the Ignite input resulting in a crash. I was running Sourcemod and Metamod at the time, but the crash also occurs with only Source.Python loaded.

Console log with -debug:

exit
[Source.Python] Unloading...
pure virtual method called
terminate called without an active exception
Wrote minidump to: /home/jayess/srcds/tf2/tf/addons/sourcemod/data/dumps/0e1ab7bc-7206-e895-5e0d47d4-5e131603.dmp
Aborted (core dumped)
BFD: Warning: /home/jayess/srcds/tf2/core is truncated: expected core file size >= 516898816, found: 1179648.
Cannot access memory at address 0xf777a8f8
Cannot access memory at address 0xf777a8f4
debug.cmds:1: Error in sourced command file:
Cannot access memory at address 0xff8acff8
email debug.log to [email protected]
Sat Jun  6 02:39:49 SAST 2015: Server restart in 10 seconds
Sat Jun  6 02:39:52 SAST 2015: Server Quit

Crash dump: https://crash.limetech.org/7jxvvvoembxk

PlayerEntity "get_primary" method.

[SP] Caught an Exception:
Traceback (most recent call last):
File '..\addons\source-python\plugins\popup\popup.py', line 99, in callback
if ent.get_primary(): BaseEntity(ent.get_primary()).Kill()
File '..\addons\source-python\packages\source-python\players\weapons__init__.py', line 328, in get_primary
return self.get_weapon_index(is_filters='primary')
File '..\addons\source-python\packages\source-python\players\weapons__init__.py', line 339, in get_weapon_index
for index in self.weapon_indexes(classname, is_filters, not_filters):
File '..\addons\source-python\packages\source-python\players\weapons__init__.py', line 371, in weapon_indexes
index = index_from_inthandle(handle)

ValueError: Conversion failed...

ValueError occurs upon the user supplied not having a primary weapon.

RuntimeError: access violation - no RTTI data

It was though to find code that actually replicates this issue, because at first it seemed to happen quite randomly. There might be more cases then this one.

It seems to happen when passing/storing playerinfo objects to multiple functions; I'm guessing they go out of scope when the first function finishes execution:

import command_c

def h(playerinfo, command):
    test(playerinfo)
    test(playerinfo)

def test(playerinfo):
    e = playerinfo.get_edict()
    e.get_index()
    print(e)

def load():
    command_c.register_client_command_filter(h)

def unload():
    command_c.unregister_client_command_filter(h)

Running this code will result in:

<entity_c.CEdict object at 0x12345678>
(Traceback here)
RuntimeError: access violation - no RTTI data

mathlib's Vector long float issue

I came across an issue where I precalculate long floats, and after initializing a Vector object, the x y z values differed from the original ones.
It looks like after the 9th number, mathlib.Vector() has a calculation error.

Example:

from mathlib import Vector

x, y, z = (-14.49353846153846, -10.87015384615385, 0.31507692307692)
vec = Vector(x, y, z)

print(x, y, z)
print(vec.x, vec.y, vec.z)

Result is this (on every 9th number it starts to differ):
-14.49353846153846, -10.87015384615385, 0.31507692307692
-14.493538856506348, -10.870153427124023, 0.31507691740989685

Unable to find some properties

There are properties which can't be found by < Entity >.get/set_property_< type >(). E.g. this little script will cause an error, although the property exists (CBaseEntity.m_flGravity).

from players.entity import PlayerEntity

player = PlayerEntity(1)
print(player.get_property_float('m_flGravity'))
Traceback (most recent call last):
  File '..\addons\source-python\packages\source-python\plugins\manager.py', line 72, in __missing__
    instance = self.instance(plugin_name, self.base_import)
  File '..\addons\source-python\packages\source-python\plugins\instance.py', line 82, in __init__
    self._plugin = import_module(import_name)
  File '..\addons\source-python\plugins\test8\test8.py', line 13, in <module>
    print(player.get_property_float('m_flGravity'))
  File '..\addons\source-python\packages\source-python\entities\entity.py', line 356, in get_property_float
    return self._get_property(name, 'float')
  File '..\addons\source-python\packages\source-python\entities\entity.py', line 419, in _get_property
    name, self.classname))

ValueError: Property 'm_flGravity' not found for entity type 'player'

UnicodeDecodeError when retrieving engine string that contains invalid bytes

It appears that this can happen in a number of places. Here are some easily reproducible situations:

from commands.say import SayFilter
from events import Event
from players.helpers import playerinfo_from_userid

@SayFilter
def say_filter(playerinfo, teamonly, command):
    command.get_arg_string()

@Event
def player_changename(event):
    event.get_string('newname')

@Event
def player_activate(event):
    playerinfo = playerinfo_from_userid(event.get_int('userid'))
    playerinfo.get_name()

Running the above example, the following steps will raise a UnicodeEncodeError:

  • Changing your Steam name to: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaยฃยฃ
[SP] Caught an Exception:
Traceback (most recent call last):
  File '../addons/source-python/packages/source-python/events/listener.py', line 90, in fire_game_event
    callback(game_event)
  File '../addons/source-python/plugins/sandbox/sandbox.py', line 11, in player_changename
    event.get_string('newname')

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc2 in position 30: unexpected end of data
  • Saying in chat: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaยฃ
[SP] Caught an Exception:
Traceback (most recent call last):
  File '../addons/source-python/plugins/sandbox/sandbox.py', line 7, in say_filter
    command.get_arg_string()

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc2 in position 127: invalid continuation byte
  • Connecting to server with a Steam name of: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaยฃยฃ
[SP] Caught an Exception:
Traceback (most recent call last):
  File '../addons/source-python/packages/source-python/events/listener.py', line 90, in fire_game_event
    callback(game_event)
  File '../addons/source-python/plugins/sandbox/sandbox.py', line 16, in player_activate
    playerinfo.get_name()

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc2 in position 30: unexpected end of data

Calling messages.types.saytext.SayText causes AttributeErrors

Simple test code here:

from messages.types.saytext import SayText
SayText(message="test")

will cause


[SP] Caught an Exception:
Traceback (most recent call last):
  File '..\addons\source-python\packages\source-python\messages\base.py', line 3
33, in __getattr__
    return super(BaseMessage, self).__getattr__(attribute)
AttributeError: 'super' object has no attribute '__getattr__'

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File '..\addons\source-python\packages\source-python\messages\base.py', line 3
33, in __getattr__
    return super(BaseMessage, self).__getattr__(attribute)
AttributeError: 'super' object has no attribute '__getattr__'

continually.
I am using the latest release (March-08-2015) on CSS

Two instances of Model class with the same model path cause an error

Two instances of Model class with the same model path cause an exception.

Test code:

from engines.precache import Model

test_model = Model('models/player/t_leet.mdl')
test_model2 = Model('models/player/t_leet.mdl')

It produces this error on load:

[SP] Loading plugin 'testik'...

[SP] Caught an Exception:
Traceback (most recent call last):
  File '..\addons\source-python\packages\source-python\plugins\manager.py', line 72, in __missing__
    instance = self.instance(plugin_name, self.base_import)
  File '..\addons\source-python\packages\source-python\plugins\instance.py', line 82, in __init__
    self._plugin = import_module(import_name)
  File '..\addons\source-python\plugins\testik\testik.py', line 4, in <module>

    test_model2 = Model('models/player/t_leet.mdl')
  File '..\addons\source-python\packages\source-python\engines\precache.py', line 75, in __init__
    event_registry.register_for_event('server_spawn', self._server_spawn)
  File '..\addons\source-python\packages\source-python\events\manager.py', line 65, in register_for_event
    self[event].append(callback)
  File '..\addons\source-python\packages\source-python\events\listener.py', line 63, in append
    'for event '{1}''.format(callback, self.event))

ValueError: Event callback '<bound method Model._server_spawn of Model('models/player/t_leet.mdl')>' is already registered for event 'server_spawn'


[SP] Plugin 'testik' was unable to be loaded.

Probably there is the same problem with Generic and Decal classes.

Tested only on CS:S Windows server with Jan 15 build.

VGUIMenu issues

This was first reported here.

So, I did some testing, and it seems there are a few issues. First, in this line, if you pass any more than 2 parameters, since we have "length" set to 2, only 2 parameters are iterated over, not all of them.

Also, in that same line, since we iterate over parameter_values, we are only iterating over the keys themselves and we never account for the values.

Also, we never seem to set the 'length'. I do see where we account for length. However, this seems to just be setting the length to 1 (and it never specifies "length", though I don't think we really have to on the OrangeBox). The length should be set to the number of subkeys.

Here is my test code:

from events import Event
from messages import VGUIMenu
from messages import SayText2
from players.helpers import index_from_userid


motd = VGUIMenu(name='info', show=True, subkeys={
    'title': 'GunGame Winner', 'type': '2',
    'msg': 'http://gungame.net/gg5_win.php?winningTeam=Terrorist',})

chat = SayText2(message='This is a test.')


@Event
def player_say(game_event):
    motd.send(index_from_userid(game_event.get_int('userid')))

    # Make sure I didn't break other messages with special parameters
    chat.send(index_from_userid(game_event.get_int('userid')))

Emit Sound does not work correctly (attenuation)

Hi Guys,

I noticed that the Emit sound function of SP isn't work correctly.

If i change attenuation > 0 it does not work. No Sound gets played. But if its zero it works.

Tried this:

cheer = Sound((), SOUND_FROM_WORLD, "source-python/zombiemod/fz_scream1.mp3", volume= 0.6, attenuation = 0.9)

also this

cheer = Sound((), SOUND_FROM_LOCAL_PLAYER, "source-python/zombiemod/fz_scream1.mp3", volume= 1.0 , attenuation = 0.9)

I want to play a sound from a Player but the volume should be set by distance to the Player.

Like ES did:

es.emitsound('player', userid, sound, 1.0, 0.9) # 1.0 = Volume , 0,9 attenuation

Thanks :)

[CS:GO] Unable to change WeaponEntity's color

Using the following code:

from players.entity import PlayerEntity
from players.helpers import index_from_userid
from colors import Color
from events import Event
from entities.helpers import index_from_inthandle
from weapons.entity import WeaponEntity


@Event('player_jump')
def player_jump(event):
    player = PlayerEntity(index_from_userid(event['userid']))
    weapon = WeaponEntity(index_from_inthandle(player.active_weapon))
    weapon.color = Color(0, 0, 0)

I was able to raise the following error:

[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\test\test.py', line 13, in player_jump
    weapon.color = Color(0, 0, 0)
  File '..\addons\source-python\packages\source-python\entities\entity.py', line
 105, in __setattr__
    super().__setattr__(attr, value)
  File '..\addons\source-python\packages\source-python\entities\entity.py', line
 303, in set_color
    self.render_mode |= RenderMode.TRANS_COLOR
  File '..\addons\source-python\packages\source-python\entities\entity.py', line
 117, in __setattr__
    setattr(server_class(self.pointer, wrap=True), attr, value)
  File '..\addons\source-python\packages\source-python\entities\classes.py', lin
e 517, in fset
    pointer), 'set_key_value_' + type_name)(name, value)

NameError: 'rendermode' is not a valid KeyValue for entity class 'CWeaponCSBase'

menus.PagedMenu() idea of "back" option

It would be really nice if we could bind the "Back"-button in the first page of a PagedMenu() manually in our scripts. Example script of how it could look in usage:

def some_menu(index):
    menu = SimpleMenu()
    menu.append(SimpleOption(1, "some other menu", 1)
    menu.select_callback = some_menu_callback
    menu.send(index)

def some_menu_callback(menu, index, option):
    if option.value == 1:
        some_other_menu(index)

def some_other_menu(index):
    # create a paged menu with 2 pages
    menu = PagedMenu()
    for x in range(1, 10):
        menu.append(PagedOption(x, x))

    # this would tell the PagedMenu that we want to bind the "Back"-button on the first page on ourselves
    # the argument is what would be passed as option.value in the callback
    menu.add_back_option('go_back')

    menu.select_callback = some_other_menu_callback
    menu.send(index)

def some_other_menu_callback(menu, index, option):
    if option.value == "go_back":
        # would be only called if we are in the first page of the menu, otherwise behave normally
        return some_menu(index)

    print(option.value)

Might not be the best way to do this, but it's just an idea so you know what I mean.

NullPointers with several wraps

Several wraps may use a null pointer internally; thus causing a server crash when trying to call member functions.

This can probably happen for more wraps then the examples, and this is an problem that should be fixed as a whole when wrapping the game's interfaces.

It should either mimic the behaviour and simply return a python None object, so you can work with a nonetype error, or raise a python exception or so.
As an extend, this also becomes problem if a pointer becomes null for some reason, in the original SP write this wasn't as much of an issue, as it would be simply none then, but since all the methods are abstracted, it might just crash when trying to call member functions.

CPlayerInfo
player_connect: IPlayerInfo does not work so early on, i.e. the object returned is NULL, but you can create an instance of CPlayerInfo, and once you call any member function the server crashes

CNetChannelInfo
-> INetChanneInfo returns NULL for bots, so if you use it on bots, server will crash

PlayerEntity "cash" error

If you change the player's cash. The cash attribute doesn't update when they gain cash due to round start or on player kill. The value just stays at whatever it was set at.

PlayerWeapons class issues in CSGO

I was playing around with setting the clips/ammo of weapons and when setting the clip of weapon_knife, I'm getting this error:

PlayerEntity(1).set_ammo('weapon_knife', 1)

  File '..\addons\source-python\packages\source-python\players\weapons\__init__.py', line 117, in set_ammo
    self._set_weapon_ammo(value, classname)
  File '..\addons\source-python\packages\source-python\players\weapons\__init__.py', line 150, in _set_weapon_ammo
    weapon_manager.ammoprop + '%03d' % weapon.ammoprop, value)
  File '..\addons\source-python\packages\source-python\entities\entity.py', line 434, in set_property_int
    self._set_property(name, 'int', value)
  File '..\addons\source-python\packages\source-python\entities\entity.py', line 502, in _set_property
    name, self.classname))

ValueError: Property 'm_iAmmo.-01' not found for entity type 'player'

Furthermore I found a weird behaviour when setting the ammo of other weapons. For example, I've set the ammo of weapon_awp to 10, and after I reloaded the gun it resetted back to it's previous value, before I set it in my script.

Test script:

from events import Event

from players.entity import PlayerEntity
from players.helpers import index_from_userid

@Event
def player_jump(game_event):
    userid = game_event.get_int('userid')
    index = index_from_userid(userid)
    player = PlayerEntity(index)
    player.set_ammo('weapon_awp', 10)

If you test this, jump, then shoot once or more, then reload. Ammo will set back to the value it had before setting it.

EDIT
First bug can be ignored, as answered by satoon.
Second bug was just a temporary game bug, I had sv_inifinite_ammo set to 1 before I tested this, setting it back to 0 created this weird behavior. I restarted my server with default value 0 and it worked fine.
And by doing this, I discovered another bug: For example, if I manually set the ammo to 10, then shoot 10 times and reload, I should have now 0 ammo. But instead the game sets it back to the default value (awp 30).

And this bug still exists:
Setting the ammo to 0 does nothing.

PlayerEntity.set_model causes AttributeError

I'm using the May 21, 2015 release

Edit: I should also mention that it's orangebox/css.

Whenever I want to set a player's model to another one, it raises an AttributeError:

File '../addons/source-python/packages/source-python/menus/radio.py', line 343, in _select 
    return super(PagedRadioMenu, self)._select(player_index, choice_index) 
  File '../addons/source-python/packages/source-python/menus/radio.py', line 97, in _select 
    self._player_pages[player_index].options[choice_index]) 
  File '../addons/source-python/packages/source-python/menus/base.py', line 124, in _select 
    return self.select_callback(self, player_index, choice_index) 
  File '../addons/source-python/plugins/seekme/models.py', line 48, in model_menu_callback 
    player.model = option.value 
  File '../addons/source-python/packages/source-python/entities/entity.py', line 118, in __setattr__ 
    super(Entity, self).__setattr__(attr, value) 
  File '../addons/source-python/packages/source-python/entities/entity.py', line 335, in set_model 
    self.edict.set_model_index(model.index) 

AttributeError: 'Edict' object has no attribute 'set_model_index' 

The model's index definitely exists because it's a server-side model and has been instantiated with engines.prechache.Model.

Code which handles setting the player's model:
https://github.com/backraw/seekme/blob/master/addons/source-python/plugins/seekme/models.py#L48

Code which instantiates the model:
https://github.com/backraw/seekme/blob/master/addons/source-python/plugins/seekme/models.py#L99

... from an ini file's section's "path" key, if you want to know:
https://github.com/backraw/seekme/blob/master/addons/source-python/data/plugins/seekme/models/de_dust2.ini

PagedMenu select_callback raises AttributeError

This code:

from players.entity import PlayerEntity

player_models = dict()


def menu_callback(menu, index, option):
    """Called by a player selecting an option from the Models menu."""
    # Get a PlayerEntity instance
    player = PlayerEntity(index)

    # Tell what's happened
    player.say('model changed to {0}'.format(option.value.name))

    # Save what has been chosen
    player_models[player.userid] = option.value

    # Is the player alive and on a team?
    if not player.isdead and not player.dead_flag and player.team > 1:

        # If yes, change their model to the one chosen
        player.model = option.value.path


class _Models(dict):

    """Extends dict to map models to Model instances by their basenames."""

    def __init__(self):
        """Called on instantiation."""
        # Call dict's constructor
        super(_Models, self).__init__()

        # Create a PagedMenu instance
        self._menu = PagedMenu(
            select_callback=menu_callback,
            title='{0}: Models'.format(info.name),
            description='Choose a model below.'
        )

        # .........

raises the error as soon as I choose the first option I get when the menu is sent to me.
attrib error

PlayerEntity.run_command & BotCmd bug

I tried hooking run_command in CSGO and came up with an issue.
The attributes in BotCmd are not working or are mixed. What should be BotCmd.buttons is actually BotCmd.weaponsubtype. The most attributes are not giving correct values.

import memory

from entities.hooks import EntityPreHook
from entities.hooks import EntityCondition
from entities.helpers import index_from_pointer

from players.bots import BotCmd
from players.entity import PlayerEntity

@EntityPreHook(EntityCondition.is_player, 'run_command')
def pre_player_run_command(args):
    index = index_from_pointer(args[0])
    cmd = memory.make_object(BotCmd, args[1])
    player = PlayerEntity(index)
    print(cmd.weaponsubtype)

Warnings printing more than once

Using warnings.warn should only show the first time a specific warning is given. However, each warning currently shows every time it is called.

I tested this prior to the new hooks.warnings.WarningHooks implementation and saw the exact same result. Doing the same thing in IDLE on both Python 3.4 and even back on 2.7 only show each warning once, as it should.

Test script:

import warnings
warnings.warn('This is a test')
warnings.warn('This is another test')
warnings.warn('This is a test')

PlayerEntity (BaseEntity) doesn't update itself

If you save PlayerEntity of some player (BaseEntity of some entity), then all it's properties will not be updated if something "outside" will change them. Before recent entities update it works fine...

Here is a simple plugin, which gives player 100HP when he uses a game chat:

from events import Event
from players.entity import PlayerEntity

player = None

@Event
def player_say(event):
    global player

    if player is None:
        player = PlayerEntity(index_from_userid(event.get_int('userid')))

    player.health += 100

Let's say player got 300HP (in total) and died, but then when he will use the chat dor only one time after respawn, he will recieve 400HP in total (300 that he got before death + 100 new) instead of 200HP (100 from spawn + 100 new). Same for all other properties (tested with speed, gravity and cash).

CSS, Jan 15 build

Apparent memory leak in output listener manager

This one was a little tricky to track down. It seems to only happen (or at least with a much higher rate) on maps with func_tracktrain. Memory usage will steadily increase with at least one player connected to the server (tested in CS:S and TF2 on Debian).

It's possible to reproduce on this map: http://files.gamebanana.com/maps/surf_fast.7z

Commenting out this line seems to stop the leak: https://github.com/Source-Python-Dev-Team/Source.Python/blob/master/addons/source-python/packages/source-python/listeners/_entity_output.py#L40

ValueError in PlayerIter when server is full

I was able to reproduce this in CS:S and TF2 on Debian. September 14 2015 build.

To reproduce:

  • Run SRCDS with +maxplayers 2
  • Get someone else to join the server
  • Load this test plugin:
from filters.players import PlayerIter

def load():
    for x in PlayerIter(return_types='userid'):
        pass
[SP] Caught an Exception:
Traceback (most recent call last):
  File '../addons/source-python/packages/source-python/plugins/manager.py', line 78, in __missing__
    instance.globals['load']()
  File '../addons/source-python/plugins/sandbox/sandbox.py', line 4, in load
    for x in PlayerIter(return_types='userid'):
  File '../addons/source-python/packages/source-python/filters/iterator.py', line 48, in __iter__
    yield self.manager._return_types[self.return_types](item)

ValueError: Unable to get a UserID from the given Edict instance (eab43058).

Gravity not resetting

PlayerEntity.gravity attribute's value is not resetting on player death or round end (needs to be reset to 1.0 manually on spawn to avoid stacking gravity values).

error: invalid use of incomplete type 'struct optimized_datamap_t'

Hello,

Im getting this error when i try to compile source python:
./SDK.sh
then
./Build.sh

/data/sourcepython/src/thirdparty/boost/boost/python/type_id.hpp: In function 'boost::python::type_info boost::python::type_id() [with T = optimized_datamap_t]':
/data/sourcepython/src/thirdparty/boost/boost/python/converter/pytype_function.hpp:38:35: instantiated from 'static boost::python::converter::detail::unwind_type_id_helper::result_type boost::python::converter::detail::unwind_type_id_helper::execute(U_) [with U = optimized_datamap_t, boost::python::converter::detail::unwind_type_id_helper::result_type = boost::python::type_info]'
/data/sourcepython/src/thirdparty/boost/boost/python/detail/unwind_type.hpp:30:32: instantiated from 'typename Generator::result_type boost::python::detail::unwind_type_cv(U_, boost::python::detail::cv_unqualified, Generator_) [with Generator = boost::python::converter::detail::unwind_type_id_helper, U = optimized_datamap_t, typename Generator::result_type = boost::python::type_info, boost::python::detail::cv_unqualified = boost::python::detail::cv_tag<false, false>]'
/data/sourcepython/src/thirdparty/boost/boost/python/detail/unwind_type.hpp:59:46: instantiated from 'typename Generator::result_type boost::python::detail::unwind_ptr_type(U_, Generator_) [with Generator = boost::python::converter::detail::unwind_type_id_helper, U = optimized_datamap_t, typename Generator::result_type = boost::python::type_info]'
/data/sourcepython/src/thirdparty/boost/boost/python/detail/unwind_type.hpp:138:51: instantiated from 'static typename Generator::result_type boost::python::detail::unwind_helper2<3>::execute(U& ()(), Generator) [with Generator = boost::python::converter::detail::unwind_type_id_helper, U = optimized_datamap_t_, typename Generator::result_type = boost::python::type_info]'
/data/sourcepython/src/thirdparty/boost/boost/python/detail/unwind_type.hpp:165:72: instantiated from 'typename Generator::result_type boost::python::detail::unwind_type(boost::type, Generator) [with Generator = boost::python::converter::detail::unwind_type_id_helper, U = optimized_datamap_t_&, typename Generator::result_type = boost::python::type_info]'
/data/sourcepython/src/thirdparty/boost/boost/python/converter/pytype_function.hpp:45:74: instantiated from 'boost::python::type_info boost::python::converter::detail::unwind_type_id_(boost::type, mpl::false__) [with T = optimized_datamap_t_&, mpl_::false_ = mpl_::bool_]'
/data/sourcepython/src/thirdparty/boost/boost/python/converter/pytype_function.hpp:68:13: instantiated from 'static const PyTypeObject* boost::python::converter::expected_pytype_for_arg::get_pytype() [with T = optimized_datamap_t_&, PyTypeObject = typeobject]'
/data/sourcepython/src/thirdparty/boost/boost/python/detail/signature.hpp:98:13: instantiated from 'static const boost::python::detail::signature_element
boost::python::detail::signature_arity<1u>::impl::elements() [with Sig = boost::mpl::vector2<optimized_datamap_t*&, datamap_t&>]'
/data/sourcepython/src/thirdparty/boost/boost/python/detail/caller.hpp:232:78: instantiated from 'static boost::python::detail::py_func_sig_info boost::python::detail::caller_arity<1u>::impl<F, Policies, Sig>::signature() [with F = boost::python::detail::member<optimized_datamap_t*, datamap_t>, Policies = boost::python::return_value_policyboost::python::return_by_value, Sig = boost::mpl::vector2<optimized_datamap_t*&, datamap_t&>]'
/data/sourcepython/src/thirdparty/boost/boost/python/object/py_function.hpp:48:35: instantiated from 'boost::python::detail::py_func_sig_info boost::python::objects::caller_py_function_impl::signature() const [with Caller = boost::python::detail::caller<boost::python::detail::member<optimized_datamap_t*, datamap_t>, boost::python::return_value_policyboost::python::return_by_value, boost::mpl::vector2<optimized_datamap_t*&, datamap_t&> >]'
/data/sourcepython/src/core/modules/datamap/datamap_wrap_python.cpp:267:1: instantiated from here
/data/sourcepython/src/thirdparty/boost/boost/python/type_id.hpp:89:9: error: invalid use of incomplete type 'struct optimized_datamap_t'
/data/sourcepython/src/sdks/hl2sdk-csgo/public/datamap.h:302:8: error: forward declaration of 'struct optimized_datamap_t'
/data/sourcepython/src/thirdparty/boost/boost/python/type_id.hpp:90:1: warning: control reaches end of non-void function [-Wreturn-type]
make[2]: *** [CMakeFiles/core.dir/core/modules/datamap/datamap_wrap_python.cpp.o] Error 1
make[1]: *** [CMakeFiles/core.dir/all] Error 2
make: *** [all] Error 2

mathlib's Vector.normalize() returns false result

I am getting the exact same result as Vector.get_length() (a float), but it should return a Vector, like this:

def normalize_vector(vec):
    x, y, z = tuple(vec)
    length = vec.get_lenght()
    return Vector(x / length, y / length, z / length)

(April 15 csgo release)

engine_sound.stop_sound issue

Stopping a sound does not work (tested in csgo only, but shouldn't matter?):

from events import Event
from engines.sound import Sound, engine_sound

@Event
def player_jump(game_event):
    #engine_sound.stop_sound(0, 1, "test.wav")
    Sound((), 0, "test.wav").stop()
  File '..\addons\source-python\plugins\test\test.py', line 46, in player_jump
    Sound((), 0, 'test.wav').stop()
  File '..\addons\source-python\packages\source-python\engines\sound.py', line 170, in stop
    engine_sound.stop_sound(index, channel, self.sample)

Boost.Python.ArgumentError: Python argument types in
    _EngineSound.stop_sound(_EngineSound, int, Channels, str)
did not match C++ signature:
    stop_sound(class IEngineSound {lvalue}, int, int entity_index, char const * channel, unsigned int sample)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.