[SCRIPT] blockweapon.py

Intended for use on live public servers.
3 posts Page 1 of 1
kmsi
Mapper
Mapper
Posts: 46
Joined: Fri Jan 03, 2014 3:25 am


Blocks Specific Weapons. (ex. smg..)
Usage : /blocksmg, /blockrifle, /blockshotgun, /blocknade, /blockspade
Thank you.
Code: Select all
"""
Scrip t by kmsi([email protected])
Blocks Specific Weapons. (ex. smg..)
Usage : /blocksmg, /blockrifle, /blockshotgun, /blocknade, /blockspade
"""
from commands import add, admin
from pyspades.constants import *

#Edit here to change default settings
BlockSMGBool = False
BlockRifleBool = False
BlockShotgunBool = False
BlockNadeBool = False
BlockSpadeBool = False

@admin
def blocksmg(connection):
    global BlockSMGBool
    if BlockSMGBool:
        BlockSMGBool=False
        connection.protocol.send_chat('SMG is enabled now.')
    elif BlockSMGBool == False:
        BlockSMGBool=True
        connection.protocol.send_chat('SMG is disabled now.')
add(blocksmg)
        
@admin        
def blockrifle(connection):
    global BlockRifleBool
    if BlockRifleBool:
        BlockRifleBool=False
        connection.protocol.send_chat('Rifle is enabled now.')
    elif BlockRifleBool == False:
        BlockRifleBool=True
        connection.protocol.send_chat('Rifle is disabled now.')
add(blockrifle)
        
@admin 
def blockshotgun(connection):
    global BlockShotgunBool
    if BlockShotgunBool:
        BlockShotgunBool=False
        connection.protocol.send_chat('Shotgun is enabled now.')
    elif BlockShotgunBool == False:
        BlockShotgunBool=True
        connection.protocol.send_chat('Shotgun is disabled now.')
add(blockshotgun)
 
@admin 
def blocknade(connection):
    global BlockNadeBool
    if BlockNadeBool:
        BlockNadeBool=False
        connection.protocol.send_chat('Grenade is enabled now.')
    elif BlockNadeBool == False:
        BlockNadeBool=True
        connection.protocol.send_chat('Grenade is disabled now.')
add(blocknade)
        
@admin        
def blockspade(connection):
    global BlockSpadeBool
    if BlockSpadeBool:
        BlockSpadeBool=False
        connection.protocol.send_chat('Spade is enabled now.')
    elif BlockSpadeBool == False:
        BlockSpadeBool=True
        connection.protocol.send_chat('Spade is disabled now.')
add(blockspade)
        
def apply_script(protocol, connection, config):
    class BlockWeaponConnection(connection):
        global BlockSMGBool
        global BlockRifleBool
        global BlockShotgunBool
        global BlockNadeBool
        global BlockSpadeBool
        
        def on_hit(self, hit_amount, hit_player, type, grenade):
            if self.weapon==SMG_WEAPON and BlockSMGBool:
                self.send_chat('SMG is disabled now. Use another weapon!')
                return False
            elif self.weapon==RIFLE_WEAPON and BlockRifleBool:
                self.send_chat('Rifle is disabled now. Use another weapon!')
                return False
            elif self.weapon==SHOTGUN_WEAPON and BlockShotgunBool:
                self.send_chat('Shotgun is disabled now. Use another weapon!')
                return False
            elif self.tool==SPADE_TOOL and BlockSpadeBool:
                self.send_chat('Spade is disabled now. Use another weapon!')
                return False
            return connection.on_hit(self, hit_amount, hit_player, type, grenade)
            
        def on_grenade(self, time_left):
            if BlockNadeBool:
                self.send_chat('Grenade is disabled now. Use another weapon!')
                return False
            return connection.on_grenade(self, time_left)
    return protocol, BlockWeaponConnection
Attachments
blockweapon.py
(3.39 KiB) Downloaded 140 times
LeCom
Post Demon
Post Demon
Posts: 866
Joined: Sat May 24, 2014 8:07 am


2 things you could improve: you also should check type in the on_hit function (since on_hit is also called when hitting somebody with a nade IIRC) and use protocol.BlockxyzBool instead of making it global (though this one isn't necessary if you just want your code to work).
kmsi
Mapper
Mapper
Posts: 46
Joined: Fri Jan 03, 2014 3:25 am


LeCom wrote:
2 things you could improve: you also should check type in the on_hit function (since on_hit is also called when hitting somebody with a nade IIRC) and use protocol.BlockxyzBool instead of making it global (though this one isn't necessary if you just want your code to work).
Thank you.
3 posts Page 1 of 1
Return to “Completed Releases”

Who is online

Users browsing this forum: No registered users and 1 guest