Scripting ideas

223 posts Page 6 of 15 First unread post
danhezee
Former Admin / Co-founder
Former Admin / Co-founder
Posts: 1710
Joined: Wed Oct 03, 2012 12:09 am


Changing gamemodes on the fly is something I would like to see. I actually tried to use map extensions to set the gamemode. But babel, arena, and push running at the same time generated errors and I abandoned the project for the time being.
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


first attempt failed... quite badly. I made it able to set the gamemode upon opening a server, but not much after that. Got n'other idea though!
TB_
Post Demon
Post Demon
Posts: 998
Joined: Tue Nov 20, 2012 6:59 pm


I've asked cowie about it, he had no luck. So it's definitively not an easy task.
Other people might be able to help you if you're stuck though, this is something that is sorely needed in aos.
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


ahhhhh.... fell flat on my face.
If anyone think they can make this work
Code: Select all
#mixed.py by thepolm3
"""mixes up gamemodes"""
#ftw
from pyspades.constants import CTF_MODE
from commands import add, admin, alias

game_modes=["babel","irpg","push","ded","tournament","arena","tow","tdm"]

@admin
@alias("gm")
def gamemode(connection, mode):
    if mode.lower() in game_modes:
        connection.protocol.set_gamemode(mode.lower())
        print("Gamemode set to "+mode.upper())
        return "Gamemode set to "+mode.upper()
    else:
        return "Invalid mode"
add(gamemode)

def setGamemode(self, protocol, connection, config, modename):
    exec("import "+modename)
    self.gmp,self.gmc=eval(modename+".apply_script(protocol, connection, config)")
    
def apply_script(protocol,connection,config):

    class MixedConnection(connection):
        #taken straight from server.py

        def on_respawn(self, pos):
            return self.protocol.gmc.on_respawn(self, pos)

        def get_respawn_time(self):
            return self.protocol.gmc.get_respawn_time(self)

        def on_connect(self):
            return self.protocol.gmc.on_connect(self)

        def on_disconnect(self):
            return self.protocol.gmc.on_disconnect(self)

        def on_user_login(self, name, login):
            return self.protocol.gmc.on_user_login(self, name, login)

        def on_join(self):
            return self.protocol.gmc.on_join(self)
        
        def on_login(self, name):
            return self.protocol.gmc.on_login(self, name)
        
        def on_spawn(self, pos):
            return self.protocol.gmc.on_spawn(self, pos)
        
        def on_chat(self, value, global_message):
            return self.protocol.gmc.on_chat(self, value, global_message)
            
        def on_command(self, command, parameters):
            return self.protocol.gmc.on_command(self, command, parameters)
        
        def on_hit(self, hit_amount, hit_player):
            return self.protocol.gmc.on_hit(self, hit_amount, hit_player)
        
        def on_kill(self, killer, type, weapon):
            return self.protocol.gmc.on_kill(self, killer, type, weapon)
        
        def on_team_join(self, team):
            return self.protocol.gmc.on_team_join(self,team)

        def on_team_leave(self):
            return self.protocol.gmc.on_team_leave(self)
        
        def on_tool_set_attempt(self, tool):
            return self.protocol.gmc.on_tool_set_attempt(self, tool)
        
        def on_tool_changed(self, tool):
            return self.protocol.gmc.on_tool_changed(self, tool)
        
        def on_grenade(self, time_left):
            return self.protocol.gmc.on_grenade(self, time_left)
        
        def on_grenade_thrown(self, grenade):        
            return self.protocol.gmc.on_grenade_thrown(self, grenade)
        
        def on_block_build_attempt(self, x, y, z):
            return self.protocol.gmc.on_block_build_attempt(self, x, y, z)
        
        def on_block_build(self, x, y, z):
            return self.protocol.gmc.on_block_build(self, x, y, z)
        
        def on_line_build_attempt(self, points):
            return self.protocol.gmc.on_line_build_attempt(self,points)
        
        def on_line_build(self, points):
            return self.protocol.gmc.on_line_build(self,points)
        
        def on_chat_sent(self, chat, global_message):
            return self.protocol.gmc.on_chat_sent(self,chat, global_message)
        
        def on_block_destroy(self, x, y, z, mode):
            return self.protocol.gmc.on_block_destroy(self, x, y, z, mode)
            
        def on_block_removed(self, x, y, z):
            return self.protocol.gmc.on_block_removed(self, x,  y, z)
        
        def on_refill(self):
            return self.protocol.gmc.on_refill(self)
        
        def on_color_set_attempt(self, color):
            return self.protocol.gmc.on_color_set_attempt(self, color)
        
        def on_color_set(self, color):
            return self.protocol.gmc.on_color_set(self, color)

        def on_color_set_attempt(self, color):
            return self.protocol.gmc.on_color_set_attempt(self,color)

        def on_flag_take(self):
            return self.protocol.gmc.on_flag_take(self)
        
        def on_flag_capture(self):
            return self.protocol.gmc.on_flag_capture(self)
        
        def on_flag_drop(self):
            return self.protocol.gmc.on_flag_drop(self)
        
        def on_hack_attempt(self, reason):
            return self.protocol.gmc.on_hack_attempt(self, reason)

        def on_position_update(self):
            return self.protocol.gmc.on_position_update(self)
        
        def on_input_update(self):
            return self.protocol.gmc.on_input_update(self)
        
        def on_orientation_update(self, x, y, z):
            return self.protocol.gmc.on_orientation_update(self,x,y,z)

        def on_position_update(self):
            return self.protocol.gmc.on_position_update(self)

        def on_animation_update(self, jump, crouch, sneak, sprint):
            return self.protocol.gmc.on_animation_update(self, jump, crouch, sneak, sprint)

        def on_weapon_set(self, value):
            return self.protocol.gmc.on_weapon_set(self, value)
        
        def on_fall(self, damage):
            return self.protocol.gmc.on_fall(self, damage)
        
        def on_reset(self):
           return self.protocol.gmc.on_reset(self)

    class MixedProtocol(protocol):
        import arena
        gmp,gmc = arena.apply_script(protocol,connection,config)
        game_mode=CTF_MODE
        
        def set_gamemode(self, mode):
            setGamemode(self, protocol, connection, config, mode)

        def on_game_end(self):
            return self.gmp.on_game_end(self)
    
        def on_world_update(self):
            return self.gmp.on_world_update(self.gmp)
    
        def on_map_change(self, map):
            return self.gmp.on_map_change(self, map)

        def on_advance(self, map):
            return self.gmp.on_advance(self, map)

        def on_ban(self, player, instigator, ban):
            return self.gmp.on_ban(self, player, instigator, ban)

        def on_ban_attempt(self, player, instigator, ban):
            return self.gmp.on_ban_attempt(self, player, instigator, ban)

        def on_base_spawn(self, x,y,z, base, entity_id):
            return self.gmp.on_base_spawn(self, x,y,z, base, entity_id)

        def on_connect(self, player):
            return self.gmp.on_connect(self, player)

        def on_disconnect(self, player):
            return self.gmp.on_disconnect(self, player)

        def on_cp_capture(self, territory):
            return self.gmp.on_cp_capture(self, territory)

        def on_flag_spawn(self, x,y,z,flag, entity_id):
            return self.gmp.on_flag_spawn(self, x,y,z, flag, entity_id)

        def on_map_leave(self):
            return self.gmp.on_map_leave(self)

        def on_update_entity(self, entity):
            return self.gmp.on_update_entity(self,entity)

        def get_cp_entities(self):
            return self.gmp.get_cp_entities(self)
    return MixedProtocol,MixedConnection
lol
TB_
Post Demon
Post Demon
Posts: 998
Joined: Tue Nov 20, 2012 6:59 pm


^ so that's the gamemode changer? If so, then what is it that you have problems with?
Jdrew
Mapper
Mapper
Posts: 4808
Joined: Tue Oct 30, 2012 10:48 pm


Intel with intel, like a coordinate of a enemy play or a message
danhezee
Former Admin / Co-founder
Former Admin / Co-founder
Posts: 1710
Joined: Wed Oct 03, 2012 12:09 am


What I found when I was working on the variety server was the protocol overrides are set up correctly. They would check to see if the map extension was set to true for that gamemode but the connection overrides didnt make that check and would cause conflict.

Probably would have to modify every gamemode script you want to have on your server to check in the connection to see if the gamemode is set to true.

Some maps are made exclusively for a gamemode, that is why I wanted to toggle the gamemodes through map extensions. However, some maps work very well with with multiple gamemodes. So they are pros and cons to changing via map extensions.
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


yeah... thats the principle. I want a script that can change the gamemode without having to have all scripts active and editing them all (because that would be way too much work)
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


third attemp failed XD
Code: Select all

#mixed.py by thepolm3
"""mixes up gamemodes"""
#ftw
from pyspades.constants import CTF_MODE
from commands import add, admin, alias

game_modes=["babel","irpg","push","ded","tournament","arena","tow","tdm"]

@admin
@alias("gm")
def gamemode(connection, mode):
    if mode.lower() in game_modes:
        connection.protocol.set_gamemode(mode.lower())
        print("Gamemode set to "+mode.upper())
        return "Gamemode set to "+mode.upper()
    else:
        return "Invalid mode"
add(gamemode)

def setGamemode(self, protocol, connection, config, modename):
    exec("import "+modename)
    self.gmp,self.gmc=eval(modename+".apply_script(protocol, connection, config)")

def apply_script(protocol,connection,config):

    class MixedConnection(connection):
       def __repr__(self):
           return repr(self.protocol.gmc)

    class MixedProtocol(protocol):
        gmp,gmc = protocol,connection
        game_mode=CTF_MODE
        
        def set_gamemode(self, mode):
            setGamemode(self, protocol, connection, config, mode)

        def __repr__(self):
            return repr(self.protocol.gmp)
    return MixedProtocol,MixedConnection

phew this is hard!
Handles
League Participant
League Participant
Posts: 1087
Joined: Tue Jan 08, 2013 9:46 pm


Keep up the good work!
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


ty ^^
TB_
Post Demon
Post Demon
Posts: 998
Joined: Tue Nov 20, 2012 6:59 pm


thepolm3 wrote:
ty ^^
hows it going thepolm? Been working hard or have you burned out. Blue_Happy3
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


yeah... I think this might be a hard task, perhaps something that merits going into the code of pyspades itself, and maybe not just making an external script.
TB_
Post Demon
Post Demon
Posts: 998
Joined: Tue Nov 20, 2012 6:59 pm


thepolm3 wrote:
yeah... I think this might be a hard task, perhaps something that merits going into the code of pyspades itself, and maybe not just making an external script.
oh, I see. That's unfortunate.
Sucks that making scripts like this has its limits, I still hope it's possible though, maybe some other scripters knows a way around?
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


yeah :)
223 posts Page 6 of 15 First unread post
Return to “Ideas / Requests”

Who is online

Users browsing this forum: No registered users and 6 guests