Note: This forum is merely an archive. It is no longer possible to register or post. - StackOverflow
New Ace of Spades Forums: http://buildandshoot.com/

MapTxtFiles Scripting common & unique. Part 1

Having problems creating a map? Ask around in here.

MapTxtFiles Scripting common & unique. Part 1

Postby DaDMaR » Tue Jan 31, 2012 3:07 am

This topic was for Map Scripting only - I now realize all map scripting - relies on its partnered Server Script.

So far we have several map scripts. All for use within Pyspades Servers. (None mine - most are from mat^2 ??)
I have removed tabs I used in code sections replaced with spaces - tabs affect script apparently. (anyone confirm ??)
Working or not working I'll let the forum decide. Will try to setup links for examples used.
(This is a chronicle of scripts as I learn them - Hoping to mold this in to a Tutorial - To be added to the WIKI )

Standard map Description (by mat^2)
Code: Select all
name = 'BestMap'
version = '9.0'
author = 'mat^2'
description = ('BEST MAP EVER')


Example for Water Damage
Code: Select all
name = 'Mapname'
version = '1.0'
author = 'Anonymous'
description = ('My description goes here.')
extensions = { 'water_damage' : 2,
               'boundary_damage' : {'left' : 64,
                                    'right' : 448,
                                    'top' : 128,
                                    'bottom' : 384,
                                    'damage': 1 } }

Water Damage
This activates once per second when the player is at water level(z>=61). The player takes the listed amount of HP damage and will die at 0 health.
Boundary Damage
This defines a "safe area" for play. Players who wander outside take damage.
It activates once per second when the player is OUTSIDE the rectangle coordinates. The player takes the listed amount of HP damage and will die at 0 health.

Example for Flag location (by mat^2)
The map metadata (mapname.txt) lets you define 3 special functions:

get_entity_location(): Override entity(flag and base) locations
get_spawn_location(): Override player locations
gen_script(): Generate terrain. For more on this see http://code.google.com/p/pyspades/wiki/MapMakerApi


Example usage:
Code: Select all
      name = 'BestMap'
                version = '9.0'
                author = 'mat^2'
                description = ('BEST MAP EVER')

           # scripting

                from pyspades.constants import *
                from pyspades.server import ServerConnection

                 def get_entity_location(team, entity_id):
                         if entity_id == BLUE_FLAG:
                                # puts only the blue flag in the corner
                                # you can also use GREEN_FLAG, BLUE_BASE, and GREEN_BASE as entity locations
                                z = team.protocol.map.get_z(0, 0)
                                return (0, 0, z)

                 def get_spawn_location(connection):
                          if connection.name == 'mat^2':
                                # put players with the name "mat^2"
                                # into the sky
                                x, y, z = ServerConnection.get_spawn_location(connection)
                                return (x, y, 30)

                                #to set spawn for a specific team, do the following:

                           if connection.team is connection.protocol.blue_team:
                                #sets a static spawn for just the blue team, but you could use "green_team" too.
                                x, y, z = ServerConnection.get_spawn_location(connection)
                                return (110, 110, 50)


Example Water Damage / Spawn Location (by Dany0)
Code: Select all
name = 'miniFootball'
version = '1.0'
author = 'Dany0'
description = 'Mini football for everyone!.'
extensions = { 'water_damage' : 200}

# script
from pyspades.constants import *
import random

def get_entity_location(team, entity_id):
    if entity_id == BLUE_FLAG:
        x, y, z = 256, 255, 36
        return (x, y, z)
    if entity_id == GREEN_FLAG:
        x, y, z = 256, 256, 36
        return (x, y, z)
    if entity_id == BLUE_BASE:
        x, y, z = 280, 256, 36
        return (x, y, z)
    if entity_id == GREEN_BASE:
        x, y, z = 232, 256, 36
        return (x, y, z)

def get_spawn_location(connection):
    if connection.team is connection.protocol.blue_team:
        x = random.randrange(294,302)
        y = random.randrange(235,242)
        x2 = random.randrange(294,302)
        y2 = random.randrange(269,276)
        x3, y3 = random.choice([(x,y),(x2,y2)])
        z3 = 38
        return (x3, y3, z3-1)
    if connection.team is connection.protocol.green_team:
        x = random.randrange(210,218)
        y = random.randrange(235,242)
        x2 = random.randrange(210,218)
        y2 = random.randrange(269,276)
        x3, y3 = random.choice([(x,y),(x2,y2)])
        z3 = 38
        return (x3, y3, z3-1)



Example of an elaborate map text 'Skull Island' that should be used with 'Hompy's Kraken Server Script
http://ace-spades.com/forums/viewtopic.php?f=79&t=753&hilit=kraken for details
Code: Select all
name = 'Skull Island'
version = '1.3'
author = 'hompy'
description = ('warning: squid hazard')
arena = (256 - 64, 256 - 64, 256 + 64, 256 + 64)
boss = True

from itertools import product
from twisted.internet.reactor import callLater
from pyspades.constants import *
from pyspades.server import grenade_packet, block_action, set_color
from pyspades.world import Grenade
from pyspades.common import Vertex3, make_color

SPAWN_RECT = (265, 282, 304, 293)
CHEST_AABB = (261, 202, 60, 3, 2, 2)
ORB_AABB = (209, 243, 53, 2, 2, 2)
ORB_COLOR = make_color(255, 0, 0)
NAG_INTERVAL = 17.0
KRAKEN_SPAWN = (256, 128)

def aabb(x, y, z, i, j, k, w, d, h):
    return not (x < i or x > i + w or y < j or y > j + d or z < k or z > k + h)

def prism(x, y, z, w, d, h):
    return product(xrange(x, x + w), xrange(y, y + d), xrange(z, z + h))

def set_block_color(protocol, color):
    set_color.value = color
    set_color.player_id = 32
    protocol.send_contained(set_color, save = True)

def remove_block(protocol, x, y, z, user = False):
    if z >= 63:
        return False
    if not protocol.map.remove_point(x, y, z, user):
        return False
    block_action.value = DESTROY_BLOCK
    block_action.player_id = 32
    block_action.x = x
    block_action.y = y
    block_action.z = z
    protocol.send_contained(block_action, save = True)
    return True

def build_block(protocol, x, y, z, color, force = False):
    if x < 0 or y < 0 or z < 0 or x >= 512 or y >= 512 or z >= 62:
        return False
    if force:
        remove_block(protocol, x, y, z)
    if not protocol.map.get_solid(x, y, z):
        protocol.map.set_point_unsafe_int(x, y, z, color)
        block_action.value = BUILD_BLOCK
        block_action.player_id = 32
        block_action.x = x
        block_action.y = y
        block_action.z = z
        protocol.send_contained(block_action, save = True)
        return True
    return False

def create_explosion_effect(protocol, position):
    protocol.world.create_object(Grenade, 0.0, position, None,
        Vertex3(), None)
    grenade_packet.value = 0.0
    grenade_packet.player_id = 32
    grenade_packet.position = position.get()
    grenade_packet.velocity = (0.0, 0.0, 0.0)
    protocol.send_contained(grenade_packet)

chest_active = True
orb_active = True
nag_call = None

def chest_nag(protocol):
    global nag_call
    protocol.send_chat('*** Under the X lies a buried treasure... open it, '
        'and the monster shall rise', global_message = None)
    nag_call = callLater(NAG_INTERVAL, chest_nag, protocol)

def challenge_nag(protocol):
    global nag_call
    protocol.send_chat('*** Not challenging enough? Another treasure remains '
        'hidden in the rocky islands...', global_message = None)
    nag_call = callLater(NAG_INTERVAL, challenge_nag, protocol)

def cancel_nag():
    global nag_call
    if nag_call:
        nag_call.cancel()
        nag_call = None

def get_spawn_location(connection):
    return connection.protocol.get_random_location(True, SPAWN_RECT)

def on_map_change(protocol, map):
    chest_nag(protocol)

def on_map_leave(protocol):
    cancel_nag()

def victory(caller = None):
    challenge_nag(caller.protocol)

def on_block_destroy(connection, x, y, z, mode):
    global chest_active, orb_active
    protocol = connection.protocol
    kraken = getattr(protocol, 'boss', None)
    boss_ready = getattr(protocol, 'boss_ready', False)
    if chest_active and aabb(x, y, z, *CHEST_AABB):
        if kraken is None and mode == SPADE_DESTROY:
            chest_active = False
            cancel_nag()
            create_explosion_effect(protocol, connection.world_object.position)
            if boss_ready:
                x, y, = KRAKEN_SPAWN
                kraken = protocol.start_kraken(x, y, finally_call = victory)
        else:
            return False
    if aabb(x, y, z, *ORB_AABB):
        if kraken is None and orb_active:
            chest_active = orb_active = False
            cancel_nag()
            set_block_color(protocol, ORB_COLOR)
            for u, v, w in prism(*ORB_AABB):
                build_block(protocol, u, v, w, ORB_COLOR, True)
            if boss_ready:
                x, y = KRAKEN_SPAWN
                protocol.start_kraken(x, y, hardcore = True)
        return False

def is_indestructable(protocol, x, y, z):
    if chest_active and aabb(x, y, z, *CHEST_AABB):
        return True
    if orb_active and aabb(x, y, z, *ORB_AABB):
        return True


"Attack of the giant Calamari!" (kraken)

Postby hompy » Sat Jan 21, 2012 2:58 am
http://dl.dropbox.com/u/31711941/aos/kraken.py
http://dl.dropbox.com/u/31711941/aos/skullisland.zip

Quick how to:

Update pyspades. You'll need latest, from the repo, not the release zip
Code:
hg pull -u

Place kraken.py in pyspades/feature_server/scripts
Put skullisland.txt and skullisland.vxl in pyspades/feature_server/maps
In config.txt, change the game mode to "kraken". The full line should look like this:
Code:
"game_mode" : "kraken",

Do NOT add the kraken script to the script list
Add "daycycle" to the script list. It's necessary for fancy mood-setting fog stuff
Code:
"scripts" : [
"daycycle"
],


Set the map to "skullisland" in the config OR change it in game with /map
Code:
"maps" : ["skullisland"],

Wear your favorite pirate hat. Lose an eye in battle."

UPDate Re: Attack of the giant Calamari! (kraken [now released])
Postby Tocksman » Tue Jun 05, 2012 4:01 am
I am currently in the process of updating this script. However, I know very little about how the real thing is actually supposed to go, so I can't tell the difference between what's supposed to happen in the chain of events, and what isn't.
Here is a kraken.py replacement that has all immediate exceptions fixed.
http://pastebin.com/LPx5f09t
http://ace-spades.com/forums/viewtopic.php?f=79&t=753&start=45


Dynamic Fog
http://ace-spades.com/forums/viewtopic.php?f=80&t=964
Postby SLoW » Thu Jan 19, 2012 8:46 pm
So I've written a simple little script that allows you to change the color of the fog on a per-map basis. I originally wrote it for my Firestorm map, (because you can't play Firestorm without orange fog) but I'm sure other people might find it useful too.

Code: Select all
    import commands

    def apply_script(protocol, connection, config):
        class FogProtocol(protocol):
            default_fog = (128, 232, 255)
            def on_map_change(self, name):
                self.set_fog_color(getattr(self.map_info.info, 'fog', self.default_fog))
                protocol.on_map_change(self, name)
        return FogProtocol, connection

This first block of code should be saved as "dynfog.py" in the scripts folder in pyspades and then added to the config.txt file. The second block of code gets added to the map .txt file (map metadata).

To implement, open your map.txt file, and add the following:

Code: Select all
    fog = (232, 128, 5)


(and replace the numbers with the RGB color of fog you want.) Enjoy. :)



_____________________________________________________________________________________________________
Disclaimer: All scripts are not mine........thanks for reading.
Last edited by DaDMaR on Wed Jul 11, 2012 12:10 am, edited 26 times in total.
User avatar
DaDMaR
Member
 
Posts: 14
Joined: Wed Jan 04, 2012 4:13 am

Re: MapTxtFiles Scripting common & unique.

Postby Lazy » Mon Apr 16, 2012 10:32 pm

Hi everyone, now a question : your scripts works for setting bases in ctf mode, but it doesn't in tc mode. Is there a way to fix that? and also to set the number of bases in tc mode ?
Lazy
[Animus] Member
 
Posts: 1
Joined: Mon Apr 16, 2012 10:30 pm

Re: MapTxtFiles Scripting common & unique.

Postby Ki11aWi11 » Sat May 05, 2012 11:36 am

With Dany0's spawn location how do you use it? Do you make a box with the to bounding points being (X1,Y1) and (X2,Y2)? Or, you make a box with the x range of the box being 294 to 302 and the y range being 235 to 242? Could some body please explain?
Image
Image
User avatar
Ki11aWi11
Member
 
Posts: 296
Joined: Wed Mar 21, 2012 12:07 pm
Location: Inside a bunker in Trenches.

Re: MapTxtFiles Scripting common & unique.

Postby Ki11aWi11 » Sat May 19, 2012 10:21 am

Thank you so much DaDMaR, this is probably the most useful pyspades post I have found on the forums, I've been using these posts extensively with my own maps such as using parts of Dany0's and Mat^2's spawn scripts to place static spawns (from Mat^2's) in several places per team (multiple/randomized spawns from Dany0's). I also used the flag and base spawns to customize where the intel spawns on Capitol (in the helicopters) and the bases (in the Town Hall). I was only able to learn how to do this by using this post.
Image
Image
User avatar
Ki11aWi11
Member
 
Posts: 296
Joined: Wed Mar 21, 2012 12:07 pm
Location: Inside a bunker in Trenches.

MapTxtFiles Scripting common & unique. Part 2

Postby DaDMaR » Tue Jul 10, 2012 5:14 am

MapTxtFiles Scripting common & unique. Part 2

Example of start locations in space.
[Map] International Space [Video][Arena]
Postby Ki11aWi11 » Sat May 19, 2012 10:19 pm (Thank you for your kind words.)
http://ace-spades.com/forums/viewtopic.php?f=67&t=8702
He has put a lot of comments in the script they have the hash in front of line - please read script.
Note not just "x" and "y" axis defined but "z" axis is hugely used. Start location randomization also.

Code: Select all
name = 'Space Station'

version = '1.1'

author = 'Ki11aWi11'

description = ('In Space, no one can hear you scream...')

fog = (256, 256, 256)

extensions = { 'water_damage' : 100,}

from pyspades.constants import *
from pyspades.server import ServerConnection

def get_entity_location(team, entity_id):
    if entity_id == BLUE_FLAG:
        x, y, z = 225, 291, 12
        return (x, y, z)
    if entity_id == GREEN_FLAG:
        x, y, z = 347, 291, 22
        return (x, y, z)
    if entity_id == BLUE_BASE:
        x, y, z = 238, 309, 25
        return (x, y, z)
    if entity_id == GREEN_BASE:
        x, y, z = 336, 291, 23
        return (x, y, z)

# script
from pyspades.constants import *
import random

def get_spawn_location(connection):
    if connection.name == 'mat^2':
        # put players with the name "mat^2"
        # into the sky
        x, y, z = ServerConnection.get_spawn_location(connection)
        return (x, y, 30)
    # to set spawn for a specific team, do the following:
    if connection.team is connection.protocol.blue_team:
        # sets a static spawn for just the blue team, but you could use "green_team" too.
        x=223
        y=290
        z=23
        x2=237
        y2=275
        z2=24
        x3=225
        y3=289
        z3=14
        x4=237
        y4=324
        z4=23
        x5, y5, z5 = random.choice([(x,y,z),(x2,y2,z2),(x3,y3,z3),(x4,y4,z4)])
        return (x5, y5, z5)
    if connection.team is connection.protocol.green_team:
        # sets a static spawn for just the blue team, but you could use "green_team" too.
        x2=346
        y2=291
        z2=22
        x3=337
        y3=291
        z3=23
        x4=317
        y4=294
        z4=11
        x5, y5, z5 = random.choice([(x2,y2,z2),(x3,y3,z3),(x4,y4,z4)])
        return (x5, y5, z5)


Re: [HOW TO] Set spawns with VOXEL[?]
Postby BuffetOfLies » Tue Apr 24, 2012 9:06 pm
You simply add the necessary lines with notepad. You might need to get some coordinate info via voxed but it's not really very difficult. Let's take a peek at my Black Widow map's config text:

Code: Select all
    name = 'Black Widow'
    version = '1.0'
    author = 'Buffet of Lies'
    description = 'Map by Buffet_of_Lies for AoS'
    extensions = { 'water_damage' : 5 }
    # scripting

    from pyspades.constants import *
    from pyspades.server import ServerConnection

    def get_entity_location(team, entity_id):
        if entity_id == BLUE_FLAG:
            # puts only the blue flag in the corner
            # you can also use GREEN_FLAG, BLUE_BASE, and GREEN_BASE as entity locations
            z = team.protocol.map.get_z(0, 0)
            return (0, 0, z)

    def get_spawn_location(connection):
        if connection.name == 'Buffet_of_Lies':
            # put players with the name "Buffet_of_Lies"
            # into the sky
            x, y, z = ServerConnection.get_spawn_location(connection)
            return (x, y, 30)
        #to set spawn for a specific team, do the following:
        if connection.team is connection.protocol.blue_team:
            #sets a static spawn for just the blue team, but you could use "green_team" too.
            #set_location_safe tries to keep the player outside of walls.
            x, y, z = ServerConnection.get_spawn_location(connection)
            return ServerConnection.set_location_safe(connection, (110, 110, 50))




See where it says "entity design == BLUE_FLAG" or GREEN_BASE? You can just change and add lines to those. You seem to be able to just tack it onto the end of map's config file. See where it says "get_spawn_location"? See how it says it is spawning the blue team at coordinates 110, 110, 50? If you were to add another line that said "if connection.team is connection.protocol.green_team:" then you could specify a new set of co-ords for the green team!




"BuffetOfLies" / thank you


_____________________________________________________________________________________________________
Disclaimer: All scripts are not mine........thanks for reading.
Last edited by DaDMaR on Thu Jul 12, 2012 7:15 am, edited 3 times in total.
User avatar
DaDMaR
Member
 
Posts: 14
Joined: Wed Jan 04, 2012 4:13 am

Re: MapTxtFiles Scripting common & unique. Part 1

Postby ei8htx » Tue Jul 10, 2012 7:56 am

Is there a map script to make certain blocks invulnerable by coord?
User avatar
ei8htx
Member
 
Posts: 73
Joined: Mon Apr 16, 2012 4:58 am
Location: US West Coast

Re: MapTxtFiles Scripting common & unique. Part 1

Postby PXYC » Thu Jul 12, 2012 2:41 pm

ei8htx wrote:Is there a map script to make certain blocks invulnerable by coord?

I don't think you can do it in the map.txt file, but you can do it manually or with a script using the /protect <coord> command.
Image

<+laserlamp> lil b is my fav
User avatar
PXYC
Local Mod
 
Posts: 1068
Joined: Wed Dec 14, 2011 2:52 am
Location: Near Philadelphia, PA

Re: MapTxtFiles Scripting common & unique. Part 1

Postby Ki11aWi11 » Fri Jul 13, 2012 12:38 am

PXYC wrote:
ei8htx wrote:Is there a map script to make certain blocks invulnerable by coord?

I don't think you can do it in the map.txt file, but you can do it manually or with a script using the /protect <coord> command.


I often use the protect command to protect the launch pad on Rocket Island, it would be useful if their was a line in the text file for automatically protecting coordinates.
Image
Image
User avatar
Ki11aWi11
Member
 
Posts: 296
Joined: Wed Mar 21, 2012 12:07 pm
Location: Inside a bunker in Trenches.

Re: MapTxtFiles Scripting common & unique. Part 1

Postby DaDMaR » Tue Jul 24, 2012 1:44 pm

Cant find it but here was a map, each side had - pink tower / small 4 columned pink bandstand and both were indestructible by color
Map also had shallow river across brown landscape - with single skinny bridge across the river

"in script was 'turple= 123 132 112'(whatever hot pink is)
'if block=turple block_indestructible "

again sorry cant find the dam script
User avatar
DaDMaR
Member
 
Posts: 14
Joined: Wed Jan 04, 2012 4:13 am


Return to Mapping Help



Who is online

Users browsing this forum: No registered users and 1 guest

cron