Downloads containing chatindicator.mut

Downloads
Name Author Game Mode Rating
JJ2+ Only: Chat IndicatorFeatured Download szmol96 Mutator 9.2 Download file

File preview

#pragma name "Chat Indicator"
#pragma require "chatindicator.j2a"

enum packet_type {packet_chatOpen, packet_chatClose, packet_keyPress};

const array<int> keysToCheck = {0x25, 0x26, 0x27, 0x28, 0x08, 0x20, 0x2E, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6D, 0x6E, 0x6F, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, 0xC0, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, 0xE2};
const int ENTER = 0x0D;
const int ESC = 0x1B;

uint customAnimID = 0;
uint8 frameCounter = 0;
array<bool> isInChatMode(32, false);
array<uint> typing(32, 0);

void findCustomAnimID() { //This function is copied from Bunny Must Die! guns
	while (jjAnimSets[ANIM::CUSTOM[customAnimID]].firstAnim != 0) ++customAnimID;
	
	jjAnimSets[ANIM::CUSTOM[customAnimID]].load(0, "chatindicator.j2a");
}

void sendChatOpen(uint8 playID) {
	jjSTREAM packet;
	packet.push(uint8(packet_chatOpen));
	packet.push(playID);
	jjSendPacket(packet);
}

void sendChatClose(uint8 playID) {
	jjSTREAM packet;
	packet.push(uint8(packet_chatClose));
	packet.push(playID);
	jjSendPacket(packet);
}

void sendKeyPress(uint8 playID) {
	jjSTREAM packet;
	packet.push(uint8(packet_keyPress));
	packet.push(playID);
	jjSendPacket(packet);
}

void onLevelLoad() {
	findCustomAnimID();
}

void onPlayer(jjPLAYER@ p) {
	if (jjKey[jjKeyChat] && !isInChatMode[p.playerID]) {
		if (jjIsServer) {
			isInChatMode[p.playerID] = true;
			sendChatOpen(p.playerID);
		} else {
			sendChatOpen(p.playerID);
		}
	}
	
	if ((jjKey[ENTER] || jjKey[ESC]) && isInChatMode[p.playerID]) {
		if (jjIsServer) {
			isInChatMode[p.playerID] = false;
			sendChatClose(p.playerID);
		} else {
			sendChatClose(p.playerID);
		}
	}
	
	if (isInChatMode[p.playerID]) {
		for (uint8 i = 0; i < keysToCheck.length; i++) {
			if (jjKey[keysToCheck[i]]) {
				typing[p.playerID] = 140;
				sendKeyPress(p.playerID);
			}
		}
	}

	if (jjGameTicks % 7 == 0) {
		if (frameCounter == 11) frameCounter = 0;
		else frameCounter++;
	}
}

void onReceive(jjSTREAM &in packet, int clientID) {
	uint8 type;
	
	packet.pop(type);
	if (jjIsServer) {
		switch (type) {
			case packet_chatOpen:
			{
				uint8 playID;
				packet.pop(playID);
				
				isInChatMode[playID] = true;
				sendChatOpen(playID);
			}
				break;
			case packet_chatClose:
			{
				uint8 playID;
				packet.pop(playID);
				
				isInChatMode[playID] = false;
				sendChatClose(playID);
			}
				break;
			case packet_keyPress:
			{
				uint8 playID;
				packet.pop(playID);
				
				typing[playID] = 140;
				sendKeyPress(playID);
			}
				break;
		}
	} else {
		switch (type) {
			case packet_chatOpen:
			{
				uint8 playID;
				packet.pop(playID);
				
				isInChatMode[playID] = true;
			}
				break;
			case packet_chatClose:
			{
				uint8 playID;
				packet.pop(playID);
				
				isInChatMode[playID] = false;
			}
				break;
			case packet_keyPress:
			{
				uint8 playID;
				packet.pop(playID);
				
				typing[playID] = 140;
			}
				break;
		}
	}
}

bool onDrawHealth(jjPLAYER@ player, jjCANVAS@ canvas) {
	for (uint8 i = 0; i < 32; i++) {
		if (isInChatMode[i] && typing[i] > 0) {
			canvas.drawSprite(jjPlayers[i].xPos - jjLocalPlayers[0].cameraX, (jjPlayers[i].yPos - jjLocalPlayers[0].cameraY) - 40, ANIM::CUSTOM[customAnimID], 0, frameCounter, 0, SPRITE::NORMAL, 0);
		}
		if (typing[i] > 0) typing[i] = typing[i] - 1;
	}
	return false;
}