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/

Goon Haven Santa Script

Finished a script? Pop it in here.

Goon Haven Santa Script

Postby Tocksman » Sat Jan 07, 2012 6:44 pm

Here's Goon Haven's Santa script. It's a bit of a hackjob (I only spent about an hour writing it), but it sure was fun to play with.

Code: Select all

from commands import add
from pyspades.contained import BlockAction, SetColor
from pyspades.constants import *
from pyspades.world import Grenade
from pyspades.common import Vertex3
from pyspades.server import orientation_data, grenade_packet
from twisted.internet.task import LoopingCall
from twisted.internet import reactor
from math import sin, cos
import random

def apply_script(protocol, connection, config):
   class SantaConnection(connection):
      def on_block_build_attempt(self, x, y, z):
         c1, c2, c3 = self.color
         if (c1 > 100 and c2 > 100 and c3 > 100) and ((c1 + c2 + c3) > 500):
            return False
         return connection.on_block_build_attempt(self, x, y, z)
      
      def spew_santa_grenades(self, x, y, z):
         santa_nade = False
         for i in xrange(0, 6):
            grenade_packet.value = 3 # fuse
            grenade_packet.player_id = 32
            grenade_packet.position = (x, y, z)
            pi = 3.14159265
            a = i * ((2 * pi) / 6)
            
            vel_x = sin(a)
            vel_y = cos(a)
            vel_z = 1.0
            
            grenade_packet.velocity = (vel_x, vel_y, vel_z)
            self.protocol.send_contained(grenade_packet)
            
            position = Vertex3(x, y, z)
            velocity = Vertex3(vel_x, vel_y, vel_z)
            
            santa_nade = self.protocol.world.create_object(Grenade, 3,
               position, None, velocity, self.grenade_exploded)
            santa_nade = 'Santa'
      
      def spawn_santa_grenade_fountain(self, x, y, z):
         santa_nade = False
         grenade_packet.value = 3 # fuse
         grenade_packet.player_id = 32
         grenade_packet.position = (x, y, z)

         vel_x = random.random() * random.randrange(-1, 2, 2)
         vel_y = random.random() * random.randrange(-1, 2, 2)
         vel_z = -0.5
            
         grenade_packet.velocity = (vel_x, vel_y, vel_z)
         self.protocol.send_contained(grenade_packet)
            
         position = Vertex3(x, y, z)
         velocity = Vertex3(vel_x, vel_y, vel_z)
            
         santa_nade = self.protocol.world.create_object(Grenade, 3,
            position, None, velocity, self.grenade_exploded)
         santa_nade = 'Santa'
            
      def grenade_fountain(self, x, y, z):
         for i in xrange(16):
            time = i * 0.5
            reactor.callLater(time, self.spawn_santa_grenade_fountain,
                          x, y, z)
      
      def on_block_destroy(self, x, y, z, mode):
         if ((x, y, z) in self.protocol.santa_blocks) and self.name is not None:
            gift = ""
            val = random.randrange(1, 8)
            if val == 1:
               gift = "death"
               self.kill()
            elif val == 2:
               gift = "an airstrike"
               self.airstrike = True
               self.refill()
               if self.kills < self.protocol.airstrike_min_score_req:
                  self.kills = self.protocol.airstrike_min_score_req
               self.send_chat('Airstrike support ready! Launch with e.g. '
                           '/airstrike B4')
            elif val == 3 or val == 4:
               gift = "a restock"
               self.refill()
            elif val == 5:
               gift = "several grenades without the pin"
               self.spew_santa_grenades(x, y, z)
            elif val == 6:
               gift = "a grenade fountain"
               self.grenade_fountain(x, y, z)
            else:
               gift = "nothing"
            self.protocol.send_chat('%s opened one of Santa\'s presents and '
                              'received %s!' % (self.name, gift))
            self.protocol.irc_say('%s opened one of Santa\'s presents and '
                              'received %s!' % (self.name, gift))
         return connection.on_block_destroy(self, x, y, z, mode)

      def on_block_removed(self, x, y, z):
         if ((x, y, z) in self.protocol.santa_blocks):
            self.protocol.santa_blocks.discard((x, y, z))
         return connection.on_block_removed(self, x, y, z)

   class SantaProtocol(protocol):
      santa_blocks = set()
      
      def __init__(self, *arg, **kw):
         protocol.__init__(self, *arg, **kw)
         self.santa_gift_loop = LoopingCall(self.santa_drop)
         self.santa_gift_loop.start(300) # 5 minutes
   
      def santa_drop(self):
         """Spawns random blocks in the center of the map D4, D5, E4, E5"""
         if len(self.santa_blocks) > 4: # don't add anymore if there
            print "Too many gifts exist right now." # are more than 10.
            return

         block_num = random.randrange(1, 3)
         print "Attempting to place " + str(block_num) + " gifts"
         print str(len(self.santa_blocks)) + " gifts currently"
         for i in xrange(1, (block_num + 1)):
            x, y, z = self.get_random_location(True, (192, 192, 320, 320))
            z -= 1
            self.santa_drop_block(x, y, z)
            self.santa_blocks.add((x, y, z))
         self.send_chat('Santa just dropped off some goodies!')
      
      def santa_drop_block(self, x, y, z):
         """Places a gift from Santa"""
         block_action = BlockAction()
         block_action.player_id = 32
         set_color = SetColor()
         set_color.value = 0xFFFFFF
         set_color.player_id = block_action.player_id
         self.send_contained(set_color, save = True)
         self.map.set_point_unsafe_int(x, y, z, 0xFFFFFF)
         block_action.value = BUILD_BLOCK
         set_color.value = 0xFFFFFF
         block_action.x = x
         block_action.y = y
         block_action.z = z
         self.send_contained(block_action, save = True)
         
   return SantaProtocol, SantaConnection
Last edited by Tocksman on Fri Jan 13, 2012 4:39 pm, edited 2 times in total.
Tocksman
Member
 
Posts: 90
Joined: Mon Jan 02, 2012 10:46 pm

Re: Goon Haven Santa Script

Postby Szuwar » Sat Jan 07, 2012 8:11 pm

Code: Select all
pi = 3.14159265

Wouldn't be better to use
Code: Select all
math.pi

I know it's just nitpicking but still, it might affect accuracy of santa nades (if it matters).

I like the idea of random presents.
User avatar
Szuwar
Member
 
Posts: 31
Joined: Thu Dec 29, 2011 6:20 pm

Re: Goon Haven Santa Script

Postby Tocksman » Sat Jan 07, 2012 8:28 pm

Szuwar wrote:
Code: Select all
pi = 3.14159265

Wouldn't be better to use
Code: Select all
math.pi

I know it's just nitpicking but still, it might affect accuracy of santa nades (if it matters).

Probably, although the accuracy didn't matter too much. Like I said, it was a bit of a hackjob. :P
Tocksman
Member
 
Posts: 90
Joined: Mon Jan 02, 2012 10:46 pm

Re: Goon Haven Santa Script

Postby Dany0 » Fri Jan 13, 2012 2:02 pm

File doesn't exist.
Image
User avatar
Dany0
Member
 
Posts: 358
Joined: Mon Dec 26, 2011 7:29 pm

Re: Goon Haven Santa Script

Postby Tocksman » Fri Jan 13, 2012 4:38 pm

Fixed.
Tocksman
Member
 
Posts: 90
Joined: Mon Jan 02, 2012 10:46 pm

Re: Goon Haven Santa Script

Postby jaymin » Mon Jan 16, 2012 9:39 am

sorry but how do we download this?
jaymin
Member
 
Posts: 38
Joined: Wed Dec 28, 2011 1:48 am
Location: Australia

Re: Goon Haven Santa Script

Postby Tocksman » Mon Jan 16, 2012 5:02 pm

jaymin wrote:sorry but how do we download this?

Hit "Select All" in the code box, press CTRL + C (or CMD + C if you're on a Mac), paste it in a text document (notepad or text wrangler is best), and save as a .py file.
Tocksman
Member
 
Posts: 90
Joined: Mon Jan 02, 2012 10:46 pm

Re: Goon Haven Santa Script

Postby jaymin » Tue Jan 17, 2012 1:19 pm

thanks but now im even more confused i cant run this on my server. does anyone know why or how to fix it. thanks
jaymin
Member
 
Posts: 38
Joined: Wed Dec 28, 2011 1:48 am
Location: Australia

Re: Goon Haven Santa Script

Postby PXYC » Sat Jan 21, 2012 3:04 pm

First, put the .py file in your 'scripts' folder of pyspades.
Second, in config.txt, add the name of the file (excluding the .py extension) under 'scripts'.

Ex.


Code: Select all
"scripts" : [
        "welcome",
        "rollback",
        "trusted",
        "autohelp",
        "protect",
        "map_extensions",
        "airstrike",
        "squad",
        "disco",
        "FileName"



Make sure you have commas at the end of each name except the last one.
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: Goon Haven Santa Script

Postby jaymin » Sun Jan 22, 2012 7:37 am

thanks but i all ready knew how to do that PXYC

when i go to run the server it says
Code: Select all
C:\Documents and Settings\Administrator\Desktop\dist>run.exe
('from' command disabled - missing pygeoip)
Traceback (most recent call last):
  File "run.py", line 935, in <module>
  File "C:\Documents and Settings\Administrator\Desktop\dist\scripts\script.py",
line 2
    from commands import add
    ^
IndentationError: unexpected indent

C:\Documents and Settings\Administrator\Desktop\dist>pause
Press any key to continue . . .


my config text looks like this

Code: Select all
{
    "name" : "pyspades server",
    "motd" : [
        "Welcome to %(server_name)s! See /help for new commands.",
        "Map is %(map_name)s by %(map_author)s.",
        "(server powered by pyspades)"
    ],
    "help" : [
        "/SQUAD    Creates or joins a squad, letting you spawn with friends",
        "/STREAK    Shows how many kills in a row you got without dying",
        "/AIRSTRIKE Air support!  Try it out just like that for more details",
        "/INTEL     Tells you who's got the enemy intel",
        "/PING      Shows your ping (how good your connection to the server is)"
    ],
    "tips" : [
        "Here you can deploy airstrikes, form squads and more!  Type /help for info.",
        "The spade does melee damage!  Use it wisely."
    ],
    "tip_frequency" : 5,
    "rules" : [
        "No griefing, no bad words, etc."
    ],
    "max_players" : 32,
    "max_connections_per_ip" : 3,
    "game_mode" : "ctf",
    "cap_limit" : 10,
    "maps" : ["pyspades"],
    "random_rotation" : false,
    "default_time_limit" : 15,
    "advance_on_win" : false,
    "respawn_time" : 15,
    "squad_respawn_time" : 8,
    "squad_size" : 4,
    "auto_squad" : false,
    "master" : true,
    "friendly_fire" : false,
    "grief_friendly_fire_time" : 2,
    "melee_damage" : 100,
    "fall_damage" : true,
    "set_god_build" : false,
    "teamswitch_interval" : 0,
    "votekick_percentage" : 25,
    "votekick_ban_duration" : 15,
    "votekick_public_votes" : true,
    "default_ban_duration" : 1440,
    "speedhack_detect" : true,
    "network_interface" : "",
    "team1" : {
        "name" : "Blue",
        "color" : [0, 0, 255]
    },
    "team2" : {
        "name" : "Green",
        "color" : [0, 255, 0]
    },
    "passwords" : {
        "admin" : ["*****"],
        "trusted" : []
    },
    "ssh" : {
        "enabled" : false,
        "port" : 32887,
        "users" : {
            "user" : "pass"
        }
    },
    "status_server" : {
        "enabled" : false,
        "port" : 32886
    },
    "ban_publish" : {
        "enabled" : false,
        "port" : 32885
    },
    "ban_subscribe" : {
        "enabled" : true,
        "urls" : [
            ["http://www.blacklist.spadille.net/subscribe.json", []]
        ]
    },
    "server_prefix" : "[*]",
    "user_blocks_only" : false,
    "logfile" : "./logs/log.txt",
    "rotate_daily" : true,
    "debug_log" : false,
    "balanced_teams" : 1,
    "login_retries" : 3,
    "irc" : {
        "enabled" : false,
        "nickname" : "pyspades",
        "username" : "pyspades",
        "realname" : "pyspades server bot",
        "server" : "irc.quakenet.org",
        "port" : 6667,
        "channel" : "#pyspades.bots",
        "password" : "",
        "commandprefix" : ".",
        "chatprefix" : ""
    },
    "iocp" : true,
    "profile" : false,

    "scripts" : [
        "welcome",
        "rollback",
        "trusted",
        "autohelp",
        "protect",
        "map_extensions",
        "airstrike",
        "squad",
        "disco",
        "antijerk",
        "savemap",
"script"
    ],
   
    "load_saved_map" : false,
   
    "statistics" : {
        "host" : "localhost",
        "server_name" : "stats server",
        "port" : 32880,
        "password" : "marmelade"
    },
   
    "welcomes" : {
        "mat^2" : "The very likeable mat^2 has entered!"
    },
    "rollback_on_game_end" : false
}


and i have saved the script as script.py in the scripts folder
jaymin
Member
 
Posts: 38
Joined: Wed Dec 28, 2011 1:48 am
Location: Australia

Re: Goon Haven Santa Script

Postby PXYC » Sun Jan 22, 2012 3:47 pm

Is there an indent before the line 'from commands import add'? Pyspades is picky about that, so don't have any weird indents.

Edit:
Download this one: http://www.mediafire.com/?585ig1tmuqb8cqd
I already checked to make sure it works.
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: Goon Haven Santa Script

Postby jaymin » Sun Jan 22, 2012 11:57 pm

thanks PXYC i downloaded that and it worked
jaymin
Member
 
Posts: 38
Joined: Wed Dec 28, 2011 1:48 am
Location: Australia


Return to Script releases



Who is online

Users browsing this forum: No registered users and 3 guests

cron