Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
<c> zombie

 
Post new topic   Reply to topic Printable version
 View previous topic  >goal< spree module Post :: Post <py> autoprize  View next topic  
Author Message
Animate Dreams
Gotta buy them all!
(Consumer whore)


Age:36
Gender:Gender:Male
Joined: May 01 2004
Posts: 821
Location: Middle Tennessee
Offline

PostPosted: Wed May 09, 2007 6:46 pm    Post subject: <c> zombie Reply to topic Reply with quote

I've been working on event modules for AS3, and I just got my zombie module to actually run a game without error today, so here it is. Hosting instructions are in the .c file at the moment. Even though it works, it isn't pretty, so I'll hopefully update this soon. In the .rar I've included the .c file, the .mk file, a .so file for asss-1.4.3, and a sample event.conf. As I update the module, I'll include better documentation(like a readme file) than what it has now.

I already know the next changes I'm going to make. Next I'll work on being able to override default/event.conf settings by adding parameters to the zombiestart command. Also, the purpose of the start() and stop() functions probably isn't obvious, but I eventually plan to write an event manager module or something like that, to theoretically make it a bit easier for event refs and the like to run events. It would also help to make the events automated - I could write an event manager that would work kind of like the event bot that everyone's familiar with on MERV, with elim, conquer, etc. - it would display all loaded events, take a vote, and then run the event. Basically, I just want the event to be able to be started and stopped by other modules(like was talked about in this topic: http://forums.minegoboom.com/viewtopic.php?t=7193 ), and eventually, I'll have this module capable of doing that.

Here's the code, any criticism would be appreciated(except from Brain):
Code: Show/Hide
#include "asss.h"


/* Interfaces */
local Imodman *mm;
local Ichat *chat;
local Igame *game;
local Iplayerdata *pd;
local Icmdman *cmd;
local Iconfig *cfg;
local Iarenaman *aman;
local Imainloop *ml;


/* Player data */
typedef struct ZombieData
{
    int died;
} ZombieData;

local int playerKey;


/* Arena data */
typedef struct EventData
{
    int isRunning;

    int humanSpawnX;
    int humanSpawnY;
    int zombieSpawnX;
    int zombieSpawnY;

    int humanShip;
    int zombieShip;
} EventData;

local int arenaKey;


/* Function Prototypes */
local void Czombiestart(const char *command, const char *params, Player *p, const Target *target);
local void Czombiestop(const char *command, const char *params, Player *p, const Target *target);

local void Kill(Arena *arena, Player *killer, Player *killed, int bounty, int flags, int *pts, int *green);
local void ShipChange(Player *p, int newship, int newfreq);

local void start(Arena *arena);
local void stop(Arena *arena);
local int CountHumans(Arena *arena);


/* Functions */
local void start(Arena *arena)
{
    // Initializing all event data
    ZombieData *zData;
    EventData *eData = P_ARENA_DATA(arena, arenaKey);

    // Check to make sure game isn't running
    if(eData->isRunning == TRUE)
    {
//        chat->SendMessage(p, "Event is already running, Zombie event canceled.");
        return;
    }
    eData->isRunning = TRUE;

    // Arena data initialization
    eData->humanSpawnX = cfg->GetInt(arena->cfg, "Zombie", "HumanSpawn-X", 512);
    eData->humanSpawnY = cfg->GetInt(arena->cfg, "Zombie", "HumanSpawn-Y", 512);
    eData->zombieSpawnX = cfg->GetInt(arena->cfg, "Zombie", "ZombieSpawn-X", 512);
    eData->zombieSpawnY = cfg->GetInt(arena->cfg, "Zombie", "ZombieSpawn-Y", 512);

    eData->humanShip = cfg->GetInt(arena->cfg, "Zombie", "HumanShip", SHIP_WARBIRD) - 1;    // Err, fix because players will want to write
    eData->zombieShip = cfg->GetInt(arena->cfg, "Zombie", "ZombieShip", SHIP_SPIDER) - 1;   // HumanShip = 1 in conf, AS3 uses 0 for WB


    // Continue with Zombie initialization
    // This stuff is needed just to loop through players and warp correctly.
    Player *tempPlayer;
    Link *link;
    Target t;
    t.type = T_PLAYER;

    pd->Lock(); // Lock, necessary when cycling through players
    FOR_EACH_PLAYER_P(tempPlayer, zData, playerKey) // Cycles through each player, I use this to set playerdata and warp.
    {
        zData->died = FALSE;

        if (tempPlayer->p_freq == 0) // If human...
        {
            t.u.p = tempPlayer;
            game->WarpTo (&t, eData->humanSpawnX, eData->humanSpawnY); // Warp to human spawn.
        }
        else if (tempPlayer->p_freq == 1) // Repeat for Zombies.
        {
            t.u.p = tempPlayer; // I still don't understand t.u.p.
            game->WarpTo (&t, eData->zombieSpawnX, eData->zombieSpawnY);
        }
    }
    pd->Unlock(); // End cycle and lock

    chat->SendArenaSoundMessage(arena, SOUND_GOAL, "GOGOGO!");

    mm->RegCallback(CB_KILL, Kill, arena);
    mm->RegCallback(CB_SHIPCHANGE, ShipChange, arena);
}

local void stop(Arena *arena)
{
    EventData *eData = P_ARENA_DATA(arena, arenaKey);

    chat->SendArenaMessage(arena, "Game over. Searching for survivors....");

    Player *temp;
    Link *link;
    pd->Lock();
    FOR_EACH_PLAYER(temp)
    {
        if (temp->p_ship == eData->humanShip)
            chat->SendArenaMessage(temp->arena, "%s has survived!", temp->name);
    }
    pd->Unlock();

    eData->isRunning = FALSE;

    mm->UnregCallback(CB_SHIPCHANGE, ShipChange, arena);
    mm->UnregCallback(CB_KILL, Kill,    arena);
}

local int CountHumans(Arena *arena)
{
    int players = 0;
    EventData *eData = P_ARENA_DATA(arena, arenaKey);

    Player *temp;
    Link *link;
    pd->Lock();
    FOR_EACH_PLAYER(temp)
    {
        if (temp->p_ship == eData->humanShip)
            players++;
    }
    pd->Unlock();

    return players;
}


/* Commands */

/* ?zombiestart: starts the Zombie event */
local void Czombiestart(const char *command, const char *params, Player *p, const Target *target)
{
    start(p->arena);
}
local helptext_t zombiestart_help =
"Module: zombie:zombie\n"
"Possible Targets: none\n"
"Arguments: none\n"
"Starts the Zombie event.";


/* ?zombiestop: stops the Zombie event */
local void Czombiestop(const char *command, const char *params, Player *p, const Target *target)
{
    stop(p->arena);
}
local helptext_t zombiestop_help =
"Module: zombie:zombie\n"
"Possible Targets: none\n"
"Arguments: none\n"
"Stops the Zombie event.";


/* Callbacks */
local void Kill(Arena *arena, Player *killer, Player *killed, int bounty, int flags, int *pts, int *green)
{
    ZombieData *zData = PPDATA(killed, playerKey);
    EventData *eData = P_ARENA_DATA(arena, arenaKey);

    if (zData->died == TRUE)
        return;

    if(zData->died == FALSE)
    {
        zData->died = TRUE;

        game->SetFreqAndShip(killed, eData->zombieShip, 1);

        chat->SendArenaSoundMessage(killed->arena, SOUND_SCREAM,
                "%s dies a miserable, horrible death at the hands of a Zombie!", killed->name);
    }

    if (CountHumans(arena) <= 1)
        stop(arena);
}

local void ShipChange(Player *p, int newship, int newfreq)
{
    ZombieData *zData = PPDATA(p, playerKey);
    EventData *eData = P_ARENA_DATA(p->arena, arenaKey);

    if (newship == eData->humanShip)
    {
        zData->died = FALSE;
        game->SetFreq(p, 0);
    }
    else if (newship == eData->zombieShip)
    {
        zData->died = TRUE;
        game->SetFreq(p, 1);
    }
}


/* Loading and unloading */
EXPORT int MM_zombie(int action, Imodman *mm_, Arena *arena)
{
    if (action == MM_LOAD)
    {
        mm = mm_;
        chat = mm->GetInterface(I_CHAT, ALLARENAS);
        game = mm->GetInterface(I_GAME, ALLARENAS);
        pd = mm->GetInterface(I_PLAYERDATA, ALLARENAS);
        cmd = mm->GetInterface(I_CMDMAN, ALLARENAS);
        cfg = mm->GetInterface(I_CONFIG, ALLARENAS);
        aman = mm->GetInterface(I_ARENAMAN, ALLARENAS);
        ml = mm->GetInterface(I_MAINLOOP, ALLARENAS);

        if (!chat || !game || !pd || !cmd || !cfg || !aman || !ml)
            return MM_FAIL;

        return MM_OK;
    }
    else if (action == MM_UNLOAD)
    {
        mm->ReleaseInterface(ml);
        mm->ReleaseInterface(aman);
        mm->ReleaseInterface(cfg);
        mm->ReleaseInterface(cmd);
        mm->ReleaseInterface(pd);
        mm->ReleaseInterface(game);
        mm->ReleaseInterface(chat);

        return MM_OK;
    }
    else if (action == MM_ATTACH)
    {
        playerKey = pd->AllocatePlayerData(sizeof(ZombieData));
        if (playerKey == -1)
            return MM_FAIL;

        arenaKey = aman->AllocateArenaData(sizeof(EventData));
        if (arenaKey == -1)
            return MM_FAIL;

        cmd->AddCommand("zombiestart", Czombiestart, arena, zombiestart_help);
        cmd->AddCommand("zombiestop", Czombiestop, arena, zombiestop_help);

        return MM_OK;
    }
    else if (action == MM_DETACH)
    {
        cmd->RemoveCommand("zombiestop", Czombiestop, arena);
        cmd->RemoveCommand("zombiestart", Czombiestart, arena);

        aman->FreeArenaData(arenaKey);
        pd->FreePlayerData(playerKey);

        return MM_OK;
    }
    return MM_FAIL;
}


Oh yeah, I meant to add, the ShipChange callback is in case a staffer ?setships someone into game. I should probably document that. Is that an alright way of doing things? I was worried about it going off after someone got zombified, but it didn't give me any problems.




zombie.rar - 11.45 KB
File downloaded or viewed 39 time(s)


Last edited by Animate Dreams on Wed May 09, 2007 7:00 pm, edited 1 time in total
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website AIM Address MSN Messenger
tcsoccerman
Server Help Squatter


Age:31
Gender:Gender:Male
Joined: Jan 15 2007
Posts: 694
Location: Atlantis
Offline

PostPosted: Wed May 09, 2007 6:51 pm    Post subject: Reply to topic Reply with quote

nice
Back to top
View users profile Send private message Add User to Ignore List Send email AIM Address
Smong
Server Help Squatter


Joined: 1043048991
Posts: 0x91E
Offline

PostPosted: Thu May 17, 2007 2:55 pm    Post subject: Reply to topic Reply with quote

Unless you lock the arena players can just change back to a human ship and the module will set them back as a human.

Also might want to add the PlayerAction callback to check if you should stop the game when players leave.

If you don't know python you should look into it, something like zombies will be very easy to make in python. But I already made zombies in py, it's in my port of the merv elim bot (the game is called "spiders").
_________________
ss news
Back to top
View users profile Send private message Add User to Ignore List Visit posters website MSN Messenger
Animate Dreams
Gotta buy them all!
(Consumer whore)


Age:36
Gender:Gender:Male
Joined: May 01 2004
Posts: 821
Location: Middle Tennessee
Offline

PostPosted: Mon May 21, 2007 2:35 pm    Post subject: Reply to topic Reply with quote

Smong wrote:
Unless you lock the arena players can just change back to a human ship and the module will set them back as a human.

Also might want to add the PlayerAction callback to check if you should stop the game when players leave.

If you don't know python you should look into it, something like zombies will be very easy to make in python. But I already made zombies in py, it's in my port of the merv elim bot (the game is called "spiders").


Right now, the module is meant to be hosted, and I explain in the hosting instructions(commented at the top of the actual copy of the module, I cut the block of comments out when I copied/pasted the code into the post) that the arena must be locked. But eventually I plan to make it slightly more automated, just to save the hoster some work, I've just not gotten around to it yet.

Again, since it's meant to be hosted, I don't feel the need to handle the case of players leaving. I just can't really figure out why I'd need to. Though I probably do need to modify the stop() to do different things based on whether the event finished normally or not.

I've never sat down to learn Python or anything, but I probably know as much as I need to for this. Maybe it would be different with more complex modules, but when I've tried Python in the past, I was able to use it even though I've had no exposure to Python. The syntax threw me off for a bit, but I stared it down and figured it out before too long. And I've seen your module before, and used it... I remember having problems with it, but I'm pretty sure I remember it being my fault, as well. But I'm making this for a different reason. For one, I'm hoping it will be more customizable, and it'll have an interface. So by the time I'm done, I'm hoping it will be able to run itself, like your module does, concurrently with any other event modules that happen to be loaded in the arena, but also hosted by itself. Right now, it works in my head, but it's hard to explain - which, unfortunately, probably means it will be hard to program or even conceptualize properly.

But I actually wrote this module mainly to teach someone else how to write modules. I figured it'd be easiest to teach him by actually going through it myself with him. It helps me learn, as well. Eventually I'd like to write several event modules, since AS3 doesn't have anywhere near the number of events TWCore or MERV has.
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website AIM Address MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> ASSS Custom Projects All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 687 page(s) served in previous 5 minutes.

phpBB Created this page in 0.487737 seconds : 31 queries executed (79.8%): GZIP compression disabled