Member
Join Date: Sep 2010
Location: Paracin/Srbija
|
11-13-2011
, 05:25
!up Playername
|
#1
|
Hello everyone, I have a question regarding Plugin. !up PlayerName
Plugin already exists for EventScript, but I'm not a fan of ES, but SourceMod
here are the data, who is interested to make plugin for SourceMod
this plugin is like FinallBatleGround
PHP Code:
import es, cmdlib, cfglib, cPickle
from path import path
# === RESPECT POINTS PLUGIN ==================================
# ========= CREATED BY HANNIBAL AND CRAZIEST =================
# ================ DO NOT EDIT ANYTHING BELOW THIS LINE ======
# ========================= OPEN & EDIT THE CONFIG.CFG FILE ==
''' Addon Information '''
info = es.AddonInfo()
info.name = 'Respect'
info.version = '1.0'
info.basename = 'respect'
info.author = 'Craziest & Hannibal'
info.description = 'Give respect points to your friends, or take it from them'
es.ServerVar("respect_version", info.version).makepublic()
''' Config Generator '''
cfg = cfglib.AddonCFG(es.getAddonPath("respect") + "/config/config.cfg")
cfg.text("******************************")
cfg.text("****** RESPECT SETTINGS ******")
cfg.text("******** BY CRAZIEST *********")
cfg.text("")
cfg.text("Load this plugin with: es_load respect")
cfg.text("")
cfg.text("Edit the following settings:")
cfg.text("")
cfg.text("-- Command Options --")
cfg.text("")
upCommand = cfg.cvar("respect_give_command", "!up", "The command used to give someone a respect point")
downCommand = cfg.cvar("respect_take_command", "!down", "The command used to take a respect point from someone")
viewCommand = cfg.cvar("respect_view_command", "!repview", "The command to view your respect points / given respect points")
helpCommand = cfg.cvar("respect_help_command", "!rephelp", "The command used to tell players how to use the respect system")
cfg.text("")
cfg.text("-- Other Options --")
cfg.text("")
maxUses = cfg.cvar("respect_max_uses", 2, "The maximum times the player can give/take respect - resets on map change (0 = Unlimited)")
announce = cfg.cvar("respect_announce_plugin", 1, "Announce on round start the plugin is running")
saveRespect = cfg.cvar("respect_save", 1, "Save the respect to a database on map start/unload so the data isn't lost")
cfg.text("")
cfg.text("End of config!")
cfg.text("Post on the forums if you have any suggestions/problems")
cfg.text("")
cfg.text("Coded by .craziesT")
cfg.write()
# =========================================================
usedList= []
class RespectManagerMain(object):
''' The engine of the script '''
helpCommand = None
def __init__(self):
''' Called everytime the script initiates '''
self.respect = {}
def registerSay(self, command):
''' Manages registering the give command '''
cmdlib.registerSayCommand(command, self.useCommand, 'Respect Plugin Commands')
self.helpCommand = command
def unregisterSay(self):
''' Unregisters the command when told to '''
cmdlib.unregisterSayCommand(self.helpCommand)
def message(self, text, userid=None, type=None):
''' Message Handler '''
if userid and type == True:
es.tell(userid, '#multi', '#green--- ' + text)
else:
es.msg('#multi', '#green--- ' + text)
def checkPlayer(self, userid):
''' Check and adds the player to the database if he doesn't exist '''
target = '0'
if userid:
if es.isbot(userid):
uid = es.getplayername(userid)
else:
uid = es.getplayersteamid(userid)
if uid not in self.respect:
self.respect[uid] = {}
self.respect[uid]['total'] = 0
self.respect[uid]['uses'] = 0
def resetTries(self, userid):
''' Sets the players uses to 0 when told to '''
if es.isbot(userid):
uid = es.getplayername(userid)
else:
uid = es.getplayersteamid(userid)
self.respect[uid]['uses'] = 0
def addPlayerRelation(self, uid, tid):
''' Checks player relationship and adds it if it doesn\'t exist '''
if tid not in self.respect:
self.respect[tid] = {}
self.respect[tid]['total'] = 0
if tid not in self.respect[uid]:
self.respect[uid][tid] = {}
self.respect[uid][tid]['rep'] = 0
def useCommand(self, userid, args):
self.message('Type #lightgreen%s#green to give respect, #lightgreen%s#green to take respect and #lightgreen%s#green to view your stats or given points to others!' % (upCommand, downCommand, viewCommand), userid, True)
def announcer(self):
if announce:
self.message('Respect plugin is running. Type #lightgreen%s#green to get more help ---' % helpCommand)
def saveRespect(self):
''' Manages saving the respect points to a database file '''
p = open(es.getAddonPath("respect") + '/respect.db', 'wb')
cPickle.dump(self.respect, p)
p.close()
def openRespect(self):
''' Manages opening the respect database '''
p = es.getAddonPath("respect") + '/respect.db'
if path(p).isfile():
f = open(p, 'rb')
self.respect = cPickle.load(f)
f.close()
mainManager = RespectManagerMain()
class RespectManagerGive(RespectManagerMain):
''' Manages giving respect to someone '''
giveCommand = None
def registerSay(self, command):
''' Manages registering the give command '''
cmdlib.registerSayCommand(command, self.upCommand, 'Respect Plugin Commands')
self.giveCommand = command
def unregisterSay(self):
''' Unregisters the command when told to '''
cmdlib.unregisterSayCommand(self.giveCommand)
def upCommand(self, userid, args):
''' Manages the give command functions '''
uid = es.getplayersteamid(userid)
if args:
target = es.getuserid(args)
if target in (0, None):
self.message('The specified player doesnt not exist.', userid, True)
return
if es.isbot(target):
tid = es.getplayername(target)
else:
tid = es.getplayersteamid(target)
if userid != target:
if mainManager.respect[uid]['uses'] < maxUses or maxUses == 0:
mainManager.addPlayerRelation(uid, tid)
mainManager.respect[uid]['uses'] += 1
mainManager.respect[uid][tid]['rep'] += 1
mainManager.respect[tid]['total'] += 1
self.checkSituationGive(uid, tid)
else:
self.message('You have used all of your respect points!', userid, True)
usedList.append(userid)
else:
self.message('You can not give respect to yourself.', userid, True)
else:
self.message('Invalid syntax! #green%s <name/userid/steamid>' % self.giveCommand, userid, True)
def checkSituationGive(self, uid, tid):
''' Checks the current respect between the two players '''
targetName = es.getplayername(es.getuserid(tid))
useridName = es.getplayername(es.getuserid(uid))
if mainManager.respect[uid][tid]['rep'] == 0:
self.message('#lightgreen%s#green has neutral respect towards #lightgreen%s#green!' % (useridName, targetName))
else:
self.message('#lightgreen%s#green gave a respect point to #lightgreen%s#green (Score: #lightgreen%s#green)' % (useridName, targetName, mainManager.respect[uid][tid]['rep']))
giveManager = RespectManagerGive()
class RespectManagerTake(RespectManagerMain):
''' Manages giving respect to someone '''
takeCommand = None
def registerSay(self, command):
''' Manages registering the give command '''
cmdlib.registerSayCommand(command, self.downCommand, 'Respect Plugin Commands')
self.takeCommand = command
def unregisterSay(self):
''' Unregisters the command when told to '''
cmdlib.unregisterSayCommand(self.takeCommand)
def downCommand(self, userid, args):
''' Called when the person uses the !down command '''
uid = es.getplayersteamid(userid)
if args:
target = es.getuserid(args)
if target in (0, None):
self.message('The specified player doesnt not exist.', userid, True)
return
if es.isbot(target):
tid = es.getplayername(target)
else:
tid = es.getplayersteamid(target)
if userid != target:
if mainManager.respect[uid]['uses'] < maxUses or maxUses == 0:
mainManager.addPlayerRelation(uid, tid)
if mainManager.respect[tid]['total'] > 0:
mainManager.respect[tid]['total'] -= 1
if mainManager.respect[uid][tid]['rep'] > -1:
mainManager.respect[uid][tid]['rep'] -= 1
self.checkSituationTake(uid, tid)
else:
self.message('You have used all of your respect points!', userid, True)
usedList.append(userid)
else:
self.message('You can not give respect to yourself.', userid, True)
else:
self.message('Invalid syntax! #lightgreen%s <name/userid/steamid>' % self.takeCommand, userid, True)
def checkSituationTake(self, uid, tid):
''' Checks the current respect between the two players '''
targetName = es.getplayername(es.getuserid(tid))
useridName = es.getplayername(es.getuserid(uid))
if mainManager.respect[uid][tid]['rep'] == 0:
self.message('#lightgreen%s#green has neutral respect towards #lightgreen%s#green!' % (useridName, targetName))
elif mainManager.respect[uid][tid]['rep'] == -1:
self.message('#lightgreen%s#green has negative respect towards #lightgreen%s#green!' % (useridName, targetName))
else:
self.message('#lightgreen%s#green took a respect point from #lightgreen%s#green (Score: #lightgreen%s#green)' % (useridName, targetName, mainManager.respect[uid][tid]['rep']))
takeManager = RespectManagerTake()
class RespectManagerView(RespectManagerMain):
''' Manages giving respect to someone '''
lookCommand = None
def registerSay(self, command):
''' Manages registering the give command '''
cmdlib.registerSayCommand(command, self.viewCommand, 'Respect Plugin Commands')
self.lookCommand = command
def unregisterSay(self):
''' Unregisters the command when told to '''
cmdlib.unregisterSayCommand(self.lookCommand)
def viewCommand(self, userid, args):
''' Handles the !view command and it\'s functions '''
uid = es.getplayersteamid(userid)
if args:
target = es.getuserid(args)
if target in (0, None):
self.message('The specified player doesnt not exist.', userid, True)
return
if es.isbot(target):
tid = es.getplayername(target)
else:
tid = es.getplayersteamid(target)
if userid != target:
mainManager.addPlayerRelation(uid, tid)
self.checkSituationView(uid, tid)
else:
self.message('To view your points #lightgreendo not#green type any arguments with the command!', userid, True)
else:
if mainManager.respect[uid]['total'] > 0:
self.message('#lightgreen%s#green has #lightgreen%s#green respect points on his account!' % (es.getplayername(userid), mainManager.respect[uid]['total']))
elif mainManager.respect[uid]['total'] in (0, None):
self.message('#lightgreen%s#green has no respect points currently.' % es.getplayername(userid))
else:
self.message('Invalid syntax! #lightgreen%s <name/userid/steamid>#green or no arguments for your stats.' % self.lookCommand, userid, True)
def checkSituationView(self, uid, tid):
''' Checks the current respect between the two players '''
targetName = es.getplayername(es.getuserid(tid))
useridName = es.getplayername(es.getuserid(uid))
if mainManager.respect[uid][tid]['rep'] == 0:
self.message('#lightgreen%s#green has neutral respect towards #lightgreen%s#green!' % (useridName, targetName))
elif mainManager.respect[uid][tid]['rep'] == -1:
self.message('#lightgreen%s#green has negative respect towards #lightgreen%s#green!' % (useridName, targetName))
else:
self.message('#lightgreen%s#green has positive respect towards #lightgreen%s#green (Score: #lightgreen%s#green)' % (useridName, targetName, mainManager.respect[uid][tid]['rep']))
viewManager = RespectManagerView()
# ========================================================
def load():
''' Called when the script loads '''
for x, y in [(giveManager, upCommand), (takeManager, downCommand), (viewManager, viewCommand), (mainManager, helpCommand)]:
x.registerSay(y)
for userid in es.getUseridList():
mainManager.checkPlayer(userid)
if saveRespect:
mainManager.openRespect()
del usedList[:]
for userid in es.getUseridList(): mainManager.resetTries(userid)
def unload():
for x in [giveManager, takeManager, viewManager, mainManager]:
x.unregisterSay()
if saveRespect:
mainManager.saveRespect()
del usedList[:]
for userid in es.getUseridList(): mainManager.resetTries(userid)
def es_map_start(ev):
if saveRespect:
mainManager.saveRespect()
if userid in usedList:
mainManager.resetTries(userid)
def round_start(ev):
mainManager.announcer()
def player_activate(ev):
userid = int(ev['userid'])
mainManager.checkPlayer(userid)
if userid in usedList:
mainManager.resetTries(userid)
# ===========================================================
Sorry for my BAD ENGLISH
|
|