Jump to content

Photo

Item-3: Desctruction Machine


  • Please log in to reply
20 replies to this topic

#1 Nimono

Nimono

    Ultra Miyoa Extraordinaire!

  • Members
  • Real Name:Matthew
  • Location:Static Void Kingdom

Posted 14 February 2007 - 04:57 PM

Well, ignore the lame name for this script. The only other name I had for it was "Random Killer", and that didn't sound very good. This sounds a bit better. No variables to change this time- The script does everything for you. icon_biggrin.gif What does it do? Kills one random enemy. For now, it requires no magic. Why? I couldn't seem to get it to work. -_- Oh well.

CODE
// Destruction Machine- This item randomly kills one enemy in the current room.

item script Killer
{
    int RandNum = 0;
    int RandNPC = 0;
    int Magic = 192;

    void run()
    {
    if (Link->MP >= Magic)
    {
    int ScrnNPC = Screen->NumNPCs();
    if (ScrnNPC == 0)
    {
    Quit();
    }
        else if (ScrnNPC == 1)
        {
            npc RandNPC = Screen->LoadNPC (1);
            RandNPC->HP = 0;
        }
        else if (ScrnNPC == 2)
        {
            RandNum = 1 + Rand(2);
            npc RandNPC = Screen->LoadNPC (RandNum);
            RandNPC->HP = 0;
        }
        else if (ScrnNPC == 3)
        {
            RandNum = 1 + Rand(3);
            npc RandNPC = Screen->LoadNPC (RandNum);
            RandNPC->HP = 0;
        }
        else if (ScrnNPC == 4)
        {
            RandNum = 1 + Rand(4);
            npc RandNPC = Screen->LoadNPC (RandNum);
            RandNPC->HP = 0;
        }
        else if (ScrnNPC == 5)
        {
            RandNum = 1 + Rand(5);
            npc RandNPC = Screen->LoadNPC (RandNum);
            RandNPC->HP = 0;
        }
        else if (ScrnNPC == 6)
        {
            RandNum = 1 + Rand(6);
            npc RandNPC = Screen->LoadNPC (RandNum);
            RandNPC->HP = 0;
        }
        else if (ScrnNPC == 7)
        {
            RandNum = 1 + Rand(7);
            npc RandNPC = Screen->LoadNPC (RandNum);
            RandNPC->HP = 0;
        }
        else if (ScrnNPC == 8)
        {
            RandNum = 1 + Rand(8);
            npc RandNPC = Screen->LoadNPC (RandNum);
            RandNPC->HP = 0;
        }
        else if (ScrnNPC == 9)
        {
            RandNum = 1 + Rand(9);
            npc RandNPC = Screen->LoadNPC (RandNum);
            RandNPC->HP = 0;
        }
        else if (ScrnNPC == 10)
        {
            RandNum = 1 + Rand(10);
            npc RandNPC = Screen->LoadNPC (RandNum);
            RandNPC->HP = 0;
        }
    Link->MP = Link->MP - Magic;
    }
    }
}


Yes, all those checks are necessary. It'll crash ZC if it finds an invalid NPC, so... icon_wink.gif Oh yeah, you might want to disable this in Guy rooms. Otherwise, you'll KILL the guy. :O I think. Oh well. Have fun. Oh yeah, I'm still open to more requests. However....

If you request an item from Twilight Princess, you WILL be denied! But only because I haven't beaten the game yet and have yet to see very many items.... icon_razz.gif

Edit: Yay, got the Magic to work. This script now takes away Magic when used, but if you don't have enough magic when you use it..... NOTHING HAPPENS. Just like the Lens. :O By the way, new Variable: Magic. It's pre-defined at a whopping SIX WHOLE Magic Containers worth of Magic (192 units!), but if you think that's too harsh, you're welcome to change it. If you want whole containers, multiply 32 (Magic units in one Magic Container) by the number of containers to take away. 6 times 32 is 192, so.... That's where I got 192 from. icon_razz.gif Good luck using this....

Edit 2: Oopsie. I made a minor mistake on my part. The Magic check isn't supposed to fail if you have more than the required amount of Magic. XD

Edited by Matthew, 15 February 2007 - 07:34 PM.


#2 Fire Wizzrobe

Fire Wizzrobe

    Master

  • Members
  • Real Name:T

Posted 14 February 2007 - 05:39 PM

Use (rand()%10)+1 to generate a number from one to ten..

Ideal Code that will shorten yours by a lot:

Just declare every varaible as a double (Meaning it can take on - and + values) for safety.
...else if (ScreenNCP <= 2){
RandNum = (Rand()%(abs(0 - ScreenNCP)))+1;
ncp RandNCP = Screen->LoadNCP (RandNum);
RandNCP->HP = 0;
}

Basicly, you don't have to preform any checks after that. (Place this peice of code after the 1 Ncp check)

Edited by Fire Wizzrobe, 14 February 2007 - 09:42 PM.


#3 Nimono

Nimono

    Ultra Miyoa Extraordinaire!

  • Members
  • Real Name:Matthew
  • Location:Static Void Kingdom

Posted 14 February 2007 - 06:14 PM

QUOTE(Fire Wizzrobe @ Feb 14 2007, 05:39 PM) View Post

Use (rand()%10)+1 to generate a number from one to ten..

Ideal Code that will shorten yours by a lot:

...else if (ScreenNPC <= 1){
RandNum = (rand()%(10 - ScreenNCP))+1;
ncp RandNcp = Screen->LoadNcp (RandNum);
RandNcp->HP = 0;
}

Basicly, you don't have to preform any checks after that. (Place this peice of code after the 0 Ncp check)

No thank you. I don't care how long the script is as long as it works. And by the way, will that code ever pick an invalid NPC? Like, say there was only 9 NPCs on the screen. Would that number ever turn up as 10?

#4 Fire Wizzrobe

Fire Wizzrobe

    Master

  • Members
  • Real Name:T

Posted 14 February 2007 - 06:34 PM

No it wouldn't pick up an invalid NCP ever. (Well, being the new code I edited in. I just realized my flawed logic)

Shorter = faster, so why not?

Edited by Fire Wizzrobe, 14 February 2007 - 06:35 PM.


#5 Kite

Kite

  • Members

Posted 14 February 2007 - 07:15 PM

If, for some reason, someone wanted to make changes to what happens with this item, people could change one or two blocks of code much easier than eleven. That's why shorter would be better in this situation. icon_shrug.gif

#6 Nimono

Nimono

    Ultra Miyoa Extraordinaire!

  • Members
  • Real Name:Matthew
  • Location:Static Void Kingdom

Posted 14 February 2007 - 07:33 PM

QUOTE(Nick @ Feb 14 2007, 07:15 PM) View Post

If, for some reason, someone wanted to make changes to what happens with this item, people could change one or two blocks of code much easier than eleven. That's why shorter would be better in this situation. icon_shrug.gif

If you say so.

Fire Wizzrobe, I guess I'll test out your code then.

Edit: o.o Why did you misspell NPC EVERY time you used it?

Edit 2: This line isn't working:
CODE
RandNum = (Rand() % (Abs (0 - ScrnNPC) ) ) + 1;

Something's going wrong with the "Rand" part, possibly the fact that you're not putting ANYTHING in the () beside "Rand"....

Edit 3: I don't know WHY you're doing "% (Abs (0 - ScrnNPC))", so I took that out and used "Rand(ScrnNPC)". That didn't work. So, for now, people will have to use the old version.

Edited by Matthew, 14 February 2007 - 07:49 PM.


#7 Kite

Kite

  • Members

Posted 14 February 2007 - 08:12 PM

[codebox]// Destruction Machine- This item randomly kills one enemy in the current room.

item script Killer
{
int RandNum = 0;
int RandNPC = 0;

void run()
{
int ScrnNPC = Screen->NumNPCs();
if (ScrnNPC == 0)
{
Quit();
}
else if (ScrnNPC == 1)
{
npc RandNPC = Screen->LoadNPC (1);
RandNPC->HP = 0;
Quit();
}
else if (ScrnNPC > 1 && ScrnNPC <= 10)
{
RandNum = 1 + Rand(ScrnNPC);
npc RandNPC = Screen->LoadNPC (RandNum);
RandNPC->HP = 0;
Quit();
}
}
}[/codebox]

I just edited the if-else statement. I didn't touch the actual code within beyond changing what Rand(x) referred to. This code compiled on my end, but I've not tested if it actually works.

In actuality, this if-else sequence could be made even more simple, but I'd rather not fool with it. While I like smaller code, I don't go insane with it. icon_razz.gif

#8 Nimono

Nimono

    Ultra Miyoa Extraordinaire!

  • Members
  • Real Name:Matthew
  • Location:Static Void Kingdom

Posted 14 February 2007 - 08:20 PM

QUOTE(Nick @ Feb 14 2007, 08:12 PM) View Post

[codebox]// Destruction Machine- This item randomly kills one enemy in the current room.

item script Killer
{
int RandNum = 0;
int RandNPC = 0;

void run()
{
int ScrnNPC = Screen->NumNPCs();
if (ScrnNPC == 0)
{
Quit();
}
else if (ScrnNPC == 1)
{
npc RandNPC = Screen->LoadNPC (1);
RandNPC->HP = 0;
Quit();
}
else if (ScrnNPC > 1 && ScrnNPC <= 10)
{
RandNum = 1 + Rand(ScrnNPC);
npc RandNPC = Screen->LoadNPC (RandNum);
RandNPC->HP = 0;
Quit();
}
}
}[/codebox]

I just edited the if-else statement. I didn't touch the actual code within beyond changing what Rand(x) referred to. This code compiled on my end, but I've not tested if it actually works.

In actuality, this if-else sequence could be made even more simple, but I'd rather not fool with it. While I like smaller code, I don't go insane with it. icon_razz.gif

I'd appreciate it if you'd test it for me, though. I'm kinda getting tired of everyone shoving code fixes in my face and execting ME to test it all out.... Thanks.

#9 Fire Wizzrobe

Fire Wizzrobe

    Master

  • Members
  • Real Name:T

Posted 14 February 2007 - 08:30 PM

Guess I don't know how to use Absolute Values well or your not declaring your doubles.... Guess I should practice more because C++ does not work exactly the same way as Z-scripts. What are the exact errors the compiler is giving you?

Try putting this in the beggining of the run:
srand((unsigned)time(0));

Edited by Fire Wizzrobe, 14 February 2007 - 09:49 PM.


#10 Kite

Kite

  • Members

Posted 14 February 2007 - 08:36 PM

My code works if it's supposed to kill an enemy each time the item is used. Might want to think of a way to get that working with magic or come up with another limiter in the future, though. Makes things insanely easy otherwise. icon_shrug.gif

Edit: Maybe the item could be a one time use thing? Once Link uses it, the script will make the item take itself away. Then you have to go get another one.

#11 Nimono

Nimono

    Ultra Miyoa Extraordinaire!

  • Members
  • Real Name:Matthew
  • Location:Static Void Kingdom

Posted 14 February 2007 - 09:08 PM

QUOTE(Nick @ Feb 14 2007, 08:36 PM) View Post

My code works if it's supposed to kill an enemy each time the item is used. Might want to think of a way to get that working with magic or come up with another limiter in the future, though. Makes things insanely easy otherwise. icon_shrug.gif

Edit: Maybe the item could be a one time use thing? Once Link uses it, the script will make the item take itself away. Then you have to go get another one.

Oh, I was gonna do that, but I kinda messed up on the Link->MP thing.... or so I thought.... I just need this code to work like it was supposed to before in a shorter version, and it'll be good to go. icon_wink.gif I already have the magic-draining working. icon_wink.gif

Edit: icon_unsettled.gif Your code isn't working, either, Nick. You guys'll just have to use the version I posted until this is fixed.... even though it works perfectly fine right now....

Edited by Matthew, 14 February 2007 - 09:36 PM.


#12 CastChaos

CastChaos

    Deified

  • Members

Posted 15 February 2007 - 04:39 AM

This item really kills the Guy? It shouldn't do it. As I see, this script kills one enemy from the 10 placed enemy. Well, the guy isn't among the 10 placed Data->Enemies. It's in a different menu (Data->Guy). Of course you can use the enemy editor to make a new guy and place it among the 10 enemies... in this case this script surely kills the guy.

Also, this script makes the game extremely easy... just thik about having a 4-head-fire-gleeok. It should be very hard, but this item kills it with ease. My first thought were to decrease the magic usage, but thinking about it, I should set it to maximum. Or some very high number, since I don't know how much the maximum is.

This could get the graphics of the Holy Cross from Castlevania Chronicles, since it destroyed all enemies on screen.

#13 Nimono

Nimono

    Ultra Miyoa Extraordinaire!

  • Members
  • Real Name:Matthew
  • Location:Static Void Kingdom

Posted 15 February 2007 - 09:34 AM

QUOTE(CastChaos @ Feb 15 2007, 04:39 AM) View Post

This item really kills the Guy? It shouldn't do it. As I see, this script kills one enemy from the 10 placed enemy. Well, the guy isn't among the 10 placed Data->Enemies. It's in a different menu (Data->Guy). Of course you can use the enemy editor to make a new guy and place it among the 10 enemies... in this case this script surely kills the guy.

Also, this script makes the game extremely easy... just thik about having a 4-head-fire-gleeok. It should be very hard, but this item kills it with ease. My first thought were to decrease the magic usage, but thinking about it, I should set it to maximum. Or some very high number, since I don't know how much the maximum is.

This could get the graphics of the Holy Cross from Castlevania Chronicles, since it destroyed all enemies on screen.

No, here's the thing: The Guy is an NPC. Enemies are ALSO NPCs. Screen->NumNPCs finds the number of Enemies AND guys in the room! And plus, if you don't want it to work against a boss, DISABLE IT IN A NEW DMAP FOR THE BOSS. What's so hard about that? Plus, this should be placed as a bonus item at the end of the game. But think about this: You can only have 8 Magic Containers at a time, right? Well, if you leave this script alone, it requires 6 Magic Containers worth of Magic to use. In other words, even with a max Magic Meter (8 Containers), you'll STILL only be able to use it once before you have to refill your Magic! Plus, with another line, you can take the item away from Link the moment he uses it. So there. And just so you know, 8 Magic Containers is 256 pieces of Magic (Hmm, where have I seen that number before? icon_razz.gif), so replace 192 with 256 if you want this script to use all 8 Magic Containers. And seriously, you can't say this item makes the game easy if it requires SIX WHOLE MAGIC CONTAINERS. It'd take a while to get all that Magic back. ....You know, we need some Bubbles that take away Link's Magic....

#14 Kite

Kite

  • Members

Posted 15 February 2007 - 12:05 PM

QUOTE(Matthew @ Feb 14 2007, 09:08 PM) View Post

Edit: icon_unsettled.gif Your code isn't working, either, Nick. You guys'll just have to use the version I posted until this is fixed.... even though it works perfectly fine right now....

All I can tell you is that it worked for me. I compiled the script and placed it on the letter to test it out. icon_shrug.gif

It doesn't really matter, to be honest. It's mainly just a good programming practice to avoid redundant code. I'm overly picky about redundant code... much the same way that I'm picky about how I comment my own code. However, it ultimately doesn't matter for something like ZC. icon_shrug.gif

#15 Nimono

Nimono

    Ultra Miyoa Extraordinaire!

  • Members
  • Real Name:Matthew
  • Location:Static Void Kingdom

Posted 15 February 2007 - 12:08 PM

QUOTE(Nick @ Feb 15 2007, 12:05 PM) View Post

All I can tell you is that it worked for me. I compiled the script and placed it on the letter to test it out. icon_shrug.gif

It doesn't really matter, to be honest. It's mainly just a good programming practice to avoid redundant code. I'm overly picky about redundant code... much the same way that I'm picky about how I comment my own code. However, it ultimately doesn't matter for something like ZC. icon_shrug.gif

Well, it doesn't really do anything once I add the code for Magic consumption. icon_unsettled.gif Maybe THAT'S why. Maybe it expects an indent for every line.... otherwise, it fails.


1 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users


    Bing (1)