View Single Post
FawFul FawFul's Avatar

JCF Member

Joined: Jun 2007

Posts: 517

FawFul is a forum legendFawFul is a forum legendFawFul is a forum legend

Feb 1, 2013, 04:12 AM
FawFul is offline
Reply With Quote
JJ2 AngelScript Presets!

Hello everyone, I'm starting this official thread to collect some easy preset codes for jj2's AngelScript so people won't have to make it over and over. It's also a tool to help new people understand seperately without being overwhelmed by really big scripts. only post basic preset scripts please, without much addition. for example, my script about giving a random power up to random players. I'm not adding all kinds of gimmicks like 3% chance of shield and fastfire, unlimited ammo on certain weapons and so on: keep it basic / editable.

Everyone is free to post Angelscripts here that quoted. I will try to compile them in this newspost. I made up a few categories myself (name more if you like). Also make sure your code works well. Text covered in red will be the variables you change



Weapon and firing related
Code:
Full Ammo randomizer #1 - Cooba (works multiple times)

int num;

void onFunction0() {
	num = (jjRandom()%9) + 1;
	    p.powerup[num] = true;
	    p.currWeapon = num;
	    if (num > 1) p.ammo[num] = 50;
	    switch (num) {
	    	case 1: p.showText("§1#@@@@@@||||||||B|||||||L|||||||A|||||||S|||||||T|||||||E|||||||R|||||||!"); break;
	    	case 2: p.showText("§1#@@@@@@||||B||||O||U||||N||C||||E||R||||!"); break;
	    	case 3: p.showText("§1#@@@@@@||||I|||C|||E|||!"); break;
	    	case 4: p.showText("§1#@@@@@@||||S||||||||E||||||EK||||||ER|||||||!"); break;
	    	case 5: p.showText("§1#@@@@@@|||R|||||||F|||||||!"); break;
	    	case 6: p.showText("§1#@@@@@@||||T||||||OA||||||ST||||||ER||||||!"); break;
	    	case 7: p.showText("§1#@@@@@@|||T|N|||||T|!"); break;
	    	case 8: p.showText("§1#@@@@@@|||||P|E|||||P|P|||||E|R|||||! |||||||o||r ||||F|I|||||R|E|||||B|A|||||L|L|||||!"); break;
	    	case 9: p.showText("§1#@@@@@@|||||E|||||||L|||||||E|||||||C|||||||T|||||||R|||||||O |||||||B|||||||L|||||||A|||||||S|||||||T|||||||E|||||||R|||||||!"); break;
	    }
}


Full Ammo randomizer #2 - FawFuL (works one time till death)

void onFunction0() {
	if (p.health != 0) {
		switch(jjRandom()%9) {
	  		case 0: p.powerup[1] = true;
				p.showText("§1#@@@@@@||||||||B|||||||L|||||||A|||||||S|||||||T|||||||E|||||||R|||||||!");
				p.currWeapon = WEAPON::BLASTER; break;
		  	case 1: p.ammo[2]=50;
				p.powerup[2] = true;
				p.showText("§1#@@@@@@||||B||||O||U||||N||C||||E||R||||!");
				p.currWeapon = WEAPON::BOUNCER; break;
		  	case 2: p.ammo[3]=50;
				p.powerup[3] = true;
				p.showText("§1#@@@@@@||||I|||C|||E|||!");
				p.currWeapon = WEAPON::ICE; break;
		  	case 3: p.ammo[4]=50;
				p.powerup[4] = true;
				p.showText("§1#@@@@@@||||S||||||||E||||||EK||||||ER||||||S!");
				p.currWeapon = WEAPON::SEEKER; break;
		  	case 4: p.ammo[5]=50;
				p.powerup[5] = true;
				p.showText("§1#@@@@@@|||R|||||||F|||||||!");
				p.currWeapon = WEAPON::RF; break;
		  	case 5: p.ammo[6]=50;
				p.powerup[6] = true;
				p.showText("§1#@@@@@@||||T||||||OA||||||ST||||||ER||||||!");
				p.currWeapon = WEAPON::TOASTER; break;
		  	case 6: p.ammo[7]=50;
				p.showText("§1#@@@@@@|||T|N|||||T|!");
				p.currWeapon = WEAPON::TNT; break;
		  	case 7: p.ammo[8]=50;
				p.powerup[8] = true;
				p.showText("§1#@@@@@@|||||P|E|||||P|P|||||E|R|||||!  |||||||o||r  ||||F|I|||||R|E|||||B|A|||||L|L|||||!");
				p.currWeapon = WEAPON::GUN8; break;
		  	case 8: p.ammo[9]=50;
				p.powerup[9] = true;
				p.showText("§1#@@@@@@|||||E|||||||L|||||||E|||||||C|||||||T|||||||R|||||||O |||||||B|||||||L|||||||A|||||||S|||||||T|||||||E|||||||R|||||||!");
				p.currWeapon = WEAPON::GUN9; break;
			}
		}
	}
}

void onPlayer() {
	if (p.health == 0) jjEnabledASFunctions[TextID Variable] = true; //Unvanishes Textstring 0, Works again upon respawning
}
Object related
Code:
-
Animation related
Code:
-
Sound related
Code:
-
Pallette and Light related
Code:
Day and Night cycle - Sir Elementaler

const uint dnCYCLELENGTH=700; // Day Length.
const uint dnEVERYXTICKS=4; //the amount ticks the pallette refreshes it's colours.
const uint dnINITIALTICKS=256; //determines the initial time of the day. 0 means dawn, 256 means noon, 512 means dusk, 768 means midnight and 1024 means dawn again. All values allowed.
const string dnNIGHTTILESET="Carrot1N.j2t"; // the name of the tileset whose palette should be used in midnight.
jjPAL PaletteNight;

void onLevelLoad()
{
  PaletteNight.load(dnNIGHTTILESET);
}

void onMain()
{
  if(jjGameTicks%dnEVERYXTICKS==0)
  {
    jjPalette=PaletteNight;
    jjPalette.copyFrom(2,252,2,jjBackupPalette,(jjSin(1024*jjGameTicks/dnCYCLELENGTH+dnINITIALTICKS)+1)/2);
    jjPalette.apply();
  }
}
Layer (speed) related
Code:
-
SP and RPG (story) related
Code:
-
Physics and Character changes related
Code:
-
Area & Trigger related
Code:
Punish campers - Grytolle

/** script settings **/
const uint checkCampInterval=80; 		 //how often to check for camping (gameticks)
/*********************/

/** level settings: define camp areas **/
array>> campArea = {
 /* A camparea is a rectangle referred to by its top left and bottom right corner
x,y -----------
    |         |
    |         |
    ----------- a,b                                                              */
//	camparea(x,y)	camparea(a,b)	allowed camp time(gameticks)
	{{29,12}, 		{40,12},      	{500}},      //camparea #0: on top of seek pu
	{{64,05}, 		{101,19},     	{500}}       //camparea #1: the rf area
};
//it doesn't seem like you can have mixed arrays in AS
//so we just put the strings in a separatr array
array campAreaName = {			  
  "above seeks",						  //camparea #0
  "in the rf area"						  //camparea #1
};
/******** end of level settings ********/

/** script globals **/
const uint campAreas = campArea.length(); //save the number of campAreas for easy reference
array campTime(campAreas,0);		  //initialize campTime for all areas as 0 gameticks
/********************/


/** This function checks if a player is in a certain camparea        **/
/** and returns two bools: 1) whether the player is in the camp area **/
/** and 2) whether they have been there for too long                 **/
array isInCampArea(int player, int camparea) {	//use an array to return multiple bools
	array returnThis = {false, false};			//we assume that the player is not camping 
	                                                                 //      (and not for too long)
	int maxCamp = campArea[camparea][2][0];				//store a bunch of information in temporary
	int xCamp = campArea[camparea][0][0];				//variables for easier reading
	int aCamp = campArea[camparea][1][0];
	int yCamp = campArea[camparea][0][1];
	int bCamp = campArea[camparea][1][1];
	int xPos = jjPlayers[player].xPos / 32;
	int yPos = jjPlayers[player].yPos / 32;

	if ((xPos >= xCamp)&&(xPos <= aCamp)&&(yPos >= yCamp)&&(yPos <= bCamp)) {   //is player in camparea?
	   campTime[camparea] += checkCampInterval;
	   returnThis[0] = true; 												    //set bool is camping
	   jjPlayers[player].showText("You are camping " + campAreaName[camparea]); //display text (looks stupid if
	   if (maxCamp < campTime[camparea]) {                                         // camping is checked too often)
		  returnThis[1] = true; 											    //set bool camped for too long
	   }
	}
	else campTime[camparea] = 0;											    //player not camping -> reset timer

	return returnThis;														    //return the (possibly altered) bool
}

/** You guys know what this one does already! **/
void onPlayer() {
	if (jjGameTicks % checkCampInterval == 0) {								//(thanks Artem/Foly)
		for (uint i=0; i < campAreas;i++) {									//loop through all camp areas
		    //^uint to avoid warning "Signed/Unsigned mismatch"
			array isCamping = isInCampArea(p.localPlayerID, i);		//check player and area, store result
			if (isCamping[0]) {												//is current player in camparea #1?
				if (isCamping[1]) {   										//has current player been there for too long?
					jjChat("I camped for too long " + campAreaName[i] + ". Now I die :c");
					p.health = 0;											//kill the player
					campTime[i] = 0;										//reset timer
				}
			}
		}
	}
}

Last edited by FawFul; Feb 3, 2013 at 07:46 AM. Reason: Update