Downloads containing defenddestroy.mut

Downloads
Name Author Game Mode Rating
TSF with JJ2+ Only: Defend and Destroy ThunDerDraGon Mutator N/A Download file

File preview

#pragma name "Defend and Destroy"

float redBaseX, redBaseY, 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@ redBase, 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];
			int a;
			if (o.isActive && o.eventID == OBJECT::CTFBASE) {
				a = o.var[1];
				o.delete();
				jjOBJ@ newBase = jjObjects[jjAddObject(OBJECT::CTFBASE, o.xPos, o.yPos)];
				newBase.var[1] = a;
				if (o.var[1] == 1) {
					redBaseX = o.xPos;
					redBaseY = o.yPos;
					@redBase = newBase;
				} else {
					blueBaseX = o.xPos;
					blueBaseY = o.yPos;
					@blueBase = newBase;
				}
			}
		}
	}
	if (jjGameTicks%8 == 7 && jjIsServer) {
		jjSTREAM packet;
		packet.push(uint8(base_health));
		packet.push(redBase.special);
		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);
				redBase.special = 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))
		&& ((obj.var[1] == 1 && blueBase.special > 0) || (obj.var[1] == 0 && redBase.special > 0)) && 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((obj.var[1] == 1) ? "/bluescore " + (jjTeamScore[TEAM::BLUE] + 1) : "/redscore " + (jjTeamScore[TEAM::RED] + 1));
					jjChat("/k all");
					jjAlert((obj.var[1] == 1) ? "||Red Base Destroyed, ALL Die" : "|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(redBaseX);
		packet1.push(redBaseY);
		packet1.push(blueBaseX);
		packet1.push(blueBaseY);
		jjSendPacket(packet1, clientID);
	} else {
		uint8 type;
		packet.pop(type);
		if (type == base_position) {
			packet.pop(redBaseX);
			packet.pop(redBaseY);
			packet.pop(blueBaseX);
			packet.pop(blueBaseY);
			@redBase = jjObjects[jjAddObject(OBJECT::CTFBASE, redBaseX, redBaseY - 29)];
			redBase.var[1] = 1;
			@blueBase = jjObjects[jjAddObject(OBJECT::CTFBASE, blueBaseX, blueBaseY - 29)];
			blueBase.var[1] = 0;
			
		} else {
			packet.pop(redBase.special);
			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;
				redBase.special = int(defaultbaseHP*baseHPmulti);
				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 && redBase !is null) {
		canvas.drawString(10, 70, (blueBase.age == 0 && blueBase.special != int(defaultbaseHP*baseHPmulti)) ? "|||BaseHP:| " + blueBase.special + " (R)" : "|||BaseHP:| " + blueBase.special);
		canvas.drawString(10, 90, (redBase.age == 0 && redBase.special != int(defaultbaseHP*baseHPmulti)) ? "||BaseHP:|| " + redBase.special + " (R)" : "||BaseHP:|| " + redBase.special);
	}
	return true;
}