PDA

View Full Version : Silver Arrow As Separate Item



Lelouche Vi Britannia
03-16-2018, 01:38 AM
So I got the brilliant idea to have silver arrows be a different weapon in the game, which of course means scripting time.

This is what I have so far...



CONST CR_SARROW = 18 //Set Counter for Silver Arrows to Script 12
CONST CR_MAX_CL = 21 //Set Max Counter Clone for Sub Screen use to Script 15

item script SilverArrow
{
void run(int a, int damage) //D0 reserved for pick up message script
{
if (Game->Counter[CR_SARROW]<1){Quit();}
else
{
if Link->Item(15)=true; //Bow check Short Bow
{
int step = 100
}
if Link->Item(68)=true; //Bow check Long Bow
int step = 200
}
if Link->Item(50)=true; //Bow check Fairy Bow
int step = 400
}
lweapon shot = NextToLink(LW_ARROW,0);
Game->PlaySound(1);
shot->Dir = Link->Dir;
shot->Step = step;
shot->UseSprite(11);
shot->Damage = damage;
Game->Counter[CR_SARROW]--;
}
}
}


Now for questions based on the above.

1) What is the base step speed of the Short Bow? I figure 100 is probably too high but I don't know for sure. Conversely, is there a way to pull this information from elsewhere without setting a variable or is this an okay way to do it?
2) How do I make the projectile pierce?
3) How do I make the projectile leave a spark trail? I'm researching this since I think I might have asked for something like this a while back but don't remember the answer I was given on that note.

Thanks in advance.

Dimentio
03-16-2018, 03:42 AM
You don't need scripts for this. Just set silver arrows and wooden arrows as the "item override" in the subscreen for two different slots, and you'll be able to have both. At least, I believe it can work that way. I know DarkMatt did this with silver arrows also costing magic in his Fun in the Sun II.

Base Speed for Short Bow is 100. Scripted weapon speed is measured in 1/100ths of pixels per frame.
Piercing is an option in the item editor for silver arrows, though yo'll have to manually keep it alive if you go with scripts.
Sparkle trail you just set the sparkle sprite in the item editor and it'll enable it. If you wish to do this via scripts, just create LW_SPARKLE at the arrow's locations every few frames.

Lelouche Vi Britannia
03-16-2018, 11:12 AM
You don't need scripts for this. Just set silver arrows and wooden arrows as the "item override" in the subscreen for two different slots, and you'll be able to have both. At least, I believe it can work that way. I know DarkMatt did this with silver arrows also costing magic in his Fun in the Sun II.

Base Speed for Short Bow is 100. Scripted weapon speed is measured in 1/100ths of pixels per frame.
Piercing is an option in the item editor for silver arrows, though yo'll have to manually keep it alive if you go with scripts.
Sparkle trail you just set the sparkle sprite in the item editor and it'll enable it. If you wish to do this via scripts, just create LW_SPARKLE at the arrow's locations every few frames.

Which just leaves one tiny little problem which I'm sure is something else that needs to be scripted... a separate counter for the remaining shots. I don't think its as easy as changing the counter reference in the editor as this something hard-coded. Correct me if I'm wrong.

Anarchy_Balsac
03-16-2018, 06:29 PM
It may be easier to do if you replace the bows with scripted bows. This will allow you to do a simple:


If (arrows wooden)
Then deduct arrows
If (arrows silver)
Then deduct new variable for silver arrow count

As a bonus, if you later decide you want to do more tweeks, like, say, make the Fairy Bow do a Tri-Shot, you can.

Lelouche Vi Britannia
03-16-2018, 06:56 PM
It may be easier to do if you replace the bows with scripted bows. This will allow you to do a simple:


If (arrows wooden)
Then deduct arrows
If (arrows silver)
Then deduct new variable for silver arrow count

As a bonus, if you later decide you want to do more tweeks, like, say, make the Fairy Bow do a Tri-Shot, you can.

I had thought about that... but probably not going to go that route. I did, after much debuging and testing come up with a solution (its mixed with my RPG Counter Script so try to ignore that)...



import "std.zh"

const int CR_LIFEMIRRORMAX = 8; //Life Mirror for Max HP display on SS script 2
const int CR_MAGICMIRRORMAX = 9; //Magic Mirror for Max MP display on SS script 3
const int CR_LIFECUR = 10; //Life Current Mirror Script 4
const int CR_MAGICCUR = 11; //Magic Current Mirror Script 5
const int CR_SARROW = 18;// Silver Arrow Counter set to Script 12

//MaxHP and MaxMP for max values


global script Active
{
void run()
{
while(true)
{
GetEquipmentA();
GetEquipmentB();
SilverArrowStatus();
CounterUpdate();
Waitdraw();
Waitframe();
}
}
}

void SilverArrowStatus()
{
int j;
for(int i = Screen->NumLWeapons(); i>0; i--)
{
lweapon w=Screen->LoadLWeapon(i);
if (w->ID==LW_ARROW){j++;}
}
if (UsingItem(14)==true)
{
if (Game->Counter[CR_SARROW] < 1)
{
Link->ItemJinx = -1;
}
if (j > 0)
{
Link->ItemJinx = -1;
}
}
else
{
Link->ItemJinx = 0;
}
}

void CounterUpdate()
{
Game->Counter[CR_LIFEMIRRORMAX]=Link->MaxHP;
Game->Counter[CR_LIFECUR]=Link->HP;
Game->Counter[CR_MAGICMIRRORMAX]=Link->MaxMP;
Game->Counter[CR_MAGICCUR]=Link->MP;
}

item script SilverArrow
{
void run()
{
Game->Counter[CR_SARROW]--;
Game->Counter[CR_ARROWS]++;
}
}


The only downside I see with this method is plays with item jinx times, but I don't ever use enemies that cause item Jinx in game as its too easy to render Link completely helpless if both types of jinxers are in the same room, so in my case not much of a downside.

ZoriaRPG
03-17-2018, 11:49 AM
Here, try this script (https://github.com/ZoriaRPG/RPG_zh/blob/0.97-Alpha-Development/RPG_zh/ITEM_ARROW_CustomItemClass_v0.4.zs).

I wrote it ages ago, and it should do what you want to do, easily.

I wrote this when I was originally mucking about with itemdata in the source. That's why there are lines commented out, everywhere, as those only work in ZC >= 2.54. The script itself, as-is, works in 2.50.x.Pm

P.S. Here is the companion script, for custom bombs (https://github.com/ZoriaRPG/RPG_zh/blob/0.97-Alpha-Development/RPG_zh/ITEM_BOMB_CustomItemClass_v0.4.zs).

I recall writing that one for Evan.

Lelouche Vi Britannia
03-17-2018, 06:14 PM
I'll take a look when I'm off work. I'm actually quite proud if the one I wrote, it's my first successful for loop I've ever written, but I'm sure yours will work better.

Edit

Ok I glanced it while at work, it's a bit slow. I think I'll stick with my current, but this will come in handy when I get around to doing another quest I'm brainstorming.

Is there a link to your shared scripts? I'd love to see more of your work since I've been teaching myself coding by looking at the library files and other scripts to see how things interact. Its how I figured out how For Loops work.

ZoriaRPG
03-19-2018, 04:15 AM
I'll take a look when I'm off work. I'm actually quite proud if the one I wrote, it's my first successful for loop I've ever written, but I'm sure yours will work better.

Edit

Ok I glanced it while at work, it's a bit slow. I think I'll stick with my current, but this will come in handy when I get around to doing another quest I'm brainstorming.

Is there a link to your shared scripts? I'd love to see more of your work since I've been teaching myself coding by looking at the library files and other scripts to see how things interact. Its how I figured out how For Loops work.

Err.... The links are in my signature.

In what way was the item script 'slow'?

The arrow step speed can be changed, you know. ;)

ZoriaRPG
03-19-2018, 04:36 AM
For Loops

A for loop is similar to a while loop, except that the variable on which it depends can be in the scope of the loop.

The syntax is:
for ( DECLARATION/ASSIGN; STATEMENT; EXPRESSION )

Consider:



int x = 10;
while ( x > 0)
{
--x;
//do things
}


Using a for loop, you do not need a variable outside the loop (although you can still use a variable at a higher scope).



for (int x = 10; x > 0; --x )
{
//do things
}


That is functionally identical to the while loop.

ZScript for loops are identical to C for loops, so, I suggest reading more on those.

You can, as I mentioned, use an external variable, either with or without an assign in the for loop.



int x = 10;
for ( x = 5; x > 0; --x) //Changes the value of 'x' to '5' as the loop begins.
int y = 8;
for ( ; y > 0; --y ) //Uses the existing value of y.


That should help you get started. ;)

Lelouche Vi Britannia
03-20-2018, 01:10 PM
I meant its a slow work day. Your scripts are far from slow.