[SCRIPT] Rotate v3

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


little tool to rotate a map by any angle
Do f1 to save the map
+added option to make rotating optional with a command; rotatemap
Code: Select all
from math import cos,sin,pi
from commands import add,admin

theta=90
degrees=True #degrees or radians
clockwise=True #cloakwise or counter-clockwise
always_rotate=False #rotates every map you load

if degrees:
    theta /= 180 / pi
if clockwise:
    theta = ( 2 * pi ) - theta

@admin
def rotatemap(connection,*args): #this will kick everyone
    global theta
    temp=theta
    if args:
        try:
            theta=int(args[0])
        except Exception:
            return "Invalid degrees"
    if len(args)>1:
        theta /= 180 / pi
    if len(args)>2:
        theta = ( 2 * pi ) - theta
    connection.protocol.rotate_map()
    theta=temp
add(rotatemap)
    

def get_new_coord(x,y,z):
    x,y=x-255,y-255
    x2 = x*cos(theta) - y*sin(theta)
    y2 = x*sin(theta) + y*cos(theta)
    return int(x2+255),int(y2+255),z

def apply_script(protocol,connection,config):
    class RotateProtocol(protocol):

        def rotate_map(self):
            map=self.map
            newmap=map.copy()
            print("Rotating map")
            for x in range(512):
                if x%50==0:
                    print(str(x/5)+"% done")
                for y in range(512):
                    for z in range(64):
                        a,b,c=get_new_coord(x,y,z)
                        solid,colour=newmap.get_point(a,b,c)
                        if solid and 0<x<511>y>0<a<511>b>0:
                            map.set_point(x,y,z,colour)
                        else:
                            if z==63:
                                map.set_point(x,y,z,(0,0,0))
                            else:
                                map.remove_point(x,y,z)
            self.map=map

        def on_map_change(self,map):
            if always_rotate:
                self.rotate_map()
            return protocol.on_map_change(self,self.map)
    return RotateProtocol,connection
hallway 45 degrees
Image
Attachments
rotate.py
(1.9 KiB) Downloaded 216 times
Last edited by thepolm3 on Sat Jun 15, 2013 11:32 am, edited 4 times in total.
Leif_The_Head
Deuced Up
Posts: 200
Joined: Tue Apr 09, 2013 12:52 pm


That's what I needed (I requested it also xD)
Jdrew
Mapper
Mapper
Posts: 4808
Joined: Tue Oct 30, 2012 10:48 pm


great, I was looking for something like this so thanks
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


I'm just working out the kinks in v2, and let me tell you that 45 degree hallway is just Oo
Jdrew
Mapper
Mapper
Posts: 4808
Joined: Tue Oct 30, 2012 10:48 pm


thepolm3 wrote:
I'm just working out the kinks in v2, and let me tell you that 45 degree hallway is just Oo
That would be werid as with hallway it kinda has to be straight or else it looks all ugly
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


I know, but thats why its (O_o)
It actually looks quite interesing
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


I changed it for you leif :)
Lostmotel
League Participant
League Participant
Posts: 298
Joined: Sun Nov 18, 2012 1:09 pm


another very usefull script Blue_Happy3
I rotated some kvx files I inserted on a map and exported them back into kv6. Now I have twice as much trees.

Also: A tractor rotated by 45° Blue_Tongue
Image
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


That most certainly is an epic tractor
Buffet_of_Lies
Mapper
Mapper
Posts: 402
Joined: Tue Nov 20, 2012 11:25 am


Brilliant!
KillerShot


Nice!
11 posts Page 1 of 1 First unread post
Return to “Completed Releases”

Who is online

Users browsing this forum: No registered users and 18 guests