Downloads containing player_collision_example.mut

Downloads
Name Author Game Mode Rating
TSF with JJ2+ Only: Player-to-Player Collision... froducish Mutator N/A Download file

File preview

#pragma require "player_collision_detector_header.asc"
#include "player_collision_detector_header.asc"

COLLIDE::DetectorI@ collisionDetector;

void onLevelLoad() {
	@collisionDetector = COLLIDE::getDetector();
	if (collisionDetector !is null) {
		// setHook actually takes two arguments: function that will be called when a collision is detected (COLLIDE::HOOK@) and the module ID (uint)
		// These arguments are already filled for you (setHook assumes you have a global function named onCollide, and the module ID is set to this script module's ID)
		// However, if you want to provide a different funcion instead then you may do say by calling setHook(myFunction). You could even provide a different ID by calling
		// setHook(myFunction, id), but this is not a good idea!
		collisionDetector.setHook();
		// Don't forget to call this to get the hook actually working.
		collisionDetector.startDetecting();
	}
}

void onCollide(jjPLAYER@ victim, jjPLAYER@ collider, COLLIDE::Collide collision, uint8 eventID) {
	const array<string> labels = {"BULLET", "BULLETPU", "BUMP", "STOMP", "SUGARRUSH", "SPECIALMOVE"};

	const array<string> objectStrings = {
		"N/A",
		"OBJECT::BLASTERBULLET",
		"OBJECT::BOUNCERBULLET",
		"OBJECT::ICEBULLET",
		"OBJECT::SEEKERBULLET",
		"OBJECT::RFBULLET",
		"OBJECT::TOASTERBULLET",
		"OBJECT::FIREBALLBULLET",
		"OBJECT::ELECTROBULLET",
		"OBJECT::BLASTERBULLETPU",
		"OBJECT::BOUNCERBULLETPU",
		"OBJECT::ICEBULLETPU",
		"OBJECT::SEEKERBULLETPU",
		"OBJECT::RFBULLETPU",
		"OBJECT::TOASTERBULLETPU",
		"OBJECT::FIREBALLBULLETPU",
		"OBJECT::ELECTROBULLETPU",
		"OBJECT::FIRESHIELDBULLET",
		"OBJECT::WATERSHIELDBULLET",
		"OBJECT::LIGHTNINGSHIELDBULLET",
		"OBJECT::BULLET"
	};

	const string objectString = (eventID == OBJECT::TNT) ? "OBJECT::TNT" : objectStrings[eventID];
	jjSamplePriority(SOUND::RAPIER_HITCHAR);
	jjAlert("[" + jjLocalPlayers[0].nameUnformatted + "] " + collider.nameUnformatted + " collided with " + victim.nameUnformatted + " via " + labels[collision] + " through event " + objectString);
	
	jjOBJ@ bullet = COLLIDE::getProbableBulletAccordingToThisCollision(victim, collider, eventID); // This function is experimental. Reliance on it is not recommended unless you know what you are doing.
	if (bullet !is null) {
		jjPARTICLE@ particle = jjAddParticle(PARTICLE::STRING);
		if (particle !is null) {
			particle.xPos = bullet.xPos;
			particle.yPos = bullet.yPos;
			particle.string.text = "|hit!";
			particle.ySpeed = -1;
		}
	}

}