Page 1 of 1

Randomizer

Posted: Tue Jul 29, 2025 12:53 am
by Lunacy_1984
Hello. I am looking to retire the last of my old eventscripts that I am currently using with the ES_emulator.
This is a fairly simple script I use to change the spawn weapon of my bots any time there is a death of any kind.
This triggers a random number to place a console command

hrcbot_player_spawnweapon pistol The weapons can be changed.

I am hoping to use this randomizer for several other scripts I am looking to replace with other command types.

// if (event_var(es_steamid) equalto "BOT") do

event player_death
{
es_doblock randombotweapon/randomize
}
block randomize
{
es_setinfo botweapon 0
es_rand botweapon 1 1100

if (server_var(botweapon) >= 100) do
{
hrcbot_player_spawnweapon pistol
}
if (server_var(botweapon) >= 150) do
{
hrcbot_player_spawnweapon crowbar
}
if (server_var(botweapon) >= 200) do
{
hrcbot_player_spawnweapon stunstick
}
if (server_var(botweapon) >= 250) do
{
hrcbot_player_spawnweapon frag
}
if (server_var(botweapon) >= 300) do
{
hrcbot_player_spawnweapon smg1
}
if (server_var(botweapon) >= 350) do
{
hrcbot_player_spawnweapon ar2
}
if (server_var(botweapon) >= 400) do
{
hrcbot_player_spawnweapon shotgun
}
if (server_var(botweapon) >= 450) do
{
hrcbot_player_spawnweapon slam
}
if (server_var(botweapon) >= 500) do
{
hrcbot_player_spawnweapon rpg
}
if (server_var(botweapon) >= 550) do
{
hrcbot_player_spawnweapon crossbow
}
if (server_var(botweapon) >= 600) do
{
hrcbot_player_spawnweapon frag
}
if (server_var(botweapon) >= 650) do
{
hrcbot_player_spawnweapon pistol
}
if (server_var(botweapon) >= 700) do
{
hrcbot_player_spawnweapon crowbar
}
if (server_var(botweapon) >= 750) do
{
hrcbot_player_spawnweapon stunstick
}
if (server_var(botweapon) >= 800) do
{
hrcbot_player_spawnweapon frag
}
if (server_var(botweapon) >= 850) do
{
hrcbot_player_spawnweapon smg1
}
if (server_var(botweapon) >= 900) do
{
hrcbot_player_spawnweapon ar2
}
if (server_var(botweapon) >= 950) do
{
hrcbot_player_spawnweapon shotgun
}
if (server_var(botweapon) >= 1000) do
{
hrcbot_player_spawnweapon slam
}
if (server_var(botweapon) >= 1025) do
{
hrcbot_player_spawnweapon crossbow
}
if (server_var(botweapon) >= 1050) do
{
hrcbot_player_spawnweapon frag
}

}

Re: Randomizer

Posted: Tue Jul 29, 2025 8:04 am
by satoon101
Try this:

Syntax: Select all

from random import randint

from cvars import ConVar
from events import Event


hrcbot_player_spawnweapon = ConVar("hrcbot_player_spawnweapon")
weapon_dict = {
100: "pistol",
150: "crowbar",
200: "stunstick",
250: "frag",
300: "smg1",
350: "ar2",
400: "shotgun",
450: "slam",
500: "rpg",
550: "crossbow",
600: "frag",
650: "pistol",
700: "crowbar",
750: "stunstick",
800: "frag",
850: "smg1",
900: "ar2",
950: "shotgun",
1000: "slam",
1025: "crossbow",
1050: "frag",
}

@Event("player_death")
def _set_spawn_weapon(game_event):
weapon = get_weapon()
if weapon is not None:
hrcbot_player_spawnweapon.set_string(weapon)


def get_weapon():
check_value = randint(1, 1100)
for key, value in reversed(sorted(weapon_dict.items())):
if check_value >= key:
return value

return None

Re: Randomizer

Posted: Wed Jul 30, 2025 10:55 pm
by Lunacy_1984
That simple. Thankyou for the script. I will be using this as an example to rewrite more of my old material.
HL2DM servers: Brand New For 1979, West Coast Canadian, and Pacific Coast Pirates

Re: Randomizer

Posted: Thu Jul 31, 2025 12:50 am
by Lunacy_1984
A bit of a change and so far so good.

Code: Select all

from random import randint

from cvars import ConVar
from events import Event

hrcbot_player_spawnweapon = ConVar("hrcbot_player_spawnweapon")
weapon_dict = {
    1: "pistol",
    2: "crowbar",
    3: "stunstick",
    4: "frag",
    5: "smg1",
    6: "ar2",
    7: "shotgun",
    8: "slam",
    9: "rpg",
    10: "crossbow",
    11: "frag",
    12: "pistol",
    13: "crowbar",
    14: "stunstick",
    15: "frag",
    16: "smg1",
    17: "ar2",
    18: "shotgun",
    19: "slam",
    20: "crossbow",
    21: "frag",
}

@Event("player_death")
def _set_spawn_weapon(game_event):
    weapon = get_weapon()
    if weapon is not None:
        hrcbot_player_spawnweapon.set_string(weapon)


def get_weapon():
    check_value = randint(1, 21)
    for key, value in reversed(sorted(weapon_dict.items())):
        if check_value >= key:
            return value

    return None

Re: Randomizer

Posted: Thu Jul 31, 2025 5:21 pm
by Ayuto
Well, the initial version includes some kind of probability per weapon. E. g. the chance to get a crossbow is much lower than a frag.

If you don't need that kind of probability you could also use a list of weapons and use random.choice(). The function get_weapon() then will be a one liner.