Page 1 of 1

CSGO: default weapon

Posted: Sun Sep 06, 2015 10:23 am
by nullable
Please help me to resolve problem with Source.Python. I need to set default weapon like game is starting. How can I do it?

Posted: Sun Sep 06, 2015 12:53 pm
by nullable
or like after team switch

Posted: Sun Sep 06, 2015 2:57 pm
by stonedegg
Search for mp_ct_default_* / mp_t_default_* commands.

Posted: Mon Sep 07, 2015 5:42 am
by nullable
stonedegg, thanks but it's very hard to find all weapons like this.

it may be possible after player.switch_team(team_id) do reset weapons?

Posted: Mon Sep 07, 2015 3:55 pm
by stonedegg
I don't understand what you mean. If you set mp_ct_default_primary "p90", every CT would spawn with a p90.

Posted: Tue Sep 08, 2015 12:08 am
by satoon101
I am not 100% sure what you are looking for. I will say that we already have the ability to drop/remove weapons and give new ones, if that will suffice.

Posted: Thu Sep 24, 2015 10:11 am
by nullable
satoon101 wrote:I am not 100% sure what you are looking for. I will say that we already have the ability to drop/remove weapons and give new ones, if that will suffice.


Can you show me example? How I can do it?

Posted: Thu Sep 24, 2015 1:29 pm
by nullable
The idea is after round end winner team should be start with default weapons like after map start.

Posted: Fri Sep 25, 2015 9:22 am
by stonedegg
Try this (untested):


Syntax: Select all

from events import Event
from entities.entity import Entity
from filters.players import PlayerIter
from listeners import LevelInit
from listeners.tick import tick_delays

last_winner = 0
default_weapons = {
't': ['weapon_glock', 'weapon_knife'],
'ct': ['weapon_hkp2000', 'weapon_knife']
}


@LevelInit
def map_start(mapname):
global last_winner
last_winner = 0

@Event('round_end')
def round_end(game_event):
global last_winner
if game_event.get_int('reason') in (9,15):
last_winner = 0
return

last_winner = game_event.get_int('winner')

@Event('round_start')
def round_start(game_event):
global last_winner
if not last_winner:
return

team = 't' if last_winner == 2 else 'ct'
for player in PlayerIter(team, return_types='player'):
tick_delays.delay(0.1, remove_weapons, player)
tick_delays.delay(0.2, give_weapons, player, team)

def remove_weapons(player):
for index in player.weapon_indexes():
entity = Entity(index)
player.drop_weapon(entity.pointer, None, None)
entity.remove()

def give_weapons(player, team):
for weapon in default_weapons[team]:
player.give_named_item(weapon, 0, None, False)

Posted: Fri Sep 25, 2015 3:36 pm
by nullable
It's working but not correct. Gived weapon is not active in hand.

Posted: Fri Sep 25, 2015 5:13 pm
by stonedegg
Do you mean, when the players get their default weapons equipped, the weapon is not on their hand? That shouldn't happen. What else do they have on their hand?

By the way, I just updated the script so you can give more than one default weapon, like knife.

Posted: Sat Sep 26, 2015 7:59 am
by nullable
It's not working. I understood that give_named_item not working in csgo now. Code for reproduce.

Syntax: Select all

@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)

Posted: Sat Sep 26, 2015 11:53 am
by stonedegg
If you use this code for reference that it's not working, then I'm not surprised. player_activate fires when the player has finished loading the map, but still is in the loading screen. You can't give a weapon to a player that did not spawn yet.
Use player_spawned event for that.

But did you test my code? Are the players not getting a weapon?

Posted: Sat Sep 26, 2015 1:24 pm
by nullable
I have tested your code. Screen bellow:
Image

After round I have only knife which is not active.

Posted: Sat Sep 26, 2015 3:22 pm
by stonedegg
That is really odd.. Can you try this code please:

Syntax: Select all

from events import Event
from entities.entity import Entity
from filters.players import PlayerIter
from listeners import LevelInit
from listeners.tick import tick_delays

last_winner = 0
default_weapons = {
't': ['weapon_glock', 'weapon_knife'],
'ct': ['weapon_hkp2000', 'weapon_knife']
}


@LevelInit
def map_start(mapname):
global last_winner
last_winner = 0

@Event('round_end')
def round_end(game_event):
global last_winner
if game_event.get_int('reason') in (9,15):
last_winner = 0
return

last_winner = game_event.get_int('winner')

@Event('round_start')
def round_start(game_event):
global last_winner
if not last_winner:
return

team = 't' if last_winner == 2 else 'ct'
for player in PlayerIter(team, return_types='player'):
tick_delays.delay(0.1, remove_weapons, player)
tick_delays.delay(0.2, give_weapons, player, team)

def remove_weapons(player):
for index in player.weapon_indexes():
entity = Entity(index)
player.drop_weapon(entity.pointer, None, None)
entity.remove()

def give_weapons(player, team):
for weapon in default_weapons[team]:
player.give_named_item(weapon, 0, None, False)

Posted: Sat Sep 26, 2015 8:14 pm
by nullable
Thanks, but new code is not working too. The same result.

Posted: Sat Sep 26, 2015 9:33 pm
by satoon101
If you are the one that reported the give_named_item issue, please wait till that is resolved before continuing this discussion.

Posted: Sat Sep 26, 2015 10:23 pm
by stonedegg
Update your offsets in \addons\source-python\data\source-python\entities\csgo\CBasePlayer.ini which I posted here: https://github.com/Source-Python-Dev-Team/Source.Python/issues/72
Or wait for an official upate.

The code is working now, I've tested it, but you need to take my latest edit because I fixed a NameError. I upated both my posts to have the working version now.

Posted: Sun Sep 27, 2015 12:53 am
by satoon101
There is a new build being created right now. @stonedegg - if you wish, you can update all of the virtuals and post a pull request the next time this happens.

Posted: Sun Sep 27, 2015 10:54 am
by nullable
Now all is working. Thanks guys.