Bots don't get weapons without using PlayerEntity.give_named_item()

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Bots don't get weapons without using PlayerEntity.give_named_item()

Postby BackRaw » Sun Jan 18, 2015 9:41 pm

Hi everyone,

as a real player, I get a flashbang perfectly fine when using this code:

Syntax: Select all

class Player(PlayerEntity):

def __init__(self, index):
super(Player, self).__init__()

def equip(self):
"""
Equips the player with a flashbang
"""

# remove any existing flashbangs from the player
if self.get_property_int("localdata.m_iAmmo.012"):
self.strip()
self.set_property_int("localdata.m_iAmmo.012", 0)

# create a new flashbang entity
flashbang = BaseEntity(create_entity("weapon_flashbang"))

# set its origin to the player's
flashbang.origin = self.origin

# spawn it there
spawn_entity(flashbang.index)

Syntax: Select all

from events import Event

from flashfunsp.players import Player

@Event
def flashbang_detonate(game_event):
"""
Gets called whenever a flashbang grenade detonates.
"""

# re-equip the player with a flashbang after a second
tick_delays.delay(1, Player(index_from_userid(game_event.get_int("userid"))).equip)


But Bots don't :(
Tho, they seem to get the flashbang entity as they drop it after I killed them and I can actually pick it up. Why is that? Did I forget something? :)

within equip(), self.give_named_item() works fine for bots and real players, but only for CS:S because it's commented out in csgo/CBasePlayer.ini..
My Github repositories:

Source.Python: https://github.com/backraw
User avatar
L'In20Cible
Project Leader
Posts: 1536
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Mon Jan 19, 2015 5:19 am

Did you try to force "use weapon_flashbang" on them?
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Postby BackRaw » Mon Jan 19, 2015 11:13 am

L'In20Cible wrote:Did you try to force "use weapon_flashbang" on them?

No, good point![python]from engines.erver import engine_server

# ... in Player.equip():

engine_server.client_command(self.edict, "use weapon_flashbang")[/python]results in

Code: Select all

[SP] Caught an Exception:
Traceback (most recent call last):
  File '../addons/source-python/packages/source-python/listeners/tick/delays.py', line 60, in __call__
    self.callback(*self.args, **self.kwargs)
 
Boost.Python.ArgumentError: Python argument types in
    _EngineServer.client_command(_EngineServer, tuple)
did not match C++ signature:
    client_command(IVEngineServer*, edict_t* edict, char const* command)
:(
My Github repositories:

Source.Python: https://github.com/backraw
User avatar
L'In20Cible
Project Leader
Posts: 1536
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Mon Jan 19, 2015 11:35 am

The problem is how you use tick_delays.delay. Unlike ES's gamethread, passed arguments doesn't need to be a tuple:[python]tick_delays.delay(1, engine_server.client_command, self.edict, 'use weapon_flashbang')[/python]
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Postby BackRaw » Mon Jan 19, 2015 1:07 pm

L'In20Cible wrote:The problem is how you use tick_delays.delay. Unlike ES's gamethread, passed arguments doesn't need to be a tuple:[python]tick_delays.delay(1, engine_server.client_command, self.edict, 'use weapon_flashbang')[/python]


Oh, I didn't see that lol. Thanks! I'll try again.
My Github repositories:

Source.Python: https://github.com/backraw
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Postby BackRaw » Mon Jan 19, 2015 1:11 pm

It doesn't solve the problem.. The error is gone, but it still looks like the attached screenshot.
Current code: https://github.com/backraw/backraw.sp/blob/master/addons/source-python/plugins/flashfunsp/players.py

By the way, I'm using the Jan 17 release.
Attachments
css_bots_screen.jpg
My Github repositories:

Source.Python: https://github.com/backraw
User avatar
L'In20Cible
Project Leader
Posts: 1536
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Mon Jan 19, 2015 7:20 pm

Yeah, engine_server.client_command cannot execute the "use" command as clients' console are preventing its execution (not flagged as SERVER_CAN_EXECUTE). I believe this would works using IServerPluginHelpers::ClientCommand but unfortunately, we doesn't have it exposed for now. May seems drastic but, what if you force it as active weapon?

Syntax: Select all

self.set_property_int('m_hActiveWeapon', flasbang.inthandle)
Also, I looked at your code and, you can remove the following lines as it is actually fixed.

Syntax: Select all

# change the hammerid for CS:GO -- EXPERIMENTAL TEMPORARY FIX
if SOURCE_ENGINE == "csgo":
weapon.set_key_value_int("hammerid", weapon.index)
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Postby BackRaw » Mon Jan 19, 2015 9:45 pm

L'In20Cible wrote:Yeah, engine_server.client_command cannot execute the "use" command as clients' console are preventing its execution (not flagged as SERVER_CAN_EXECUTE). I believe this would works using IServerPluginHelpers::ClientCommand but unfortunately, we doesn't have it exposed for now. May seems drastic but, what if you force it as active weapon?

Syntax: Select all

self.set_property_int('m_hActiveWeapon', flasbang.inthandle)
Also, I looked at your code and, you can remove the following lines as it is actually fixed.

Syntax: Select all

# change the hammerid for CS:GO -- EXPERIMENTAL TEMPORARY FIX
if SOURCE_ENGINE == "csgo":
weapon.set_key_value_int("hammerid", weapon.index)


That worked! Thanks, now the script is finished :smile:
My Github repositories:

Source.Python: https://github.com/backraw

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 159 guests