Feb 1, 2013, 04:12 AM | |
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 } Code:
- Code:
- Code:
- 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(); } } Code:
- Code:
- Code:
- 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 |
Feb 1, 2013, 04:33 AM | |
![]()
Great idea for a thread.
Allow me to submit my own ammo randomizer, though! Not that anything is technically wrong with Faw's (very good and ambitious first script), of course. Code:
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; } } |
Feb 1, 2013, 06:33 AM | |
I would really love to see a Respawn trigger crate script for any ID explained, short and with variables!
__________________
|
Feb 1, 2013, 07:31 AM | |
I want something else than JCF for this too, something easier to look over and with search functions. Meanwhile, best is to use this till there is another solution.
__________________
|
Feb 1, 2013, 09:11 AM | ||
Quote:
1) Trigger crates only query their Trigger ID when they're destroyed, so it's a question of the xOrg/yOrg bitfeld, not setting some other property to the desired ID. 2) Unless you're doing a single player level, you should probably use a generator object instead, so that the trigger crate is shared throughout the server. Otherwise you run the risk of the crate only existing locally and thus only changing a trigger locally. If you still want such a script, though, I'd be tempted to do something like this pseudocode: Code:
class myTriggerCrateGenerator: uint16 xOrg; uint16 yOrg; uint respawnCounter = 0; uint respawnDelay; int object = 0; void myTriggerCrateGenerator(uint16 x, uint16 y, uint d) { xOrg = x*32; yOrg = y*32; respawnDelay = d; } void do() { switch (respawnCounter) { case 0: jjOBJ@ o = jjObjects[object]; if (!(o.isActive && o.eventID == OBJECT::TRIGGERCRATE && o.xOrg == xOrg && o.yOrg == yOrg)) respawnCounter = 1; break; case respawnDelay: //this doesn't work, but in pseudo-code it does! respawnCounter = 0; object = jjAddObject(OBJECT::TRIGGERCRATE, xOrg, yOrg); break; default: ++respawnCounter; } } |
Feb 1, 2013, 12:39 PM | ||
Quote:
The thing i just want is to regenerate any trigger crate ID that is not just ID 31 that also works in MP (as in works as well as a normal trigger crate). I've never scripted before this update, i also have no idea what psuedo-code is. I just keep wondering if this is possible for MP, and i still haven't got clear answers yet.
__________________
|
Feb 1, 2013, 12:53 PM | |
Feb 1, 2013, 02:58 PM | ||
Quote:
Code:
formatInt(value,"l");
__________________
I am an official JJ2+ programmer and this has been an official JJ2+ statement. |
Feb 1, 2013, 11:06 PM | ||
Quote:
![]() Either i did it wrong or it isn't build in with jj2+.
__________________
[13:07:13] *** Foly is on a KILLING SPREE! [13:07:14] *** you killed yourself [13:07:14] *** Foly was looking good but died instead... |
Feb 2, 2013, 01:37 AM | |
I hadn't been sure either so I had checked it before I posted that, it works just fine. Try something like this (in multiplayer) to test:
Code:
void onPlayer() { jjChat(formatInt(jjGameTicks,"l")); }
__________________
I am an official JJ2+ programmer and this has been an official JJ2+ statement. |
Feb 2, 2013, 01:43 AM | ||
Quote:
![]()
__________________
[13:07:13] *** Foly is on a KILLING SPREE! [13:07:14] *** you killed yourself [13:07:14] *** Foly was looking good but died instead... |
Feb 2, 2013, 02:49 AM | |
I found this for syntax highlighting of AngelScript in Notepad++.
I just dropped it in the program folder\plugins\APIs, and then I am able to select it for a specific file by clicking Language -> AngelScript. It would be nicer if it could be made so that it automatically identifies .j2as files as AngelScript, but I couldn't get it to work and I'm not really intending to try coding anything myself at the moment, so I'll leave that up to you. AngelScript syntax highlighting |
Feb 2, 2013, 05:46 AM | ||
Quote:
__________________
|
Feb 2, 2013, 09:31 AM | |
Add 32 to the leftmost MCE Event's "Event" parameter to make it act as an Off crate, or 64 to make it act as a Switch crate.
|
Feb 2, 2013, 10:03 AM | |
Day / night cycle
This script will smoothly change tileset palette between day and night. If used in multiplayer, it works for every client locally, meaning that each client will see a different time of the day. Code:
const uint dnCYCLELENGTH=700; const uint dnEVERYXTICKS=4; const uint dnINITIALTICKS=256; const string dnNIGHTTILESET="Carrot1N.j2t"; 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(); } }
In team games, this script will let players heal their teammates by shooting ice bullets at them. A single bullet can heal multiple people. Each bullet will heal 1 heart of damage. If freezer is powered-up, it shoots two bullets, so if both hit a player, it heals 2 hearts of damage in total. It won't heal the person who shot the bullet nor members of the opposite team. Code:
void onPlayer() { for (int i=1;i<jjObjectCount;i++) { if(jjObjects[i].isActive&&(jjObjects[i].eventID==OBJECT::ICEBULLET||jjObjects[i].eventID==OBJECT::ICEBULLETPU)) { if(jjObjects[i].xPos>p.xPos-12 &&jjObjects[i].xPos<p.xPos+12 &&jjObjects[i].yPos>p.yPos-12 &&jjObjects[i].yPos<p.yPos+12 &&jjObjects[i].state!=STATE::KILL &&jjPlayers[jjObjects[i].creator].playerID!=p.playerID &&jjPlayers[jjObjects[i].creator].teamRed==p.teamRed) { if(p.health<jjMaxHealth) { p.health=p.health+1; } jjObjects[i].state=STATE::KILL; } } } }
__________________
I am an official JJ2+ programmer and this has been an official JJ2+ statement. Last edited by Sir Ementaler; Feb 2, 2013 at 11:09 AM. Reason: Improved day / night cycle script. |
Feb 3, 2013, 12:32 AM | |
I would appreciate if someone writes a script that:
1) Makes text on text events not bouncing, or bouncing even more. 2) Changing direction of text on text events appearing. (Default is from right to left) 3) Makes it appear on different horizontal line. |
Feb 3, 2013, 05:16 AM | |
Just A Random User: I am pretty sure that such functions first need to be implemented in plus.dll, not really anything that a script can solve.
Punish campers xd! This was the first thing I could think of when I wanted to try out AngelScript, but it could probably be altered quite easily for trigger-like purposes or something. It also illustrates the use of (multi-layered) arrays and return in conjunction with an array. semi.j2as: Pastebin'd for easier reading Code:
old code removed to save space Edit2: It would make more sense to execute jjPlayers[player].showText("You are camping " + campAreaName[camparea]); outside of the function. If there are more improvements that will have to be made, I will work that into the next version. :P Last edited by Grytolle; Feb 3, 2013 at 09:45 AM. Reason: removed code to save space (still in pastebin) |
Feb 3, 2013, 05:55 AM | |
Oh NICE Grytolle! That one's REALLY awesome
![]()
__________________
|
Feb 3, 2013, 08:58 AM | |
Punishment should be -1h. Killing a player sounds too severe. If I use this script, will this work for -1h punishment?
Code:
if (isCamping[1]) { jjChat("I camped for too long " + campAreaName[i] + ". Now I get punishment"); p.health = p.health - 1; campTime[i] = 0; } |
Feb 3, 2013, 09:44 AM | ||
Quote:
Code:
p.health -= 1; Code:
jjPlayers[pID].pHealth -= 1; //or jjPlayers[pID].pHealth = jjPlayers[pID].pHealth - 1; Please use pastebin to see everything properly: http://pastebin.com/fwQ1Q3b9 Code:
saving space Last edited by Grytolle; Feb 3, 2013 at 01:59 PM. Reason: SE pointed out that relative expressions might not work well with objects |
Feb 3, 2013, 09:46 AM | |
You need to be more open-minded. It can be done with a script. I could do it myself but it's very highly complicated and requires a lot of time, while I have many other scripts to write. Also, I'm afraid it would be limited to about 100 characters on screen.
__________________
I am an official JJ2+ programmer and this has been an official JJ2+ statement. |
Feb 3, 2013, 10:24 AM | |
Doesn't work, unfortunately. Health is one of a number of properties that are actually pairs of get_health/set_health methods being passed off as simple properties, and -=/+=/--/++ don't work on those.
SE, are you proposing drawing text manually by creating objects with individual characters as their sprites? If so, that's very resourceful, but eww. |
Feb 3, 2013, 10:47 AM | ||
Quote:
![]() But hey, for short enough strings it works!
__________________
I am an official JJ2+ programmer and this has been an official JJ2+ statement. |
Feb 3, 2013, 12:38 PM | |
I figure we could provide API access to the drawText series of functions, so people can write their own UI elements. By doing it that way such elements would benefit from the fact that someday I'll implement 3D support for the UI itself, which will mostly happen in the drawText stuff.
__________________
|
Feb 3, 2013, 02:05 PM | ||
Quote:
Made a new version where you can define several rectangles to form one camp area (see id #3, the seekbox on semi). Illustrating what tiles are marked: ![]() It was a bit tricky to select the right ones, because when you jump into a tile above you your head (atleast as spaz) sticks into it a bit (the right outer side of the seekbox). I also made a small alteration to the comparison code, changing (xPos <= aCamp) to (xPos < aCamp). Not sure why it's better, but trial and error tells me that it is so. Punish campers! xd v2.0 http://pastebin.com/XBQhpkAK (as always, please read it on pastebin) Code:
/* Punish campers xd! v2.0 changes v2.0: -made non-rectangular camp areas possible changes v1.1: -had to recreate the onPlayer function, because it wouldn't work for clients :S -moved a message out of isInCampArea() -killed player with .kill() instead of .health=0 (thx cooba) improvements needed: -make it not needed to state maxcamp for every sub-area -show time remaining in campspot (could be achieved with the timer functions, I assume) -don't kill players if the game is stopped (the AngelScript implementation needs a new bool) -the chat is sent as teamchat if the player last used teamchat -you regain health if you die on purpose with flag xd */ /** script settings **/ const uint checkCampInterval=70; //how often to check for camping (gameticks) 70 = one second /*********************/ /** level settings: define camp areas **/ array |
Feb 3, 2013, 02:20 PM | |
http://www.jazz2online.com/snippets/
Quick and dirty, but seems to work. Will make it look more fancy later. Feature requests and bug reports are possible, can't say much about when they'd be addressed though. |
Feb 3, 2013, 02:42 PM | |
Here's my blade gun!
http://www.youtube.com/watch?v=Qr8pahz-QTs Pastebin: http://pastebin.com/5WYsBEQT It's also on the snippets page, here: http://www.jazz2online.com/snippets/...troblaster-pu/
__________________
WebJCS 2 (new and in progress) WebJCS 1 (old but complete) SGIP Simple Games in Progress list Level Packer v2 - With a GUI! PHP Tileset Compiler Last edited by djazz; Feb 3, 2013 at 02:45 PM. Reason: new url |
Feb 3, 2013, 03:47 PM | ||
Quote:
![]() |
Feb 3, 2013, 09:30 PM | |
Oh nice, that and ctrl+A solves the issue as was lack of a "select the whole code" button that I didn't even have time to mention yet.
__________________
I am an official JJ2+ programmer and this has been an official JJ2+ statement. |
Feb 3, 2013, 11:07 PM | |
DJazz, mind if I put that blade gun video on the Mod DB page? It's pretty cool-looking.
|
Feb 3, 2013, 11:51 PM | ||
Quote:
![]()
__________________
WebJCS 2 (new and in progress) WebJCS 1 (old but complete) SGIP Simple Games in Progress list Level Packer v2 - With a GUI! PHP Tileset Compiler |
Feb 4, 2013, 08:42 AM | |
I'm making a little SP level, and I have made a little part of the script...
void onLevelLoad() { jjObjectPresets[OBJECT::NORMTURTLE].energy = 8; jjObjectPresets[OBJECT::BEE].energy = 8; jjObjectPresets[OBJECT::TURTLESHELL].energy = 32; } void onMain() { p.food = 99; if (p.health > 1) p.health = 1; } I managed to make some enemies health x8, emulate the Instagib command, and make Jazz get the sugar rush with one only food item (would help a lot in the Jazz Unleashed Hell level), but I have spent a whole unsuccesful hour trying to make an expression for me to have as the level completing goal to kill every single enemy and collect every single item. I tried "if (OBJECT::NORMTURTLE = 0)", "if (OBJECT::NORMTURTLE.state = STATE::KILL)", "if (OBJECT::NORMTURTLE.jjObjectCount = 0)" but they all crashed the j2as file instead. Can anyone help me here? |
Feb 4, 2013, 11:06 AM | |
Hmmm. That's a tricky one, because SP doesn't store jjOBJ copies of objects that aren't near to the player. It's only in MP that you get jjOBJs for everything all the time. But there might still be a solution...
Code:
bool areAllNormTurtlesDestroyed() { jjOBJ@ o; for (int i = 1; i < jjObjectCount; ++i) { @o = jjObjects[i]; if (o.isActive && o.eventID == OBJECT::NORMTURTLE) return false; } for (uint16 x = 0; x < jjLayerWidth[4]; ++x) { (for uint16 y = 0; y < jjLayerHeight[4]; ++y) { if (jjEventGet(x,y) == OBJECT::NORMTURTLE && jjParameterGet(x,y,-1,1) == 0) return false; } } return true; } jjParameterGet(x,y,-1,1) , which is a bit that is set to 1 in the event field when an object is created. The bit is set back to 0 if the object passes off screen and gets deactivated, but it is left at 1 if you destroy the object. Basically, if it's at 0 JJ2 takes that as a cue to create the object when that tile is close enough to the player -- if it's at 1, JJ2 ignores it. So that code might work, unless there's something else I'm not thinking of.
|
Feb 4, 2013, 01:50 PM | |
Notice: Undefined variable: oPackage in /home/jazzonli/public_html/J2Ov2/snippets/form.php on line 29
Fatal error: Call to a member function info() on a non-object in /home/jazzonli/public_html/J2Ov2/snippets/form.php on line 29 : ( |
![]() |
«
Previous Thread
|
Next Thread
»
Thread Tools | |
|
|
All times are GMT -8. The time now is 09:31 AM.
Jazz2Online © 1999-INFINITY (Site Credits). 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. Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Original site design by Ovi Demetrian. DrJones is the puppet master. Eat your lima beans, Johnny.