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)

Foly Feb 16, 2013 12:57 AM

AngelScript Requests & Help
 
Since there is no thread like this yet, I've decided to make one. This thread is about requests for scripts and help with JJ2 AngelScript. You can post requests for scripts you want to use in your level and ask people for help when something is not working with your code or you don't know if something is executeable.

There are a few rules/guidelines for posting:
  • When your code is long use a spoiler or link to the code instead.
  • Stay on topic, that also means no discussions about what should be added to jj2+ (there is another thread for that).
  • You can post critics about another code, just make sure this is really going to improve the code and not just changes the style of coding. Also if your code is criticized don't start a flamewar, let others decide if the critics are justified.
  • Be specific with what you want, if you want a frog to fly don't forget to mention how it will fly (i.e. floating at one tile or following the player like a bird).
  • If you know how to code consider asking for pseudocode instead, it is more likely people respond to pseudocode requests.
  • If your code is level specific consider posting the level.
Know that some requests are too hard/long or people don't always have motivation or time to spend to help you. Personally I don't mind to create some codes for other people, so don't think you shouldn't post because noone is going to help you :)

DoubleGJ Aug 9, 2013 03:42 AM

Digging up this thread with a plea for help.

I'm absolutely new to this scripting thing so pardon me if I ask for something completely obvious, but is it possible to write a script so a particular sucker tube will only work if a player moves with enough speed while touching it?

Violet CLM Aug 9, 2013 09:50 AM

You could try making your own sucker tube out of an onFunction# and the xSpeed, ySpeed, xPos, yPos, ballTime, and noClip properties, but there would still end up being some things you couldn't set at the moment, like turning off special moves. jjEventSet is probably closer to what you want.

MilloCz2 Aug 14, 2013 03:12 PM

Could someone explain me please why jjTileSet function does not work properly?

To describe problem: I want it to create 1 tile in the air in the cords X,Y in layer 4. It does not create that 1 tile, but it creates invisible pillars all around the map. I really have no clue why.

If you haven't tried it, you can:
Quote:

void onLevelLoad(){
jjTileSet(4,0,0,8);
}
You can pick any map with any tileset, but created tile (in my code, tile with number 8) should be masked.

Violet CLM Aug 14, 2013 04:47 PM

The 4x1 tile block you're setting a tile in is not unique to that position, therefore all other instances of that same 4x1 block receive the same change. The easiest way to ensure uniqueness is to make one of the tiles an animated tile and place an event—even one that doesn't do anything—on that animated tile.

MilloCz2 Aug 15, 2013 01:58 AM

Hah, thanks for quick reply! I will check it out.

(1) Also, is there any way how to show int/doubles etc. in showText/in jjDebug ?

EDIT: (2) What are some good ways of player's INPUT ? I have seen pressing buttons 1-9 as weapon change; is there anything better? Such as input text via jj2 chat?

I'm just starting, both with Angelscript and C++ and I'm very interested in it, since JJ2 is one of my most favourite games.

Violet CLM Aug 15, 2013 02:50 AM

(1) AngelScript has a built-in (i.e. I didn't write it) function formatInt which does what you're looking for and can output in a variety of formats. Search the documentation for details.

(2) There's no direct way of accessing input in the most recent release, but it'll turn up later. "Player-Guided Missile" on J2O is an example of indirectly testing the left and right arrow keys (or A/D or whatever the player happens to be using).

PurpleJazz Aug 17, 2013 12:28 AM

Is there any way of detecting whether or not a playing is currently pressing the fire button? I'm trying to write a script where the player's ammo regenerates over a period of time, with a short delay after the last press of the fire button. This would stop ammo from regenerating continuously even when the player is constantly firing.

Violet CLM Aug 17, 2013 12:40 AM

Nope. But you could check whether the ammo count has gone down lately?

Seren Aug 17, 2013 08:16 AM

This is another possible solution that has insignificantly longer execution time but doesn't use global variables and is more flexible (can be used for players who aren't local):
Code:

bool playerHasShot(jjPLAYER@ player){
  jjOBJ@ obj;
  for(int i=0;i<jjObjectCount;i++){
    @obj=jjObjects[i];
    if(obj.isActive&&(obj.eventID<OBJECT::SMOKERING||obj.eventID==OBJECT::TNT)&&obj.creatorType==CREATOR::PLAYER&&jjPlayers[obj.creator] is player&&(obj.state==STATE::FLY||obj.state==STATE::ROCKETFLY)&&obj.counter==1) return true;
  }
  return false;
}


Jerrythabest Aug 17, 2013 01:41 PM

Whoa, that script could use some white space and comments. Is it checking whether a new bullet of a certain player has appeared?

Seren Aug 17, 2013 02:23 PM

If there exists an object that is active, is a bullet, was created by the player the function is called for, and has parameters that indicate it has just spawned, return true, otherwise don't.

MilloCz Aug 29, 2013 08:50 AM

Hey it's me again.

Could you tell me how to properly use formatInt? Since I don't understand it. I need jjAlert to display "You have X coins." (where X represents the number of coins you have)

cooba Aug 29, 2013 08:52 AM

Code:

jjAlert("You have " + p.coins + " coins.");

MilloCz Aug 29, 2013 10:06 AM

Oh, when I last tried to write it like that, I forgot to include +'s.
Thanks.

MilloCz Sep 1, 2013 07:54 AM

Another question: Why doesn't jjEventSet(p.xPos,p.yPos, 65) work for creating objects like, diamonds? It creates nothing instead, while 65 = Blue gem's ID. Doesn't work even for "OBJECT::BLUEGEM".

cooba Sep 1, 2013 08:34 AM

Code:

jjAddObject(OBJECT::BLUEGEM, p.xPos, p.yPos);
?

Violet CLM Sep 1, 2013 09:40 AM

Also, you'd want jjEventSet(p.xPos / 32,p.yPos / 32, OBJECT::BLUEGEM) to the extent that worked at all, since events occupy whole tiles.

MilloCz Sep 2, 2013 12:13 AM

Quote:

Originally Posted by Violet CLM (Post 479931)
Also, you'd want jjEventSet(p.xPos / 32,p.yPos / 32, OBJECT::BLUEGEM) to the extent that worked at all, since events occupy whole tiles.

Well I give an example; If I place vine event on block and then I use jjEventSet BLUEGEM on the block, the vine disappears, but gem does not appear.

(this works even without dividing xPos by 32)

Toni_ Sep 6, 2013 10:20 AM

I know nothing about angel scripting and it's possibilities, so I will ask some questions:

- is it possible to change counting on DOM level, so the checkpoint increases your points every 10 seconds? For example if your team has 3 CPs, your score increases by 3 every 10 seconds.

- is it possible to trigger somehow gems in DOM, so if your team owns checkpoint, you can spawn at that area? Otherwise you spawn at another CP you own, or your team loses.

- is it possible to make gems first neutralize and then capture, just like on beginning of the game? For example, red team captures the CP, blue player neutralizes it by standing there for 5 seconds (and nobody can spawn there when it's neutralized), and after that 5 more seconds to capture the checkpoint so players could spawn there.

I am trying to make something that looks similar to Shadowgun's Zone Control gamemode. That could work very well in JJ2 with some changes.

Toni_ Sep 14, 2013 10:22 AM

Could anyone answer me, please?

Foly Sep 14, 2013 11:39 AM

I don't think this is possible yet because there is no OBJECT:: DOMAREA. I've also tried to see if I could get the handle of a DOM object in case it's just another object with special properties but no luck there too.

Toni_ Sep 14, 2013 01:22 PM

I have no knowledge of angel script, but is something like this possible? I will just try to show what I mean, without any real function there.

if gemCaptured = TRUE (activate some trigger)

where trigger is area (for example) 15x15 tiles around the gem, and when player spawns, he can warp there.

Violet CLM Sep 14, 2013 01:37 PM

JJ2+ doesn't presently allow you direct scripting access to DOM mechanics, but you could probably make your own facsimile.

Toni_ Sep 15, 2013 03:30 AM

Not sure if I understand you what you wanted to tell me about Foly's level, but I am sad to hear that DOM scripting isn't possible. :(

Foly Sep 15, 2013 03:42 AM

Quote:

Originally Posted by Just a Random User (Post 480098)
Not sure if I understand you what you wanted to tell me about Foly's level, but I am sad to hear that DOM scripting isn't possible. :(

He means it is also possible to create your own domination area's like I did in that level, although looking back at that level I think it's a bit sloppy ;)

minmay Oct 28, 2013 09:15 PM

Is there any reliable way to check if a non-local player is spectating via AngelScript?

Violet CLM Oct 28, 2013 10:11 PM

Testing their position for being inside the level (instead of at 0,0) seems to be the preferred method at present.

minmay Oct 28, 2013 10:46 PM

I've tried that, but their position seems to lag a few frames behind when they actually start spectating (at least going by the console announcement)...even if they're the server!

Violet CLM Oct 28, 2013 10:53 PM

Console announcements are, without exception that I can think of, barely more than normal chat messages. They do not reflect the client receiving a notification to actually update any values locally.

minmay Oct 28, 2013 11:22 PM

Hm, I was expecting they would at least coincide in the server's case.

DoubleGJ Oct 30, 2013 09:43 AM

I'm having trouble with using parameters in place of numerical values. I tried making a script that would spawn an object and make it constantly float near the player, but simply inputting p.xPos and p.yPos for the object's x and y values breaks the whole script. Is there any particular syntax I must use to make this work?

Violet CLM Oct 30, 2013 10:03 AM

Sorry, that description's much too vague for me to diagnose your problem. My best guess is that either a) "p" is not a defined variable at the time the function is called or b) you're not passing the parameters in the correct order. If that's not it, you may have to post some more of your code for inspection.

DoubleGJ Oct 30, 2013 10:44 AM

Okay. Here's how it looks right now, for testing purposes:

void onFunction1()
{
jjOBJ@ angryegg = jjObjects[jjAddObject(OBJECT::EGGPLANT, p.xPos + 50, p.yPos + 50)];
angryegg.bulletHandling(HANDLING::IGNOREBULLET);
angryegg.xPos = p.xPos + 50;
angryegg.yPos = p.yPos + 50;
}

that's the whole thing so far.

cooba Oct 30, 2013 10:44 AM

p as a global property got deprecated. You need to use this:
Code:

void onFunction1(jjPLAYER@ p)
This will spawn the eggplant, but not constantly adjust its position. plusHeaven has an example of an object behaving the way you want.

Seren Oct 30, 2013 11:13 AM

Quote:

Originally Posted by DoubleGJ (Post 480962)
angryegg.bulletHandling(HANDLING::IGNOREBULLET);

bulletHandling is not a function.
Code:

angryegg.bulletHandling=HANDLING::IGNOREBULLET;

DoubleGJ Oct 30, 2013 11:33 AM

ok after the fixes it works somewhat... the eggplant appears where it should, but when I try to make it stay there with onMain, it says I didn't declare angryegg and I don't know what to do

cooba Oct 30, 2013 12:06 PM

The beauty of custom behaviors is that you no longer need onMain to do anything complicated with objects:
Code:

void AngryEgg(jjOBJ@ obj) {
        jjPLAYER@ p = jjLocalPlayers[obj.creatorID];
        obj.xPos = p.xPos + 50;
        obj.yPos = p.yPos + 50;
        obj.draw();
}

void onLevelLoad() {
        jjObjectPresets[OBJECT::EGGPLANT].behavior = AngryEgg;
        jjObjectPresets[OBJECT::EGGPLANT].bulletHandling = HANDLING::IGNOREBULLET;
}

void onFunction1(jjPLAYER@ p) {
        jjAddObject(OBJECT::EGGPLANT, p.xPos + 50, p.yPos + 50, p.playerID, CREATOR::PLAYER);
        jjAlert("Eggplant added!");
}


Violet CLM Oct 30, 2013 12:22 PM

p the global object should still work, though—deprecated is not the same thing as removed.

Jerrythabest Oct 30, 2013 03:36 PM

AngryEgg? I see some Angry Birds game coming!


All times are GMT -8. The time now is 01:53 AM.

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