Register FAQ Search Today's Posts Mark Forums Read
Go Back   JazzJackrabbit Community Forums » Open Forums » JCS & Scripting

AngelScript Requests & Help

Reply
 
Thread Tools
AvalancheMaster

JCF Member

Joined: Sep 2013

Posts: 89

AvalancheMaster is doing well so far

Jul 17, 2014, 06:52 PM
AvalancheMaster is offline
Reply With Quote
Quote:
Originally Posted by Sir Ementaler View Post
Here's the kind of code I meant:
The number in red should be modified to the palshift parameter value you want to use. Notice this code doesn't require a snow event in the level.
Works like charm! One question left, though: is there a way to make it appear above all layers (layer 3, mainly)? Currently it reveals all secret passages in my level. If not, I'll just make it react with mask tiles immediately.

EDIT: Violet, I seem to have found a bug.

I've currently set:
Code:
	jjWeapons[WEAPON::BLASTER].infinite = false;
	jjWeapons[WEAPON::BLASTER].maximum = 99;
	p.ammo[WEAPON::BLASTER]==99;
However, when I run out of blaster, my ammo switches to the remaining bouncers I have, and correctly shows their number, but it never goes down. Basically it seems that it makes them "infinite".
Violet CLM

JCF Éminence Grise

Joined: Mar 2001

Posts: 11,063

Violet CLM has disabled reputation

Jul 17, 2014, 07:02 PM
Violet CLM is offline
Reply With Quote
Quote:
Originally Posted by AvalancheMaster View Post
Works like charm! One question left, though: is there a way to make it appear above all layers (layer 3, mainly)? Currently it reveals all secret passages in my level. If not, I'll just make it react with mask tiles immediately.
Replace onDrawLayer4 with onDrawLayer3 or onDrawLayer1. :P

I'll look into the other thing. What's the context here? onLevelLoad or what? (And note that p is deprecated.)
__________________
AvalancheMaster

JCF Member

Joined: Sep 2013

Posts: 89

AvalancheMaster is doing well so far

Jul 17, 2014, 07:14 PM
AvalancheMaster is offline
Reply With Quote
Here's the whole thing:

Code:
void onLevelBegin() {
	jjWeapons[WEAPON::BLASTER].infinite = false;
	jjWeapons[WEAPON::BLASTER].maximum = 99;
	p.ammo[WEAPON::BLASTER]=99;
}
cooba

JCF Veteran

Joined: Jan 2004

Posts: 7,813

cooba is a glorious beacon of lightcooba is a glorious beacon of lightcooba is a glorious beacon of lightcooba is a glorious beacon of lightcooba is a glorious beacon of lightcooba is a glorious beacon of light

Jul 18, 2014, 01:36 AM
cooba is offline
Reply With Quote
I don't know about your problem, but you really need to make that into
Code:
jjPlayers[0].ammo[WEAPON::BLASTER] = 99;
Violet CLM

JCF Éminence Grise

Joined: Mar 2001

Posts: 11,063

Violet CLM has disabled reputation

Jul 18, 2014, 02:03 AM
Violet CLM is offline
Reply With Quote
Not if it's a multiplayer level, which hopefully it is or else the infinite line is the only one that does anything. For multiplayer you'd want jjLocalPlayers[0]. (Alternatively, set maximum in onLevelLoad instead of onLevelBegin, which should take care of setting ammo to 99 all on its own.)
__________________
AvalancheMaster

JCF Member

Joined: Sep 2013

Posts: 89

AvalancheMaster is doing well so far

Jul 18, 2014, 02:27 AM
AvalancheMaster is offline
Reply With Quote
It's a single player level.

EDIT: Bizarrely enough, when I get rid of p.ammo[WEAPON::BLASTER]=99;, the problem disappears.
Violet CLM

JCF Éminence Grise

Joined: Mar 2001

Posts: 11,063

Violet CLM has disabled reputation

Jul 18, 2014, 02:42 AM
Violet CLM is offline
Reply With Quote
p is only supposed to work for onPlayer, onFunction#, and onPlayerTimerEnd, and even in those cases it's only there for backwards compatibility and you should define a jjPLAYER@ argument instead. Using p in onLevelBegin is undefined behavior.
__________________
AvalancheMaster

JCF Member

Joined: Sep 2013

Posts: 89

AvalancheMaster is doing well so far

Jul 20, 2014, 12:43 AM
AvalancheMaster is offline
Reply With Quote
EDIT: Ok, no matter where I put jjWeapons[WEAPON::BLASTER].maximum = 35; it never works. How to fix this in singleplayer? Am I missing something?

Also, a question regarding FF. I managed to successfully turn the fastfire pickup into an ammo, but only for pre-places fastfire pickups. When an enemy drops fastfire, it acts as usual (no ammo, decreases bullets frequency).

Last edited by AvalancheMaster; Jul 20, 2014 at 12:57 AM.
Violet CLM

JCF Éminence Grise

Joined: Mar 2001

Posts: 11,063

Violet CLM has disabled reputation

Jul 20, 2014, 01:56 AM
Violet CLM is offline
Reply With Quote
Quote:
Originally Posted by AvalancheMaster View Post
EDIT: Ok, no matter where I put jjWeapons[WEAPON::BLASTER].maximum = 35; it never works. How to fix this in singleplayer? Am I missing something?
Code:
void onLevelLoad() {
	jjWeapons[WEAPON::BLASTER].maximum = 35;
	jjWeapons[WEAPON::BLASTER].infinite = false;
}
I would think?
Quote:
Also, a question regarding FF. I managed to successfully turn the fastfire pickup into an ammo, but only for pre-places fastfire pickups. When an enemy drops fastfire, it acts as usual (no ammo, decreases bullets frequency).
Hmm... it looks like the code for dropping pickups like that (also used by crates) sets scriptedCollisions to false. (Also isTarget and triggersTNT, and deactivates to true.) This is conceivably a bug. You should be able to get around it by doing something like this:

Code:
void onLevelLoad() {
	jjObjectPresets[OBJECT::FASTFIRE].behavior = MyFastfire;
}
void MyFastfire(jjOBJ@ obj) {
	obj.scriptedCollisions = true;
	obj.behavior = BEHAVIOR::PICKUP;
	obj.behave();
}
__________________
AvalancheMaster

JCF Member

Joined: Sep 2013

Posts: 89

AvalancheMaster is doing well so far

Jul 20, 2014, 07:05 PM
AvalancheMaster is offline
Reply With Quote
Quote:
Originally Posted by Violet CLM View Post
Code:
void onLevelLoad() {
	jjWeapons[WEAPON::BLASTER].maximum = 35;
	jjWeapons[WEAPON::BLASTER].infinite = false;
}
I would think?
No, it didn't work. But I managed to find a workaround with several ifs doing the job.

However, I've got another problem at hand. I'm trying to tint the ball platform to blue, but when I put jjObectPresets[OBJECT::BOLLPLATFORM].behavior = IceballPlatform; in onLevelLoad, no part of the code loads up. I even tried it with the simple rat example, given in the AngelScript guide (void MyRat(jjOBJ@ rat) {rat.behave(BEHAVIOR::LABRAT);}). It didn't work as well.

Here's the relevant part of the code:

Code:
onLevelLoad(){
	jjObectPresets[OBJECT::BOLLPLATFORM].behavior = IceballPlatform;
}
void IceballPlatform(jjOBJ@ plat) {
	plat.behave(BEHAVIOR::PLATFORM, false);
	jjDrawSpriteFromCurFrame(plat.xPos, plat.yPos, plat.curFrame, plat.direction, SPRITE::TINTED, 151);
}
Violet CLM

JCF Éminence Grise

Joined: Mar 2001

Posts: 11,063

Violet CLM has disabled reputation

Jul 20, 2014, 07:24 PM
Violet CLM is offline
Reply With Quote
jjObjectPresets, with a j.

Blaster: how are you running the level? If you're cycling to it from another level that doesn't have that code, then you're going to start with 99 blaster left over from that previous level, and it won't be until you go below 35 that maximum is going to mean anything.
__________________
AvalancheMaster

JCF Member

Joined: Sep 2013

Posts: 89

AvalancheMaster is doing well so far

Jul 20, 2014, 07:35 PM
AvalancheMaster is offline
Reply With Quote
Quote:
Originally Posted by Violet CLM View Post
jjObjectPresets, with a j.

Blaster: how are you running the level? If you're cycling to it from another level that doesn't have that code, then you're going to start with 99 blaster left over from that previous level, and it won't be until you go below 35 that maximum is going to mean anything.
Single player, first level off the pack.

Also, DID I REALLY fell for a typo mistake. x_

EDIT: And it still doesn't draw the chainlinks of the platform. Only the ball.

Last edited by AvalancheMaster; Jul 21, 2014 at 04:02 AM.
Seren

JCF Member

Joined: Feb 2010

Posts: 868

Seren is a name known to allSeren is a name known to allSeren is a name known to allSeren is a name known to allSeren is a name known to allSeren is a name known to all

Jul 21, 2014, 08:42 AM
Seren is offline
Reply With Quote
Quote:
Originally Posted by AvalancheMaster View Post
Also, DID I REALLY fell for a typo mistake.
That would suggest you don't have debug mode enabled. It's strongly suggested to have it on whenever you're doing anything with AngelScript. The readme introduction explains how to do that. You may also be interested in this download as, while it couldn't detect a mistake, said mistake would have never been made if the auto-completion feature were used.
Quote:
Originally Posted by AvalancheMaster
And it still doesn't draw the chainlinks of the platform. Only the ball.
That's because jjOBJ::behave, when its second argument is set to false, stops all drawing operations from the behavior. You could solve that by drawing the chain manually but in your case a simpler solution may be to just call behave with the second argument set to true. This will have the effect of your tinted sprite being drawn on top of the regular one, which should be visually identical to what you're trying to achieve.
__________________

I am an official JJ2+ programmer and this has been an official JJ2+ statement.
AvalancheMaster

JCF Member

Joined: Sep 2013

Posts: 89

AvalancheMaster is doing well so far

Jul 21, 2014, 04:10 PM
AvalancheMaster is offline
Reply With Quote
Quote:
Originally Posted by Sir Ementaler View Post

That's because jjOBJ::behave, when its second argument is set to false, stops all drawing operations from the behavior. You could solve that by drawing the chain manually but in your case a simpler solution may be to just call behave with the second argument set to true. This will have the effect of your tinted sprite being drawn on top of the regular one, which should be visually identical to what you're trying to achieve.
I did it, and it worked, but the chainlinks are still drawn as usual. It seems that I will have to code them as well.

Also, palshifting the bat does this:



I do realise it comes from the direction (capt'n obvious) yet I do not know how to solve it.

Code:
Code:
void Icebat(jjOBJ@ bat) {
	bat.behave(BEHAVIOR::BAT, true);
	jjDrawSpriteFromCurFrame(bat.xPos, bat.yPos, bat.curFrame, bat.direction, SPRITE::PALSHIFT, -56);
}
Violet CLM

JCF Éminence Grise

Joined: Mar 2001

Posts: 11,063

Violet CLM has disabled reputation

Jul 21, 2014, 05:10 PM
Violet CLM is offline
Reply With Quote
I refer you to our discussion on the previous page of SPRITE::PALSHIFT not working with leftward facing sprites.
__________________
AvalancheMaster

JCF Member

Joined: Sep 2013

Posts: 89

AvalancheMaster is doing well so far

Jul 21, 2014, 05:19 PM
AvalancheMaster is offline
Reply With Quote
Quote:
Originally Posted by Violet CLM View Post
I refer you to our discussion on the previous page of SPRITE::PALSHIFT not working with leftward facing sprites.


Damn. What about the chain links?
Violet CLM

JCF Éminence Grise

Joined: Mar 2001

Posts: 11,063

Violet CLM has disabled reputation

Jul 21, 2014, 06:15 PM
Violet CLM is offline
Reply With Quote
Code:
void onLevelLoad(){
	jjObjectPresets[OBJECT::BOLLPLATFORM].behavior = IceballPlatform;
}
void IceballPlatform(jjOBJ@ plat) {
	int angle = 0;
	
	//get part of the angle before it moves
	if (plat.state == STATE::PUSH)
		angle = plat.var[4];
	else if (plat.state == STATE::ACTION || plat.state == STATE::FREEZE)
		if (plat.var[3] == 1) //U swing
			angle = 1024 + int(jjSin(plat.var[4])*65536)/256;
		else
			angle = plat.var[4];
	
	plat.behave(BEHAVIOR::PLATFORM, false);
	angle += plat.var[5] * plat.var[2];
			
	//links
	int radius = 0;
	jjObjects[0].curAnim = plat.killAnim;
	jjObjects[0].frameID = 0;
	int frame = jjObjects[0].determineCurFrame(false);
	int radadd = 11; //one less than the width of the sprite, so change this if dealing with other platforms
	int angleadd = -plat.var[5];
	SPRITE::Mode mode = (plat.freeze != 0) ? SPRITE::FROZEN : SPRITE::TINTED;
	for (int n=0; n< plat.var[2]; ++n) {
		jjDrawSpriteFromCurFrame(
			plat.xOrg + radius * jjSin(angle),
			plat.yOrg + radius * jjCos(angle),
			frame, 0,
			mode, 151
		);
		angle+=angleadd;
		radius+=radadd;
	}
	//ball
	jjDrawSpriteFromCurFrame(plat.xPos, plat.yPos, plat.curFrame, plat.direction, SPRITE::TINTED, 151);
}
__________________
AvalancheMaster

JCF Member

Joined: Sep 2013

Posts: 89

AvalancheMaster is doing well so far

Jul 22, 2014, 03:11 AM
AvalancheMaster is offline
Reply With Quote
Quote:
Originally Posted by Violet CLM View Post
Code:
void onLevelLoad(){
	jjObjectPresets[OBJECT::BOLLPLATFORM].behavior = IceballPlatform;
}
void IceballPlatform(jjOBJ@ plat) {
	int angle = 0;
	
	//get part of the angle before it moves
	if (plat.state == STATE::PUSH)
		angle = plat.var[4];
	else if (plat.state == STATE::ACTION || plat.state == STATE::FREEZE)
		if (plat.var[3] == 1) //U swing
			angle = 1024 + int(jjSin(plat.var[4])*65536)/256;
		else
			angle = plat.var[4];
	
	plat.behave(BEHAVIOR::PLATFORM, false);
	angle += plat.var[5] * plat.var[2];
			
	//links
	int radius = 0;
	jjObjects[0].curAnim = plat.killAnim;
	jjObjects[0].frameID = 0;
	int frame = jjObjects[0].determineCurFrame(false);
	int radadd = 11; //one less than the width of the sprite, so change this if dealing with other platforms
	int angleadd = -plat.var[5];
	SPRITE::Mode mode = (plat.freeze != 0) ? SPRITE::FROZEN : SPRITE::TINTED;
	for (int n=0; n< plat.var[2]; ++n) {
		jjDrawSpriteFromCurFrame(
			plat.xOrg + radius * jjSin(angle),
			plat.yOrg + radius * jjCos(angle),
			frame, 0,
			mode, 151
		);
		angle+=angleadd;
		radius+=radadd;
	}
	//ball
	jjDrawSpriteFromCurFrame(plat.xPos, plat.yPos, plat.curFrame, plat.direction, SPRITE::TINTED, 151);
}
That's quite helpful, thanks! While I did not end up using it, it did help me create a platform chain out of the tileset. Now I'm trying to create the platform itself using the tileset, but I'm experiencing troubles with making it solid. As far as I understand drawTile only draws a tile and disregards mask, right?
Violet CLM

JCF Éminence Grise

Joined: Mar 2001

Posts: 11,063

Violet CLM has disabled reputation

Jul 22, 2014, 03:22 AM
Violet CLM is offline
Reply With Quote
Quote:
int drawTile(int xPixel, int yPixel, uint16 tile, TILE::Quadrant tileQuadrant = TILE::ALLQUADRANTS)
Draws a tile of your choice at some position on the screen. This is purely a drawing operation; using it to draw masked tiles to the screen does not create masked areas for players or other objects to interact with.
__________________
AvalancheMaster

JCF Member

Joined: Sep 2013

Posts: 89

AvalancheMaster is doing well so far

Jul 22, 2014, 03:50 AM
AvalancheMaster is offline
Reply With Quote
Quote:
Originally Posted by Violet CLM View Post
Ya, but I found a solution to this. A side question: can DrawTile use Resize modifier?
XxMoNsTeRXM

JCF Member

Joined: Sep 2013

Posts: 191

XxMoNsTeRXM is doing well so far

Aug 4, 2014, 02:05 AM
XxMoNsTeRXM is offline
Reply With Quote
I want to verify if a player is at x-pos 53 and y-pos 79. I created a code but it doesn't work:

Code:
void onPlayer(jjPLAYER@ p) {
      if ((p.xPos / 32 == 53 && p.yPos / 32 == 79) && jjGameTicks % 70 == 0)
        jjAlert("Test");
}
Violet CLM

JCF Éminence Grise

Joined: Mar 2001

Posts: 11,063

Violet CLM has disabled reputation

Aug 4, 2014, 03:13 AM
Violet CLM is offline
Reply With Quote
Instead of p.xPos / 32, try int(p.xPos / 32). Otherwise you're comparing a float to an integer and the chances are rather lower they'll be equal.
__________________
XxMoNsTeRXM

JCF Member

Joined: Sep 2013

Posts: 191

XxMoNsTeRXM is doing well so far

Aug 4, 2014, 03:47 AM
XxMoNsTeRXM is offline
Reply With Quote
Quote:
Originally Posted by Violet CLM View Post
Instead of p.xPos / 32, try int(p.xPos / 32). Otherwise you're comparing a float to an integer and the chances are rather lower they'll be equal.
It worked, thanks!" also can you make a global timer? with timerStart to start it global, not player-based, or at least to verify the server game timer (server timer after pregame server timer), is it possible?
DennisKainz

JCF Member

Joined: Dec 2005

Posts: 422

DennisKainz is notorious for his worthless posts

Aug 19, 2014, 05:14 AM
DennisKainz is offline
Reply With Quote
I spent half an hour searching for a way to make the bats follow you all over the map.
All I found is that setting var[0] and var[11++] to 0 makes them chase you when you're close (and for some reason makes them shout while they're NOT awake and viceversa)
And setting these to anything else makes them NEVER chase you.
I also can't change their movement speed for chasing you.

I didn't want to bother you with more requests, but I can't do this by myself.

So, how do I give bats unlimited range? And how do I change their chasing speed?
__________________
Free will was a mistake.
- God

Last edited by DennisKainz; Aug 19, 2014 at 05:30 AM.
Seren

JCF Member

Joined: Feb 2010

Posts: 868

Seren is a name known to allSeren is a name known to allSeren is a name known to allSeren is a name known to allSeren is a name known to allSeren is a name known to all

Aug 19, 2014, 06:30 AM
Seren is offline
Reply With Quote
Most of behavior constants for the majority of objects are hard-coded so you can't technically change only the distance bats detect you from or chase you from without rewriting the whole behavior. However, the position bats return to when they lose interest is their (xOrg, yOrg), so you could keep setting those to player's current position in order to make the bat chase them regardless of whether the range check succeeds. The variable you mention, var[0], stores ID of currently chased player, so you should use
Code:
const jjPLAYER@ player = jjPlayers[obj.var[0]];
obj.xOrg = player.xPos;
obj.yOrg = player.yPos;
or equivalent code. Speed values for bats are also more or less hard-coded but you can just adjust their position manually yourself. We established that xOrg and yOrg will always contain the position the bat is trying to reach so the code can look something like this:
Code:
obj.xPos = obj.xPos + (obj.xOrg > obj.xPos ? 2.f : -2.f);
obj.yPos = obj.yPos + (obj.yOrg > obj.yPos ? 2.f : -2.f);
Both of these pieces of code will naturally best fit in a custom behavior function that also calls the original behavior. However, at least the second one of them only makes sense to call when the bat is actually chasing somebody. You can make sure about that with a state check.
Code:
void bat(jjOBJ@ obj) {
	const jjPLAYER@ player = jjPlayers[obj.var[0]];
	obj.xOrg = player.xPos;
	obj.yOrg = player.yPos;
	obj.behave(BEHAVIOR::BAT);
	if (obj.state == STATE::FLY) {
		obj.xPos = obj.xPos + (obj.xOrg > obj.xPos ? 2.f : -2.f);
		obj.yPos = obj.yPos + (obj.yOrg > obj.yPos ? 2.f : -2.f);
	}
}
__________________

I am an official JJ2+ programmer and this has been an official JJ2+ statement.
XxMoNsTeRXM

JCF Member

Joined: Sep 2013

Posts: 191

XxMoNsTeRXM is doing well so far

Nov 2, 2014, 02:57 AM
XxMoNsTeRXM is offline
Reply With Quote
I got a code that does not work in multiplayer, it might be because it uses local variables, what I mean is that, if I join as a server it works, if I join as a normal player it crashes.
Code:
array savedgems(3, 0);
bool access = true;

void onPlayer(jjPLAYER@ p) {

 switch(p.health) {
	    case 0:
		    if (access) {
			savedgems[0] = p.gems[GEM::RED];
		        savedgems[1] = p.gems[GEM::GREEN];
		        savedgems[2] = p.gems[GEM::BLUE];
			jjAlert("Red gems current: " + p.gems[GEM::RED]);
			jjAlert("|Red gems saved: " + savedgems[0]);
			jjAlert("Green gems current: " + p.gems[GEM::GREEN]);
			jjAlert("|Green gems saved: " + savedgems[1]);
			jjAlert("Blue gems current: " + p.gems[GEM::BLUE]);
			jjAlert("|Blue gems saved: " + savedgems[2]);
			access = false;
			}
			break;
		case 5:
		    p.gems[GEM::RED] = savedgems[0];
		    jjAlert("||Red gems loaded: " + p.gems[GEM::RED]);
		    p.gems[GEM::GREEN] = savedgems[1];
		    jjAlert("||Green gems loaded: " + p.gems[GEM::GREEN]);
		    p.gems[GEM::BLUE] = savedgems[2];
		    jjAlert("||Blue gems loaded: " + p.gems[GEM::BLUE]);
	            if (!access) access = true;
		    p.health = 4;
		    break;
	}

}
__________________
~XxMoNsTeR
cooba

JCF Veteran

Joined: Jan 2004

Posts: 7,813

cooba is a glorious beacon of lightcooba is a glorious beacon of lightcooba is a glorious beacon of lightcooba is a glorious beacon of lightcooba is a glorious beacon of lightcooba is a glorious beacon of light

Nov 2, 2014, 03:09 AM
cooba is offline
Reply With Quote
"Crashes" tells me nothing. Is it an Access Violation, or an other kind of error? If it's an Access Violation, what are the two addresses listed in the message?
XxMoNsTeRXM

JCF Member

Joined: Sep 2013

Posts: 191

XxMoNsTeRXM is doing well so far

Nov 2, 2014, 03:28 AM
XxMoNsTeRXM is offline
Reply With Quote
Yea it is.
"At adress 0043CC2Bh by attempting to read from adress 9F763A48h"

EDIT: Maybe I gotta put [p.localPlayerID]? I tested that with the blaster reloading script, if I remove all the p.localPlayerID it crashes, if I have them, it works fine. I'll test that.

EDIT 2: Still not working...

Also here's the new magic code:

Code:
bool access = true;

class savedGems {
	savedGems() {
		red = green = blue = 0;
	}
	int red;
	int green;
	int blue;
};

array gemsArray(4);

void onPlayer(jjPLAYER@ p) {
	reloadBlaster(p);
	switch(p.health) {
	    case 0:
		    if (access) {
			gemsArray[p.localPlayerID].red = p.gems[GEM::RED];
		        gemsArray[p.localPlayerID].green = p.gems[GEM::GREEN];
		        gemsArray[p.localPlayerID].blue = p.gems[GEM::BLUE];
		        jjAlert("Red gems current: " + p.gems[GEM::RED]);
			jjAlert("|Red gems saved: " + gemsArray[p.localPlayerID].red);
			jjAlert("Green gems current: " + p.gems[GEM::GREEN]);
			jjAlert("|Green gems saved: " + gemsArray[p.localPlayerID].green);
			jjAlert("Blue gems current: " + p.gems[GEM::BLUE]);
			jjAlert("|Blue gems saved: " + gemsArray[p.localPlayerID].blue);
			access = false;
			}
			break;
		case 5:
		        p.gems[GEM::RED] = gemsArray[p.localPlayerID].red;
			jjAlert("||Red gems loaded: " + p.gems[GEM::RED]);
			p.gems[GEM::GREEN] = gemsArray[p.localPlayerID].green;
			jjAlert("||Green gems loaded: " + p.gems[GEM::GREEN]);
			p.gems[GEM::BLUE] = gemsArray[p.localPlayerID].blue;
		        jjAlert("||Blue gems loaded: " + p.gems[GEM::BLUE]);
	                if (!access) access = true;
			p.health = 4;
			break;
	}
}
__________________
~XxMoNsTeR

Last edited by XxMoNsTeRXM; Nov 2, 2014 at 04:24 AM. Reason: Still not working...
Seren

JCF Member

Joined: Feb 2010

Posts: 868

Seren is a name known to allSeren is a name known to allSeren is a name known to allSeren is a name known to allSeren is a name known to allSeren is a name known to all

Nov 2, 2014, 05:06 AM
Seren is offline
Reply With Quote
The error is not caused by your script. Your script is technically correct (except for the accidental undefined reloadBlaster call in your latest post). The only problem it has is that p.health = 4; is a poor choice because, a) it's not obvious why this is done and b) the health change will cause a status update packet to be sent, which means unnecessary efficiency loss that could be avoided (finding a way to do so is left as an exercise for the reader).

The crash is most likely caused by the level alone but finding the cause proves troublesome. From the access violation error window, please provide the value of ESI.
__________________

I am an official JJ2+ programmer and this has been an official JJ2+ statement.
XxMoNsTeRXM

JCF Member

Joined: Sep 2013

Posts: 191

XxMoNsTeRXM is doing well so far

Nov 2, 2014, 05:14 AM
XxMoNsTeRXM is offline
Reply With Quote
reloadBlaster is not accidental, I didn't wrote the functionon the forum.
__________________
~XxMoNsTeR
XxMoNsTeRXM

JCF Member

Joined: Sep 2013

Posts: 191

XxMoNsTeRXM is doing well so far

Nov 2, 2014, 05:52 AM
XxMoNsTeRXM is offline
Reply With Quote
Welp... still not working, even though I am not changing health, I am just using it.
Let's try do it without even using health at all.

EDIT: There's no way I can make this without testing for health, I need a onDeath function.
__________________
~XxMoNsTeR

Last edited by XxMoNsTeRXM; Nov 2, 2014 at 06:12 AM.
Seren

JCF Member

Joined: Feb 2010

Posts: 868

Seren is a name known to allSeren is a name known to allSeren is a name known to allSeren is a name known to allSeren is a name known to allSeren is a name known to all

Nov 2, 2014, 07:54 AM
Seren is offline
Reply With Quote
I already said your script doesn't cause this error so your further modifications will not fix it. If I wanted you to avoid using the health variable, I would say so. What I said where I was talking about possible improvements to your script is that you should avoid writing to this variable when unnecessary because it involves additional actions, which in turn decrease efficiency, i.e. script execution speed. Most importantly, I never said avoiding its use would get rid of the error you experience, as that would be untrue. Now focus on what I wrote and notice I requested the value of the ESI register at the point of crashing that you can obtain from the error message. This is currently the only information from your side I'm interested in.
__________________

I am an official JJ2+ programmer and this has been an official JJ2+ statement.
XxMoNsTeRXM

JCF Member

Joined: Sep 2013

Posts: 191

XxMoNsTeRXM is doing well so far

Nov 3, 2014, 04:01 AM
XxMoNsTeRXM is offline
Reply With Quote
The ESI is 6h.

Also it would be possible to do my script on a function, instead of putting the death
pit on the level I could add a line of "Text" events in the level at the bottom of the level.
__________________
~XxMoNsTeR

Last edited by XxMoNsTeRXM; Nov 3, 2014 at 04:17 AM.
Seren

JCF Member

Joined: Feb 2010

Posts: 868

Seren is a name known to allSeren is a name known to allSeren is a name known to allSeren is a name known to allSeren is a name known to allSeren is a name known to all

Nov 3, 2014, 12:45 PM
Seren is offline
Reply With Quote
It appears that somewhere in your script you're trying to call jjPLAYER::showText on a non-local or undefined player. JJ2+ probably has a bug that makes this action potentially crash the game, thank you for the report; regardless of that though, calling it on a non-local player would have no effect and therefore also likely indicates a bug in your script. The call is likely to have a form of p.showText somewhere in the onLevelLoad hook function but that's just one of the possibilities. In case your code really contains references to the global variable p / jjP as the symptoms would suggest, you should consider completely refraining from its use, as mixing deprecated and new features may and will result in undefined behavior.
__________________

I am an official JJ2+ programmer and this has been an official JJ2+ statement.
XxMoNsTeRXM

JCF Member

Joined: Sep 2013

Posts: 191

XxMoNsTeRXM is doing well so far

Nov 4, 2014, 04:20 AM
XxMoNsTeRXM is offline
Reply With Quote
This is the only place I use show text:

Code:
void onLevelBegin() {
   p.showText("@@@@@@#Treasure Jail", STRING::LARGE);
	
}


There's something wrong... I tested another level without the code that originally I thought it crashed when other client joins. About 1 month ago that map worked successfully, no crashes on multiplayer, so... it... might be... something with my server?
__________________
~XxMoNsTeR
cooba

JCF Veteran

Joined: Jan 2004

Posts: 7,813

cooba is a glorious beacon of lightcooba is a glorious beacon of lightcooba is a glorious beacon of lightcooba is a glorious beacon of lightcooba is a glorious beacon of lightcooba is a glorious beacon of light

Nov 4, 2014, 04:39 AM
cooba is offline
Reply With Quote
That really should be
Code:
jjLocalPlayers[0].showText
XxMoNsTeRXM

JCF Member

Joined: Sep 2013

Posts: 191

XxMoNsTeRXM is doing well so far

Nov 4, 2014, 06:28 AM
XxMoNsTeRXM is offline
Reply With Quote
Quote:
Originally Posted by cooba View Post
That really should be
Code:
jjLocalPlayers[0].showText
It actually is, that's the problem, I tested, I commented the p.showText and... cha-ching, works... lol...

It's interesting that people were able to join on my server 1 or 2 months ago, without any problem and it had
Code:
p.showText

then.

Everyone: Note that one line of your code could damage your entire level.
__________________
~XxMoNsTeR

Last edited by XxMoNsTeRXM; Nov 4, 2014 at 06:38 AM.
XxMoNsTeRXM

JCF Member

Joined: Sep 2013

Posts: 191

XxMoNsTeRXM is doing well so far

Jan 10, 2015, 12:36 AM
XxMoNsTeRXM is offline
Reply With Quote
Quote:
Originally Posted by Primpy View Post
Ok, I obviously made a mistake, but I don't know where did I go wrong. I just tried to add the "Fall Damage" and "Wall Jumping" snippets. Argh, I don't even know how to modify two scripts.
Code:
int jumpKey = 0;
int fallTimer = 0;
const double maxFallTime = 4;
 
void onMain() {
  jjPLAYER@ p = jjLocalPlayers[0];
  p.ammo[2] = 3;
  if (p.keyJump == true) {
    jumpKey = jumpKey+1;
  } else {
    jumpKey = 0;
  }
 
  if (jjMaskedPixel(p.xPos + (p.direction * 13), p.yPos) && p.keyJump == true && jumpKey < 3) {
    p.ySpeed = -10;
    p.direction = p.direction * (-1);
    p.xSpeed = p.direction * 5;
//    && p.ySpeed < 0
  }
 
  if (jjMaskedPixel(p.xPos + 13, p.yPos)  && p.ySpeed > 0 && p.keyRight == true) {
    p.ySpeed = 1;
    p.alreadyDoubleJumped = false;
  }
  if (jjMaskedPixel(p.xPos - 13, p.yPos)  && p.ySpeed > 0 && p.keyLeft == true) {
    p.ySpeed = 1;
    p.alreadyDoubleJumped = false;
  }

 int fallTimer = 0;
const double maxFallTime = 4;
 
void onMain() {
    if (!jjMaskedPixel(p.xPos, p.yPos + 32) && p.ySpeed > 0) {
      fallTimer++;
  } else if (jjMaskedPixel(p.xPos, p.yPos + 32)) {
    int repeats = (fallTimer / 70) / maxFallTime;
                if (fallTimer >= maxFallTime) {
    for (int i = 0; i < (fallTimer / 70) / maxFallTime; i++) {
        p.health = p.health - 1;
        if (p.health < 0) p.health = 0;
    }
                }
      fallTimer = 0;
  }
    if (p.health == 0) {
        fallTimer = 0;
    }
}
AngelScript reminds me a little bit about LUA, but LUA was slightly easier, or at least on Roblox. Don't judge the Roblox players, it takes a lot of time to do a decent game and you need to know both modeling and programming...
Well... you got 2 "void onMain()", you gotta put both snippets into one "void onMain()", that might be the problem. I remember I did that too and I was like "Why isn't it working?", the chatlogger didn't give me any errors, and I realized I've got 2 of them.
Also you declared the variables "fallTimer" & "maxFallTime" twice.

(I moved this reply from the JJ2+ Thread to this thread)
__________________
~XxMoNsTeR
Primpy

JCF Member

Joined: Nov 2014

Posts: 843

Primpy is an asset to this forumPrimpy is an asset to this forum

Jan 10, 2015, 01:52 AM
Primpy is offline
Reply With Quote
Quote:
Originally Posted by XxMoNsTeRXM View Post
Well... you got 2 "void onMain()", you gotta put both snippets into one "void onMain()", that might be the problem. I remember I did that too and I was like "Why isn't it working?", the chatlogger didn't give me any errors, and I realized I've got 2 of them.
Also you declared the variables "fallTimer" & "maxFallTime" twice.

(I moved this reply from the JJ2+ Thread to this thread)
Thanks a lot, I didn't notice I put two "void onMain()".
__________________

"Floppy ears and a big butt?" - Slaz
Primpy

JCF Member

Joined: Nov 2014

Posts: 843

Primpy is an asset to this forumPrimpy is an asset to this forum

Jan 10, 2015, 02:30 AM
Primpy is offline
Reply With Quote
Just wondering, but can Devan Shell be a playable character using Angel Script?
__________________

"Floppy ears and a big butt?" - Slaz
Reply

Tags
angelscript, code, jcs, request

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump

All times are GMT -8. The time now is 04:25 PM.