Code:
const int T_HOLDOUTWEAPON = 0; //Here we set the tile for the weapon. There should be 4 tiles on the tilesheet for it, arranged as the up sprite, then down, then left, then right
//We're going to use these two functions to check whether Link has the weapon equipped on A or B
//I'll let you work them out for yourself; if you don't want to you just have to use them, no need to understand them really
int StoreInput;
//Store whether Link pressed A or B to use an item
void StoreInput(){
if(Link->InputA && !Link->InputB) StoreInput = 1;
else if(Link->InputB && !Link->InputA) StoreInput = 2;
else if(Link->InputB && Link->InputA) StoreInput = 3;
else StoreInput = 0;
}
//Returns true if Link is holding down the button input we stored earlier
bool CheckInputs(){
return ((StoreInput == 1 && Link->InputA) || (StoreInput == 2 && Link->InputB)
|| (StoreInput == 3 && Link->InputA && Link->InputB));
}
bool HoldOutWeapon; //We use this to link to the global script
//I'm doing it as an item. If you don't like that, tough.
item script HoldOutLWeapon{
void run(){
HoldOutWeapon = true; //Tell the global script we've used the weapon
StoreInputs(); //Store which button Link has the weapon equipped on
}
}
//We're gonna need to link to the global script cause our item scripts run for only one frame
global script Slot2{
void run(){
HoldOutWeapon = false; //Make sure the weapon doesn't start when the game starts
while(true){
HoldOutWeapon(); //Call our function
Waitframe();
}
}
//The function to handle our weapon
void HoldOutLWeapon(){
if(!HoldOutWeapon || !CheckInputs()){//If we're not using the weapon, or if Link isn't holding down the button anymore, remove the weapon and return the function so the rest of the code doesn't run.
lweapon Remove = FindHeldWeapon(); //Load our weapon
if(Remove->IsValid()){ //Remember, the weapon might not actually be on the screen anyway, so in that case we don't need to get rid of it
Remove->DeadState = WDS_DEAD; //Remove it from the screen
}
return; //return the function so the rest of the code doesn't run
}
//Now for the part of the code that actually handles the weapon
lweapon HoldOut = FindHeldWeapon(); //First we check if we already made a weapon
if(!HoldOut->IsValid()){ //If we haven't made one yet, or if our weapon hit an enemy, we'll need to make a new one
HoldOut = Screen->CreateLWeapon(LW_SCRIPT1); //Actually make the weapon. Remember, when a weapon hits an enemy it's removed from the screen
HoldOut->Misc[0] = 1; //Here we mark our weapon so that we know later that it's the one we made, rather than another weapon
}
//We're going to use these variables in working out where the weapon should be positioned
int x; int y;
//I'll let you work out what this bit does, but basically it's my method for making sure the weapon is infront of Link
if(Link->Dir == DIR_UP || Link->Dir == DIR_DOWN) y = Link->Dir*32-16;
else x = (Link->Dir-2)*32-16;
HoldOut->X = Link->X+x; //Place the weapon infront of Link
HoldOut->Y = Link->Y+y;
HoldOut->Dir = Link->Dir; //This will make sure that the weapon pushes enemies back when it hits them
HoldOut->Damage = 8; //I think that's one hearts worth of damage, might not be though. I'll let you play around with that
HoldOut->Tile = T_HOLDOUTWEAPON+HoldOut->Dir; //Set the graphics for the weapon
}
//This function finds the weapon we made
lweapon FindHeldWeapon(){
for(int i=1;i<=Screen->NumLWeapons();i++){
//Check through all of the lweapons on the screen till we find the one we made earlier
lweapon l = Screen->LoadLWeapon(i);
//Our weapon is marked by setting it's Misc[0] value to 1, so we'll know if we've found it
if(l->Misc[0] == 1) return l;
}
//If our weapon's not on the screen, return an invalid pointer
return Screen->LoadLWeapon(0);
}
}
Right well.
I perhaps went a bit over the top there, but that should be quite a nice way of doing it.
If you don't get any of it, let me know and I'll explain it some more.
It will only work in builds 982 and 984 currently, but it should also work in the next build that we get. It won't work in 987.
For number 2, you can just make a new hookshot weapon with the item editor and make it only extend for 2 combos.
I'd rather not do the enemy weapon one, I'm not too keen on working with enemies.
Oh yeah, and I haven't actually tested that code so it might not compile quite right.
It'll just be a couple of semi-colons or brackets at the end of functions missed or something though, so I'm sure you can fix that.