[GAME MODE] Build!

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


As per usual, here's the code
Code: Select all

# Gamemode by thepolm3, influenced strongly by "strongblock" by hompy
from pyspades import world
from pyspades.constants import *
from twisted.internet import reactor
from twisted.internet.task import LoopingCall
from commands import add, admin, name, alias, get_player, join_arguments, InvalidPlayer
from collections import namedtuple
from pyspades.server import block_action, set_color
from pyspades.common import make_color
from pyspades.color import rgb_distance
from pyspades.constants import *

ON_GRENADE_THROW="Grenades are not allowed; This is a BUILD server"
ON_SHOOT_KILL="Don't try to shoot anyone; This is a BUILD server"
ON_SPADE_KILL="Don't try to spade anyone; This is a BUILD server"
ON_GRENADE_KILL="Don't try to blow up anyone; This is a BUILD server"
ON_KILL="No killing!"
ON_SUICIDE="Ouch. That looks like it hurt"
ON_FLAG_GET="You can't get the intel; This is a BUILD server"
ON_BLOCK_DESTROY="You can't destroy that"
DIRT_COLOR = (71, 48, 35)

@name("ask")
def ask_for_block_permission(connection, player):
    try:
        # vanilla aos behavior
        subject = get_player(connection.protocol, '#' + player)
    except InvalidPlayer:
        subject = get_player(connection.protocol, player)
    if connection==subject:
        return "You are already allowed to break your own blocks!"
    subject.send_chat("to let him break your blocks.")
    subject.send_chat("to break you blocks. Do /allow %s" %(connection.name))
    subject.send_chat("%s is asking for permission" %(connection.name))
    return "Asked %s" %(subject.name)

@name("allow")
def allow_to_break_blocks(connection, player=None):
    try:
        # vanilla aos behavior
        subject = get_player(connection.protocol, '#' + player)
    except InvalidPlayer:
        subject = get_player(connection.protocol, player)
    if connection==subject:
        return "You are already allowed to break your own blocks!"
    strong_blocks=connection.protocol.strong_blocks
    for permission in strong_blocks:
        if strong_blocks[permission][0]==connection:
            strong_blocks[permission].append(subject)
    connection.allowing.append(subject)
    subject.send_chat("%s has allowed you to break his blocks!" %(connection.name))
    return "%s can now break your blocks! Use /deny to stop them" %(subject.name)

@name("deny")
def stop_breaking_blocks(connection, player=None):
    try:
        # vanilla aos behavior
        subject = get_player(connection.protocol, '#' + player)
    except InvalidPlayer:
        subject = get_player(connection.protocol, player)
    if connection==subject:
        return "You cannot stop yourself breaking blocks!"
    strong_blocks=connection.protocol.strong_blocks
    for permission in strong_blocks:
        if strong_blocks[permission][0]==connection:
            if subject in strong_blocks[permission]:
                del(strong_blocks[subject])
    connection.allowing.pop(connection.allowing.index(subject))
    subject.send_chat("%s has stopped you to breaking his blocks!" %(connection.name))
    return "%s can no longer break your blocks!" %(subject.name)


def check_if_buried(protocol, x, y, z):
    if not protocol.map.is_surface(x, y, z):
        protocol.strong_blocks.pop((x, y, z), None)

def bury_adjacent(protocol, x, y, z):
    check_if_buried(protocol, x, y, z - 1)
    check_if_buried(protocol, x, y, z + 1)
    check_if_buried(protocol, x - 1, y, z)
    check_if_buried(protocol, x + 1, y, z)
    check_if_buried(protocol, x, y - 1, z)
    check_if_buried(protocol, x, y + 1, z)

def is_color_dirt(color):
    return rgb_distance(color, DIRT_COLOR) < 30

add(ask_for_block_permission)
add(allow_to_break_blocks)
add(stop_breaking_blocks)

def apply_script(protocol, connection, config):
    class buildConnection(connection):
        allowing=[]
        def on_connect(self):
            self.allowing=[self]
            return connection.on_connect(self)
        def on_grenade(self, time_left):
            self.send_chat(ON_GRENADE_THROW)
            return False
        
        def on_hit(self, hit_amount, hit_player, type, grenade):
            if self.tool == SPADE_TOOL:
                self.send_chat(ON_SPADE_KILL)
            if self.tool == WEAPON_TOOL:
                self.send_chat(ON_SHOOT_KILL)
            if self.tool == GRENADE_TOOL:
                self.send_chat(ON_GRENADE_KILL)
            return False
        
        def on_kill(self, killer, type, grenade):
            if killer:
                killer.send_chat(ON_KILL)
                return False
            else:
                self.send_chat(ON_SUICIDE)
                return connection.on_kill(self, killer, type, grenade)
        
        def on_block_build(self, x, y, z):
            if not is_color_dirt(self.color):
                self.protocol.strong_blocks[str((x,y,z))] = self.allowing
                bury_adjacent(self.protocol, x, y, z)
            connection.on_block_build(self, x, y, z)
        
        def on_line_build(self, points):
            if not is_color_dirt(self.color):
                for xyz in points:
                    self.protocol.strong_blocks[str((xyz))] = self.allowing
                    bury_adjacent(self.protocol, *xyz)
            connection.on_line_build(self, points)

        def on_flag_take(self):
            self.send_chat(ON_FLAG_GET)
            return False
        
        def on_block_destroy(self, x, y, z, value):
            try:
                strong_block = self.protocol.strong_blocks[str((x,y,z))]
            except KeyError:
                return connection.on_block_destroy(self, x, y, z, value)
            if strong_block:
                if self in strong_block:
                    del(self.protocol.strong_blocks[str((x,y,z))])
                else:
                    
                    self.send_chat("Do /ask %s to gain access to his blocks" %(strong_block[0].name)) 
                    self.send_chat(ON_BLOCK_DESTROY)
                    return False
            return connection.on_block_destroy(self, x, y, z, value)
            
    class buildProtocol(protocol):
        game_mode=CTF_MODE
        strong_blocks = None
        
        def on_map_change(self, map):
            self.strong_blocks = {}
            protocol.on_map_change(self, map)

    return buildProtocol, buildConnection
        

Just turns the server into a build server. Based heavily on Strong Block by hompy. I didn't even change the variable names Green_Cookie
luckluck all!
Attachments
build.py
(6.75 KiB) Downloaded 191 times
Last edited by thepolm3 on Sat Jul 13, 2013 2:41 pm, edited 1 time in total.
IceCream
Hoster
Hoster
Posts: 322
Joined: Thu Nov 01, 2012 12:18 pm


Nice :)
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


ty ^^
3 posts Page 1 of 1 First unread post
Return to “Completed Releases”

Who is online

Users browsing this forum: No registered users and 25 guests