Name | Author | Game Mode | Rating | |||||
---|---|---|---|---|---|---|---|---|
Defend and Destroy | ThunDerDraGon | Mutator | N/A |
#pragma name "Defend or Destroy"
float blueBaseX, blueBaseY;
float baseHPmulti = 1;
int globalCounter;
const int defaultbaseHP = 300;
const string FILENAME = "DD_SETTINGS.ASDAT";
enum packet_type {base_position, base_health};
jjOBJ@ blueBase;
void onLevelLoad() {
if (!jjIsServer) {
jjSTREAM packet;
jjSendPacket(packet);
} else {
jjSTREAM settings(FILENAME);
settings.pop(baseHPmulti);
}
}
void onMain() {
if (jjGameTicks == 1) {
jjObjectPresets[OBJECT::CTFBASE].behavior = DestructibleBase();
jjObjectPresets[OBJECT::CTFBASE].scriptedCollisions = true;
jjObjectPresets[OBJECT::CTFBASE].playerHandling = HANDLING::SPECIAL;
jjObjectPresets[OBJECT::CTFBASE].bulletHandling = HANDLING::DETECTBULLET;
for (int i = 1; i < jjObjectCount; i++) {
jjOBJ@ o = jjObjects[i];
if (o.isActive && o.eventID == OBJECT::CTFBASE) {
if (o.var[1] == 0) {
jjOBJ@ newBase = jjObjects[jjAddObject(OBJECT::CTFBASE, o.xPos, o.yPos)];
newBase.var[1] = 0;
blueBaseX = o.xPos;
blueBaseY = o.yPos;
@blueBase = newBase;
}
o.delete();
}
}
}
if (jjGameTicks%8 == 7 && jjIsServer) {
jjSTREAM packet;
packet.push(uint8(base_health));
packet.push(blueBase.special);
packet.push(baseHPmulti);
jjSendPacket(packet);
}
if (jjIsServer) {
if (globalCounter > 0) {
globalCounter--;
if (globalCounter == 3*70)
jjAlert("|||New Round Starts in 3..", true, STRING::MEDIUM);
else if (globalCounter == 2*70)
jjAlert("|||2..", true, STRING::MEDIUM);
else if (globalCounter == 1*70)
jjAlert("|1..", true, STRING::MEDIUM);
else if (globalCounter == 1) {
jjAlert("GO!", true, STRING::MEDIUM);
blueBase.special = int(defaultbaseHP*baseHPmulti);
}
}
}
}
class DestructibleBase : jjBEHAVIORINTERFACE {
void onBehave(jjOBJ@ obj) {
if (obj.age > 0) obj.age--;
if (obj.state == STATE::START) {
obj.yPos += 12;
obj.special = int(defaultbaseHP*baseHPmulti);
obj.determineCurAnim(ANIM::FLAG, 1);
obj.direction = ((obj.xPos/32) < jjLayerWidth[4]/2) ? -1 : 1;
obj.state = STATE::IDLE;
} else if (obj.state == STATE::IDLE) {
if (obj.age == 0 && obj.special < int(defaultbaseHP*baseHPmulti) && jjIsServer)
if (++obj.counter%140 == 139)
if (obj.special + int(defaultbaseHP*baseHPmulti/50) < defaultbaseHP*baseHPmulti)
obj.special += int(defaultbaseHP*baseHPmulti/50);
else
obj.special = int(defaultbaseHP*baseHPmulti);
}
}
void onDraw(jjOBJ@ obj) {
obj.frameID = (obj.var[1] == 0) ? 0 : 1;
obj.determineCurFrame();
obj.draw();
jjTEXTAPPEARANCE appearance;
appearance.align = STRING::CENTER;
appearance.spacing = -1;
appearance.pipe = STRING::SPECIALSIGN;
jjDrawSprite(obj.xPos - 15, obj.yPos + 25, ANIM::PICKUPS, 41, 0, 0, SPRITE::NORMAL, 0, -10);
jjDrawString(obj.xPos + 5, obj.yPos + 27, "||||" + obj.special, STRING::SMALL, appearance, 0, SPRITE::PALSHIFT, 0, -10);
jjDrawResizedSpriteFromCurFrame(obj.xPos, obj.yPos, obj.curFrame,
(1+((jjGameTicks%150)/220.f))*obj.direction,
1+((jjGameTicks%150)/220.f),
SPRITE::BLEND_NORMAL, 150 - ((jjGameTicks%150)));
}
bool onObjectHit(jjOBJ@ obj, jjOBJ@ bullet, jjPLAYER@ player, int force) {
if (bullet !is null && jjGameState != GAME::STOPPED && jjGameState != GAME::PREGAME &&
((jjPlayers[bullet.creatorID].team == TEAM::RED && obj.var[1] == 0) || (jjPlayers[bullet.creatorID].team == TEAM::BLUE && obj.var[1] == 1))
&& jjPlayers[bullet.creatorID].blink == 0) {
obj.justHit = 5;
obj.age = 70*4;
bullet.state = STATE::EXPLODE;
if (jjIsServer && globalCounter == 0) {
if ((bullet.eventID >= OBJECT::BLASTERBULLET && bullet.eventID < OBJECT::BLASTERBULLETPU) || bullet.eventID == OBJECT::RFBULLETPU) {
if (obj.special > 0)
obj.special -= 1;
} else if (obj.special >= 1)
obj.special -= (obj.special == 1) ? 1 : 2;
if (obj.special == 0) {
jjChat("/bluescore " + (jjTeamScore[TEAM::BLUE] + 1));
jjChat("/k all");
jjAlert("|Blue Base Destroyed, ALL Die", true, STRING::MEDIUM);
globalCounter = 70*10;
}
}
}
return true;
}
}
void onReceive(jjSTREAM &in packet, int clientID) {
if (jjIsServer) {
jjSTREAM packet1;
packet1.push(uint8(base_position));
packet1.push(blueBaseX);
packet1.push(blueBaseY);
jjSendPacket(packet1, clientID);
} else {
uint8 type;
packet.pop(type);
if (type == base_position) {
packet.pop(blueBaseX);
packet.pop(blueBaseY);
@blueBase = jjObjects[jjAddObject(OBJECT::CTFBASE, blueBaseX, blueBaseY - 29)];
blueBase.var[1] = 0;
} else {
packet.pop(blueBase.special);
packet.pop(baseHPmulti);
}
}
}
void onChat(int clientID, string &in text, CHAT::Type chatType) {
array<string> results;
if (jjRegexIsValid(text) && (clientID == 0 || jjPlayers[clientID].isAdmin) && jjIsServer) {
if (jjRegexMatch(text, "!basehpmultiplier" + """\s([+-]?([0-9]*[.])?[0-9]+)""", results, true)) {
float num = parseFloat(results[1]);
if (num >= 0.5 && num <= 5 && baseHPmulti != num) {
baseHPmulti = num;
blueBase.special = int(defaultbaseHP*baseHPmulti);
jjConsole("Base Hitpoints Multiplier has been set to |||" + baseHPmulti, true);
jjSTREAM settings;
settings.push(baseHPmulti);
settings.save(FILENAME);
} else {
if (baseHPmulti == num)
jjConsole("|Base Hitpoints Multiplier has already been set to " + baseHPmulti, true);
else
jjConsole("|Base Hitpoints Multiplier must be a value equal to or between 0.5 and 5", true);
}
}
}
}
bool onDrawGameModeHUD(jjPLAYER@ player, jjCANVAS@ canvas) {
canvas.drawString(10, 20, "|||" + jjTeamScore[TEAM::BLUE] + "/" + jjMaxScore);
canvas.drawString(10, 40, "||" + jjTeamScore[TEAM::RED] + "/" + jjMaxScore);
if (blueBase !is null) {
canvas.drawString(10, 70, (blueBase.age == 0 && blueBase.special != int(defaultbaseHP*baseHPmulti)) ? "|||BaseHP:| " + blueBase.special + " (R)" : "|||BaseHP:| " + blueBase.special);
}
return true;
}
Jazz2Online © 1999-INFINITY (Site Credits). We have a Privacy Policy. Jazz Jackrabbit, Jazz Jackrabbit 2, Jazz Jackrabbit Advance and all related trademarks and media are ™ and © Epic Games. Lori Jackrabbit is © Dean Dodrill. J2O development powered by Loops of Fury and Chemical Beats.
Eat your lima beans, Johnny.