Code: Show/Hide #include <stdlib.h>
#include <stdio.h> #include "asss.h" /* standard includes */ local Ichat *chat; /* required so you can do the chat->SendArenaMessage */ local Imodman *mm; /* just to keep the same design as other modules */ void TellShipChange(Player *p, int newship, int newfreq) /* this function is of the same type as [b]ShipChangeFunc[/b] is defined * in game.h */ { /* SendArenaMessage requires a pointer to the arena info * (which Player data contains as p->arena), then the text you want */ chat->SendArenaMessage(p->arena, "Player %s changed to ship %d on freq %d", p->name, newship, newfreq); } EXPORT int MM_shiptell(int action, Imodman *_mm, Arena *arena) /* the ONLY thing you need to ever change in EXPORT function is the part * after the MM_. The MM_ is required, but after it is free game (no spaces, * as usual for functions */ { if (action == MM_LOAD) { /* MM_LOAD is the action whenever the dll is first started * up. This is where you load in other interfaces and setup * any initial values */ mm = _mm; chat = mm->GetInterface(I_CHAT, ALLARENAS); /* this will let us use the chat interface */ if (!chat) return MM_FAIL; /* make sure this dll is loaded after the chat dll is, since * our code assumes that [b]chat[/b] is always a valid pointer */ mm->RegCallback(CB_SHIPCHANGE, TellShipChange, ALLARENAS); /* a RegCallback sets up a function to be called whenever * the action you request is done. In game.h, you can see * the CB_SHIPCHANGE callback, so we setup a function * to use it. */ return MM_OK; } else if (action == MM_UNLOAD) /* MM_UNLOAD happens right before your dll is about to be * free'd, so now is the time to dealloc memory and * unregister any interfaces/callbacks we have so the server * won't crash after we leave. Do [b]NOT[/b] assume the server * is shutting down if you get this! */ { /* Just undoing what we did in MM_LOAD */ mm->UnregCallback(CB_SHIPCHANGE, TellShipChange, ALLARENAS); mm->ReleaseInterface(chat); return MM_OK; } return MM_FAIL; } |
Code: Show/Hide chat = mm->GetInterface(I_CHAT, ALLARENAS); |
Code: Show/Hide mm->RegCallback(CB_SHIPCHANGE, onShipChange, ALLARENAS); mm->RegCallback(CB_FREQCHANGE,onFreqChange,ALLARENAS); mm->RegCallback(CB_KILL,onKill,ALLARENAS); |
Code: Show/Hide // helicon.cpp : Defines the entry point for the DLL application. // #include <stdlib.h> #include <string.h> #include <stdio.h> #include "asss.h" //// GLOBAL VARS //// local Ichat *chat; local Imodman *mm; ///////////////////// /* EVENT HANDLER PROTOTYPES *\ (call these anywhere) \* */ void onArenaAction(Arena *a, int action); void onFlagWin(Arena *arena, int freq); void onFlagPos(Arena *arena, int fid, int x, int y, int freq); void onFlagDrop(Arena *arena, Player *p, int count, int neut); void onPlayerAction(Player *p, int action, Arena *arena); void onGoal(Arena *arena, Player *p, int bid, int x, int y); void onFlagPickup(Arena *arena, Player *p, int fid, int oldfreq, int carried); void onBallFire(Arena *arena, Player *p, int bid); void onBallPickup(Arena *arena, Player *p, int bid); void onKill(Arena *arena, Player *killer, Player *killed, int bounty, int flags); void onFreqChange(Player *p, int newfreq); void onShipChange(Player *p, int newship, int newfreq); void onChatMsg(Player *p, int type, Player *target, int freq, const char *text); int startup(); //// EVENT HANDLERS //// void onChatMessage(Player *p, int type, Player *target, int freq, const char *text){ } void onArenaAction(Arena *a, int action){ } void onFlagWin(Arena *arena, int freq){ } void onFlagPos(Arena *arena, int fid, int x, int y, int freq){ } void onFlagDrop(Arena *arena, Player *p, int count, int neut){ } void onPlayerAction(Player *p, int action, Arena *arena){ switch(action){ case PA_CONNECT: break; case PA_DISCONNECT: break; case PA_PREENTERARENA: break; case PA_ENTERARENA: break; case PA_LEAVEARENA: break; } } void onFlagPickup(Arena *arena, Player *p, int fid, int oldfreq, int carried){ } void onGoal(Arena *arena, Player *p, int bid, int x, int y){ } void onBallFire(Arena *arena, Player *p, int bid){ } void onBallPickup(Arena *arena, Player *p, int bid){ } void onKill(Arena *arena, Player *killer, Player *killed, int bounty, int flags){ } void onFreqChange(Player *p, int newfreq){ } void onShipChange(Player *p, int newship, int newfreq){ chat->SendArenaMessage(p->arena, "Player %s changed to ship %d on freq %d", p->name, newship, newfreq); } int startup(){ //TODO:stick you initialization code here return 1; } /********************* MAIN DLL BODY ************************/ EXPORT int MM_botcore(int action, Imodman *mm_, Arena *arena){ if (action == MM_LOAD){ mm = mm_; //shorthand //REGISTER INTERFACES chat = mm->GetInterface(I_CHAT, ALLARENAS); //RUN STARTUP FUNCTION, KILL IF BAD RETURN if(!startup()) return MM_FAIL; if (!chat) return MM_FAIL; //REGISTER CALLBACKS //game.h mm->RegCallback(CB_SHIPCHANGE, onShipChange, ALLARENAS); mm->RegCallback(CB_FREQCHANGE,onFreqChange,ALLARENAS); mm->RegCallback(CB_KILL,onKill,ALLARENAS); //balls.h mm->RegCallback(CB_BALLPICKUP,onBallPickup,ALLARENAS); mm->RegCallback(CB_BALLFIRE,onBallFire,ALLARENAS); mm->RegCallback(CB_GOAL,onGoal,ALLARENAS); //core.h mm->RegCallback(CB_PLAYERACTION, onPlayerAction, ALLARENAS); //flags.h mm->RegCallback(CB_FLAGPICKUP, onFlagPickup, ALLARENAS); mm->RegCallback(CB_FLAGDROP, onFlagDrop, ALLARENAS); mm->RegCallback(CB_FLAGPOS,onFlagPos,ALLARENAS); mm->RegCallback(CB_FLAGWIN,onFlagWin,ALLARENAS); //arena.h mm->RegCallback(CB_ARENAACTION, onArenaAction, ALLARENAS); //chat.h mm->RegCallback(CB_CHATMSG,onChatMessage,ALLARENAS); } else if (action == MM_UNLOAD){ //UNREGISTER THE CALLBACKS //game.h mm->UnregCallback(CB_SHIPCHANGE, onShipChange, ALLARENAS); mm->UnregCallback(CB_FREQCHANGE,onFreqChange,ALLARENAS); mm->UnregCallback(CB_KILL,onKill,ALLARENAS); //balls.h mm->UnregCallback(CB_BALLPICKUP,onBallPickup,ALLARENAS); mm->UnregCallback(CB_BALLFIRE,onBallFire,ALLARENAS); mm->UnregCallback(CB_GOAL,onGoal,ALLARENAS); mm->UnregCallback(CB_PLAYERACTION, onPlayerAction, ALLARENAS); //flags.h mm->UnregCallback(CB_FLAGPICKUP, onFlagPickup, ALLARENAS); mm->UnregCallback(CB_FLAGDROP, onFlagDrop, ALLARENAS); mm->UnregCallback(CB_FLAGPOS,onFlagPos,ALLARENAS); mm->UnregCallback(CB_FLAGWIN,onFlagWin,ALLARENAS); //arena.h mm->UnregCallback(CB_ARENAACTION, onArenaAction, ALLARENAS); //chat.h mm->UnregCallback(CB_CHATMSG,onChatMessage,ALLARENAS); //RELEASE INTERFACES mm->ReleaseInterface(chat); return MM_OK; } return MM_FAIL; //problem } |
Code: Show/Hide void onShipChange(Player *p, int newship, int newfreq){ //chat->SendArenaMessage(p->arena, "Player %s changed to ship %d on freq %d", p->name, newship, newfreq); } |
Code: Show/Hide void (*SendArenaMessage)(Arena *arena, const char *format, ...); |
Code: Show/Hide //// chat.c //// local void SendArenaMessage(Arena *arena, const char *str, ...) { LinkedList set = LL_INITIALIZER; va_list args; get_arena_set(&set, arena); va_start(args, str); v_send_msg(&set, MSG_ARENA, 0, str, args); va_end(args); } |
Code: Show/Hide ...){ |
Warhaven wrote: |
Continuum is written in VB |