Randomizer

A place for requesting new Source.Python plugins to be made for your server.

Please request only one plugin per thread.
User avatar
Lunacy_1984
Junior Member
Posts: 9
Joined: Tue May 27, 2025 2:37 am
Location: Vancouver, BC, Canada
Contact:

Randomizer

Postby Lunacy_1984 » Tue Jul 29, 2025 12:53 am

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
}

}
User avatar
satoon101
Project Leader
Posts: 2726
Joined: Sat Jul 07, 2012 1:59 am

Re: Randomizer

Postby satoon101 » Tue Jul 29, 2025 8:04 am

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
Image
User avatar
Lunacy_1984
Junior Member
Posts: 9
Joined: Tue May 27, 2025 2:37 am
Location: Vancouver, BC, Canada
Contact:

Re: Randomizer

Postby Lunacy_1984 » Wed Jul 30, 2025 10:55 pm

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
User avatar
Lunacy_1984
Junior Member
Posts: 9
Joined: Tue May 27, 2025 2:37 am
Location: Vancouver, BC, Canada
Contact:

Re: Randomizer

Postby Lunacy_1984 » Thu Jul 31, 2025 12:50 am

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
User avatar
Ayuto
Project Leader
Posts: 2212
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Randomizer

Postby Ayuto » Thu Jul 31, 2025 5:21 pm

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.
User avatar
Lunacy_1984
Junior Member
Posts: 9
Joined: Tue May 27, 2025 2:37 am
Location: Vancouver, BC, Canada
Contact:

Re: Randomizer

Postby Lunacy_1984 » Sat Aug 02, 2025 12:52 am

As I gain more experience with SP I may change how this works. I am mostly trying to stop bots spawning with a 357 but still have a rare chance of an RPG.
The main thing is I am using this script to help me make other randomizers as part of other scripts as I replace some of the still functioning eventscripts
User avatar
Lunacy_1984
Junior Member
Posts: 9
Joined: Tue May 27, 2025 2:37 am
Location: Vancouver, BC, Canada
Contact:

Re: Randomizer

Postby Lunacy_1984 » Thu Aug 07, 2025 12:57 am

After using the script for the weapon randomizer I wrote another script using the same principle. Player death triggers three commands to randomize settings via console command. I just need someone to check my work please.
********************************


from random import randint

from cvars import ConVar
from events import Event

sm_cbomb_bomblet_count = ConVar("sm_cbomb_bomblet_count")
count_dict = {
1: "30",
2: "3",
3: "1",
4: "10",
5: "30",
6: "25",
7: "6",
8: "18",
9: "9",
10: "16",
11: "3",
12: "25",
13: "12",
14: "18",
15: "14" ,
16: "8",
17: "20",
18: "10",
19: "7",
20: "15",
21: "30",
22: "28",
23: "35",
24: "20",
25: "50",
}

sm_cbomb_bomblet_magnitude = ConVar("sm_cbomb_bomblet_magnitude")
mag_dict = {
1: "90",
2: "450",
3: "500",
4: "200",
5: "80",
6: "10",
7: "200",
8: "120",
9: "110",
10: "90",
11: "200",
12: "80",
13: "100",
14: "88",
15: "300",
16: "200",
17: "50",
18: "60",
19: "50",
20: "130",
21: "500",
22: "130",
23: "500",
24: "130",
25: "500",
}

sm_cbomb_detonation_delay = ConVar("sm_cbomb_detonation_delay")
delay_dict = {
1: "1",
2: "5",
3: "3",
4: "3",
5: "2",
6: "4",
7: "2",
8: "3",
9: "5",
10: "2",
11: "4",
12: "1",
13: "3",
14: "2",
15: "5",
16: "2",
17: "4",
18: "3",
19: "4",
20: "2",
21: "5",
22: "6",
23: "3",
24: "1",
25: "5",
}

@Event("player_death")
def _set_spawn_weapon(game_event):
weapon = get_weapon()
if weapon is not None:
sm_cbomb_bomblet_count.set_string(count)
sm_cbomb_bomblet_magnitude.set_string(mag)
sm_cbomb_detonation_delay.set_string(delay)

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

return None

Return to “Plugin Requests”

Who is online

Users browsing this forum: Bing [Bot] and 219 guests