[SCRIPT] WeaponDisable

Intended for use on live public servers.
15 posts Page 1 of 1 First unread post
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


This script lets you control which weapons are in play and freely change them with a commmand
the commands are;
Spoiler:
/toggle [rifle/smg/shotgun/all] <on/off>
/trifle <on/off>
/tshotgun <on/off>
/tsmg <on/off>

(you can leave out the on/off in order to togglefrom its current state)
By default the SMG is disabled, the defaults can be changed in the script config
Code: Select all
"""
thepolm3
Enable or disable weapons at will
requested by Faker
"""

RIFLE_ENABLED=True
SHOTGUN_ENABLED=True
SMG_ENABLED=False

from commands import add,admin,name
from pyspades.server import weapon_reload
from twisted.internet.reactor import callLater

def RCNI(letters,string): #remove charachters not in letters
    ret=""
    for letter in string:
        if letter in letters:
            ret+=letter
    return ret

@admin
@name("toggle")
def toggle_weapon( connection , weapon , boolean = None ):
    if RCNI("rifle",weapon.lower())=="rifle":
        return toggle_rifle(connection,boolean)
    if RCNI("shotgun",weapon.lower())=="shotgun":
        return toggle_shotgun(connection,boolean)
    if RCNI("smg",weapon.lower())=="smg":
        return toggle_smg(connection,boolean)
    if RCNI("all",weapon.lower())=="all":
        if boolean==None:
            return "Please do either '/toggle all off' or '/toggle all on'"
        toggle_rifle(connection,boolean)
        toggle_shotgun(connection,boolean)
        toggle_smg(connection,boolean)
        return "All weapon now %s" %(["OFF","ON"][boolean=="on"])
    return "Please specify either rifle, smg, shotgun or all"

@admin
@name("trifle")
def toggle_rifle(connection,boolean=None):
    global RIFLE_ENABLED
    RIFLE_ENABLED = boolean.lower()=="on" if boolean!=None else not RIFLE_ENABLED
    connection.protocol.reset_all_weapons()
    return "Rifle %sabled." %(["dis","en"][RIFLE_ENABLED])

@admin
@name("tshotgun")
def toggle_shotgun(connection,boolean=None):
    global SHOTGUN_ENABLED
    SHOTGUN_ENABLED = boolean.lower()=="on" if boolean!=None else not SHOTGUN_ENABLED
    connection.protocol.reset_all_weapons()
    return "Shotgun %sabled." %(["dis","en"][SHOTGUN_ENABLED])

@admin
@name("tsmg")
def toggle_smg(connection,boolean=None):
    global SMG_ENABLED
    SMG_ENABLED = boolean.lower()=="on" if boolean!=None else not SMG_ENABLED
    connection.protocol.reset_all_weapons()
    return "SMG %sabled." %(["dis","en"][SMG_ENABLED])

add(toggle_weapon)
add(toggle_rifle)
add(toggle_shotgun)
add(toggle_smg)

def apply_script(protocol,connection,config):
    class WDConnection(connection):
        
        def spawn(self):
            self.refresh_weapon()
            return connection.spawn(self)

        def refresh_weapon(self):
            if self.weapon==0 and not RIFLE_ENABLED: self.weapon=2
            if self.weapon==2 and not SHOTGUN_ENABLED: self.weapon=1
            if self.weapon==1 and not SMG_ENABLED: self.weapon=0
            if not (RIFLE_ENABLED or SHOTGUN_ENABLED or SMG_ENABLED): #if all disabled
                self.set_ammo(0,0)
            else:
                wep=self.weapon_object
                if wep.current_stock==0 and wep.current_ammo==0:
                    self.set_ammo(wep.ammo,wep.stock)

        def on_weapon_set(self,weapon):
            if weapon==0 and not RIFLE_ENABLED: return False
            if weapon==2 and not SHOTGUN_ENABLED: return False
            if weapon==1 and not SMG_ENABLED: return False
            return connection.on_weapon_set(self,weapon)

        def set_ammo(self, new_ammo, new_stock=None):
            new_ammo=max(min(255,new_ammo),0)
            new_stock=max(min(255,new_stock),0)
            weapon=self.weapon_object
            weapon.current_ammo = new_ammo
            weapon_reload.player_id = self.player_id
            weapon_reload.clip_ammo = new_ammo
            weapon.current_stock = new_stock
            weapon_reload.reserve_ammo = new_stock
            self.send_contained(weapon_reload)

    class WDProtocol(protocol):
        def reset_all_weapons(self):
            for player in self.players.values():
                player.refresh_weapon()
                
    return WDProtocol,WDConnection
Happy customweaponing!
Attachments
WD.py
(3.8 KiB) Downloaded 333 times
Last edited by thepolm3 on Sun Sep 29, 2013 1:38 pm, edited 1 time in total.
MrHaaax
Modder
Modder
Posts: 1360
Joined: Sun Nov 25, 2012 2:58 am


gg polm. g-fucking-g.
TB_
Post Demon
Post Demon
Posts: 998
Joined: Tue Nov 20, 2012 6:59 pm


Great as usual, this can turn out very useful! :)
PigsFTW
Winter Celebration 2013
Winter Celebration 2013
Posts: 180
Joined: Fri Aug 09, 2013 3:20 am


I can't seem to get this script to work. Does it need to be updated?
extra
Build and Shoot's 1st Birthday
Build and Shoot's 1st Birthday
Posts: 864
Joined: Mon Aug 26, 2013 10:56 pm


Wow nice script!
Simon Freeman
Deuce
Posts: 15
Joined: Mon Aug 12, 2013 10:00 pm


thepolm3 wrote:
This script lets you control which weapons are in play and freely change them with a commmand
the commands are;
Spoiler:
/toggle [rifle/smg/shotgun/all] <on/off>
/trifle <on/off>
/tshotgun <on/off>
/tsmg <on/off>

(you can leave out the on/off in order to togglefrom its current state)
By default the SMG is disabled, the defaults can be changed in the script config
Code: Select all
"""
thepolm3
Enable or disable weapons at will
requested by Faker
"""

RIFLE_ENABLED=True
SHOTGUN_ENABLED=True
SMG_ENABLED=False

from commands import add,admin,name
from server import weapon_reload
from twisted.internet.reactor import callLater

def RCNI(letters,string): #remove charachters not in letters
    ret=""
    for letter in string:
        if letter in letters:
            ret+=letter
    return ret

@admin
@name("toggle")
def toggle_weapon( connection , weapon , boolean = None ):
    if RCNI("rifle",weapon.lower())=="rifle":
        return toggle_rifle(connection,boolean)
    if RCNI("shotgun",weapon.lower())=="shotgun":
        return toggle_shotgun(connection,boolean)
    if RCNI("smg",weapon.lower())=="smg":
        return toggle_smg(connection,boolean)
    if RCNI("all",weapon.lower())=="all":
        if boolean==None:
            return "Please do either '/toggle all off' or '/toggle all on'"
        toggle_rifle(connection,boolean)
        toggle_shotgun(connection,boolean)
        toggle_smg(connection,boolean)
        return "All weapon now %s" %(["OFF","ON"][boolean=="on"])
    return "Please specify either rifle, smg, shotgun or all"

@admin
@name("trifle")
def toggle_rifle(connection,boolean=None):
    global RIFLE_ENABLED
    RIFLE_ENABLED = boolean.lower()=="on" if boolean!=None else not RIFLE_ENABLED
    connection.protocol.reset_all_weapons()
    return "Rifle %sabled." %(["dis","en"][RIFLE_ENABLED])

@admin
@name("tshotgun")
def toggle_shotgun(connection,boolean=None):
    global SHOTGUN_ENABLED
    SHOTGUN_ENABLED = boolean.lower()=="on" if boolean!=None else not SHOTGUN_ENABLED
    connection.protocol.reset_all_weapons()
    return "Shotgun %sabled." %(["dis","en"][SHOTGUN_ENABLED])

@admin
@name("tsmg")
def toggle_smg(connection,boolean=None):
    global SMG_ENABLED
    SMG_ENABLED = boolean.lower()=="on" if boolean!=None else not SMG_ENABLED
    connection.protocol.reset_all_weapons()
    return "SMG %sabled." %(["dis","en"][SMG_ENABLED])

add(toggle_weapon)
add(toggle_rifle)
add(toggle_shotgun)
add(toggle_smg)

def apply_script(protocol,connection,config):
    class WDConnection(connection):
        
        def spawn(self):
            self.refresh_weapon()
            return connection.spawn(self)

        def refresh_weapon(self):
            if self.weapon==0 and not RIFLE_ENABLED: self.weapon=2
            if self.weapon==2 and not SHOTGUN_ENABLED: self.weapon=1
            if self.weapon==1 and not SMG_ENABLED: self.weapon=0
            if not (RIFLE_ENABLED or SHOTGUN_ENABLED or SMG_ENABLED): #if all disabled
                self.set_ammo(0,0)
            else:
                wep=self.weapon_object
                if wep.current_stock==0 and wep.current_ammo==0:
                    self.set_ammo(wep.ammo,wep.stock)

        def on_weapon_set(self,weapon):
            if weapon==0 and not RIFLE_ENABLED: return False
            if weapon==2 and not SHOTGUN_ENABLED: return False
            if weapon==1 and not SMG_ENABLED: return False
            return connection.on_weapon_set(self,weapon)

        def set_ammo(self, new_ammo, new_stock=None):
            new_ammo=max(min(255,new_ammo),0)
            new_stock=max(min(255,new_stock),0)
            weapon=self.weapon_object
            weapon.current_ammo = new_ammo
            weapon_reload.player_id = self.player_id
            weapon_reload.clip_ammo = new_ammo
            weapon.current_stock = new_stock
            weapon_reload.reserve_ammo = new_stock
            self.send_contained(weapon_reload)

    class WDProtocol(protocol):
        def reset_all_weapons(self):
            for player in self.players.values():
                player.refresh_weapon()
                
    return WDProtocol,WDConnection
Happy customweaponing!

how do i get the scripts working? i put the WD.py in scripts but i dont know why it wont work! (i dont know anytihng about programming)
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


what do you want it to do?
Simon Freeman
Deuce
Posts: 15
Joined: Mon Aug 12, 2013 10:00 pm


thepolm3 wrote:
what do you want it to do?
what it was intended to do: disable certain weaponry!
(i hate the shot gun)
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


Ok, so just go intk script and change defaults at the top
Simon Freeman
Deuce
Posts: 15
Joined: Mon Aug 12, 2013 10:00 pm


thepolm3 wrote:
Ok, so just go intk script and change defaults at the top

dude im talking as in I CANT activate it! you can still use shotgun!
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


copy and paste the script and provide a screenshot please
TimeToDie
Green Master Race
Green Master Race
Posts: 37
Joined: Tue Sep 17, 2013 3:52 pm


I cant make it Work. in the run.exe that write : "<script 'WD' not found : ImportError<'no module named server',>>"
and i put the script in the script folder : "scripts" and i Updated it in the Config.exe and that still not working.
Do you know what can i do ?
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


That should sort it out. re-download
TimeToDie
Green Master Race
Green Master Race
Posts: 37
Joined: Tue Sep 17, 2013 3:52 pm


thepolm3 wrote:
That should sort it out. re-download

Oh Thanks ! :D.
do you want be admin on my server ? i will very happy if yes ! :D :D :D
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


I'm not gonna say no :)
15 posts Page 1 of 1 First unread post
Return to “Completed Releases”

Who is online

Users browsing this forum: No registered users and 6 guests