Page 1 of 1
[Cs:s] Zombie Plugin
Posted: Mon Dec 21, 2020 10:32 am
by cssbestrpg
Hi, i have started making for cs:s zombie plugin, this zombie plugin infects to you zombie when t hits.
I have issue make switch all players to ct and keep infected one t.
Here is the code
Syntax: Select all
import os
import random
import path
from events import Event
from listeners.tick import Delay
from players.entity import Player
from players.helpers import index_from_userid
from filters.players import PlayerIter
from entities.entity import Entity
from engines.precache import Model
from stringtables.downloads import Downloadables
from engines.server import queue_command_string
from events.hooks import PreEvent
from events.hooks import EventAction
from messages import SayText2
from messages import HintText
from filters.weapons import WeaponClassIter
weapons = [weapon.basename for weapon in WeaponClassIter(not_filters='knife')]
def hint(attacker, userid):
hudhint(attacker, 'Name: %s \nHp: %s' % (Player(index_from_userid(userid)).name, Player(index_from_userid(userid)).health))
def hudhint(userid, text):
HintText(message=text).send(index_from_userid(userid))
@PreEvent('server_cvar', 'player_team', 'player_connect', 'player_disconnect', 'player_connect_client')
def pre_player_team(game_event):
return EventAction.STOP_BROADCAST
def tell(userid, text):
SayText2(message='' + text).send(index_from_userid(userid))
__FILEPATH__ = path.path(__file__).dirname()
DOWNLOADLIST_PATH = os.path.join(__FILEPATH__ + '/materials.txt')
def server_command(cmd):
queue_command_string(cmd)
def player_list():
for i in PlayerIter.iterator():
yield i.userid
def load():
server_command('bot_quota 20')
server_command('bot_quota_mode fill')
server_command('mp_roundtime 5')
setDl()
def ct_count():
return len(PlayerIter(['all', 'ct']))
def round_checker():
if ct_count() == 0:
Entity.find_or_create('info_map_parameters').fire_win_condition(3)
def setDl():
downloadables = Downloadables()
with open(DOWNLOADLIST_PATH) as f:
for line in f:
line = line.strip()
if not line:
continue
downloadables.add(line)
@Event('player_spawn')
def player_spawn(args):
userid = args.get_int('userid')
Player(index_from_userid(userid)).gravity = 1 # Should restore old gravity
if Player(index_from_userid(userid)).team == 2:
Player(index_from_userid(userid)).restrict_weapons(*weapons)
if random.randint(1, 20) <= 1:
infect(userid)
@Event('player_hurt')
def player_hurt(args):
if args.get_string('weapon') == 'knife':
userid = args.get_int('userid')
attacker = args.get_int('attacker')
if attacker > 0:
if not Player(index_from_userid(userid)).team == Player(index_from_userid(attacker)).team:
infect(userid)
@Event('player_hurt')
def player_hurt(args):
userid = args.get_int('userid')
attacker = args.get_int('attacker')
if attacker > 0:
if not Player(index_from_userid(userid)).team == Player(index_from_userid(attacker)).team:
if not Player(index_from_userid(attacker)).is_bot():
Delay(2, hint, (attacker, userid))
def infect(userid):
Player(index_from_userid(userid)).switch_team(2)
Player(index_from_userid(userid)).set_noblock(True)
Player(index_from_userid(userid)).health = 10000
Player(index_from_userid(userid)).speed = 1.5 # Should make 50% faster walk
Player(index_from_userid(userid)).gravity = 0.75 # Should make 25% less have gravity
chance = random.randint(1, 4)
if chance == 1:
Player(index_from_userid(userid)).set_model(Model('models/player/zh/zh_charple001.mdl'))
elif chance == 2:
Player(index_from_userid(userid)).set_model(Model('models/player/zh/zh_corpse002.mdl'))
elif chance == 3:
Player(index_from_userid(userid)).set_model(Model('models/player/zh/zh_zombie003.mdl'))
elif chance == 4:
Player(index_from_userid(userid)).set_model(Model('models/player/ics/hellknight_red/t_guerilla.mdl'))
for i in player_list():
tell(i, '\x04%s has infected to zombie!' % (Player(index_from_userid(userid)).name))
Delay(0.1, round_checker)
@Event('item_pickup')
def item_pickup(args):
userid = args.get_int('userid')
if Player(index_from_userid(userid)).team == 2:
Player(index_from_userid(userid)).restrict_weapons(*weapons)
Re: [Cs:s] Zombie Plugin
Posted: Mon Dec 21, 2020 2:52 pm
by Kami
Hey, I added some lines in your infect() function to change everyone but the Zombie to the CT team :)
Edit: I also moved the restriction to the actual infection function. Otherwise a person could spawn as a T, have his weapons restricted and then be switched to CT.
Syntax: Select all
import os
import random
import path
from events import Event
from listeners.tick import Delay
from players.entity import Player
from players.helpers import index_from_userid
from filters.players import PlayerIter
from entities.entity import Entity
from engines.precache import Model
from stringtables.downloads import Downloadables
from engines.server import queue_command_string
from events.hooks import PreEvent
from events.hooks import EventAction
from messages import SayText2
from messages import HintText
from filters.weapons import WeaponClassIter
weapons = [weapon.basename for weapon in WeaponClassIter(not_filters='knife')]
def hint(attacker, userid):
hudhint(attacker, 'Name: %s \nHp: %s' % (Player(index_from_userid(userid)).name, Player(index_from_userid(userid)).health))
def hudhint(userid, text):
HintText(message=text).send(index_from_userid(userid))
@PreEvent('server_cvar', 'player_team', 'player_connect', 'player_disconnect', 'player_connect_client')
def pre_player_team(game_event):
return EventAction.STOP_BROADCAST
def tell(userid, text):
SayText2(message='' + text).send(index_from_userid(userid))
__FILEPATH__ = path.path(__file__).dirname()
DOWNLOADLIST_PATH = os.path.join(__FILEPATH__ + '/materials.txt')
def server_command(cmd):
queue_command_string(cmd)
def player_list():
for i in PlayerIter.iterator():
yield i.userid
def load():
server_command('bot_quota 20')
server_command('bot_quota_mode fill')
server_command('mp_roundtime 5')
setDl()
def ct_count():
return len(PlayerIter(['all', 'ct']))
def round_checker():
if ct_count() == 0:
Entity.find_or_create('info_map_parameters').fire_win_condition(3)
def setDl():
downloadables = Downloadables()
with open(DOWNLOADLIST_PATH) as f:
for line in f:
line = line.strip()
if not line:
continue
downloadables.add(line)
@Event('player_spawn')
def player_spawn(args):
userid = args.get_int('userid')
Player(index_from_userid(userid)).gravity = 1 # Should restore old gravity
if random.randint(1, 20) <= 1:
infect(userid)
@Event('player_hurt')
def player_hurt(args):
if args.get_string('weapon') == 'knife':
userid = args.get_int('userid')
attacker = args.get_int('attacker')
if attacker > 0:
if not Player(index_from_userid(userid)).team == Player(index_from_userid(attacker)).team:
infect(userid)
@Event('player_hurt')
def player_hurt(args):
userid = args.get_int('userid')
attacker = args.get_int('attacker')
if attacker > 0:
if not Player(index_from_userid(userid)).team == Player(index_from_userid(attacker)).team:
if not Player(index_from_userid(attacker)).is_bot():
Delay(2, hint, (attacker, userid))
def infect(userid):
for player in PlayerIter('alive'):
if player.userid != userid:
player.switch_team(3)
else:
player.switch_team(2)
player.set_noblock(True)
player.health = 10000
player.speed = 1.5 # Should make 50% faster walk
player.gravity = 0.75 # Should make 25% less have gravity
player.restrict_weapons(*weapons)
chance = random.randint(1, 4)
if chance == 1:
Player(index_from_userid(userid)).set_model(Model('models/player/zh/zh_charple001.mdl'))
elif chance == 2:
Player(index_from_userid(userid)).set_model(Model('models/player/zh/zh_corpse002.mdl'))
elif chance == 3:
Player(index_from_userid(userid)).set_model(Model('models/player/zh/zh_zombie003.mdl'))
elif chance == 4:
Player(index_from_userid(userid)).set_model(Model('models/player/ics/hellknight_red/t_guerilla.mdl'))
for i in player_list():
tell(i, '\x04%s has infected to zombie!' % (Player(index_from_userid(userid)).name))
Delay(0.1, round_checker)
@Event('item_pickup')
def item_pickup(args):
userid = args.get_int('userid')
if Player(index_from_userid(userid)).team == 2:
Player(index_from_userid(userid)).restrict_weapons(*weapons)
Re: [Cs:s] Zombie Plugin
Posted: Mon Dec 21, 2020 3:42 pm
by cssbestrpg
Hi Kami, i tested the code, but i found small issue
When you get infected/infect it immeadily changes infected one to different team
You are zombie and infect ct, then i got changed to ct
Chat spams
Code: Select all
Xander has infected to zombie!
Xavier has infected to zombie!
Rick has infected to zombie!
Ron has infected to zombie!
Greg has infected to zombie!
Adrian has infected to zombie!
Greg has infected to zombie!
Calvin has infected to zombie!
24/7
Re: [Cs:s] Zombie Plugin
Posted: Mon Dec 21, 2020 4:59 pm
by Kami
I tried to clean the code up a bit, it should work as you intended now.
Syntax: Select all
import os
import random
import path
from events import Event
from listeners.tick import Delay
from players.entity import Player
from players.helpers import index_from_userid
from filters.players import PlayerIter
from entities.entity import Entity
from engines.precache import Model
from stringtables.downloads import Downloadables
from engines.server import queue_command_string
from events.hooks import PreEvent
from events.hooks import EventAction
from messages import SayText2
from messages import HintText
from filters.weapons import WeaponClassIter
weapons = [weapon.basename for weapon in WeaponClassIter(not_filters='knife')]
zombie_models = ['models/player/zh/zh_charple001.mdl','models/player/zh/zh_corpse002.mdl','models/player/zh/zh_zombie003.mdl','models/player/ics/hellknight_red/t_guerilla.mdl']#
def hint(attacker, userid):
hudhint(attacker, 'Name: %s \nHp: %s' % (Player(index_from_userid(userid)).name, Player(index_from_userid(userid)).health))
def hudhint(userid, text):
HintText(message=text).send(index_from_userid(userid))
@PreEvent('server_cvar', 'player_team', 'player_connect', 'player_disconnect', 'player_connect_client')
def pre_player_team(game_event):
return EventAction.STOP_BROADCAST
def tell(userid, text):
SayText2(message='' + text).send(index_from_userid(userid))
__FILEPATH__ = path.path(__file__).dirname()
DOWNLOADLIST_PATH = os.path.join(__FILEPATH__ + '/materials.txt')
def server_command(cmd):
queue_command_string(cmd)
def player_list():
pl = []
for player in PlayerIter('alive'):
pl.append(player.userid)
return pl
def load():
server_command('bot_quota 20')
server_command('bot_quota_mode fill')
server_command('mp_roundtime 5')
setDl()
def ct_count():
return len(PlayerIter(['all', 'ct']))
def round_checker():
if ct_count() == 0:
Entity.find_or_create('info_map_parameters').fire_win_condition(3)
def setDl():
downloadables = Downloadables()
with open(DOWNLOADLIST_PATH) as f:
for line in f:
line = line.strip()
if not line:
continue
downloadables.add(line)
@Event('round_start')
def round_start(ev):
pl = []
pl = player_list()
userid = random.choice(pl)
if userid:
infect(userid)
@Event('player_spawn')
def player_spawn(args):
userid = args.get_int('userid')
Player(index_from_userid(userid)).gravity = 1 # Should restore old gravity
@Event('player_hurt')
def player_hurt(args):
if args.get_string('weapon') == 'knife':
userid = args.get_int('userid')
attacker = args.get_int('attacker')
if attacker > 0:
if not Player(index_from_userid(userid)).team == Player(index_from_userid(attacker)).team:
infect(userid)
@Event('player_hurt')
def player_hurt(args):
userid = args.get_int('userid')
attacker = args.get_int('attacker')
if attacker > 0:
if not Player(index_from_userid(userid)).team == Player(index_from_userid(attacker)).team:
if not Player(index_from_userid(attacker)).is_bot():
Delay(2, hint, (attacker, userid))
def infect(userid):
for player in PlayerIter('alive'):
if player.userid != userid:
player.switch_team(3)
else:
player.switch_team(2)
player.set_noblock(True)
player.health = 10000
player.speed = 1.5 # Should make 50% faster walk
player.gravity = 0.75 # Should make 25% less have gravity
player.restrict_weapons(*weapons)
infected_player = Player.from_userid(userid)
random_model = random.choice(zombie_models)
infected_player.set_model(Model(random_model))
SayText2("\x04%s has infected to zombie!" % (infected_player.name)).send()
Delay(0.1, round_checker)
@Event('item_pickup')
def item_pickup(args):
userid = args.get_int('userid')
if Player(index_from_userid(userid)).team == 2:
Player(index_from_userid(userid)).restrict_weapons(*weapons)
Re: [Cs:s] Zombie Plugin
Posted: Mon Dec 21, 2020 5:15 pm
by cssbestrpg
It still has issue, it just keep changing infected one, when infect
Also i loaded the script i got
Code: Select all
[SP] Loading plugin 'zr'...
[SP] Encountered a Warning:
File '..\addons\source-python\packages\site-packages\path.py', line 1713: DeprecationWarning
path is deprecated. Use Path instead.
[SP] Successfully loaded plugin 'zr'.
Server is hibernating
[SP] Caught an Exception:
Traceback (most recent call last):
File "..\addons\source-python\packages\source-python\events\listener.py", line 92, in fire_game_event
callback(game_event)
File "..\addons\source-python\plugins\zr\zr.py", line 78, in round_start
userid = random.choice(pl)
File "..\addons\source-python\Python3\random.py", line 257, in choice
raise IndexError('Cannot choose from an empty sequence') from None
IndexError: Cannot choose from an empty sequence
I also got a lot these messages at chat:
Code: Select all
Mark has infected to zombie!
Colin has infected to zombie!
Mark has infected to zombie!
Colin has infected to zombie!
Mark has infected to zombie!
Colin has infected to zombie!
Mark has infected to zombie!
Mark has infected to zombie!
Colin has infected to zombie!
Mark has infected to zombie!
Colin has infected to zombie!
Mark has infected to zombie!
Mark has infected to zombie!
Mark has infected to zombie!
Colin has infected to zombie!
Colin has infected to zombie!
Colin has infected to zombie!
Colin has infected to zombie!
Mark has infected to zombie!
Colin has infected to zombie!
Colin has infected to zombie!
Colin has infected to zombie!
Mark has infected to zombie!
Colin has infected to zombie!
Colin has infected to zombie!
Colin has infected to zombie!
Colin has infected to zombie!
Mark has infected to zombie!
Colin has infected to zombie!
Jerry has infected to zombie!
Re: [Cs:s] Zombie Plugin
Posted: Mon Dec 21, 2020 6:40 pm
by Kami
Sorry, I totally forgot to check infecting new players :D Try this:
Syntax: Select all
import os
import random
import path
from events import Event
from listeners.tick import Delay
from players.entity import Player
from players.helpers import index_from_userid
from filters.players import PlayerIter
from entities.entity import Entity
from engines.precache import Model
from stringtables.downloads import Downloadables
from engines.server import queue_command_string
from events.hooks import PreEvent
from events.hooks import EventAction
from messages import SayText2
from messages import HintText
from filters.weapons import WeaponClassIter
weapons = [weapon.basename for weapon in WeaponClassIter(not_filters='knife')]
zombie_models = ['models/player/zh/zh_charple001.mdl','models/player/zh/zh_corpse002.mdl','models/player/zh/zh_zombie003.mdl','models/player/ics/hellknight_red/t_guerilla.mdl']#
def hint(attacker, userid):
hudhint(attacker, 'Name: %s \nHp: %s' % (Player(index_from_userid(userid)).name, Player(index_from_userid(userid)).health))
def hudhint(userid, text):
HintText(message=text).send(index_from_userid(userid))
@PreEvent('server_cvar', 'player_team', 'player_connect', 'player_disconnect', 'player_connect_client')
def pre_player_team(game_event):
return EventAction.STOP_BROADCAST
def tell(userid, text):
SayText2(message='' + text).send(index_from_userid(userid))
__FILEPATH__ = path.path(__file__).dirname()
DOWNLOADLIST_PATH = os.path.join(__FILEPATH__ + '/materials.txt')
def server_command(cmd):
queue_command_string(cmd)
def player_list():
pl = []
for player in PlayerIter('alive'):
pl.append(player.userid)
return pl
def load():
server_command('bot_quota 20')
server_command('bot_quota_mode fill')
server_command('mp_roundtime 5')
setDl()
def ct_count():
return len(PlayerIter(['all', 'ct']))
def round_checker():
if ct_count() == 0:
Entity.find_or_create('info_map_parameters').fire_win_condition(3)
def setDl():
downloadables = Downloadables()
with open(DOWNLOADLIST_PATH) as f:
for line in f:
line = line.strip()
if not line:
continue
downloadables.add(line)
@Event('round_start')
def round_start(ev):
pl = []
pl = player_list()
if pl:
userid = random.choice(pl)
if userid:
infect_first(userid)
@Event('player_spawn')
def player_spawn(args):
userid = args.get_int('userid')
Player(index_from_userid(userid)).gravity = 1 # Should restore old gravity
@Event('player_hurt')
def player_hurt(args):
if args.get_string('weapon') == 'knife':
userid = args.get_int('userid')
attacker = args.get_int('attacker')
if attacker > 0:
if not Player(index_from_userid(userid)).team == Player(index_from_userid(attacker)).team:
infect(userid)
@Event('player_hurt')
def player_hurt(args):
userid = args.get_int('userid')
attacker = args.get_int('attacker')
if attacker > 0:
if not Player(index_from_userid(userid)).team == Player(index_from_userid(attacker)).team:
if not Player(index_from_userid(attacker)).is_bot():
Delay(2, hint, (attacker, userid))
def infect_first(userid):
for player in PlayerIter('alive'):
if player.userid != userid:
player.switch_team(3)
else:
player.switch_team(2)
player.set_noblock(True)
player.health = 10000
player.speed = 1.5 # Should make 50% faster walk
player.gravity = 0.75 # Should make 25% less have gravity
player.restrict_weapons(*weapons)
infected_player = Player.from_userid(userid)
random_model = random.choice(zombie_models)
infected_player.set_model(Model(random_model))
SayText2("\x04%s has infected to zombie!" % (infected_player.name)).send()
Delay(0.1, round_checker)
def infect(userid):
player = Player.from_userid(userid)
player.switch_team(2)
player.set_noblock(True)
player.health = 10000
player.speed = 1.5 # Should make 50% faster walk
player.gravity = 0.75 # Should make 25% less have gravity
player.restrict_weapons(*weapons)
infected_player = Player.from_userid(userid)
random_model = random.choice(zombie_models)
infected_player.set_model(Model(random_model))
SayText2("\x04%s has infected to zombie!" % (infected_player.name)).send()
Delay(0.1, round_checker)
@Event('item_pickup')
def item_pickup(args):
userid = args.get_int('userid')
if Player(index_from_userid(userid)).team == 2:
Player(index_from_userid(userid)).restrict_weapons(*weapons)
Re: [Cs:s] Zombie Plugin
Posted: Mon Dec 21, 2020 6:48 pm
by cssbestrpg
Thank You Kami for helping me. Now it works perfectly