EventScripts Forums
Mattie's EventScripts and Source Forums
Mattie recommends...
Premier Sponsor:Platinum Sponsor:
 
Script Categories
addon (49) admin (269) admins (14) advert (15) adverts (19) afk (15) alerts (12) ammo (23) anti (15) auth (16) automatic (11) awp (23) ban (18) ba_jail (17) bhop (19) block (18) bomb (40) bonus (23) bot (24) bot-management (19) bots (17) bunnyhop (11) Buy (21) cash (65) chat (57) cheat (11) clan (16) classes (22) color (21) colors (18) command (20) commands (18) config (22) connect (42) CS:S (16) css (2513) Damage (36) database (11) dead (15) death (19) deathmatch (70) deathrun (12) disconnect (18) Dissolve (11) dm (20) dod:s (11) dods (389) easy (18) effects (120) English (15) entity (21) es_tools (12) Eventscript (12) flashbang (25) français (99) french (36) fun (288) funny (16) Gabeee (11) gameplay (174) give (16) gravity (11) grenade (25) grenades (29) gun (14) GunGame (26) GunGame5 (11) guns (17) Hack (15) headshot (32) health (55) hegrenade (13) hl2dm (332) HP (13) info (48) information (16) IP (11) jail (26) jailbreak (11) join (23) jump (12) kick (22) kill (44) kills (22) knife (57) leveling (36) management (14) mani (14) map (25) map-management (27) maps (15) match (17) menu (106) message (20) messaging (52) mod (109) model (14) models (32) money (42) motd (13) music (29) mute (17) nades (18) name (13) noblock (35) player (40) player-management (31) player-tracking (28) popup (56) props (23) protection (27) punishment (49) python (63) quake (18) radio (21) random (36) rank (35) rates (16) rcon (13) realism (21) respawn (61) restrict (36) round (20) rpg (24) rules (41) say (11) scout (19) Script (20) script-helper (25) scriptpack (33) sdk (151) server (44) server-tools (42) shop (12) silly (31) simple (27) skins (25) slay (13) soccer (11) sound (45) sounds (92) spanish (11) spawn (63) speed (25) statistics (13) stats (48) status (11) STEAMID (24) Superhero (13) surf (31) Team (25) team-balance (14) teleport (12) text (14) TF2 (143) time (17) timer (14) tools (15) tracers (17) triggers (11) uedi (18) uses_auth (18) utility (11) vip (12) vote (36) voting (22) war (20) wcs (24) wcs:Python (32) weapon (77) weapons (114) web (14) welcome (12) zm (24) zombie (90) zombiemod (51) zombies (11)
Script Authors
*XYZ*SaYnt (12) .:MiB:. (11) .eMko* (6) 101satoon101 (10) 3R10N (24) 4u571n91 (5) 7355608 (9) Absolute (8) Ace Rimmer (40) adminc (5) Adz (8) AgathaKnuppelkuh (8) aidden (8) ajax (5) ak_47 (6) Al3c Tr3v3lyan (6) allstareng (5) ashbash1987 (9) ATAMAH (7) aznone (5) B00M (5) BackRaw (41) BFH_RedBull (8) bigfabi (7) Bioko (7) Blade (10) bladesback (13) bobdole (11) bodzsar1 (8) bonbon (36) Brainsucker (30) cagemonkey (8) carbon-14 (10) CaskioUTF (5) cbirou (15) ChaCaLz2psy4 (5) CharlesT (5) Chrisber (5) chrismrulz (9) Chun (6) cladiron (10) clipz934 (8) Colster (21) Cookieman8 (7) craziest (10) DanielB (19) Darkness123 (8) Dave (9) dbozan99 (7) deathx9 (5) Deathyy (16) dhack (16) Di[M]aN (12) DoCky (27) Don (15) dordtcore (8) DragonFreddo (8) Drassil (5) Einlanzers (42) EmbouT (10) emilplov (7) Errant (10) Eun (6) Fantole (9) Franc1sco (10) freddukes (18) Frequency (6) Fulmine (5) GAMEREN2 (8) german9114 (13) GODJonez (38) GoodfellaDeal (5) Hansi (6) HitThePipe (7) HOLLDIDAY (9) Icetouch (6) ichthys (25) infamous1 (9) Jeff91 (45) JoeyT2006 (30) Juba_PornBorn (12) jxl180 (10) KDBFame (6) L'In20Cible (7) Largo Usagi (10) Lobe (11) loKkdoKk (7) lolo-le-haricot (7) LosNir (5) Lumpi@Work (9) M4rc3L-XCN (7) macshot (6) Matth (6) Mattie (20) MBchrono (15) McFly (20) Medda (5) Memphis-84 (10) Messiah93 (12) Mickyy (5) micmacx (6) Mitchell (5) Mordavolt (7) MrScriptaz (5) mryoung (6) Nicolous (26) ojii (31) Omega_K2 (9) Owned|Myself (8) P3N (7) pand3mic (5) parsimba (5) Pascal257 (9) PatPeter (7) PDrop (10) Phaedrus (18) PhantOm Fury (7) phoenix131 (9) pinkyyy -.- (5) pitbull0993 (7) randomknifer (9) Ratzee (6) ReaCtioN2oo9 (6) Rennnyyy (17) revolutionfighters (6) RideGuy (12) Rio (9) Roeliekt (6) runamagic (13) sandking220 (6) Sarcasm_Poisoning (10) saRs| Johnny-5 (13) Schubaal (10) sea212 (5) sega74rus (7) sgt.angel (6) sicilia (5) sicman_adrian (22) skillz92 (7) sn4k3 (18) Snake12 (7) snake38 (10) sonicsight (7) spoonman184 (8) stabby (22) stas (22) Strontium Dog (30) SumGuy14 (25) SuperDave (45) surfteam (5) TaCo (5) TanaToS (17) Tealk (6) teowow (16) TheCheeTaH (20) TheDonFather (5) theresthatguy (6) Tiny Tod (7) Totyahun (9) uedi (38) Undead (25) usernamesaretaken (15) Warren (13) westham (6) WhiteAvenger (7) Wonder (14) X-Mania (5) XE_ManUp (13) xfalcon61 (5) zSweetXz (5) [Cs]Lord_Inferno2 (11) [NATO]Hunter (28) ||Wolf|| (10)
Search

Post new topic Reply to topic
Author Message
User avatar
New User
Profile

Posts: 14
 
New postPosted: 2007-11-02, 10:27 am 
   Post subject: [ES2] Round delayed lib

This lib is similary as gamethread lib but it has a new method which allow you to remove all the delayed commands.

http://addons.eventscripts.com/addons/view/roundthread

The only thing you have to do is to call the cancelAll method on the round_end event, I haven't found how to make this by default in the lib, any help?

This second lib allow you to use the gamethread.py lib to delay commands during a map, example:

PYTHON:
    import es

    import roundthread

    import gamethread



    def load():

            es.msg("0 Hello world")

            roundthread.delayed(5, es.msg, "5 Hello world")

            roundthread.delayed(10, es.msg, "10 Hello world")

            roundthread.delayed(15, es.msg, "15 Hello world")

            roundthread.delayed(20, es.msg, "20 Hello world")

            roundthread.delayed(25, es.msg, "25 Hello world")

            roundthread.delayed(30, es.msg, "30 Hello world")

           

            gamethread.delayed(15, es.msg, "15 gamethread Hello world")

            gamethread.delayed(20, es.msg, "20 gamethread Hello world")



    def round_end(event_var):

            roundthread.cancelAll()

           

    def es_map_start(event_var):

            roundthread.cancelAll()


This example will display during a round all the Hello World as normally, but if the round ends in the 10 firsts seconds for example you will only see the "15 gamethread Hello world" and "20 gamethread Hello world" during the next round.

When you call this method all delayed commands (for all the scripts using roundthread library) will be cancelled, (thats why this will be usefull to don't have to call the cancelAll command in each script)

My script allow you to cancel delayed commands at the end of a map too, just call this method in the es_map_start event.

You can easily implement theses methods in the gamethread library if you wanna stop gamethreads delayes commands at the maps end.

The 2 new methods are:

In the TimeSortedQueue class:

PYTHON:
    def removeAll(self):

        with self.lock:

          while bool(self.nodes):

            for item in self.nodes:

              self.nodes.remove(item)


and in the public part:

PYTHON:
    def cancelAll():

        '''

        Cancel all delayed commands

        '''

        timeq.removeAll()


To install it you have to create a text file named roundthread.py and put it into the cstrike\addons\eventscripts\_libs\python directory.

PYTHON:
    '''

    This module lets you execute things later within the primary gamethread.

    It provides access to queues and delayed command management such that you

    can interact safely with the server from external threads.

    '''

    from __future__ import with_statement

    import es

    import psyco

    psyco.full()

    import time

    import Queue

    import threading



    q = Queue.Queue()

    register_lock = threading.Lock()

    tickreg = False;



    class TimeSortedQueue(object):

      class TimeNode(object):

        def __init__(self, gotime, cmd, name):

          self.name = name

          self.gotime = float(gotime)

          self.cmd = cmd

        def __cmp__(self, b):

          #Should return a negative integer if self < other, zero if self == other, a positive integer if self > other

          return self.gotime - b.gotime  

      def __init__(self):

        self.nodes = []

        self.lock = threading.Lock()

      def addNode(self, node):

        with self.lock:

          self.nodes.append(node)

          self.nodes.sort()

      def add(self, gotime, cmd, args=(), kw=None, name=None):

        if not isinstance(args, tuple):

          args = (args,)

        self.addNode(self.TimeNode(gotime,(cmd, args, kw or {}),name))

      def getFirst(self):

        with self.lock:

          if self.nodes:

            return self.nodes[0]

          else:

            return None

      def getList(self):

        with self.lock:

          return self.nodes

      def removeByName(self, name):

        if not name: return   # can't kill items with no name

        with self.lock:

          self.nodes = filter(lambda i: i.name != name, self.nodes)

      def remove(self, item):

        with self.lock:

          if item in self.nodes:

            self.nodes.remove(item)

      def empty(self):

        with self.lock:

          return not bool(self.nodes)

      def printQueue(self):

        with self.lock:

          for i in self.nodes:

            es.dbgmsg(0, "[%8s] in %s seconds from now,\n  %s\n" % (i.name, i.gotime - time.time(), i.cmd))

      def removeAll(self):

        with self.lock:

          while bool(self.nodes):

            for item in self.nodes:

              self.nodes.remove(item)



    timeq = TimeSortedQueue()





    ##################################

    # begin public external interfaces

    # begin public external interfaces



    def delayed(seconds, cmd, args=(), kw=None):

        '''

        Executes a Python function at a later time. Requires a map to be started

        on the server (and ticks to be firing). Args can be passed in as a tuple,

        or as keyword argments. This is like a Python-based es_delayed.

        '''

        registerTicker()

        timeq.add(time.time()+seconds, cmd, args, kw)



    def delayedname(seconds, name, cmd, args=(), kw=None):

        '''

        Executes a Python function at a later time. Requires a map to be started

        on the server (and ticks to be firing). Args can be passed in as a tuple,

        or as keyword argments. This is like a Python-based es_delayed.

       

        Use delayedname if you want to provide an identifier that can be used with

        cancelDelayed(identifier) to stop the execution before it happens.

        '''

        registerTicker()

        timeq.add(time.time()+seconds, cmd, args, kw, name)



    def cancelDelayed(name):

        '''

        Cancel a command by name that was scheduled with delayedname()

        '''

        timeq.removeByName(name)

           

    def cancelAll():

        '''

        Cancel all delayed commands

        '''

        timeq.removeAll()

       

    def listDelayed():

        '''

        Print the contents of the delayed queue.

        '''

        timeq.printQueue()

       

    def queue(function, a=(), kw=None):

        '''

        Queue a command to be run on the very next tick. Requires a map be started

        on the server (and ticks to be firing). Args can be passed in as a tuple,

        or as keyword argments. This is like a Python-based es_soon.

        '''

        registerTicker()

        if not isinstance(a, tuple):

          a = (a,)

        q.put((function, a, kw or {}))



    # end public external interfaces

    # end public external interfaces

    ##################################





    def registerTicker():

      '''

      Internal use recommended. Registers a ticklistener for the gamethread

      usage if one isn't registered.

      '''

      global tickreg

      with register_lock:

        if not tickreg:

          tickreg = True

          es.addons.registerTickListener(tick)



    def unregisterTicker():

      '''

      Internal use recommended.

      Unregisters a ticklistener for the gamethread usage if one is configured.

      '''

      global tickreg

      with register_lock:

        if tickreg:

          tickreg = False

          es.addons.unregisterTickListener(tick)





    def _executenode(node):

        '''

        Internal use recommended.

        Helper function to execute and then remove an item from the gameq

        '''

        function, a, kw = node.cmd

        try:

            if function:

                function(*a, **kw)

        finally:

            timeq.remove(node)



    # gameframe callback

    def tick():

        '''

        Internal use recommended.

        '''

        # handle normal q

        while not q.empty():

            function, a, kw = q.get()

            function(*a, **kw)

        # check the first one to speed this up since none are ready unless it is.

        first = timeq.getFirst()

        if first:

            now = time.time()

            if first.gotime <= now:

                _executenode(first)

                # make a copy of the list so that we don't

                tasks = list(timeq.getList())

                for task in tasks:

                    if task.gotime <= now:

                        _executenode(task)

                    else:

                        break    

     

        if timeq.empty() and q.empty():  

            unregisterTicker()





User avatar
Site Administrator
Site Administrator
Profile

Posts: 7438
Location:
At Work
 
New postPosted: 2007-12-07, 2:28 pm 

gamethread already has a way to cancel all commands of a particular name. So if you wanted to cancel your own commands on a map start, you can unregister all commands using a particular name if you did gamethread.delayedname(name, ...) and then gamethread.cancelDelayed(name).

We wouldn't want a script cancelling all delayed commands because some may be intended to cross map starts. If a script wants to clear its own, then it can name them all the same and cancelDelayed() them later.

Best of luck, and thanks for the submission,
-Mattie


Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 


Who is online

Users browsing this forum: Rennnyyy and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group