PDA

View Full Version : [Request]: Scripted Shooter // Map-changer



Sylph
03-28-2009, 03:05 PM
I'm not sure on how easy these are of doing, but at first glance they don't seem too hard. However, my inability to do these is... painstakingly obvious (>>). At any rate, here are my two requests.

#1 - I want to simulate a Shooter (Fireball) enemy, but attached to a FFC. In other words, so that it would check its position, Link's position, and then create the projectile weapon in front of it. My FFC in question is moving, and as such I can't make it so that beneath it there's an Enemy 0 flag with the Shooter type.

#2 - This one seems a bit more complicated in my view, but I digress: I need an item script that can warp the player depending on its position. In a way, similar to how the Magic Mirror functioned in ALttP, but make it doable in both maps and without the 'return portal'. Basically, it would transport Link to the same position in another map (as in, a direct warp to the same screen but in a different map) with a distinct DMap. Then in the other map, whenever Link would use the item again, it would warp him back to the first map under the same conditions.

Thanks in advance.

pkmnfrk
03-29-2009, 01:15 AM
For the shooter, I'm not sure how, exactly, a Shooter (Fireball) works, so at best, I could spawn a Shooter on top of the FFC, and have it follow the FFC around and stuff. Let me know if that's what you want.

For the mirror, well:


bool itemMagicMirror = false;
int magicMirrorDestDMap = 0;
const int warpFrames = 60;

void doMagicMirror() {
int existingDMap = Game->GetCurDMap();
Link->Action = LA_FROZEN;
for(int i = 0; i < warpFrames; i++) {
Screen->Wavy = i;
Waitframe();
}
//insert other flashy graphics here
Link->PitWarp(magicMirrorDestDMap, Game->GetCurDMapScreen());
Waitframe();
Link->Action = LA_FROZEN;
Game->PlaySound(SFX_SUMMON);
if(Screen->isSolid(Link->X, Link->Y + 8)) {
for(int i = 0; i < warpFrames; i++) {
Screen->Wavy = i;
Waitframe();
}
Link->PitWarp(existingDMap, Game->GetCurDMapScreen());
}
Waitframes(warpFrames);
itemMagicMirror = false;
Link->Action = LA_NONE;
}

item script MagicMirror {
void run(int dmap1A, int dmap1B, int dmap2A, int dmap2B, int dmap3A, int dmap3B, int dmap4A, int dmap4B) {
int dmap = Game->GetCurDMap() + 1;

if(dmap == dmap1A && dmap1B > 0) {
magicMirrorDestDMap = dmap1B - 1;
itemMagicMirror = true;
} else if(dmap == dmap1B && dmap1A > 0) {
magicMirrorDestDMap = dmap1A - 1;
itemMagicMirror = true;
} else if(dmap == dmap2A && dmap2B > 0) {
magicMirrorDestDMap = dmap2B - 1;
itemMagicMirror = true;
} else if(dmap == dmap2B && dmap2A > 0) {
magicMirrorDestDMap = dmap2A - 1;
itemMagicMirror = true;
} else if(dmap == dmap3A && dmap3B > 0) {
magicMirrorDestDMap = dmap3B - 1;
itemMagicMirror = true;
} else if(dmap == dmap3B && dmap3A > 0) {
magicMirrorDestDMap = dmap3A - 1;
itemMagicMirror = true;
} else if(dmap == dmap4A && dmap4B > 0) {
magicMirrorDestDMap = dmap4B - 1;
itemMagicMirror = true;
} else if(dmap == dmap4B && dmap4A > 0) {
magicMirrorDestDMap = dmap4A - 1;
itemMagicMirror = true;
}
}
}

Put this in your script file, and in your Slot 2 Script, put this line:


if(itemMagicMirror) doMagicMirror();

(This should be in your while(true) loop. Let me know if you don't know what I mean.)

With this item, you can have up to four "pairs" of DMaps you can warp between. That is, in each pair, you can warp freely from A to B, and from B to A.

To set these pairs up, you set the D0-7 values in the Item Editor. So, after you import the script, create the Magic Mirror item and set it to a Custom Itemclass. Then, on the Action tab, set the Script box to the slot number of the Magic Mirror script.

Finally, on the Arguments tab, set D0 and D1 to the first pair, D2 and D3 to the second pair, etc. Please note that the pairs are set as (DMap Number + 1). So, if you want to be able to warp between DMaps 1 and 3, put 2 and 4 in the boxes.

Let me know if you have any trouble!

Joe123
03-29-2009, 08:54 AM
const int WSP_FIREBALL = 0; //Make a sprite for the fireball in 'Weapons/Misc.', and set its ID here.

ffc script FollowingFireballer{
void run(int rate, int damage, int speed){
if(damage == 0) damage = 2;
if(speed == 0) speed = 2;
rate = Max(1,rate);
int i=1;
while(true){
if(i==0) Projectile(this,damage,speed);
i=(i+1)%rate;
Waitframe();
}
}
void Projectile(ffc f,int d,int s){
eweapon p = Screen->CreateEWeapon(EW_FIREBALL);
p->UseSprite(WSP_FIREBALL);
p->X = f->X; p->Y = f->Y;
p->Damage = d; p->Step = s*100;
p->Angular = true;
int angle = ArcTan(Link->X-p->X,Link->Y-p->Y);
p->Angle = angle; p->Dir = AngleToDir(angle);
}
int AngleToDir(int a){
int d;
if(a==-PI || a==PI) d=DIR_LEFT;
else if(a==-PI/2) d=DIR_UP;
else if(a==PI/2) d=DIR_DOWN;
else if(a==0) d=DIR_RIGHT;
else if(a<-PI/2) d=DIR_LEFTUP;
else if(a<0) d=DIR_RIGHTUP;
else if(a>PI/2) d=DIR_LEFTDOWN;
else d=DIR_RIGHTDOWN;
return d;
}
}

Turned out to be a bit of a larger script than I had anticipated actually.
But nevermind.

Anyway, set the constant at the top, then set d0 as the rate of fire (number of frames between each fireball), d1 as the damage and d2 as the speed of the fireball.
By default damage is 8 (half a heart), and speed is 2 pixels per frame.
Rate by default it 1, but that's only to ensure we don't get division by zero. With a rate of 1, you'll get a fireball every frame. You'll have to sort out the rate yourself, as I haven't actually tested it so I don't know what sort of value you'd want there.

Sylph
03-29-2009, 09:01 PM
Sorry for the delay, homework is known to be a pain. <<;

At any rate:



-insert code here-

Anyway, set the constant at the top, then set d0 as the rate of fire (number of frames between each fireball), d1 as the damage and d2 as the speed of the fireball.
By default damage is 8 (half a heart), and speed is 2 pixels per frame.


Thanks a bunch! ^w^ Hope you don't mind - game was freezing so I added the Waitframe(); in the right place. :P Also, for some reason, 8 isn't returning half a heart for me - instead, it's returning two whole hearts, meaning, whenever I get hit, I lose two whole hearts. Am I doing something wrong? ^^;



-insert code here-

Put this in your script file, and in your Slot 2 Script, put this line:

-insert moar code here-

(This should be in your while(true) loop. Let me know if you don't know what I mean.)

With this item, you can have up to four "pairs" of DMaps you can warp between. That is, in each pair, you can warp freely from A to B, and from B to A.

To set these pairs up, you set the D0-7 values in the Item Editor. So, after you import the script, create the Magic Mirror item and set it to a Custom Itemclass. Then, on the Action tab, set the Script box to the slot number of the Magic Mirror script.

Finally, on the Arguments tab, set D0 and D1 to the first pair, D2 and D3 to the second pair, etc. Please note that the pairs are set as (DMap Number + 1). So, if you want to be able to warp between DMaps 1 and 3, put 2 and 4 in the boxes.

Let me know if you have any trouble!

Thanks! Sorry to pester you so early: you mean the first chunk of code goes into my regular script file and the other only in my (Slot 2) global script, right? Sorry for this silly inquiry, but, having never messed with global scripts so far, I'm kind of hesitant to even touch it. XD;

At any rate, huge thanks to you two for the help!

pkmnfrk
03-29-2009, 11:05 PM
Yup! If you have a global script, it probably looks like this: (if not, just copy any paste this)


global script Slot2 {
void run() {
//initialization stuff goes here
while(true) {
//other global scripted stuff here

//Magic Mirror Script:
if(itemMagicMirror) doMagicMirror();
Waitframe();
}
}
}

Joe123
03-30-2009, 10:19 AM
Thanks a bunch! ^w^ Hope you don't mind - game was freezing so I added the Waitframe(); in the right place. :P Also, for some reason, 8 isn't returning half a heart for me - instead, it's returning two whole hearts, meaning, whenever I get hit, I lose two whole hearts. Am I doing something wrong? ^^;

Oh, oops.
Don't tend to make that mistake nowadays.
Nevermind.

Ah well, must've got that one wrong. I haven't worked with eweapons in a while.
Change the 8 to a 2 at the top of the script if you want.