JazzJackrabbit Community Forums

JazzJackrabbit Community Forums (http://www.jazz2online.com/jcf/index.php)
-   JCS & Scripting (http://www.jazz2online.com/jcf/forumdisplay.php?f=5)
-   -   AngelScript Requests & Help (http://www.jazz2online.com/jcf/showthread.php?t=19503)

Love & Thunder Jan 10, 2015 07:12 AM

It should be possible as a simple sprite swap, I think.

Anyway, I'm having trouble getting an enemy surge working. The code is mostly a modified version of some code from plusEnscripted.
It turns up no errors, and the "Surge incoming" text comes up, but no enemies spawn. The coordinates of where I want to spawn stuff is between 237 and 247 widthwise, and 35 heightwise, according to JCS.
Code:

uint elapsed = 0;
bool surge = false;
int slain = 0;
const int SLAINTARGET = 10;
bool surgeover = false;

void onMain() {
    if (surge == false) {
        elapsed = 0;
    } else {
        elapsed ++;
    }
    if ((jjTriggers[5] == true) && (surgeover == false) == true) {
        if (surge == false) {
            jjLocalPlayers[0].showText("@@@@@SURGE INCOMING!", STRING::LARGE);
        }
        doEnemySurge();
    }
}

void doEnemySurge() {
    if (surge == false) {
        surge = true;
    }
    if (slain < SLAINTARGET) {
        if (elapsed % 70 == 0) { //Once per second
            uint16 randomTarget = (237 + (jjRandom()&15)) * 32;
            jjOBJ@ obj = jjObjects[jjAddObject(OBJECT::LIZARD, randomTarget, 1120)];
            obj.state = STATE::FALL;
        }
    } else { //slain >= SLAINTARGET: surge is over
        surgeover = true;
        jjMusicLoad("carrotus.j2b");
        jjLocalPlayers[0].showText("@@@@@SURGE COMPLETE!", STRING::LARGE);
        for (int i = 0; i < jjLocalPlayerCount; i++) {
            jjLocalPlayers[i].limitXScroll(43, 0);
        }
        elapsed = 0;
    }
}

Oh, also I'm triggering it using a trigger crate.

EDIT: Turns out that they're just invisible.
So, now my question is, why are they invisible, and how can I get them visible?
EDIT 2: I've placed other lizards in the level, but the ones coming from this script are still invisible.
EDIT 3: Wait, I fixed it.
Turns out it was the "STATE::FALL" that was the problem. Switching it to either a Float Lizard or removing that line fixes it.

I apologise for the slightly useless post. XD

EDIT 4: New problem: void onObjectHit(jjOBJ@ object, jjOBJ@ bullet, jjPLAYER@ player, int force) isn't triggering.

Violet CLM Jan 10, 2015 11:50 AM

onObjectHit is only called for objects with scriptedCollisions set to true.

The trouble with trying to make Devan a playable character in AngelScript is that you'd still see the rabbit sprites. You could do stuff with jjPLAYER::cameraFreeze, maybe offset layer 4 some number of tiles to the side and edit every behavior so it offsets its sprites accordingly, but that would be a pretty big hassle. Or you could stick Jazz in a wall somewhere and write your own platforming engine for Devan from scratch. Or you could decide it's probably not a great idea for 4.3.

Love & Thunder Jan 10, 2015 01:55 PM

Bullets are now going through multiple enemies, and although it does kill them, the kill counter still isn't going up.

Also, enemies are invincible in the air, and they only spawn at the two edges of the area I've specified for them to spawn in.

Violet CLM Jan 10, 2015 02:15 PM

Without knowing what the code looks like, it's pretty much impossible to point at what you're doing wrong.

Love & Thunder Jan 11, 2015 01:02 AM

Code:

uint elapsed = 0;
bool surge = false;
int slain = 0;
bool surgeover = false;

void onMain() {
    if (surge == false) {
        elapsed = 0;
    } else {
        elapsed ++;
    }
    if ((jjTriggers[5] == true) && (surgeover == false) == true) {
        if (surge == false) {
            jjLocalPlayers[0].showText("@@@@@SURGE INCOMING!", STRING::LARGE);
        }
        doEnemySurge();
    }
}

void doEnemySurge() {
    if (surge == false) {
        surge = true;
    }
    if (slain < 10) {
        if (elapsed % 70 == 0) { //Once per second
            uint16 randomTarget = (237 + (jjRandom()&8)) * 32;
            jjOBJ@ obj = jjObjects[jjAddObject(OBJECT::FLOATLIZARD, randomTarget, 1024)];
            obj.state = STATE::FALL;
            obj.var[5] = 0;
            obj.scriptedCollisions = true;
        }
    } else { //slain >= 10: surge is over
        surgeover = true;
        jjMusicLoad("carrotus.j2b");
        jjLocalPlayers[0].showText("@@@@@SURGE COMPLETE!", STRING::LARGE);
        for (int i = 0; i < jjLocalPlayerCount; i++) {
            jjLocalPlayers[i].limitXScroll(43, 0);
        }
        elapsed = 0;
    }
}

void onLevelReload() {
    slain = 0;
    elapsed = 0;
}

void onObjectHit(jjOBJ@ object, jjOBJ@ bullet, jjPLAYER@ player, int force) {
    if ((object.eventID == OBJECT::FLOATLIZARD || object.eventID == OBJECT::XMASFLOATLIZARD) && object.state != STATE::KILL) {
        if (player !is null) {//no TNT or turtle shells in this level, so shouldn't be necessary, but can't hurt
            if (force == 0) //normal collision, not using any buttstomps or whatever
                player.hurt();
            else {
                //Here JJ2 would check to see if the object is frozen, and if so,
                //unfreeze it and (possibly; some objects do this and others don't)
                //alter the amount of damage it receives from the bullet. There's no
                //ice ammo in this level, so that's not required.
                if (force > 0) //probably a bullet
                    object.energy -= force;
                else //special attack
                    object.energy -= 4;
                if (object.energy <= 0) {
                    if (bullet !is null) {
                        if ((bullet.var[6] & 2) == 2) { //toaster and its ilk
                            object.particlePixelExplosion(1); //burny explosion
                            jjSample(object.xPos, object.yPos, SOUND::COMMON_BURN);
                        } else {
                            object.particlePixelExplosion(0);
                        }
                        object.grantPickup(player, (bullet.eventID == OBJECT::BLASTERBULLET) ? 5 : 10);
                            //JJ2 only ever calls grantPickup for enemies/crates destroyed
                            //by bullets, but you can branch out a bit if you like
                    } else {
                        object.particlePixelExplosion(2); //killed by physical contact
                        jjSample(object.xPos, object.yPos, SOUND::COMMON_SPLAT1);
                    }
                    object.state = STATE::KILL; //let the object's behavior function take care of deleting it
                    player.score += object.points;
                    jjPARTICLE@ score = jjAddParticle(PARTICLE::STRING);    //JJ2 checks that jjGameMode is SP or COOP before doing this,
                    if (score !is null) {                    //and also makes sure that object.points is non-zero. We know both
                        score.xPos = object.xPos;            //are true here, so there's no need to bother.
                        score.yPos = object.yPos;
                        score.xSpeed = -0.5 - (jjRandom() & 0x3FFF) / 65536.;
                        score.ySpeed = -1  - (jjRandom() & 0x7FFF) / 65536.;
                        score.string.text = formatInt(object.points, "1");
                    }
                    ++slain; //the only reason we're going to all this effort
                } else //not yet dead
                    object.justHit = 5; //flash white for five ticks
            }
        }
        if (bullet !is null && (bullet.var[6] & 16) == 0) { //JJ2 also checks for var[6] & 4, aka the laser shield blast, but eh whatever
            bullet.state = STATE::EXPLODE;    //EXPLODE, like START, means the bullet won't be checked for collisions with other objects/players
                            //also, all normal bullet behaviors have code to dispose of themselves during EXPLODE, so that's nice
        }
    }
}


Violet CLM Jan 11, 2015 01:24 AM

Quote:

Originally Posted by Robo4900 (Post 484958)
they only spawn at the two edges of the area I've specified for them to spawn in.

You're confusing & and %

The other problems stem from your not writing obj.bulletHandling = HANDLING::DETECTBULLET; either while spawning the lizards or in their jjObjectPresets entry.

Love & Thunder Jan 11, 2015 02:08 AM

Ah, I thought it would be something simple like that.

Thank you very much. :)

EDIT:
Now having trouble adding a second wave to the surge.
I've added the following code:
Code:

} else if (slain < 30) {
    if (elapsed % 60 == 0) { //Once every just less than a second.
        uint16 randomTargetA = (237 + (jjRandom()%10)) * 32;
        jjOBJ@ obj = jjObjects[jjAddObject(OBJECT::FLOATLIZARD, randomTargetA, 1024)];
        obj.state = STATE::FALL;
        obj.var[5] = 0;
        obj.scriptedCollisions = true;
        obj.bulletHandling = HANDLING::DETECTBULLET;
    } else if (elapsed % 70 == 0) { //Once every second
        uint16 randomTarget = (237 + (jjRandom()%10)) * 32;
        jjOBJ@ obj = jjObjects[jjAddObject(OBJECT::BAT, randomTarget, 1008)];
        obj.scriptedCollisions = true;
        obj.bulletHandling = HANDLING::DETECTBULLET;
    }
} else { //slain >= 30: surge is over

But the bats spawned don't take damage.
EDIT 2: They can be killed with special attacks, but not bullets. Either way, though, they don't trigger the onObjectHit code.
EDIT 3: By removing the bullet handling part, I've fixed them being invulnerable to bullets, but they still don't activate the onObjectHit code.
EDIT 4: For debugging purposes, I've added the following code in the onObjectHit part, which should trigger every time I hit a bat:
Code:

if (object.eventID == OBJECT::BAT) {
    jjLocalPlayers[0].showText("@@@@@HIT", STRING::LARGE);
}

But it doesn't. This proves that it's not triggering the onObjectHit thing.
EDIT 5: Tried swapping the bats out for ravens. Still didn't work.

Violet CLM Jan 11, 2015 01:22 PM

Try obj.playerHandling = jjObjectPresets[OBJECT::FLOATLIZARD].playerHandling;

KRSplatinum Jan 11, 2015 10:18 PM

Is it possible to create a level script that shows radar in-game?

Here's a good example of radar taken from Halo, the radar is in the bottom-left corner:

[IMG]http://faqsmedia.ign.com/faqs/image/article/823/823401/10_halo_002.jpg[/IMG]

There's obviously precedent for finding other player's positions in the map, but I haven't seen what an HUD-based radar what look like in JJ2.

Foly Jan 12, 2015 12:14 AM

This is defininely possible. All you have to do is get some sprites, parts of tiles or whatever to draw the dots that represent players and a background. Every player has the position of all other players it's just a matter of scaling this to the dot position and making a condition for when the dots to show up. It's ofcourse also possible to put pu's, carrots and bases on it.

Toni_ Jan 12, 2015 08:25 AM

I think you should ask Artem about that. He will explain you everything about radar and how it works.

cooba Jan 12, 2015 08:54 AM

I think you should ask Artem about the 5,478 lines of code he wrote for JJ2+ instead.

XxMoNsTeRXM Jan 15, 2015 04:35 AM

Quote:

Originally Posted by KRSplatinum (Post 485014)
Is it possible to create a level script that shows radar in-game?

Here's a good example of radar taken from Halo, the radar is in the bottom-left corner:

[IMG]http://faqsmedia.ign.com/faqs/image/article/823/823401/10_halo_002.jpg[/IMG]

There's obviously precedent for finding other player's positions in the map, but I haven't seen what an HUD-based radar what look like in JJ2.

Well... I am trying to make a radar script.

Primpy Jan 15, 2015 11:00 AM

Quote:

Originally Posted by XxMoNsTeRXM (Post 485081)
Well... I am trying to make a radar script.

We know you can, good luck.
Apropo, majoritatea pustilor de varsta ta sunt niste pitici enervanti care se cred buricul pamantului. Ma bucur ca exista persoane inteligente ca tine in Romania!

XxMoNsTeRXM Jan 22, 2015 11:11 AM

I am trying to remake "somehow" the JJ1 Bonus in JJ2 (But not 3D)
[img]http://i.imgur.com/7xOjwQp.png[/img]
Quote:

Originally Posted by Primpy
Sounds interesting. I wish you luck! :)

Thanks!

Primpy Jan 23, 2015 12:18 AM

Quote:

Originally Posted by XxMoNsTeRXM (Post 485270)
I am trying to remake "somehow" the JJ1 Bonus in JJ2 (But not 3D)
[img]http://i.imgur.com/7xOjwQp.png[/img]

Sounds interesting. I wish you luck! :)

Jelly Jam Jan 23, 2015 04:56 AM

Quote:

Originally Posted by XxMoNsTeRXM (Post 485270)
I am trying to remake "somehow" the JJ1 Bonus in JJ2 (But not 3D)
[img]http://i.imgur.com/7xOjwQp.png[/img]

Does that mean the original 2d levels from JJ2 are going to be 3D, and that the 3D bonus levels will be 2D? :+
Just kidding, i wish you luck with this, cause it sounds really interesting:7

AvalancheMaster Mar 24, 2015 02:08 AM

It's not exactly a request but it would be if the answer is "yes".

Is it possible to combine a bridge and an Acc Belt? I'm thinking of modifying the MEZ03 serpentine belt so a custom "rolling" bridge can be made via Angelscript.

Violet CLM Mar 24, 2015 10:01 AM

heck, you can just put Acc Belt events in the area the bridge would take up in JCS. But more generally:
Code:

void onPlayer(jjPLAYER@ play) {
  jjOBJ@ platform = jjObjects[play.platform];
  if (playform.behavior == WHATEVER) {
    play.xSpeed CHANGES SOMEHOW;
  }
}


Love & Thunder Mar 25, 2015 08:49 AM

Do you think a Tails-like NPC would be hard to get working?

Violet CLM Mar 25, 2015 11:44 AM

The trickiest part would be writing all the logic for how to move around the level and what to react to and when to shoot and stuff. And that would be tricky. But that's because of AI, not AS.

XxMoNsTeRXM Apr 7, 2015 08:22 AM

Is it possible to do #include file.j2as?
EDIT: OF COURSE I CAN :) Because 5.0 IS SO AWESOME!
it's just:
#include "file.j2as";

XxMoNsTeRXM Apr 7, 2015 11:05 AM

ummm... it doesn't show errors in AS in 5.0
I think it's an error in the j2as I am using.
I use #include and I think maybe it can't get the error or something?

cooba Apr 7, 2015 11:07 AM

If you overwrote your old plus.ini with the one from the zip, you need to enable it manually again.

XxMoNsTeRXM Apr 7, 2015 11:20 AM

Quote:

Originally Posted by cooba (Post 486956)
If you overwrote your old plus.ini with the one from the zip, you need to enable it manually again.

I did not do that, but AngelscriptDebug was indeed false. I set it to true and now it works. Anyway, thx!

Also I gotta learn more about the new version AS.

Ok, it says a function with the same name and parameters already exist, I know why because I use some of the JJ2+ functions in the thing that I include and in the main j2as, hmmm... I think I need help.

Violet CLM Apr 7, 2015 11:38 AM

Quote:

Originally Posted by XxMoNsTeRXM (Post 486958)
Ok, it says a function with the same name and parameters already exist, I know why because I use some of the JJ2+ functions in the thing that I include and in the main j2as

Don't do that.

XxMoNsTeRXM Apr 9, 2015 08:20 AM

Ok, I need help!
[img]http://i.imgur.com/KtU4zHy.png[/img]

Violet CLM Apr 9, 2015 09:32 AM

  • ANIM::PLUS_AMMO is already loaded at the start of the level, so there's no need to load it again. Especially not every single render frame, which it looks like you're doing there. Naturally if you try to load 7 new jjANIMATION entries every frame, eventually you're going to go past 1500.
  • ANIM::AMMO and ANIM::PLUS_AMMO are different. That code would mess up every animation using any of the ANIM::AMMO animations—bullets, explosions, and so on.
  • Don't use p
  • Don't use 620, 455. That won't work at other resolutions. Use jjSubscreenWidth-20, jjSubscreenHeight-25
  • I think that'll work in that case, but in general it's good to include a jjIsTSF check when writing Lori-specific code, since 1.23 doesn't always understand Lori-related constants.

Love & Thunder Apr 9, 2015 05:52 PM

Could someone explain how I can check if an object is using a specific set and animation?

I've tried searching the readme, but I haven't found anything.

Violet CLM Apr 9, 2015 07:18 PM

I suppose something like
Code:

bool doesObjectUseAnimation(jjOBJ@ obj, uint curAnim) {
  jjANIMATION@ anim = jjAnimations[curAnim];
  return obj.curFrame >= anim.firstFrame && obj.curFrame < anim.firstFrame + anim.frameCount;
}
bool doesObjectUseAnimation(jjOBJ@ obj, ANIM::Set setID, uint animID) {
  return doesObjectUseAnimation(obj, jjAnimSets[setID].firstAnim + animID);
}


Zah dud4h Apr 13, 2015 06:48 AM

Is there something that makes the blue team lose if they didn't killed everyone from red team in tlrs after the game stopped?

Violet CLM Apr 13, 2015 09:36 AM

I'd try something like this (untested), if you're sure there'll be a time limit (maybe put some code in onLevelBegin to ensure that):
Code:

bool atLeastOneRedPlayerAlive() {
  for (uint i = 0; i < 32; ++i) {
    jjPLAYER@ play = jjPlayers[i];
    if (play.team == TEAM::RED && play.isInGame)
      return true;
  }
  return false;
}
void onGameStop(bool firstTime) {
  if (!jjIsServer) return;
  if (firstTime) return;
  if (jjGameState == GAME::PAUSED) return;
  if (atLeastOneRedPlayerAlive())
    //somehow indicate that you think blue lost
}


Zah dud4h Apr 14, 2015 08:23 AM

Quote:

Originally Posted by Violet CLM (Post 487112)
I'd try something like this (untested), if you're sure there'll be a time limit (maybe put some code in onLevelBegin to ensure that):
Code:

bool atLeastOneRedPlayerAlive() {
  for (uint i = 0; i < 32; ++i) {
    jjPLAYER@ play = jjPlayers[i];
    if (play.team == TEAM::RED && play.isInGame)
      return true;
  }
  return false;
}
void onGameStop(bool firstTime) {
  if (!jjIsServer) return;
  if (firstTime) return;
  if (jjGameState == GAME::PAUSED) return;
  if (atLeastOneRedPlayerAlive())
    //somehow indicate that you think blue lost
}


Thanks violet,now,is there something that sets the TLRS lives depending on how many people are playing?

Violet CLM Apr 14, 2015 10:04 AM

First you figure out how many people are playing; then you do whatever math you have in mind; then you set the number of lives.

XxMoNsTeRXM Apr 22, 2015 06:07 AM

I need help... I don't know much of how to use jjSTREAM, and I wanna make a custom command "!rename name" that only renames yourself, and I need to send a packet to the server to do the command "/rename clientID name".

Grytolle Apr 23, 2015 12:56 PM

Why don't you just make rename if jjisserver in the on Chat event?

XxMoNsTeRXM Apr 25, 2015 02:34 AM

Quote:

Originally Posted by Grytolle (Post 487205)
Why don't you just make rename if jjisserver in the on Chat event?

Ok, I learned quite more about jjStream, and now I think I know how to use it. :)

DennisKainz Apr 26, 2015 06:57 AM

I wanted to insert a custom sprite in my level, replacing a food with another.
1st question: How do you change the amount of set IDs and their respective frames and animation amounts in your custom j2a file? You can't do it with Jazz Sprite Dynamite.
2nd question: What should I write in Angelscript to successfully replace a food sprite with one from my custom j2a file?

Violet CLM Apr 26, 2015 09:33 AM

1: Don't use Jazz Sprite Dynamite.
2: Suppose for the sake of simplicity that your food sprite is in animation 0 in anim set 0 in your custom j2a file. Then there are various approaches you could take, but these two are probably the most practical.
Code:

jjAnimSets[ANIM::CUSTOM[0]].load(0, "myCustom.j2a");
//option 1: affects only apples
jjObjectPresets[OBJECT::APPLE].determineCurAnim(ANIM::CUSTOM[0], 0);
//option 2: affects any object that might try to use the apple animation
jjAnimations[jjObjectPresets[OBJECT::APPLE].curAnim] = jjAnimations[jjAnimSets[ANIM::CUSTOM[0]]];


DennisKainz Apr 28, 2015 05:04 AM

Thank you for the help! I now can make those custom objects I've been trying to make for years! (see "Campaign Mysteries" and other archaic levelpacks of mine)

I'm now experimenting the tile redrawing functions of AngelScript. Is there by chance an option that allows you to not only draw a tile on a specified layer, but also repeat it along with the JCS Tile Width / Height function? (as far as it is in the screen, ofcourse, otherwise it would cause a hyperlag)


All times are GMT -8. The time now is 12:25 AM.

Powered by vBulletin® Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
JCF © 2001-Infinity Jazz2Online