I tried to do this by myself but I screwed it up big time, so can someone please put these scripts together for lil' ol' me so I can use them both?
Joe123's Shovel and Pegasus Boots in one script.
Started by
Dann Woolf
, Dec 13 2008 03:18 PM
6 replies to this topic
#1
Posted 13 December 2008 - 03:18 PM
#2
Posted 13 December 2008 - 04:51 PM
You don't have to have them in the same script to make them work.
At least, I don't think you do.
I mean, I've got plenty of different kinds of scripts at the moment, and they all work fine. However, I don't know how it is with item scripts... as I'm not scripter myself.
Sorry that I can't help you any more than just telling you this.
Cause I really wish I could.
At least, I don't think you do.
I mean, I've got plenty of different kinds of scripts at the moment, and they all work fine. However, I don't know how it is with item scripts... as I'm not scripter myself.
Sorry that I can't help you any more than just telling you this.
Cause I really wish I could.
#3
Posted 13 December 2008 - 05:16 PM
No, you indeed have to get them together since they are global scripts.
But it's quite easy to get them together.
But it's quite easy to get them together.
#4
Posted 13 December 2008 - 05:18 PM
The actual item scripts I have no problem with. However both items come with a pair of Global scripts, it's there that I have trouble.
#5
Posted 13 December 2008 - 05:21 PM
CODE
//Constants
//Global variables, constants and functions
const int F_DIG = 99; //Flag for unwalkable combos you can dig, and walkable combos you can't dig
const int SFX_DIG = 50; //Digging sound effect
const int CMB_DUG = 1418; //'Dug' combo
const int T_SHOVEL = 250; //First of 8 tiles shovel animation uses
const int ShovelCSet = 10; //CSet for shovel to use
const int CF_DASH = 98; //Flag that Link can't dash through if walkable, and will break if solid
const int SFX_DASH = 67; //Dashing SFX
const int SFX_HITWALL = 68; //Hitting a wall
const int SFX_PEGASUSBREAK = 66; //SFX to play when breaking a Pegasus Boot block
const int T_DUST = 27544; //Dust Kick-up tile
const int DustAFrames = 4; //Dust Kick-up animation frames
const int DustASpeed = 4; //Dust Kick-up animation speed
const int DustCSet = 3; //Dust Kick-up CSet
const int DashSFXLength = 9; //Time between repeating Dash SFX
//Variables
bool PegasusDash;
bool PegasusCollision;
int DashCounter;
int StoreInput;
int StoreHP;
int UseShovel;
//Functions
//Check inherent and regular flags at the same time
bool ComboFI(int x,int y,int combotype){
if(Screen->ComboF[ComboAt(x,y)] == combotype
|| Screen->ComboI[ComboAt(x,y)] == combotype) return true;
}
//Stops all Link's inputs
void NoAction(){
Link->InputUp = false;
Link->InputDown = false;
Link->InputLeft = false;
Link->InputRight = false;
Link->InputR = false;
Link->InputL = false;
Link->InputA = false;
Link->InputB = false;
}
//Solidity Check, by Saffith
bool isSolid(int x,int y){
if(x<0 || x>255 || y<0 || y>175) return false;
int mask = 1111b;
if(x%16<8) mask &= 0011b;
else mask &= 1100b;
if(y%16<8) mask &= 0101b;
else mask &= 1010b;
int ret = Screen->ComboS[ComboAt(x,y)]&mask;
return ret != 0;
}
//Global scripts
global script Slot_2{
void run(){
while(true){
//Call Pegasus Boots functions
if(PegasusDash) PegasusBoots();
//Other global script functions go here
if(UseShovel > 0) Shovel();
StoreHP = Link->HP;
Waitframe();
}
}
//Pegasus Boots
void PegasusBoots(){
if(!PegasusCollision){
int loc = ComboAt(Link->X+8,Link->Y+8);
//Check if Link should be dashing
if(((StoreInput == 1 && !Link->InputA)
|| (StoreInput == 2 && !Link->InputB))
|| StoreHP < Link->HP
|| Screen->ComboT[loc] == CT_WATER){
PegasusDash = false;
DashCounter = 0;
}
//Stop all actions
NoAction();
//Movement
if(DashCounter > 10){
if(Link->Dir == 0 && DashCheck(Link->X+8,Link->Y+6,true) != 2){
Link->Y--;
Link->InputUp = true;
}else if(Link->Dir == 1 && DashCheck(Link->X+8,Link->Y+18,true) != 2){
Link->Y++;
Link->InputDown = true;
}else if(Link->Dir == 2 && DashCheck(Link->X,Link->Y+12,false) != 2){
Link->X--;
Link->InputLeft = true;
}else if(Link->Dir == 3 && DashCheck(Link->X+16,Link->Y+12,false) != 2){
Link->X++;
Link->InputRight = true;
}else{
PegasusCollision = true;
DashCounter = 0;
}
}
//Break Pegasus Blocks
if(ComboFI(Link->X+8,Link->Y+8,CF_DASH) && Screen->ComboS[loc] == 1111b){
Screen->ComboD[loc]++;
if(Screen->ComboF[loc] == CF_DASH) Screen->ComboF[loc] = 0;
Game->PlaySound(SFX_PEGASUSBREAK);
}
//Dust tile animation
lweapon Dust;
if(DashCounter%4 == 0){
for(int j=1;j<=Screen->NumLWeapons();j++){
Dust = Screen->LoadLWeapon(j);
if(Dust->ID != LW_SCRIPT10) continue;
if(Link->Dir < 1) Dust->Y-=3;
else if(Link->Dir < 2) Dust->Y+=3;
else if(Link->Dir < 3) Dust->X-=3;
else if(Link->Dir < 4) Dust->X+=3;
}
Dust = Screen->CreateLWeapon(LW_SCRIPT10);
Dust->OriginalTile = T_DUST;
Dust->CSet = DustCSet;
Dust->Y = Link->Y;
Dust->X = Link->X;
Dust->NumFrames = DustAFrames;
Dust->ASpeed = DustASpeed;
Dust->DeadState = DustAFrames*DustASpeed;
}
//Play SFX
if(DashCounter%DashSFXLength == 0) Game->PlaySound(SFX_DASH);
}else{
//Bounceback after hitting a wall
NoAction();
if(DashCounter == 1){
Screen->ClearSprites(SL_LWPNS);
Game->PlaySound(SFX_HITWALL);
Screen->Quake = 10;
}else if(DashCounter == 10){
PegasusDash = false;
PegasusCollision = false;
DashCounter = 0;
}
if(Link->Dir == 0 && DashCheck(Link->X+8,Link->Y+6,true) == 0) Link->Y++;
else if(Link->Dir == 1 && DashCheck(Link->X+8,Link->Y+18,true) == 0) Link->Y--;
else if(Link->Dir == 2 && DashCheck(Link->X+18,Link->Y+8,false) == 0) Link->X++;
else if(Link->Dir == 3 && DashCheck(Link->X-2,Link->Y+8,false) == 0) Link->X--;
if(DashCounter < 5) Link->Z++;
}
DashCounter++;
}
//Shovel
void Shovel(){
UseShovel++;
if(UseShovel < 20){
if(UseShovel == 2 || UseShovel == 6) Link->Action = LA_ATTACKING;
int t = T_SHOVEL+Link->Dir*2+Floor(UseShovel/10);
if(Link->Dir == 0) Screen->DrawTile(2+Floor(UseShovel/10),Link->X,Link->Y-12+Floor(UseShovel/10)*8,t,1,1,ShovelCSet,1,0,0,0,0,true,128);
else if(Link->Dir == 1) Screen->DrawTile(3,Link->X,Link->Y+8-Floor(UseShovel/10)*16,t,1,1,ShovelCSet,1,0,0,0,0,true,128);
else if(Link->Dir == 2) Screen->DrawTile(3,Link->X-8+Floor(UseShovel/10)*8,Link->Y-Floor(UseShovel/10)*8,t,1,1,ShovelCSet,1,0,0,0,0,true,128);
else Screen->DrawTile(3,Link->X+8-Floor(UseShovel/10)*8,Link->Y-Floor(UseShovel/10)*8,t,1,1,ShovelCSet,1,0,0,0,0,true,128);
NoAction();
}else{
int dx = Link->X%16;
int dy = Link->Y%16;
if(Link->Dir < 2){
if(Link->Dir == 0) dy = Link->Y-dy;
else if(dy > 8) dy = Link->Y+(16-dy);
else dy = Link->Y+24-dy;
if(dx < 8) dx = Link->X-dx;
else dx = Link->X+(16-dx);
}else{
if(dx > 8){
if(Link->Dir == 2) dx = Link->X-dx;
else dx = Link->X+(16-dx);
}else{
if(Link->Dir == 2) dx = Link->X-dx + (Link->Dir-2)*16-8;
else dx = Link->X+(16-dx) + (Link->Dir-2)*16-8;
}
if(dy < 8) dy = Link->Y-dy;
else dy = Link->Y+(16-dy);
}
int loc = ComboAt(dx,dy);
if(Screen->ComboT[loc] == 0 &&
((Screen->ComboS[loc] == 0 && !ComboFI(dx,dy,F_DIG)) ||
(Screen->ComboS[loc] != 0 && ComboFI(dx,dy,F_DIG)))
&& Screen->ComboD[loc] != CMB_DUG){
Screen->ComboD[loc] = CMB_DUG;
int chance = Rand(200);
item got;
if(chance < 5){
npc e = Screen->CreateNPC(44);
e->X = dx;
e->Y = dy;
}else if(chance < 6) got = Screen->CreateItem(I_RUPEE50);
else if(chance < 14) got = Screen->CreateItem(I_RUPEE5);
else if(chance < 24) got = Screen->CreateItem(I_HEART);
else if(chance < 44) got = Screen->CreateItem(I_RUPEE1);
if(got->isValid()){
got->X = loc%16*16;
got->Y = loc-loc%16;
}
Game->PlaySound(SFX_DIG);
}else Game->PlaySound(SFX_TAP1);
UseShovel = 0;
}
}
//Check whether Link can dash onto a combo
int DashCheck(int x, int y, bool xy){
int xoffset; int yoffset;
bool Solid;
if(xy) xoffset = 4;
else yoffset = 3;
if(isSolid(x-xoffset,y-yoffset) || isSolid(x+xoffset,y+yoffset)) Solid = true;
if(!Solid && !ComboFI(x-xoffset,y-yoffset,CF_DASH)
&& !ComboFI(x+xoffset,y+yoffset,CF_DASH)) return 0;
else if(Solid && (ComboFI(x-xoffset,y-yoffset,CF_DASH)
|| ComboFI(x+xoffset,y+yoffset,CF_DASH))) return 1;
else return 2;
}
}
global script Slot_3{
void run(){
PegasusDash = false;
PegasusCollision = false;
UseShovel = 0;
}
}
item script PegasusBoots{
void run(){
if(Screen->ComboT[ComboAt(Link->X+8,Link->Y+8)] == CT_WATER
|| ComboFI(Link->X+8,Link->Y+8,CF_DASH)) Quit();
PegasusDash = true;
if(Link->InputB && !Link->InputA) StoreInput = 2;
else if(Link->InputA && !Link->InputB) StoreInput = 1;
}
}
item script Shovel{
void run(){
if(Link->Z == 0) UseShovel++;
}
}
//Global variables, constants and functions
const int F_DIG = 99; //Flag for unwalkable combos you can dig, and walkable combos you can't dig
const int SFX_DIG = 50; //Digging sound effect
const int CMB_DUG = 1418; //'Dug' combo
const int T_SHOVEL = 250; //First of 8 tiles shovel animation uses
const int ShovelCSet = 10; //CSet for shovel to use
const int CF_DASH = 98; //Flag that Link can't dash through if walkable, and will break if solid
const int SFX_DASH = 67; //Dashing SFX
const int SFX_HITWALL = 68; //Hitting a wall
const int SFX_PEGASUSBREAK = 66; //SFX to play when breaking a Pegasus Boot block
const int T_DUST = 27544; //Dust Kick-up tile
const int DustAFrames = 4; //Dust Kick-up animation frames
const int DustASpeed = 4; //Dust Kick-up animation speed
const int DustCSet = 3; //Dust Kick-up CSet
const int DashSFXLength = 9; //Time between repeating Dash SFX
//Variables
bool PegasusDash;
bool PegasusCollision;
int DashCounter;
int StoreInput;
int StoreHP;
int UseShovel;
//Functions
//Check inherent and regular flags at the same time
bool ComboFI(int x,int y,int combotype){
if(Screen->ComboF[ComboAt(x,y)] == combotype
|| Screen->ComboI[ComboAt(x,y)] == combotype) return true;
}
//Stops all Link's inputs
void NoAction(){
Link->InputUp = false;
Link->InputDown = false;
Link->InputLeft = false;
Link->InputRight = false;
Link->InputR = false;
Link->InputL = false;
Link->InputA = false;
Link->InputB = false;
}
//Solidity Check, by Saffith
bool isSolid(int x,int y){
if(x<0 || x>255 || y<0 || y>175) return false;
int mask = 1111b;
if(x%16<8) mask &= 0011b;
else mask &= 1100b;
if(y%16<8) mask &= 0101b;
else mask &= 1010b;
int ret = Screen->ComboS[ComboAt(x,y)]&mask;
return ret != 0;
}
//Global scripts
global script Slot_2{
void run(){
while(true){
//Call Pegasus Boots functions
if(PegasusDash) PegasusBoots();
//Other global script functions go here
if(UseShovel > 0) Shovel();
StoreHP = Link->HP;
Waitframe();
}
}
//Pegasus Boots
void PegasusBoots(){
if(!PegasusCollision){
int loc = ComboAt(Link->X+8,Link->Y+8);
//Check if Link should be dashing
if(((StoreInput == 1 && !Link->InputA)
|| (StoreInput == 2 && !Link->InputB))
|| StoreHP < Link->HP
|| Screen->ComboT[loc] == CT_WATER){
PegasusDash = false;
DashCounter = 0;
}
//Stop all actions
NoAction();
//Movement
if(DashCounter > 10){
if(Link->Dir == 0 && DashCheck(Link->X+8,Link->Y+6,true) != 2){
Link->Y--;
Link->InputUp = true;
}else if(Link->Dir == 1 && DashCheck(Link->X+8,Link->Y+18,true) != 2){
Link->Y++;
Link->InputDown = true;
}else if(Link->Dir == 2 && DashCheck(Link->X,Link->Y+12,false) != 2){
Link->X--;
Link->InputLeft = true;
}else if(Link->Dir == 3 && DashCheck(Link->X+16,Link->Y+12,false) != 2){
Link->X++;
Link->InputRight = true;
}else{
PegasusCollision = true;
DashCounter = 0;
}
}
//Break Pegasus Blocks
if(ComboFI(Link->X+8,Link->Y+8,CF_DASH) && Screen->ComboS[loc] == 1111b){
Screen->ComboD[loc]++;
if(Screen->ComboF[loc] == CF_DASH) Screen->ComboF[loc] = 0;
Game->PlaySound(SFX_PEGASUSBREAK);
}
//Dust tile animation
lweapon Dust;
if(DashCounter%4 == 0){
for(int j=1;j<=Screen->NumLWeapons();j++){
Dust = Screen->LoadLWeapon(j);
if(Dust->ID != LW_SCRIPT10) continue;
if(Link->Dir < 1) Dust->Y-=3;
else if(Link->Dir < 2) Dust->Y+=3;
else if(Link->Dir < 3) Dust->X-=3;
else if(Link->Dir < 4) Dust->X+=3;
}
Dust = Screen->CreateLWeapon(LW_SCRIPT10);
Dust->OriginalTile = T_DUST;
Dust->CSet = DustCSet;
Dust->Y = Link->Y;
Dust->X = Link->X;
Dust->NumFrames = DustAFrames;
Dust->ASpeed = DustASpeed;
Dust->DeadState = DustAFrames*DustASpeed;
}
//Play SFX
if(DashCounter%DashSFXLength == 0) Game->PlaySound(SFX_DASH);
}else{
//Bounceback after hitting a wall
NoAction();
if(DashCounter == 1){
Screen->ClearSprites(SL_LWPNS);
Game->PlaySound(SFX_HITWALL);
Screen->Quake = 10;
}else if(DashCounter == 10){
PegasusDash = false;
PegasusCollision = false;
DashCounter = 0;
}
if(Link->Dir == 0 && DashCheck(Link->X+8,Link->Y+6,true) == 0) Link->Y++;
else if(Link->Dir == 1 && DashCheck(Link->X+8,Link->Y+18,true) == 0) Link->Y--;
else if(Link->Dir == 2 && DashCheck(Link->X+18,Link->Y+8,false) == 0) Link->X++;
else if(Link->Dir == 3 && DashCheck(Link->X-2,Link->Y+8,false) == 0) Link->X--;
if(DashCounter < 5) Link->Z++;
}
DashCounter++;
}
//Shovel
void Shovel(){
UseShovel++;
if(UseShovel < 20){
if(UseShovel == 2 || UseShovel == 6) Link->Action = LA_ATTACKING;
int t = T_SHOVEL+Link->Dir*2+Floor(UseShovel/10);
if(Link->Dir == 0) Screen->DrawTile(2+Floor(UseShovel/10),Link->X,Link->Y-12+Floor(UseShovel/10)*8,t,1,1,ShovelCSet,1,0,0,0,0,true,128);
else if(Link->Dir == 1) Screen->DrawTile(3,Link->X,Link->Y+8-Floor(UseShovel/10)*16,t,1,1,ShovelCSet,1,0,0,0,0,true,128);
else if(Link->Dir == 2) Screen->DrawTile(3,Link->X-8+Floor(UseShovel/10)*8,Link->Y-Floor(UseShovel/10)*8,t,1,1,ShovelCSet,1,0,0,0,0,true,128);
else Screen->DrawTile(3,Link->X+8-Floor(UseShovel/10)*8,Link->Y-Floor(UseShovel/10)*8,t,1,1,ShovelCSet,1,0,0,0,0,true,128);
NoAction();
}else{
int dx = Link->X%16;
int dy = Link->Y%16;
if(Link->Dir < 2){
if(Link->Dir == 0) dy = Link->Y-dy;
else if(dy > 8) dy = Link->Y+(16-dy);
else dy = Link->Y+24-dy;
if(dx < 8) dx = Link->X-dx;
else dx = Link->X+(16-dx);
}else{
if(dx > 8){
if(Link->Dir == 2) dx = Link->X-dx;
else dx = Link->X+(16-dx);
}else{
if(Link->Dir == 2) dx = Link->X-dx + (Link->Dir-2)*16-8;
else dx = Link->X+(16-dx) + (Link->Dir-2)*16-8;
}
if(dy < 8) dy = Link->Y-dy;
else dy = Link->Y+(16-dy);
}
int loc = ComboAt(dx,dy);
if(Screen->ComboT[loc] == 0 &&
((Screen->ComboS[loc] == 0 && !ComboFI(dx,dy,F_DIG)) ||
(Screen->ComboS[loc] != 0 && ComboFI(dx,dy,F_DIG)))
&& Screen->ComboD[loc] != CMB_DUG){
Screen->ComboD[loc] = CMB_DUG;
int chance = Rand(200);
item got;
if(chance < 5){
npc e = Screen->CreateNPC(44);
e->X = dx;
e->Y = dy;
}else if(chance < 6) got = Screen->CreateItem(I_RUPEE50);
else if(chance < 14) got = Screen->CreateItem(I_RUPEE5);
else if(chance < 24) got = Screen->CreateItem(I_HEART);
else if(chance < 44) got = Screen->CreateItem(I_RUPEE1);
if(got->isValid()){
got->X = loc%16*16;
got->Y = loc-loc%16;
}
Game->PlaySound(SFX_DIG);
}else Game->PlaySound(SFX_TAP1);
UseShovel = 0;
}
}
//Check whether Link can dash onto a combo
int DashCheck(int x, int y, bool xy){
int xoffset; int yoffset;
bool Solid;
if(xy) xoffset = 4;
else yoffset = 3;
if(isSolid(x-xoffset,y-yoffset) || isSolid(x+xoffset,y+yoffset)) Solid = true;
if(!Solid && !ComboFI(x-xoffset,y-yoffset,CF_DASH)
&& !ComboFI(x+xoffset,y+yoffset,CF_DASH)) return 0;
else if(Solid && (ComboFI(x-xoffset,y-yoffset,CF_DASH)
|| ComboFI(x+xoffset,y+yoffset,CF_DASH))) return 1;
else return 2;
}
}
global script Slot_3{
void run(){
PegasusDash = false;
PegasusCollision = false;
UseShovel = 0;
}
}
item script PegasusBoots{
void run(){
if(Screen->ComboT[ComboAt(Link->X+8,Link->Y+8)] == CT_WATER
|| ComboFI(Link->X+8,Link->Y+8,CF_DASH)) Quit();
PegasusDash = true;
if(Link->InputB && !Link->InputA) StoreInput = 2;
else if(Link->InputA && !Link->InputB) StoreInput = 1;
}
}
item script Shovel{
void run(){
if(Link->Z == 0) UseShovel++;
}
}
That should work.
#6
Posted 13 December 2008 - 05:47 PM
It works! Thanks man!
I can't code my way out of a wet paper bag so it's nice to have others help me out. Thanks again!
I can't code my way out of a wet paper bag so it's nice to have others help me out. Thanks again!
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users