Page 1 of 1

[SCRIPT] blockweapon.py

Posted: Thu Feb 05, 2015 12:38 pm
by kmsi
Blocks Specific Weapons. (ex. smg..)
Usage : /blocksmg, /blockrifle, /blockshotgun, /blocknade, /blockspade
Thank you.
Code: Select all
"""
Scrip t by kmsi(kmsiapps@gmail.com)
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

Re: [SCRIPT] blockweapon.py

Posted: Thu Feb 05, 2015 3:15 pm
by LeCom
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).

Re: [SCRIPT] blockweapon.py

Posted: Mon Feb 09, 2015 7:25 am
by kmsi
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.