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.