[Cs:s] Zombie Riot admin

Please post any questions about developing your plugin here. Please use the search function before posting!
cssbestrpg
Senior Member
Posts: 116
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

[Cs:s] Zombie Riot admin

Postby cssbestrpg » Mon May 03, 2021 4:24 pm

Hello guys, i have issue getting my code work for zombie riot admin module.

admin is defined as:

Syntax: Select all

__FILEPATH__	= path.Path(__file__).dirname()
admins = ConfigObj(__FILEPATH__ + '/_admins.ini')


Syntax: Select all

def get_admin(userid):
player = Player(index_from_userid(userid))
return admins.get(player.steamid.lstrip('[').rstrip(']'))


The issue it doesn't show admin option in menu.

In _admins.ini file i have:

Syntax: Select all

[U:1:182650578]
User avatar
Ayuto
Project Leader
Posts: 2140
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: [Cs:s] Zombie Riot admin

Postby Ayuto » Mon May 03, 2021 7:29 pm

What's the full code?

Instead of implementing your own admin functionality, you might want to use SP's built-in auth Module, which is also integrated in the commands system:
http://wiki.sourcepython.com/general/config-auth.html
http://wiki.sourcepython.com/developing ... ermissions
http://wiki.sourcepython.com/developing ... /auth.html
cssbestrpg
Senior Member
Posts: 116
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: [Cs:s] Zombie Riot admin

Postby cssbestrpg » Tue May 04, 2021 2:47 am

Here is the full code:

Syntax: Select all

import path
from configobj import ConfigObj
from players.entity import Player
from engines.server import engine_server
from mathlib import Vector
from effects import TempEntity
from players.helpers import index_from_userid, userid_from_index
from engines.server import queue_command_string
from menus import SimpleMenu, Text, SimpleOption
from menus import PagedMenu, PagedOption
from messages import SayText2
from zr import zr

__FILEPATH__ = path.Path(__file__).dirname()
admins = ConfigObj(__FILEPATH__ + '/_admins.ini')

def get_admin(userid):
player = Player(index_from_userid(userid))
return admins.get(player.steamid.lstrip('[').rstrip(']'))

def adminmenu(userid):
menu = SimpleMenu()
if zr.is_queued(menu, index_from_userid(userid)):
return
menu.append(Text('Admin Menu\nSection: Main'))
menu.append(Text(' '))
menu.append(SimpleOption(1, 'Zombies', 'Zombie'))
menu.append(SimpleOption(2, 'Add Days', 'day'))
menu.append(SimpleOption(3, 'Remove Days', 'day_remove'))
menu.append(Text(' '))
menu.append(SimpleOption(0, 'Close', None))
menu.select_callback = admin_menu_callback
menu.send(index_from_userid(userid))

def day_menu(userid, type):
menu = PagedMenu(title='Admin Menu\nSection: %s Days\n' % (type))
if zr.is_queued(menu, index_from_userid(userid)):
return
for i in [1, 2, 3, 4, 5, 10]:
menu.append(PagedOption('%s' % (i), (i)))
if type == 'add':
menu.select_callback = days_menu_callback
elif type == 'remove':
menu.select_callback = remove_days_menu_callback
menu.send(index_from_userid(userid))

def zomnbies_menu(userid):
menu = SimpleMenu()
if zr.is_queued(menu, index_from_userid(userid)):
return
menu.append(Text('Admin Menu\nSection: Zombies'))
menu.append(Text(' '))
menu.append(SimpleOption(1, 'Beacon', 'beacon'))
menu.append(Text(' '))
menu.append(SimpleOption(0, 'Close', None))
menu.select_callback = admin_menu_callback
menu.send(index_from_userid(userid))

def zombies_players_menu(userid):
menu = PagedMenu(title='Admin Menu\nSection: Beacon\n')
if zr.is_queued(menu, index_from_userid(userid)):
return
for i in zr.getUseridList():
if zr.isAlive(i):
menu.append(PagedOption('%s' % (Player(index_from_userid(i)).name), (i)))
menu.select_callback = zombie_menu_callback
menu.send(index_from_userid(userid))

def days_menu_callback(_menu, _index, _option):
choice = _option.value
if choice:
userid = userid_from_index(_index)
if not zr._day > zr.max_day() and not zr._day >= zr.max_day():
zr._day += choice
SayText2('\x04[Zombie Riot] » You have changed day to %s!' % (choice)).send(index_from_userid(userid))

def remove_days_menu_callback(_menu, _index, _option):
choice = _option.value
if choice:
userid = userid_from_index(_index)
if not zr._day > 0 and not zr._day < 0:
zr._day -= choice
SayText2('\x04[Zombie Riot] » You have removed %s days!' % (choice)).send(index_from_userid(userid))

def admin_menu_callback(_menu, _index, _option):
choice = _option.value
if choice:
userid = userid_from_index(_index)
if choice == 'Zombie':
zomnbies_menu(userid)
elif choice == 'day':
day_menu(userid, 'add')
elif choice == 'day_remove':
day_menu(userid, 'remove')
elif choice == 'beacon':
zombies_players_menu(userid)

def zombie_menu_callback(_menu, _index, _option):
choice = _option.value
if choice:
userid = userid_from_index(_index)
player = Player(index_from_userid(userid))
player.delay(1, beacon, (choice,))

def beacon(userid):
if zr.isAlive(userid):
player = Player(index_from_userid(userid))
player.delay(1, beacon, (userid,))
player.emit_sound(sample='buttons/blip1.wav',volume=1.0,attenuation=0.5)
if player.team == 2:
r = 235
b = 0
else:
r = 0
b = 102
beamRing(userid, 1, 350, 0, 1, 3, 3, r, 0, b, 255, 'sprites/laserbeam.vmt')
beamRing(userid, 1, 350, 0, 1, 3, 3, 255, 255, 255, 255, 'sprites/laserbeam.vmt')

def beamRing(userid, startRadius, endRadius, zplus, lifeTime, width, amplitude, r, g, b, a=255, vmt='sprites/laserbeam.vmt'):
x,y,z = getPlayerLocation(userid)
modelIndex = engine_server.precache_model(vmt)
tempEnt = TempEntity('BeamRingPoint')

tempEnt.red = r
tempEnt.green = g
tempEnt.blue = b
tempEnt.alpha = a

tempEnt.center = Vector(x, y, z + zplus)
tempEnt.start_radius = startRadius
tempEnt.end_radius = endRadius

tempEnt.life_time = lifeTime
tempEnt.start_width = width
tempEnt.end_width = width
tempEnt.amplitude = amplitude

tempEnt.halo_index = modelIndex
tempEnt.model_index = modelIndex

tempEnt.create()

def getPlayerLocation(userid):
x,y,z = Player(index_from_userid(userid)).get_key_value_string('origin').split(' ')
return (float(x), float(y), float(z))


In zr.py file menu code for admin menu:

Syntax: Select all

def main_menu(userid):
menu = SimpleMenu()
if is_queued(menu, index_from_userid(userid)):
return
menu.append(Text('Market\nSection: Main'))
menu.append(Text('-' * 30))
menu.append(SimpleOption(1, 'Weapons', 'weapon'))
menu.append(SimpleOption(2, 'Potions', 'potion'))
menu.append(SimpleOption(3, 'Info', 'info'))
if admin.get_admin(userid):
menu.append(SimpleOption(4, 'Admin', 'admin_menu'))
menu.append(Text('-' * 30))
menu.append(SimpleOption(0, 'Close', None))
menu.select_callback = main_menu_callback
menu.send(index_from_userid(userid))
User avatar
L'In20Cible
Project Leader
Posts: 1428
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [Cs:s] Zombie Riot admin

Postby L'In20Cible » Tue May 04, 2021 4:26 am

Once your ini file has been parsed, it evaluates to:

Syntax: Select all

{'U:1:182650578': {}}


When you do the following:

Syntax: Select all

return admins.get(player.steamid.lstrip('[').rstrip(']'))


It effectively returns an empty dictionary. Therefore, evaluates to False. You need to test whether that steamid is inside your container, not get the value assigned to it.

Syntax: Select all

return player.steamid.lstrip('[').rstrip(']') in admins
cssbestrpg
Senior Member
Posts: 116
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: [Cs:s] Zombie Riot admin

Postby cssbestrpg » Tue May 04, 2021 3:10 pm

Thanks for help, now it works.

Return to “Plugin Development Support”

Who is online

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