[CS:S] how to create a buyzone

Please post any questions about developing your plugin here. Please use the search function before posting!
derkalle
Junior Member
Posts: 9
Joined: Sat Nov 26, 2022 4:49 pm

[CS:S] how to create a buyzone

Postby derkalle » Sat Mar 18, 2023 1:30 pm

Hi,

I have trouble creating a buyzone. Somehow it gets created (EntityIter shows it) and I can position it where I want. But it does not get triggered. I have seen some Sourcemod and AMX mod which utilize func_buyzone and they simply "spawn" and "activate" it along with the team number. No matter what I try, I cannot get it to work. I can successful spawn new terrorists or anti-terrorists spawn points with the following code. But that is only somewhat useful when nobody can buy things.

Func: https://developer.valvesoftware.com/wiki/Func_buyzone
BuyZone Simulator (CSGO): https://forums.alliedmods.net/showthread.php?p=1793176
BuyZone Range: https://forums.alliedmods.net/showthread.php?t=141245
Move N Create: https://www.amxmod.net/forum/showthread.php?tid=28

Syntax: Select all

tmpEntity = Entity.create('func_buyzone')
tmpEntity.spawn()
tmpEntity.origin = Vector(0, 0, 0)
tmpEntity.mins = Vector(2444, -2796, -1)
tmpEntity.maxs = Vector(3034, -2149, 257)
tmpEntity.team_index = 2
# does not seem to have any effect
tmpEntity.set_key_value_int('TeamNum', 2)
# does not seem to have any effect
tmpEntity.set_key_value_int('spawnflags', 4097)
# does not seem to have any effect
tmpEntity.set_key_value_bool('StartDisabled', False)
# does not seem to have any effect
tmpEntity.call_input('Enable')


Maybe the solution is easy but I am not able to figure it out. Even ChatGPT does not seem to give me a working solution, though it often has the correct indicators for me on how to solve stuff like that.

Kind Regards,
Kalle
User avatar
L'In20Cible
Project Leader
Posts: 1511
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [CS:S] how to create a buyzone

Postby L'In20Cible » Sat Mar 18, 2023 2:37 pm

On CS:S, buy-zones are "brush" entities. Therefore, they require a brush model. It's possible to create them, but it really doesn't worth the effort. The easiest way is to just tell the clients they are in a buy-zone using a post_think hook. For example, the following allows players to buy no matter where they are on the map:

Syntax: Select all

from entities.hooks import EntityCondition
from entities.hooks import EntityPostHook
from memory import make_object
from memory.hooks import use_pre_registers
from players.entity import Player

@EntityPostHook(EntityCondition.is_player, 'post_think')
def _(stack_data, return_value):
with use_pre_registers(stack_data):
make_object(Player, stack_data[0]).in_buy_zone = True
derkalle
Junior Member
Posts: 9
Joined: Sat Nov 26, 2022 4:49 pm

Re: [CS:S] how to create a buyzone

Postby derkalle » Sat Mar 18, 2023 3:09 pm

Many thanks for the incredible fast reply. Okay, I see that I could work with that as a workaround. Main goal for me is to change different aspects of different maps, including spawns but also a lot of other stuff because some mappers did things that do not work well. I could go with your solution and simply check boundaries for the player and disable the buy zone after a specific period of time and if he got out of the range of that boundary, but that would introduce a regular check for the players I would like to avoid if there is something built-in already.

Regarding the "brush" entities: Do you mean by having a brush model that I first have to create a brush entity and link the buy_zone to it? Have already looked on how the Hammer editor is creating the buy_zones but couldn't figure it out on how to do chat programmatically.
User avatar
L'In20Cible
Project Leader
Posts: 1511
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [CS:S] how to create a buyzone

Postby L'In20Cible » Sat Mar 18, 2023 3:39 pm

derkalle wrote:Regarding the "brush" entities: Do you mean by having a brush model that I first have to create a brush entity and link the buy_zone to it? Have already looked on how the Hammer editor is creating the buy_zones but couldn't figure it out on how to do chat programmatically.
You can't really create a brush server-side, but you can use existing ones. For example, the bsp of the current map is a brush that is pre-cached, and the *1, *2, etc. Dump the model of existing brush entities (buy zones, bomb zones, rescue zones, etc.) and you will see their brush index. Keep in mind that they can have any dimensions depending how they were mapped.

It's been a while since I played with brushes but I found an example I posted on the ES archive that uses the current map: https://web.archive.org/web/20140908125 ... 28&t=43778
derkalle
Junior Member
Posts: 9
Joined: Sat Nov 26, 2022 4:49 pm

Re: [CS:S] how to create a buyzone

Postby derkalle » Sat Mar 18, 2023 4:12 pm

Ah okay, now I understand, thanks for the example code. So it is not quite easy to achieve. Many thanks for the hints. I will see on what I can do. Do you know whether these existing brushes can be resized or do I have to deal with their current size? As well as cloning them would be an option.
User avatar
L'In20Cible
Project Leader
Posts: 1511
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [CS:S] how to create a buyzone

Postby L'In20Cible » Sat Mar 18, 2023 4:22 pm

derkalle wrote:Do you know whether these existing brushes can be resized or do I have to deal with their current size? As well as cloning them would be an option.

You can scale them with the mins/maxs. But they keep the same shape. For example, a brush could look like this:

Image

Or any shape, really. And by making it bigger, or smaller, the zigzags will still not collide whatsoever.
derkalle
Junior Member
Posts: 9
Joined: Sat Nov 26, 2022 4:49 pm

Re: [CS:S] how to create a buyzone

Postby derkalle » Sat Mar 18, 2023 4:31 pm

Thanks, makes sense! :)
derkalle
Junior Member
Posts: 9
Joined: Sat Nov 26, 2022 4:49 pm

Re: [CS:S] how to create a buyzone

Postby derkalle » Sat Mar 18, 2023 5:42 pm

Hi,

just wanted to let you know how I got it working. I don't understand why I can set a bsp file as model, but it works, though.

Syntax: Select all

from engines.server import global_vars
from entities.entity import Entity

def create_buyzone(origin, mins, maxs, team_index):
tmpEntity = Entity.create('func_buyzone')
# set model
# viewtopic.php?f=20&t=2763&p=16518&sid=1042dbbcffa2cb3a714ae81929478a9f#p16518
tmpEntity.set_key_value_string('model', 'maps/{}.bsp'.format(
global_vars.map_name
))
# set team index
tmpEntity.team_index = int(team_index)
# spawn entity
tmpEntity.spawn()
# set origin
tmpEntity.origin = origin
# set mins
tmpEntity.mins = mins
# set maxs
tmpEntity.maxs = maxs
# return
return tmpEntity


That code snippet is simplified, I do read every setting for every map from the database on map change. See attached screenshot for example. This way I can remove old spawns and set new ones as well as setting the buy zone. Many thanks again! Hope I could contribute some useful source code back to the community.

css-map-changes.png
css-map-changes.png (88.65 KiB) Viewed 225 times
User avatar
L'In20Cible
Project Leader
Posts: 1511
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [CS:S] how to create a buyzone

Postby L'In20Cible » Sun Mar 19, 2023 4:45 am

derkalle wrote:I don't understand why I can set a bsp file as model, but it works, though.

The map is technically a brush model as can be seen in the model table:

Syntax: Select all

from stringtables import string_tables

for string in string_tables.modelprecache:
print(string)

"""
maps/de_dust2.bsp
*1
*2
*3
*4
*5
*6
*7
*8
*9
*10
*11
*12
*13
*14
*15
models\Gibs\wood_gib01e.mdl
models\Gibs\wood_gib01d.mdl
models\Gibs\wood_gib01c.mdl
models\Gibs\wood_gib01b.mdl
models\Gibs\wood_gib01a.mdl
models\Gibs\Glass_shard01.mdl
models\Gibs\Glass_shard02.mdl
models\Gibs\Glass_shard03.mdl
models\Gibs\Glass_shard04.mdl
models\Gibs\Glass_shard05.mdl
models\Gibs\Glass_shard06.mdl
models\props_debris\concrete_chunk08a.mdl
models\props_debris\concrete_chunk09a.mdl
models\props_debris\concrete_chunk03a.mdl
models\props_debris\concrete_chunk07a.mdl
models\props_debris\concrete_chunk02a.mdl
models\Gibs\metal_gib1.mdl
models\Gibs\metal_gib2.mdl
models\Gibs\metal_gib3.mdl
models\Gibs\metal_gib4.mdl
models\Gibs\metal_gib5.mdl
sprites/zerogxplode.vmt
sprites/steam1.vmt
sprites/bubble.vmt
sprites/laserbeam.vmt
effects/bubble.vmt
models/weapons/w_bullet.mdl
cable/cable.vmt
cable/cable_lit.vmt
cable/chain.vmt
cable/rope.vmt
sprites/blueglow1.vmt
sprites/purpleglow1.vmt
sprites/purplelaser1.vmt
sprites/white.vmt
sprites/physbeam.vmt
sprites/gunsmoke.vmt
models/gibs/hgibs.mdl
sprites/radio.vmt
models/humans/group01/female_01.mdl
models/weapons/v_shot_xm1014.mdl
models/weapons/w_shot_xm1014.mdl
models/weapons/v_pist_usp.mdl
models/weapons/w_pist_usp.mdl
models/weapons/w_pist_usp_silencer.mdl
models/weapons/v_smg_ump45.mdl
models/weapons/w_smg_ump45.mdl
models/weapons/v_smg_tmp.mdl
models/weapons/w_smg_tmp.mdl
models/weapons/v_eq_smokegrenade.mdl
models/weapons/w_eq_smokegrenade.mdl
models/weapons/v_rif_sg552.mdl
models/weapons/w_rif_sg552.mdl
models/weapons/v_snip_sg550.mdl
models/weapons/w_snip_sg550.mdl
models/weapons/v_snip_scout.mdl
models/weapons/w_snip_scout.mdl
models/weapons/v_smg_p90.mdl
models/weapons/w_smg_p90.mdl
models/weapons/v_pist_p228.mdl
models/weapons/w_pist_p228.mdl
models/weapons/v_smg_mp5.mdl
models/weapons/w_smg_mp5.mdl
models/weapons/v_smg_mac10.mdl
models/weapons/w_smg_mac10.mdl
models/weapons/v_rif_m4a1.mdl
models/weapons/w_rif_m4a1.mdl
models/weapons/w_rif_m4a1_silencer.mdl
models/weapons/v_shot_m3super90.mdl
models/weapons/w_shot_m3super90.mdl
models/weapons/v_mach_m249para.mdl
models/weapons/w_mach_m249para.mdl
models/weapons/v_knife_t.mdl
models/weapons/w_knife_t.mdl
models/weapons/v_eq_fraggrenade.mdl
models/weapons/w_eq_fraggrenade.mdl
models/weapons/v_pist_glock18.mdl
models/weapons/w_pist_glock18.mdl
models/weapons/v_rif_galil.mdl
models/weapons/w_rif_galil.mdl
models/weapons/v_snip_g3sg1.mdl
models/weapons/w_snip_g3sg1.mdl
models/weapons/v_eq_flashbang.mdl
models/weapons/w_eq_flashbang.mdl
models/weapons/v_pist_fiveseven.mdl
models/weapons/w_pist_fiveseven.mdl
models/weapons/v_rif_famas.mdl
models/weapons/w_rif_famas.mdl
models/weapons/v_pist_elite.mdl
models/weapons/w_pist_elite.mdl
models/weapons/w_eq_eholster_elite.mdl
models/weapons/w_eq_eholster.mdl
models/weapons/w_pist_elite_single.mdl
models/weapons/w_pist_elite_dropped.mdl
models/weapons/v_pist_deagle.mdl
models/weapons/w_pist_deagle.mdl
models/weapons/v_c4.mdl
models/weapons/w_c4.mdl
sprites/ledglow.vmt
models/weapons/w_c4_planted.mdl
models/weapons/v_snip_awp.mdl
models/weapons/w_snip_awp.mdl
models/weapons/v_rif_aug.mdl
models/weapons/w_rif_aug.mdl
models/weapons/v_rif_ak47.mdl
models/weapons/w_rif_ak47.mdl
models/Weapons/w_eq_smokegrenade_thrown.mdl
models/weapons/w_defuser.mdl
models/items/cs_gift.mdl
models/Weapons/w_eq_fraggrenade_thrown.mdl
models/Weapons/w_eq_flashbang_thrown.mdl
models/player/ct_urban.mdl
models/player/ct_gsg9.mdl
models/player/ct_sas.mdl
models/player/ct_gign.mdl
models/player/t_phoenix.mdl
models/player/t_leet.mdl
models/player/t_arctic.mdl
models/player/t_guerilla.mdl
sprites/glow01.vmt
materials/Sprites/glow.vmt
sprites/zerogxplode.spr
models/props/de_dust/grainbasket01c.mdl
models/props/de_dust/grainbasket01c_gib1.mdl
models/props/de_dust/grainbasket01c_gib2.mdl
models/props_junk/garbage_plasticbottle001a.mdl
models/props_junk/plasticbucket001a.mdl
models/props_junk/garbage_milkcarton002a.mdl
models/props_junk/PlasticCrate01a.mdl
models/props_junk/garbage_metalcan002a.mdl
models/props_c17/oildrum001.mdl
models/props_vehicles/carparts_axel01a.mdl
models/props_vehicles/carparts_tire01a.mdl
sprites/light_glow02_add_noz.vmt
"""


As a side note, the following:
derkalle wrote:

Syntax: Select all

tmpEntity.set_key_value_string('model', 'maps/{}.bsp'.format(
global_vars.map_name
))
Would be better as:

Syntax: Select all

tmpEntity.model = f'maps/{global_vars.map_name}.bsp'
Since the Entity.model property does more necessary stuff than the key value.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 1 guest