Jump to content

Photo

Need help with enemy scripts and scripting in general


  • Please log in to reply
35 replies to this topic

#1 Bokoblin

Bokoblin

    added tree hair

  • Members

Posted 06 March 2023 - 07:00 PM

I want to know how to make more "complex" enemies.

 

The core of TLOZ is its enemy design, and TLOZ Expanded is built upon the same core.

 

I downloaded a few things to make this endeavor easier, such as ghost.zh, status.zh, and Emily's summoner script. I need to assign slots for those, and I don't know how to do that.

 

Right now, I'm getting this weird error when I compile the scripts.

 

"[Error] ghost2_common.zh Line 5 @ Columns 11-36 - Error S008: There is already a variable with name __GHI_DRAW_COMBO in this scope."
 
It's something to do with ghost.zh on line 5, but last I checked, line 5 was perfectly fine. No misspells or anything, the file that is supposed to be on line 5 is there.
 
 
I downloaded status.zh because I need to make status effects, such as "frozen" or "on fire". I'm planning on making elemental Wizzrobes and Octoroks, you can see my Wizzrobe redesign in the official TLOZ Expanded thread.
 
I also need to make enemies teleport say...3 tiles behind the player.
 
I want to make enemies summon other enemies, that's why I downloaded the summoner script.
 
I need to make enemies spawn at your location, then despawn after 180 frames (60 fps) for a boss fight.
 
I need to make an enemy spawn right at the location another enemy died for another boss fight.
 
I need to make an enemy randomly select between multiple attacks for boss fights.
 
I need to know how to make custom attacks for enemies.
 
Can y'all please teach me how to do all of this? My dumb ass will be taking notes and everything.
 
Thanks,
-Bokoblin


#2 Moosh

Moosh

    Tiny Little Questmaker

  • ZC Developers

Posted 06 March 2023 - 08:35 PM

When you get a "There is already a variable with the name" error, that usually means you've imported a header file twice. In this case that's probably ghost.zh because I can't imagine you or a script you're using would have imported ghost2_common.zh on its own. 
 
Your other questions are a little much to answer in a forum topic, but here's some thoughts (though not necessarily answers) for each:

I also need to make enemies teleport say...3 tiles behind the player.

This is a little more complicated than it may seem. The logic for placing the enemy three tiles behind the player isn't so bad (I'd use DirX() and DirY()), but then what happens if that space is occupied? What if it's offscreen? That's the fun thing with teleporting logic, finding ways to handle these special cases.
 

I want to make enemies summon other enemies, that's why I downloaded the summoner script.

This would use Screen->CreateNPC() (ZScript.txt) or CreateNPCAt() (std_functions.zh). Pretty straightforward. To create multiple enemies, you'd do it in a loop, to spread them out use a Rand() call or some trig.
 

I need to make enemies spawn at your location, then despawn after 180 frames (60 fps) for a boss fight.

You probably don't want enemies telefragging the player without any indication, but you can get the player's position with Link->X and Link->Y, then move your enemy to that spot. Delays can be done with Waitframes() or a timer variable.
 

I need to make an enemy spawn right at the location another enemy died for another boss fight.

This is somewhat easy if you have a structure for enemies having a custom death animation down. Otherwise it may be easier to just write a separate script that tracks your boss enemy's HP and then spawns in the next one when it hits 0.
 

I need to make an enemy randomly select between multiple attacks for boss fights.

At the simplest that's just the Rand() function. Your bosses will be way more interesting if you give them some logic besides random number generation but a switch statement with Rand() is perfectly functional for something simple.
 

I need to know how to make custom attacks for enemies.

That's a doozy of a question right there. I'd still like to know myself. For starters you're probably going to be creating a lot of for loops that do different things with eweapons. Just playing around with different bullet patterns and bullet sprites is a good starting point for bosses. Then you have to start thinking about "what purpose does this attack serve?" and some might say this is the point I dropped out.

 

If you're making enemies there's a few things you're gonna want to familiarize yourself with. Definitely get to know how npc and eweapon pointers work in ZScript. There's a section in the scripting tutorial going over that and more you understand of it, the better. You'll be creating a bunch of projectiles and enemies and pointers are your way of accessing those.

 

You'll also want to know how to write your own functions. You're going to want to know how to write a wrapper function for the waitframe behavior so you can control what your enemy is doing even when it's waiting in its main loop. You're going to want to use functions for whatever you think your enemy might end up reusing. Parts of attacks, whole attacks even if that suits you. Don't write the same block of code twice if you don't need to.

 

You'll probably want to be well acquainted with either arrays (2.53, 2.55) or classes (2.55). These are powerful tools for managing data in your waitframe wrapper function as they let you cram many variables into a single parameter. This way you can keep the size of your waitframe calls to a minimum and add onto the waitframe later without the tedious process of adding new parameters to every call. Arrays also have the unique property of being passed by reference, so any change to an array in a function will affect the original in the script. This is handy because everything else in ZScript is passed by value, so the function only has access to a copy. 

 

If you're using ghost.zh, you'll want to know all the tools that gives you. You'll want to know how ghost's combo setups work, and by extension a bit about the ZQuest FFC editor. You'll want to know all the movement and eweapon functions. The special weapon behaviors too (though these are way less necessary in 2.55). For all of this ghost.txt is your friend. 

 

If you end up using npc script instead...I commend your bravery. That's no man's land there. It's a lot simpler but you'll end up having to do more on your own. I have a header that should cover for some of the stuff that's lacking, but it's definitely the harder of the two options.

 

This has been one long ramble and probably not all that helpful. Enemy design is tricky business, so if you stick with it I salute you. Wishing the best of luck!



#3 Bokoblin

Bokoblin

    added tree hair

  • Members

Posted 06 March 2023 - 09:34 PM

what i meant by "i need to know how to make custom attacks" is like simple attacks. one of my ideas is making an electric wizzrobe that stuns the player (if you want to see my new wizzrobe design, look at the tloz expanded thread)

 

i'd imagine it would be a simple eweapon, one big bullet that gives link an effect when it hits him

 

if you could make a simple enemy attack script as an example that would be helpful



#4 Bokoblin

Bokoblin

    added tree hair

  • Members

Posted 06 March 2023 - 09:59 PM

if it's a custom weapon, can't you just make the bulk of the enemy in zquest? i'm not making hardcoded enemies here, i'm just making weapons for them. there are slots for custom eweapons in the enemy editor.

 

the bosses are a different story though, they'd most likely require more scripting.

 

here's a few ideas, tell me what i'd need to make them happen

 

kalle demos- has 2 attacks, fireballs and vines. flies around like a peahat, randomly selects between the two attacks. fireballs are similar to manhandla's, vines are a 15-second long attack that spawns vines at the player's location, making the player have to run around the arena to avoid them. think that one attack from narinder's boss fight in cult of the lamb.

 

lava gohma- throws exploding boulders, summons magtails, you need to chuck bombs at it to break its armor. once its armor is broken, you can attack it. the two phases are two different enemies, the first phase can only be killed by bombs, once it dies the second phase spawns right at the location the first phase died.


Edited by Bokoblin, 06 March 2023 - 10:01 PM.


#5 Moosh

Moosh

    Tiny Little Questmaker

  • ZC Developers

Posted 06 March 2023 - 10:30 PM

if it's a custom weapon, can't you just make the bulk of the enemy in zquest? i'm not making hardcoded enemies here, i'm just making weapons for them. there are slots for custom eweapons in the enemy editor.

Oh yeah of course. If the bulk of the enemy is meant to be just like an editor one, you can achieve all manner of projectile effects with just a weapon script. You can also attach an npc script to an editor enemy for extra effects on top of its default behavior so long as they don't involve its movement or firing delay.
 

kalle demos- has 2 attacks, fireballs and vines. flies around like a peahat, randomly selects between the two attacks. fireballs are similar to manhandla's, vines are a 15-second long attack that spawns vines at the player's location, making the player have to run around the arena to avoid them. think that one attack from narinder's boss fight in cult of the lamb.

Peahat movement is wacky. There's no FlyAroundLikeAPeahat() equivalent function I think (maybe one of the ghost ones I never used, FloaterWalk?). So what you'd want would be some kind of approximation. Probably Ghost_ConstantWalk8() but with some kind of variable movement speed. Haha actually it is what Ghost_FloaterWalk() does, reading the docs before I post sometimes would be a good idea. :doh: Fireballs are as straightforward as it comes, just some FireAimedEWeapon() with EW_FIREBALL. And for the vines I'd consider some kind of weapon script. This could manage a special animation for them sprouting from the ground and any additional properties you might want on them.
 

lava gohma- throws exploding boulders, summons magtails, you need to chuck bombs at it to break its armor. once its armor is broken, you can attack it. the two phases are two different enemies, the first phase can only be killed by bombs, once it dies the second phase spawns right at the location the first phase died.

If it's just a gohma it might not necessarily need a whole enemy script with movement behaviors and all. It could just piggyback off existing behavior. Throwing rocks is a special weapon movement behavior that can be handled by ghost (EWM_THROW) but you could also recreate the effect via weapon script. Or have a weapon script assign the ghost behavior. You don't actually need to use a second enemy for phase 2 if you don't want to. You can write to the enemy's Defense[] array and tiles to change its vulnerabilities during the form change.

A sample enemy script with documentation and all is a good idea actually. I might see about doing something like that if I can find the time for it.



#6 Bokoblin

Bokoblin

    added tree hair

  • Members

Posted 06 March 2023 - 10:43 PM

lava gohma is wind waker gohma so no, not just a gohma.

 

i wouldn't worry about movement behaviors, it's a stationary boss.


Edited by Bokoblin, 07 March 2023 - 01:01 AM.


#7 Bokoblin

Bokoblin

    added tree hair

  • Members

Posted 06 March 2023 - 11:08 PM

can you please tell me how to slot scripts, i need my .zh crap



#8 Deedee

Deedee

    Bug Frog Dragon Girl

  • Moderators
  • Real Name:Deedee
  • Pronouns:She / Her, They / Them
  • Location:Canada

Posted 06 March 2023 - 11:08 PM

What helped me find my footing with ZScript was playing around with dumb simple concepts to familiarize myself with how ZScript is written. For example, I knew how to create weapons, and how to loop through all weapons; so I made an item script that looped through all boomerangs onscreen, and whenever it found one it created 8 more in the same place with each having a different direction; and the results were magical. Once I felt comfortable, I tried challenging myself with harder concepts; I did a custom sword, a custom hookshot, a party system, etc. Some of them were bad, while others were of decent quality that I'd stand by.

Another thing that helped me was when Obderhode made me a custom miniboss that had comments that were easy to follow along; I was able to use this as a reference not just for enemies, but other scripts as well. I do think having examples can help you learn pretty well.

That's basically all the script advice I can give, and custom enemies benefit from scripting.

EDIT: posted before you asked how to slot zh stuff; my brain is a bit fried right now so I can't be of much help currently. Might get back to you later on that.



#9 Bokoblin

Bokoblin

    added tree hair

  • Members

Posted 07 March 2023 - 01:56 AM

ok there's no other copy of ghost.zh in the folder, so it must be caused by something else



#10 Bokoblin

Bokoblin

    added tree hair

  • Members

Posted 07 March 2023 - 02:16 AM

o4L2hjH.png


didn't import it twice either

 

the heck am i doing wrong



#11 Moosh

Moosh

    Tiny Little Questmaker

  • ZC Developers

Posted 07 March 2023 - 05:48 AM

Well damn, I stand corrected. There is someone out there who'd import ghost2_common.zh on its own.

 

What's going on here is that each of those ghost2_ prefix files are already being imported by ghost 2.zh, so when you import them after that it's finding duplicate copies of functions and constants and has no idea which to use. You only need to import ghost.zh and none of those additional component files.


  • Taco Chopper likes this

#12 Emily

Emily

    Scripter / Dev

  • ZC Developers

Posted 07 March 2023 - 10:55 AM

o4L2hjH.png


didn't import it twice either

 

the heck am i doing wrong

You are importing EVERY SINGLE ONE OF THOSE twice. The line 'import "ghost.zh"' already imports ALL of those, you do NOT import the individual files!



#13 Bokoblin

Bokoblin

    added tree hair

  • Members

Posted 07 March 2023 - 12:37 PM

[Error] ghost2_common.zh Line 5 @ Columns 11-36 - Error S008: There is already a variable with name __GHI_DRAW_COMBO in this scope.
 
still getting the error

tAzrC8q.png



#14 Emily

Emily

    Scripter / Dev

  • ZC Developers

Posted 07 March 2023 - 02:44 PM

one of the files you are including is probably already including ghost2.zh. That error means you are importing it more than once.



#15 Bokoblin

Bokoblin

    added tree hair

  • Members

Posted 07 March 2023 - 02:47 PM

does your script include it?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users