Jump to content

Creature script


BainIhrno

Recommended Posts

I've written a creature script for one of the final bosses, I was wondering if anyone would like to take a look at it.

 

 

 

// VARNOTH //

 

begincreaturescript;

 

variables;

 

short i,j,k,choice;

 

INIT_STATE;

break;

DEAD_STATE;

break;

START_STATE;

break;

 

beginstate 3;

if who_hit_me(char_has_item_of_class_equip(get_selected_char,3,0)

damage_char(i,50,4);

break;

 

 

beginstate 4;

if (tick_difference(last_abil_time,get_current_tick()) > 0))

 

print_str_color("Varnoth breathes!",1);

put_boom_on_char(ME,0,1);

put_boom_on_char(ME,0,1);

put_boom_on_char(ME,0,1);

put_boom_on_char(ME,0,1);

put_boom_on_char(ME,0,1);

put_boom_on_char(ME,0,1);

run_animation_sound(167);

damage_near_loc(my_loc_x(),my_loc_y(),get_ran(35,2,10),2,1);

 

last_abil_time = get_current_tick();

}

if (target_ok() == FALSE)

set_state(START_STATE);

do_attack();

break;

 

-------------------------

So basically, state 4 is a custom breathing weapon. I've based it off of t13 in Za-Khazi Run

 

With state 3, I'm trying to create a weapon that does extra damage to this specific character alone. Will this coding work?

 

 

 

 

 

 

Thanks.

Link to comment
Share on other sites

State 3 and 4 aren't going to run if you don't have anything that activates them. Your creature isn't going to do anything at all.

 

In any creature script, you essentially want something that designates a target and specifies actions to take if a target is found. States simply exist to ease organization, and you can handle everything in a single state if you so choose. A creature will run through whichever state it is set to run until it runs out of AP. If it runs out of AP mid state or is told to stop, it will keep running through to the end of the script before stopping. It will not change to another state unless told to do so. basicnpc cycles between the start state (searching for a target) and state 3 (attacking). If you want your boss to check what it's damaged by every turn, you'll want that code in each state you're using.

Link to comment
Share on other sites

Check this versus basicnpc.txt, the latter will show how a creature script is supposed to work.

 

In state 3 you need an extra bracket at the end of this line:

if who_hit_me(char_has_item_of_class_equip(get_selected_char,3,0)

In state 4 you have an excess bracket at the end of this line:

if (tick_difference(last_abil_time,get_current_tick()) > 0))

 

Then you have a redundant bracket:

last_abil_time = get_current_tick();

}

should be:

last_abil_time = get_current_tick();

 

In a text editor like Crimson Editor, if the Syntax Type is set to C++, clicking on a bracket will highlight it and any matching bracket it is paired with, if it has a matching one.

Link to comment
Share on other sites

  • 1 month later...

No, sir. Scripts are like a servant. They will do everything for you inside the game, if you treat it properly and give proper orders. Actually, in fact you can give a sound of door opening to the mooing of a cow. Why the boom will even have default sound at your case. 'boom' calls don't have preset sounds.

 

I also used Enraged Slith's Sneak Attack script for a boss for my 'Second' scenario. The first one is still not posted and will require a dose of betatest. I am STILL lacking that custom graphics and scripts for which i made two topics.

Link to comment
Share on other sites

Thanks. Also, do the 'boom' calls play the sound of their fields automatically, or does that need to be programmed too? (For example, if I call a fire explosion, will the fire bolt sound play if I don't tell it to?)

In case the previous response is unclear, the answer is no. That's the reason for the run_animation_sound() call; what goes inside the parentheses tells it what sound to play as the animation runs. Otherwise you get silence.

Link to comment
Share on other sites

  • 4 weeks later...

I've now reached a town in testing where one of the creatures uses a custom script: for some reason, the game doesn't recognize the 'last_abil_time' call, even though the same call is used in ZKR.

 

Can anyone help?

 

The specific line is:

 

if (tick_difference(last_abil_time,get_current_tick()) > 0)

Link to comment
Share on other sites

Make sure it is defined where it is used, it may be a private variable. Check the ZKR files for it.

I just used the Find in Files function of Crimson Editor, I checked the ZKR files for "last_abil_time". I kept seeing "short last_abil_time;", it is being defined each time it is used, hence it is not an official BoA call, hence it must be defined in every script where it is used.

Link to comment
Share on other sites

Okay, another problem. At another creature script, I get an error message saying: "Error: No body declared", "Error: State not found - 0". I've looked through the scripts extensively, and can't find what I'm doing wrong. Could someone tell me what these messages mean?

 

EDIT: Nevermind. Figured it out.

Link to comment
Share on other sites

You're supposed to have a line that says "body;" after you declare your variables but before your states. State 0 is the INIT_STATE, so if it's telling you that you don't have that state, you need to add it.

 

Are you writing a creature script from scratch? If so, that's probably putting you in for a world of pain. You want to start from basicnpc and edit.

Link to comment
Share on other sites

  • 1 month later...
  • 2 weeks later...

Maybe I'll just have the creature fall down in a random direction (i.e. a 1/8th chance of which adjacent square).

 

I'm having trouble getting a mage fight to work properly.

 

Creature script:

 

 

 

 

beginstate 3; // attacking

 

if (tick_difference(last_abil_time,get_current_tick()) > 0)

{

print_str_color("Sovash-Thinox casts: Dark Blow",3); put_boom_on_space(char_loc_x(get_target()),char_loc_y(get_target()),7,0);

run_animation_sound(43);

damage_near_loc(char_loc_x(get_target()),char_loc_y(get_target()),get_ran(10,1,10),0,4);

 

last_abil_time = get_current_tick();

}

 

if (target_ok() == FALSE)

set_state(START_STATE);

do_attack();

break;

 

 

 

Technically, everything works, but I'm finding the Slith mage rarely casts the regular spells (he is set to level 27 on Mage Spells. The creature also is set to cr_default_strategy = 1.) The mage either (1) casts the special spell he's been given, or (2) just uses melee attacks, and he uses the Dark Blow special spell more often than I think he should be.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...