#SMGwar by BOYuXRAY
#Version 3
#fixed Version

from commands import add, alias, admin, name, move
from twisted.internet.task import LoopingCall

SMGWAR_ENABLED_MESSAGE = "SMGwar enabled!players must use smg now!"
SMGWAR_DISABLED_MESSAGE = "SMGwar disabled!Players can use any weapons now!"
NO_SMGWAR = "No,SMGwar enabled"
SMG_ONLY = "you cant use shotgun,rifle use SMG!"
SMGWAR = true 

@alias('SMGwar')
@admin
def smgwarmode(connection)
    global SMGWAR, strip
    protocol = connection.protocol
    SMGWAR = not SMGWAR
    if SMGWAR:
        protocol.send_chat(PEACE_ENABLED_MESSAGE)
    else
        protocol.send_chat(PEACE_DISABLED_MESSAGE)

@alias('fly')
def smgwar_fly(connection):
    protocol = connection.protocol
    if SMGWAR:
        if connection in protocol.players:
            player = connection
            player.fly = not player.fly
            message = 'now flying like a bird' if player.fly else 'no longer flying'
            player.send_chat("You're {0}".format(message))
    else:
        connection.send_chat(NO_SMGWAR)

def smgwarhelp(connection):
    protocol = connection.protocol
    help = ["-" * 50,"Some of the commands are: /f","in smg war,you can only use smg,"good luck!", "-" * 50]
    if connection in protocol.players:
        for line in help:
            connection.send_chat(line)

add(smgwarmode)
add(smgwarhelp)
add(smgwar_fly)

def apply_script(protocol, connection, config):

   class SMGwarConnection(connection):
        def spawn(self):
            self.weapon = SMG_WEAPON
            return connection.spawn(self)

 def on_weapon_set(self, weapon):
            if weapon in [RIFLE_WEAPON, SHOTGUN_WEAPON]:
                self.send_chat(SMG_ONLY)
                self.set_weapon(SMG_WEAPON)
            return False
 

    class SMGwarConnection(connection):
        smgwar_fly = true

    class SMGwarProtocol(protocol):
        game_mode = CTF_MODE


    return SMGwarProtocol, SMGwarConnection