[script] Teleporters

Intended for use on live public servers.
7 posts Page 1 of 1 First unread post
Desert Storm
3 Years of Ace of Spades
3 Years of Ace of Spades
Posts: 79
Joined: Wed Dec 18, 2013 3:45 pm


This script allows you to set teleporter locations in the map.txt file. It is should be completely bug free because it has been tested thoroughly. please note that this does not protect the area around the teleporters

Features:
~This will check whether or not the middle block of the player is in the same location as a defined teleport location
~multiple locations can be defined and one will be picked at random to teleport the player to
~one-way links can be made
Code: Select all
"""
Teleporters
by Desert Storm
teleport from one location to another(think halo or portal)
"""

###Summary###
#this allows the server admin to declare locations in the map config file
#there can be single, multi, one-way portal links

#the algorithim I use seaches the map config for the first location that matches
#the players coordinates. if it finds a match is will then pick a random tuple
#or int from the same group this(50,14,30) is a tuple and this(4) is an int
#the integers are used to make one-way links

###Important###
#you may modify this file, however you still have to leave the 'by Desert Storm'
#part at the top of the file AND
#give credit to me if you post this elsewhere

###Notes###
#define the location so that there is one block of air between the location
#and the ground

#this does NOT check for anything lower than 2 or higher than 60

#for the one-way link the '#' is any existing index point in the 'otps'
#decleration

#you can have no less than two declarations in a group otherwise this will
#raise an Exception

#having dipped my spoon in to assembly language I know how important
#optimization is, so I have tried to make this use as little memory as I can
#with my current knowledge of python

###Examples###
#your config file can be any combination of the following

#map config file look:
#name ***
#author ***
#version ***
#description ***
#extensions = {'tps':[(())],
#              'otps':[()]
#             }

#Normal link:
#extensions = {
#             'tps':[((x1,y1,z1),(x2,y2,z2))]
#             }

#multiple groups:
#extensions = {
#             'tps':[((x1,y1,z1),(x2,y2,z2)),((x3,y3,z3),(x4,y4,z4))]
#             }

#multi link:
#extensions = {
#             'tps':[((x1,y1,z1),(x2,y2,z2),(x3,y3,z3))]
#             }

#one-way link:
#extensions = {
#             'tps':[((x1,y1,z1),(#))]
#             'otps':[(x2,y2,z2)]
#             }

from random import choice
from commands import add, admin, alias

def Teleporters(Exception):
    pass

TPI = 'Teleporter index set to {number}'

@admin
def tpindex(connection, index=None):
    connection.tpindex = int(index)
    return TPI.format(number=index)

add(tpindex)

def apply_script(protocol, connection, config):

    class tpc(connection):

        def coord_check(self, pos):
            p = self.protocol.map_info.extensions
            newpos = pos
            if p.has_key('tps'):
                pp = p['tps']
                for i in xrange(len(pp)):
                    if pos in pp[i]:
                        if self.tpindex != None:
                            if self.tpindex <= len(pp[i]):
                                newpos = pp[i][self.tpindex]
                                if type(newpos)==int:
                                    if p.has_key('otps'):
                                        ppp = p['otps']
                                        try:
                                            newpos = ppp[newpos]
                                        except IndexError:
                                            Teleporters("There is no index %d in 'otps'" % newpos)
                                            newpos = pos
                                    else:
                                        raise Teleporters("There is no otps decleration in the map txt")
                                        newpos = pos
                            self.tpindex = None
                            break
                        if len(pp[i])>2:
                            test = True
                            testnum = 0
                            while test:
                                newpos = choice(pp[i])
                                if type(newpos)==int:
                                    if p.has_key('otps'):
                                        ppp = p['otps']
                                        try:
                                            newpos = ppp[newpos]
                                        except IndexError:
                                            raise Teleporters("There is no index %d in 'otps'" % newpos)
                                            newpos = pos
                                            test = False
                                    else:
                                        raise Teleporters("There is no 'otps' decleration in the map config file")
                                if newpos!=pos:
                                    test = False
                                if testnum==7:
                                    test = False
                                testnum += 1
                            break
                        elif len(pp[i])>1:
                            if pp[i].index(pos)==0:
                                newpos = pp[i][1]
                                if type(newpos)==int:
                                    if p.has_key('otps'):
                                        ppp = p['otps']
                                        try:
                                            newpos = ppp[newpos]
                                        except IndexError:
                                            raise Teleporters('There is no index %d in otps' % newpos)
                                            newpos = pos
                            else:
                                newpos = pp[i][0]
                                if type(newpos)==int:
                                    if p.has_key('otps'):
                                        ppp = p['otps']
                                        try:
                                            newpos = ppp[newpos]
                                        except IndexError:
                                            raise Teleporters('There is no index %d in otps' % newpos)
                                            newpos = pos
                            break
                        else:
                            raise Teleporters("There is less than two locations in group %d" % i)
                            break
            return newpos
        
        def on_position_update(self):
            x, y, z = self.get_location()
            if self.world_object.crouch:
                pos = int(x), int(y), int(z)
            else:
                pos = int(x), int(y), int(z+1)
            if pos[2]<60 or pos[2]>2:
                if pos != self.old_pos:
                    newpos = self.coord_check(pos)
                    if newpos!=pos:
                        self.set_location((newpos[0],newpos[1],newpos[2]-1))
                    self.old_pos = newpos
            return connection.on_position_update(self)

        def on_spawn_location(self, pos):
            self.old_pos = pos
            return connection.on_spawn_location(self, pos)

        def on_join(self):
            self.tpindex = None
            self.old_pos = None
            return connection.on_join(self)

    return protocol, tpc
teleporters.py
Teleporters script
(6.98 KiB) Downloaded 230 times
here are some maps that uses this script
http://www.buildandshoot.com/viewtopic.php?f=8&t=9720
Last edited by Desert Storm on Sat Feb 08, 2014 6:40 pm, edited 6 times in total.
Jdrew
Mapper
Mapper
Posts: 4808
Joined: Tue Oct 30, 2012 10:48 pm


chalenge: now make a command that lets you select the teleporter you want to teleport to such as "/tpc 1". TPC means teleport command instead of "/tp".
Desert Storm
3 Years of Ace of Spades
3 Years of Ace of Spades
Posts: 79
Joined: Wed Dec 18, 2013 3:45 pm


challenge accepted Blue_BigSmile
Desert Storm
3 Years of Ace of Spades
3 Years of Ace of Spades
Posts: 79
Joined: Wed Dec 18, 2013 3:45 pm


All done. Also in the proccess I made sure an endless loop could not occur if a config file was not setup correctly
Squad-Scope
Deuce
Posts: 4
Joined: Tue Jul 30, 2013 3:41 pm


Doesn't work!
But idea is good :)
Attachments
Error.JPG
Error.JPG (27.39 KiB) Viewed 4876 times
learn_more
Coder
Coder
Posts: 891
Joined: Sun Mar 24, 2013 9:59 pm


Squad-Scope wrote:
Doesn't work!
But idea is good :)
just add ':' (without quoted) at the end of the line lazy fuck.
Desert Storm
3 Years of Ace of Spades
3 Years of Ace of Spades
Posts: 79
Joined: Wed Dec 18, 2013 3:45 pm


Not only did I fix the little missing ';' but, I also fixed a problem where if it was not setup correctly it would raise a system exception AND it would raise my teleporter exception.

Also something funny happened while I was posting this. My browser said that this was an attack site but when I clicked on the little more details thing all of googles reports about the website said 'In the past 90(days) the site buildandshoot.com has not shown any malicious activity.' and stuff like that Blue_Tongue .
7 posts Page 1 of 1 First unread post
Return to “Completed Releases”

Who is online

Users browsing this forum: No registered users and 19 guests