Giving player a weapon in cs:go

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
velocity
Senior Member
Posts: 132
Joined: Sat May 10, 2014 6:17 pm

Giving player a weapon in cs:go

Postby velocity » Sat Sep 08, 2018 12:40 pm

How do I spawn a weapon and give it to a player in CS:GO, since Player.give_named_item('weapon_ak47') doesn't work. Should I be looking at Entity.create?
User avatar
Kami
Global Moderator
Posts: 143
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Re: Giving player a weapon in cs:go

Postby Kami » Sat Sep 08, 2018 1:10 pm

Hey, I'm not sure why give_named_item does not work for you but this worked for me:

Syntax: Select all

from players.entity import Player
from events import Event

@Event('player_say')
def _player_say(ev):
player = Player.from_userid(ev['userid'])
player.give_named_item("weapon_ak47")


Alternatively as you said Entity.create will do the trick too:

Syntax: Select all

from players.entity import Player
from events import Event
from entities.entity import Entity

@Event('player_say')
def _player_say(ev):
player = Player.from_userid(ev['userid'])
weapon = Entity.create("weapon_ak47")
weapon.spawn()
weapon.origin = player.origin


I'm testing on windows though, maybe the offsets for give_named_item are outdated on Linux (if you are on Linux)?
User avatar
velocity
Senior Member
Posts: 132
Joined: Sat May 10, 2014 6:17 pm

Re: Giving player a weapon in cs:go

Postby velocity » Sat Sep 08, 2018 1:21 pm

Okay it works now for some reason :/ meh, keep the thread open, so other people can see how to give a weapon anyways.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 9 guests