PDA

View Full Version : Calling Weapons in Scripts; Controlling Enemies with Scripts



CJC
06-20-2008, 10:06 PM
Despite my repeated visits to the wiki, I cannot seem to wrap my head around the weapon functions of Zscripting, especially those that make a weapon spawn and vanish.
Also, though I have tried many times, my attempts to create larger enemies and control only a portion of enemy movement have failed.


So, I thought I'd ask for some basic help so I can branch into more advanced scripting.

I need:


For the weapons:

An lweapon that functions like the sword stab, but remains so long as variable FOO is of a certain value. This weapon is to inflict 1 damage.
An eweapon that also functions like the sword stab, which is more difficult because all eweapons are projectile. Also, if it could be linked to another in front of it (Two in a row, a 1x2 weapon), that would be super.
An eweapon that mimicks a Link slash attack. It would be preferred if the code allowed for weapon animation, but is not a requirement.

For the enemies:

A script that spawns the first enemy specified to the first enemy flag on screen (Or to the coordinates of a specified enemy flag).
A script that forces several enemies to move and animate with the specified enemy, and share its hit points. These enemies would be set to "Other", and should be compatible with gravity.
A script that makes an enemy perform a certain action (Specifically, attack) after pausing. I really don't want this to operate standard enemy movement (Like random walking/turning/speed), but if that is impossible then so be it.




Any help at all is appreciated.

_L_
06-20-2008, 10:47 PM
A script that spawns the first enemy specified to the first enemy flag on screen (Or to the coordinates of a specified enemy flag).
None of these have been checked for syntax or compiled.



ffc script One {
void run(int enemyid) {
for (int i=0; i<176; i++)
if (Screen->ComboF[i] == CF_ENEMY0) {
npc e = Screen->CreateNPC(enemyid);
npc->X = (i%16)*16;
npc->Y = Div(i,16)*16;
break;
}
}
}



A script that forces several enemies to move and animate with the specified enemy, and share its hit points. These enemies would be set to "Other", and should be compatible with gravity.


// Each script controls its own mimic unit.
// Mimic units are created at FFC's location.
// They mimic Z movement exactly, so if anything the enemy type should be "Other (Floating)" instead of "Other".
ffc script MotionMimick {
void run(int selfid, int leader) {
npc self = Screen->CreateNPC(selfid);
self->X = this->X;
self->Y = this->Y;
npc e;
while(!e->isValid()) {
Waitframe();
e = Screen->LoadNPC(leader);
}
int oldleaderx;
int oldleadery;
int oldleaderz;
int oldleaderhp;
while(e->isValid() && self->isValid()) {
oldleaderx = e->X;
oldleadery = e->Y;
oldleaderz = e->Z;
oldleaderhp = e->HP;
Waitframe();
self->X += e->X - oldleaderx;
self->Y += e->Y - oldleadery;
self->Z += e->Z - oldleaderz;
self->HP += e->HP - oldleaderhp;
self->Dir = e->Dir; // Writing to Dir is currently undefined
}
}



A script that makes an enemy perform a certain action (Specifically, attack) after pausing. I really don't want this to operate standard enemy movement (Like random walking/turning/speed), but if that is impossible then so be it.

Not possible... this year, at least.

Joe123
06-21-2008, 04:51 AM
What does the 'break' function do?

_L_
06-21-2008, 11:25 AM
It terminates a loop.

Joe123
06-21-2008, 11:41 AM
So with break you can end while(true)?

Gleeok
06-21-2008, 07:36 PM
Yes. break will go to the first statement outside of its current loop.


So does this mean we have access to switch, goto, continue statements and cases?

This might be good to know. ;)

CJC
06-21-2008, 09:09 PM
Sorry for the late response, I really do appreciate the help you're providing _L_.
I've been a little swamped, and haven't been able to try the scripts yet.


BUT! Since the enemies are not going to be firing projectiles and only serve to extend hitbox and image, I have a nifty little trick to get around the undefined action of writing to direction.



int Refresh; //Sets the starting tile of the enemy.

...


if (e->Dir==0){
self->Tile = Refresh;
}
else if (e->Dir==1){
self->Tile = Refresh +4;
}
else if (e->Dir==2){
self->Tile = Refresh +8;
}
else if (e->Dir==3){
self->Tile = Refresh +12;
}
//etc... with other tile refreshings for different actions.


Speaking of which, though... Is writing to "NPC->Tile" undefined? By which I mean, once a script begins, is further definition of that variable ignored?

Joe123
06-22-2008, 05:10 AM
int Refresh; //Sets the starting tile of the enemy.

...


if (e->Dir==0){
self->Tile = Refresh;
}
else if (e->Dir==1){
self->Tile = Refresh +4;
}
else if (e->Dir==2){
self->Tile = Refresh +8;
}
else if (e->Dir==3){
self->Tile = Refresh +12;
}
//etc... with other tile refreshings for different actions.


self->Tile = Refresh + e->Dir*4;

Gotta love maths.



Writing to NPC->Tile is fine.