PDA

View Full Version : Combining Global Scripts



sps999
03-11-2009, 07:29 PM
Yes, I know you put them all in the same file, Yes I know pretty much hot to do it, but for some reason, I can't get it right.

Here is the code if you really want to look at it:


import "std.zh"

// Description
//
// These scripts together create an item that rapidly fires projectiles at
// random angles for as long as the B button is held. It's potentially a very
// powerful attack, but it drains MP quickly.
// Due to the limitations of ZScript, the scattershot will only work as a
// B button item; if assigned to A, it will not work properly.

// Arguments
//
// D0: The number of shots to be fired each frame. Minimum: 1
// D1: How many MP will be consumed each frame.
// D2: The amount of damage each projectile does.
// D3: The speed of each projectile, in pixels per frame.
// D4: The ID number of the sprite for the projectiles to use. This is found via
// Quest->Graphics->Sprites->Weapons/Misc. Click "Edit" and the number will
// be shown in the edit window's title bar.

// The type of projectile to be fired. Values from 31 to 40 (generic projectiles
// for scripts) are recommended.
const int SCATTERSHOT_PROJECTILE_ID = 31;



// Variables
//Global variables
bool BallChainUse;
int BallChainCounter;
bool has_hover = false;
bool on_ladder = false;


bool scattershotActive;
int scattershotNumShots;
int scattershotMPCost;
int scattershotDamage;
int scattershotSpeed;
int scattershotSprite;
int fire3;
int wand2;
//Global input constants
const int CF_BALLCHAIN = 98; //BallandChain->Next flag
const int T_BALL = 684; //Tile for the ball to use
const int T_CHAIN = 685; //Tile for the chain segments to use
const int BallChainCSet = 11; //CSet for the ball and chain to use
const int BallChainDamage = 8; //Damage for the ball to deal
const int BallChainSpeed = 5; //Speed with which the ball is swung

// Functions

void DoScattershot()
{
if(scattershotActive)
{
// Keep going?
if(Link->InputB && Link->MP>=scattershotMPCost)
{
Link->MP-=scattershotMPCost;
for(int i=0; i<scattershotNumShots; i++)
{
// Fire!
lweapon shot=Screen->CreateLWeapon(SCATTERSHOT_PROJECTILE_ID);
shot->UseSprite(scattershotSprite);
shot->X=Link->X;
shot->Y=Link->Y;
shot->Damage=scattershotDamage;
shot->Step=scattershotSpeed;
shot->Angular=true;
shot->Angle=Rand(31416)/5000;

// Set the shot's angle in case anything wants to block it.
if(shot->Angle<0.05 || shot->Angle>6.2782)
shot->Dir=DIR_RIGHT;
else if(shot->Angle<1.5658)
shot->Dir=DIR_RIGHTDOWN;
else if(shot->Angle<1.5758)
shot->Dir=DIR_DOWN;
else if(shot->Angle<3.1366)
shot->Dir=DIR_LEFTDOWN;
else if(shot->Angle<3.1466)
shot->Dir=DIR_LEFT;
else if(shot->Angle<4.7074)
shot->Dir=DIR_LEFTUP;
else if(shot->Angle<4.7174)
shot->Dir=DIR_UP;
else
shot->Dir=DIR_RIGHTUP;

}
}
// Let go of B or ran out of MP. Either way...
else
scattershotActive=false;
}
}
bool isSolid(int x, int y) {

if(x<0 || x>255 || y<0 || y>175) return false;
int mask=1111b;

if(x % 16 < 8)
mask &= 0011b;
else
mask &= 1100b;

if(y % 16 < 8)
mask &= 0101b;
else
mask &= 1010b;

int ret = Screen->ComboS[ComboAt(x, y)] & mask;
return (ret!=0);

}

void ladder(int f) {
int lc;

lc = ComboAt(Link->X+8, Link->Y+15); //for speed

if(Screen->ComboF[lc] == f || Screen->ComboI[lc] == f) {
if(!on_ladder) {
on_ladder = true;
has_hover = Link->Item[I_HOVERBOOTS];
Link->Item[I_HOVERBOOTS] = false;
}
Link->Jump = 0;
Link->Z = 0;
Link->Dir = DIR_UP;

if(Link->InputDown) {
Link->InputDown = false;
Link->Action = LA_WALKING;
if(!isSolid(Link->X, Link->Y + 16)) Link->Y += 1;
}
if(Link->InputUp) {
Link->InputUp = false;
Link->Action = LA_WALKING;
if(!isSolid(Link->X, Link->Y - 1)) Link->Y -= 1;
}
if(Link->InputLeft) {
Link->InputLeft = false;
Link->Action = LA_WALKING;
if(!isSolid(Link->X - 1 , Link->Y)) Link->X -= 1;
}
if(Link->InputRight) {
Link->InputRight = false;
Link->Action = LA_WALKING;
if(!isSolid(Link->X + 16, Link->Y)) Link->X += 1;
}
} else {
if(on_ladder) {
Link->Item[I_HOVERBOOTS] = has_hover;
on_ladder = false;
}
}
}
//Global functions
//Store whether Link pressed A or B to use an item
int StoreInput;
void StoreInput(){
if(Link->InputA && !Link->InputB) StoreInput = 1;
else if(Link->InputB && !Link->InputA) StoreInput = 2;
else StoreInput = 0;
}


// Item script

item script Scattershot
{
void run(int numShots, int mpCost, int damage, int speed, int sprite)
{
scattershotNumShots=Max(1, numShots);
scattershotMPCost=mpCost;
scattershotDamage=damage;
scattershotSpeed=speed*100;
scattershotSprite=sprite;
scattershotActive=true;
}
}


// Global scripts

global script global_2{

void run(){

int attack_delay;

while(true){

Waitframe();

int lx = Link->X; int ly = Link->Y;

if(attack_delay>0)attack_delay--;
if(Link->InputB && fire3>0){

if(attack_delay==0){
attack_delay = 6;

lweapon laser = Screen->CreateLWeapon(LW_FIRE);

if(Link->Dir==0){laser->Dir=0;laser->X=lx;laser->Y=ly-16;}
else if(Link->Dir==1){laser->Dir=1;laser->X=lx;laser->Y=ly+16;}
else if(Link->Dir==2){laser->Dir=2;laser->X=lx-16;laser->Y=ly;}
else{ laser->Dir=3;laser->X=lx+16;laser->Y=ly;}
laser->Step=200;
laser->Damage=2;
laser->CSet=8;
Game->PlaySound(13);
}
}
else fire3=0;
}
}
}

global script ScattershotGlobal_slot2

void ScatterShot()
{
while(true)
{
DoScattershot();
ladder(98);
Waitframe();
}
}

//Global script
global script Slot2{
void BallNChain(){
while(true){
//Call the ball and chain functions
if(BallChainUse) BallChain();

Waitframe();
}
}
//The ball and chain functions
void BallChain(){
//Check whether the ball should still be going
if((StoreInput == 1 && Link->InputA) || (StoreInput == 2 && Link->InputB)){
//Draw the ball and chain
for(int i=1;i<=4;i++) DrawBall(BallChainCounter,i*8);

//Enemy damage routines
int ballX = Link->X+32*Cos(BallChainCounter);
int ballY = Link->Y+32*Sin(BallChainCounter);
for(int i=1;i<=Screen->NumNPCs();i++){
npc e = Screen->LoadNPC(i);
if(Abs(e->X-ballX) < 6 && Abs(e->Y-ballY) < 6) e->HP-=BallChainDamage;
}
//BallAndChain->Next routines
int loc = ComboAt(ballX+8,ballY+8);
if(Screen->ComboI[loc] == CF_BALLCHAIN || Screen->ComboF[loc] == CF_BALLCHAIN) Screen->ComboD[loc]++;

//Link's graphics
Link->Action = LA_CHARGING;
if(BallChainCounter >= 315 || BallChainCounter < 45) Link->Dir = DIR_RIGHT;
else if(BallChainCounter >= 225) Link->Dir = DIR_UP;
else if(BallChainCounter >= 130) Link->Dir = DIR_LEFT;
else if(BallChainCounter >= 45) Link->Dir = DIR_DOWN;

//Move the ball around the circle
BallChainCounter = (BallChainCounter%(360*BallChainSpeed))+BallChainS peed;
}else BallChainUse = false;
}
//The ball drawing functions
void DrawBall(int i,int r){
int x = Link->X+r*Cos(i); int y = Link->Y-2+r*Sin(i);
int tile = T_CHAIN;
if(r>30) tile = T_BALL;
Screen->DrawTile(3,x,y,tile,1,1,BallChainCSet,1,0,0,0,0,1, 128);
}


global script ScattershotGlobal_slot3
{
void run()
{
scattershotActive=false;
}
}


item script flamethrower_item{
void run(){
fire3=3;
}
}


item script wand_lv2{
void run(int tile){

int d = 2; // damage
int c = 7; // cset
int s = 300; // speed

int t = Link->Dir;

int lx = Link->X; int ly = Link->Y;

if(wand2>=0){
lweapon laser = Screen->CreateLWeapon(LW_MAGIC);

if(Link->Dir==0){laser->Dir=0;laser->X=lx;laser->Y=ly-16;}
else if(Link->Dir==1){laser->Dir=1;laser->X=lx;laser->Y=ly+16;}
else if(Link->Dir==2){laser->Dir=2;laser->X=lx-16;laser->Y=ly;}
else{ laser->Dir=3;laser->X=lx+16;laser->Y=ly;}
laser->Step=s;laser->Tile=tile+t;
laser->Damage=d;
laser->CSet=c;
Game->PlaySound(32);
}
if(wand2>=0){
lweapon laser = Screen->CreateLWeapon(LW_MAGIC);

if(Link->Dir==0){laser->Dir=0;laser->X=lx+8;laser->Y=ly-16;}
else if(Link->Dir==1){laser->Dir=1;laser->X=lx+8;laser->Y=ly+16;}
else if(Link->Dir==2){laser->Dir=2;laser->X=lx-16;laser->Y=ly+8;}
else{ laser->Dir=3;laser->X=lx+16;laser->Y=ly+8;}
laser->Step=s;laser->Tile=tile+t;
laser->Damage=d;
laser->CSet=c;
Game->PlaySound(32);
}
if(wand2>=0){
lweapon laser = Screen->CreateLWeapon(LW_MAGIC);

if(Link->Dir==0){laser->Dir=0;laser->X=lx-8;laser->Y=ly-16;}
else if(Link->Dir==1){laser->Dir=1;laser->X=lx-8;laser->Y=ly+16;}
else if(Link->Dir==2){laser->Dir=2;laser->X=lx-16;laser->Y=ly-8;}
else{ laser->Dir=3;laser->X=lx+16;laser->Y=ly-8;}
laser->Step=s;laser->Tile=tile+t;
laser->Damage=d;
laser->CSet=c;
Game->PlaySound(32);
}
if(wand2>=0){
lweapon laser = Screen->CreateLWeapon(LW_MAGIC);

if(Link->Dir==0){laser->Dir=1;laser->X=lx;laser->Y=ly+16;laser->Tile=tile+1;}
else if(Link->Dir==1){laser->Dir=0;laser->X=lx+8;laser->Y=ly-16;laser->Tile=tile;}
else if(Link->Dir==2){laser->Dir=3;laser->X=lx+16;laser->Y=ly;laser->Tile=tile+3;}
else{ laser->Dir=2;laser->X=lx-16;laser->Y=ly;laser->Tile=tile+2;}
laser->Step=s;
laser->Damage=d;
laser->CSet=c;
Game->PlaySound(32);
}
}
}


item script boomerang_multi{
void run(){

int s = 300; // b_rang speed
int c = 11;

lweapon fire1 = Screen->CreateLWeapon(LW_BRANG);
fire1->Step=s;
fire1->Damage=0;
fire1->CSet=c; // cset
Game->PlaySound(4);


if(Link->InputLeft && Link->InputUp){
fire1->X = Link->X - 16;
fire1->Y = Link->Y - 16;
fire1->Dir=4;
}
else if(Link->InputRight && Link->InputUp){
fire1->X = Link->X + 16;
fire1->Y = Link->Y - 16;
fire1->Dir=5;
}
else if(Link->InputLeft && Link->InputDown){
fire1->X = Link->X - 16;
fire1->Y = Link->Y + 16;
fire1->Dir=6;
}
else if(Link->InputRight && Link->InputDown){
fire1->X = Link->X + 16;
fire1->Y = Link->Y + 16;
fire1->Dir=7;
}
else{
if(Link->Dir == 0) {
fire1->X = Link->X;
fire1->Y = Link->Y - 16;
fire1->Dir=0;
}
if(Link->Dir == 1) {
fire1->X = Link->X;
fire1->Y = Link->Y + 16;
fire1->Dir=1;
}
if(Link->Dir == 2) {
fire1->X = Link->X - 16;
fire1->Y = Link->Y;
fire1->Dir=2;
}
if(Link->Dir == 3) {
fire1->X = Link->X + 16;
fire1->Y = Link->Y;
fire1->Dir=3;
}
}
}
}

//Ball and Chain activiation script
item script BallChain{
void run(){
BallChainUse = true;
if(Link->Dir == DIR_RIGHT) BallChainCounter = 0;
else if(Link->Dir == DIR_DOWN) BallChainCounter = 90;
else if(Link->Dir == DIR_LEFT) BallChainCounter = 180;
else if(Link->Dir == DIR_UP) BallChainCounter = 270;
}
}

I just need to know how to put all the Slot 2 things together. If you could help me I would be very thankful.

pkmnfrk
03-11-2009, 08:34 PM
I apologize, but your attempt makes me wince. And, the way it's mishmashed together is a chaotic tapestry of illogic.

Could we get transcripts of the original scripts, so that we can start from scratch?

sps999
03-11-2009, 10:30 PM
import "std.zh"
int fire3;
int wand2;



global script global_2{

void run(){

int attack_delay;

while(true){

Waitframe();

int lx = Link->X; int ly = Link->Y;

if(attack_delay>0)attack_delay--;
if(Link->InputB && fire3>0){

if(attack_delay==0){
attack_delay = 6;

lweapon laser = Screen->CreateLWeapon(LW_FIRE);

if(Link->Dir==0){laser->Dir=0;laser->X=lx;laser->Y=ly-16;}
else if(Link->Dir==1){laser->Dir=1;laser->X=lx;laser->Y=ly+16;}
else if(Link->Dir==2){laser->Dir=2;laser->X=lx-16;laser->Y=ly;}
else{ laser->Dir=3;laser->X=lx+16;laser->Y=ly;}
laser->Step=200;
laser->Damage=2;
laser->CSet=8;
Game->PlaySound(13);
}
}
else fire3=0;
}
}
}

item script flamethrower_item{
void run(){
fire3=3;
}
}


item script wand_lv2{
void run(int tile){

int d = 2; // damage
int c = 7; // cset
int s = 300; // speed

int t = Link->Dir;

int lx = Link->X; int ly = Link->Y;

if(wand2>=0){
lweapon laser = Screen->CreateLWeapon(LW_MAGIC);

if(Link->Dir==0){laser->Dir=0;laser->X=lx;laser->Y=ly-16;}
else if(Link->Dir==1){laser->Dir=1;laser->X=lx;laser->Y=ly+16;}
else if(Link->Dir==2){laser->Dir=2;laser->X=lx-16;laser->Y=ly;}
else{ laser->Dir=3;laser->X=lx+16;laser->Y=ly;}
laser->Step=s;laser->Tile=tile+t;
laser->Damage=d;
laser->CSet=c;
Game->PlaySound(32);
}
if(wand2>=0){
lweapon laser = Screen->CreateLWeapon(LW_MAGIC);

if(Link->Dir==0){laser->Dir=0;laser->X=lx+8;laser->Y=ly-16;}
else if(Link->Dir==1){laser->Dir=1;laser->X=lx+8;laser->Y=ly+16;}
else if(Link->Dir==2){laser->Dir=2;laser->X=lx-16;laser->Y=ly+8;}
else{ laser->Dir=3;laser->X=lx+16;laser->Y=ly+8;}
laser->Step=s;laser->Tile=tile+t;
laser->Damage=d;
laser->CSet=c;
Game->PlaySound(32);
}
if(wand2>=0){
lweapon laser = Screen->CreateLWeapon(LW_MAGIC);

if(Link->Dir==0){laser->Dir=0;laser->X=lx-8;laser->Y=ly-16;}
else if(Link->Dir==1){laser->Dir=1;laser->X=lx-8;laser->Y=ly+16;}
else if(Link->Dir==2){laser->Dir=2;laser->X=lx-16;laser->Y=ly-8;}
else{ laser->Dir=3;laser->X=lx+16;laser->Y=ly-8;}
laser->Step=s;laser->Tile=tile+t;
laser->Damage=d;
laser->CSet=c;
Game->PlaySound(32);
}
if(wand2>=0){
lweapon laser = Screen->CreateLWeapon(LW_MAGIC);

if(Link->Dir==0){laser->Dir=1;laser->X=lx;laser->Y=ly+16;laser->Tile=tile+1;}
else if(Link->Dir==1){laser->Dir=0;laser->X=lx+8;laser->Y=ly-16;laser->Tile=tile;}
else if(Link->Dir==2){laser->Dir=3;laser->X=lx+16;laser->Y=ly;laser->Tile=tile+3;}
else{ laser->Dir=2;laser->X=lx-16;laser->Y=ly;laser->Tile=tile+2;}
laser->Step=s;
laser->Damage=d;
laser->CSet=c;
Game->PlaySound(32);
}
}
}


item script boomerang_multi{
void run(){

int s = 300; // b_rang speed
int c = 11;

lweapon fire1 = Screen->CreateLWeapon(LW_BRANG);
fire1->Step=s;
fire1->Damage=0;
fire1->CSet=c; // cset
Game->PlaySound(4);


if(Link->InputLeft && Link->InputUp){
fire1->X = Link->X - 16;
fire1->Y = Link->Y - 16;
fire1->Dir=4;
}
else if(Link->InputRight && Link->InputUp){
fire1->X = Link->X + 16;
fire1->Y = Link->Y - 16;
fire1->Dir=5;
}
else if(Link->InputLeft && Link->InputDown){
fire1->X = Link->X - 16;
fire1->Y = Link->Y + 16;
fire1->Dir=6;
}
else if(Link->InputRight && Link->InputDown){
fire1->X = Link->X + 16;
fire1->Y = Link->Y + 16;
fire1->Dir=7;
}
else{
if(Link->Dir == 0) {
fire1->X = Link->X;
fire1->Y = Link->Y - 16;
fire1->Dir=0;
}
if(Link->Dir == 1) {
fire1->X = Link->X;
fire1->Y = Link->Y + 16;
fire1->Dir=1;
}
if(Link->Dir == 2) {
fire1->X = Link->X - 16;
fire1->Y = Link->Y;
fire1->Dir=2;
}
if(Link->Dir == 3) {
fire1->X = Link->X + 16;
fire1->Y = Link->Y;
fire1->Dir=3;
}
}
}
}


import "std.zh"
//Global input constants
const int CF_BALLCHAIN = 98; //BallandChain->Next flag
const int T_BALL = 684; //Tile for the ball to use
const int T_CHAIN = 685; //Tile for the chain segments to use
const int BallChainCSet = 11; //CSet for the ball and chain to use
const int BallChainDamage = 8; //Damage for the ball to deal
const int BallChainSpeed = 5; //Speed with which the ball is swung

//Global variables
bool BallChainUse;
int BallChainCounter;

//Global functions
//Store whether Link pressed A or B to use an item
int StoreInput;
void StoreInput(){
if(Link->InputA && !Link->InputB) StoreInput = 1;
else if(Link->InputB && !Link->InputA) StoreInput = 2;
else StoreInput = 0;
}

//Global script
global script Slot2{
void run(){
while(true){
//Call the ball and chain functions
if(BallChainUse) BallChain();

Waitframe();
}
}
//The ball and chain functions
void BallChain(){
//Check whether the ball should still be going
if((StoreInput == 1 && Link->InputA) || (StoreInput == 2 && Link->InputB)){
//Draw the ball and chain
for(int i=1;i<=4;i++) DrawBall(BallChainCounter,i*8);

//Enemy damage routines
int ballX = Link->X+32*Cos(BallChainCounter);
int ballY = Link->Y+32*Sin(BallChainCounter);
for(int i=1;i<=Screen->NumNPCs();i++){
npc e = Screen->LoadNPC(i);
if(Abs(e->X-ballX) < 6 && Abs(e->Y-ballY) < 6) e->HP-=BallChainDamage;
}
//BallAndChain->Next routines
int loc = ComboAt(ballX+8,ballY+8);
if(Screen->ComboI[loc] == CF_BALLCHAIN || Screen->ComboF[loc] == CF_BALLCHAIN) Screen->ComboD[loc]++;

//Link's graphics
Link->Action = LA_CHARGING;
if(BallChainCounter >= 315 || BallChainCounter < 45) Link->Dir = DIR_RIGHT;
else if(BallChainCounter >= 225) Link->Dir = DIR_UP;
else if(BallChainCounter >= 130) Link->Dir = DIR_LEFT;
else if(BallChainCounter >= 45) Link->Dir = DIR_DOWN;

//Move the ball around the circle
BallChainCounter = (BallChainCounter%(360*BallChainSpeed))+BallChainS peed;
}else BallChainUse = false;
}
//The ball drawing functions
void DrawBall(int i,int r){
int x = Link->X+r*Cos(i); int y = Link->Y-2+r*Sin(i);
int tile = T_CHAIN;
if(r>30) tile = T_BALL;
Screen->DrawTile(3,x,y,tile,1,1,BallChainCSet,1,0,0,0,0,1, 128);
}
}

//Ball and Chain activiation script
item script BallChain{
void run(){
BallChainUse = true;
if(Link->Dir == DIR_RIGHT) BallChainCounter = 0;
else if(Link->Dir == DIR_DOWN) BallChainCounter = 90;
else if(Link->Dir == DIR_LEFT) BallChainCounter = 180;
else if(Link->Dir == DIR_UP) BallChainCounter = 270;
}
}


import "std.zh"

// Description
//
// These scripts together create an item that rapidly fires projectiles at
// random angles for as long as the B button is held. It's potentially a very
// powerful attack, but it drains MP quickly.
// Due to the limitations of ZScript, the scattershot will only work as a
// B button item; if assigned to A, it will not work properly.

// Arguments
//
// D0: The number of shots to be fired each frame. Minimum: 1
// D1: How many MP will be consumed each frame.
// D2: The amount of damage each projectile does.
// D3: The speed of each projectile, in pixels per frame.
// D4: The ID number of the sprite for the projectiles to use. This is found via
// Quest->Graphics->Sprites->Weapons/Misc. Click "Edit" and the number will
// be shown in the edit window's title bar.

// The type of projectile to be fired. Values from 31 to 40 (generic projectiles
// for scripts) are recommended.
const int SCATTERSHOT_PROJECTILE_ID = 31;



// Variables
bool has_hover = false;
bool on_ladder = false;


bool scattershotActive;
int scattershotNumShots;
int scattershotMPCost;
int scattershotDamage;
int scattershotSpeed;
int scattershotSprite;

// Functions

void DoScattershot()
{
if(scattershotActive)
{
// Keep going?
if(Link->InputB && Link->MP>=scattershotMPCost)
{
Link->MP-=scattershotMPCost;
for(int i=0; i<scattershotNumShots; i++)
{
// Fire!
lweapon shot=Screen->CreateLWeapon(SCATTERSHOT_PROJECTILE_ID);
shot->UseSprite(scattershotSprite);
shot->X=Link->X;
shot->Y=Link->Y;
shot->Damage=scattershotDamage;
shot->Step=scattershotSpeed;
shot->Angular=true;
shot->Angle=Rand(31416)/5000;

// Set the shot's angle in case anything wants to block it.
if(shot->Angle<0.05 || shot->Angle>6.2782)
shot->Dir=DIR_RIGHT;
else if(shot->Angle<1.5658)
shot->Dir=DIR_RIGHTDOWN;
else if(shot->Angle<1.5758)
shot->Dir=DIR_DOWN;
else if(shot->Angle<3.1366)
shot->Dir=DIR_LEFTDOWN;
else if(shot->Angle<3.1466)
shot->Dir=DIR_LEFT;
else if(shot->Angle<4.7074)
shot->Dir=DIR_LEFTUP;
else if(shot->Angle<4.7174)
shot->Dir=DIR_UP;
else
shot->Dir=DIR_RIGHTUP;

}
}
// Let go of B or ran out of MP. Either way...
else
scattershotActive=false;
}
}
bool isSolid(int x, int y) {

if(x<0 || x>255 || y<0 || y>175) return false;
int mask=1111b;

if(x % 16 < 8)
mask &= 0011b;
else
mask &= 1100b;

if(y % 16 < 8)
mask &= 0101b;
else
mask &= 1010b;

int ret = Screen->ComboS[ComboAt(x, y)] & mask;
return (ret!=0);

}

void ladder(int f) {
int lc;

lc = ComboAt(Link->X+8, Link->Y+15); //for speed

if(Screen->ComboF[lc] == f || Screen->ComboI[lc] == f) {
if(!on_ladder) {
on_ladder = true;
has_hover = Link->Item[I_HOVERBOOTS];
Link->Item[I_HOVERBOOTS] = false;
}
Link->Jump = 0;
Link->Z = 0;
Link->Dir = DIR_UP;

if(Link->InputDown) {
Link->InputDown = false;
Link->Action = LA_WALKING;
if(!isSolid(Link->X, Link->Y + 16)) Link->Y += 1;
}
if(Link->InputUp) {
Link->InputUp = false;
Link->Action = LA_WALKING;
if(!isSolid(Link->X, Link->Y - 1)) Link->Y -= 1;
}
if(Link->InputLeft) {
Link->InputLeft = false;
Link->Action = LA_WALKING;
if(!isSolid(Link->X - 1 , Link->Y)) Link->X -= 1;
}
if(Link->InputRight) {
Link->InputRight = false;
Link->Action = LA_WALKING;
if(!isSolid(Link->X + 16, Link->Y)) Link->X += 1;
}
} else {
if(on_ladder) {
Link->Item[I_HOVERBOOTS] = has_hover;
on_ladder = false;
}
}
}



// Item script

item script Scattershot
{
void run(int numShots, int mpCost, int damage, int speed, int sprite)
{
scattershotNumShots=Max(1, numShots);
scattershotMPCost=mpCost;
scattershotDamage=damage;
scattershotSpeed=speed*100;
scattershotSprite=sprite;
scattershotActive=true;
}
}


// Global scripts

global script ScattershotGlobal_slot2
{
void run()
{
while(true)
{
DoScattershot();
ladder(98);
Waitframe();
}
}
}

global script ScattershotGlobal_slot3
{
void run()
{
scattershotActive=false;
}
}


import "std.zh"

bool has_hover = false;
bool on_ladder = false;


global script Slot_2 {
void Ladder() {

//one time things go here

while(true) {

ladder(98);

Waitframe();
}
}

//Courtesy of Saffith/beefster09
bool isSolid(int x, int y) {

if(x<0 || x>255 || y<0 || y>175) return false;
int mask=1111b;

if(x % 16 < 8)
mask &= 0011b;
else
mask &= 1100b;

if(y % 16 < 8)
mask &= 0101b;
else
mask &= 1010b;

int ret = Screen->ComboS[ComboAt(x, y)] & mask;
return (ret!=0);

}

void ladder(int f) {
int lc;

lc = ComboAt(Link->X+8, Link->Y+15); //for speed

if(Screen->ComboF[lc] == f || Screen->ComboI[lc] == f) {
if(!on_ladder) {
on_ladder = true;
has_hover = Link->Item[I_HOVERBOOTS];
Link->Item[I_HOVERBOOTS] = false;
}
Link->Jump = 0;
Link->Z = 0;
Link->Dir = DIR_UP;

if(Link->InputDown) {
Link->InputDown = false;
Link->Action = LA_WALKING;
if(!isSolid(Link->X, Link->Y + 16)) Link->Y += 1;
}
if(Link->InputUp) {
Link->InputUp = false;
Link->Action = LA_WALKING;
if(!isSolid(Link->X, Link->Y - 1)) Link->Y -= 1;
}
if(Link->InputLeft) {
Link->InputLeft = false;
Link->Action = LA_WALKING;
if(!isSolid(Link->X - 1 , Link->Y)) Link->X -= 1;
}
if(Link->InputRight) {
Link->InputRight = false;
Link->Action = LA_WALKING;
if(!isSolid(Link->X + 16, Link->Y)) Link->X += 1;
}
} else {
if(on_ladder) {
Link->Item[I_HOVERBOOTS] = has_hover;
on_ladder = false;
}
}
}
}

//other global functions go here

global script ScattershotGlobal_slot2
{
void ScatterShot()
{
while(true)
{
DoScattershot();
Waitframe();
}
}
}
void run();
void Ladder() {
void ScatterShot()



I apologize, but your attempt makes me wince. And, the way it's mishmashed together is a chaotic tapestry of illogic.


This is actually what it was before my attempt. My attempt would've made it seem a whole lot worse.

pkmnfrk
03-11-2009, 10:55 PM
This is actually what it was before my attempt. My attempt would've made it seem a whole lot worse.

What you posted wouldn't even compile.

Anyway, I'll take a look at this in a bit.

Joe123
03-12-2009, 12:36 PM
http://www.purezc.com/forums/index.php?showtopic=38773

jman2050
03-12-2009, 02:21 PM
The only discrepency in that PZC topic is that global script slot 3 is run once when you die or press F6->Continue. The new "Continue" script is what's run when a quest is loaded up even after saving.

sps999
03-12-2009, 04:45 PM
Thanks for the link, I think I'm able to pull it off now.

Joe123
03-12-2009, 05:21 PM
Oh right yes. I'm better informed on this than I was when I wrote it (I hope).
I edited it.

Not that it's anything major though really.

sps999
03-15-2009, 12:50 PM
I meant to ask this a while ago, but but I never got t it, when I try to compile the script, it just wants to pretty much delete all of the functions on line at a time. It would say like "Unexpected LBrace," so I get rid of it, and then it says "Unexpeceted Void" and eventually I have pretty much no more script. Here is what I did:



import "std.zh"
//Global input constants
const int CF_BALLCHAIN = 98; //BallandChain->Next flag
const int T_BALL = 684; //Tile for the ball to use
const int T_CHAIN = 685; //Tile for the chain segments to use
const int BallChainCSet = 11; //CSet for the ball and chain to use
const int BallChainDamage = 8; //Damage for the ball to deal
const int BallChainSpeed = 5; //Speed with which the ball is swung
const int SCATTERSHOT_PROJECTILE_ID = 31;
//int fire3;
//int wand2;


//Global variables
bool BallChainUse;
int BallChainCounter;
int fire3;
int wand2;
bool has_hover = false;
bool on_ladder = false;
bool scattershotActive;
int scattershotNumShots;
int scattershotMPCost;
int scattershotDamage;
int scattershotSpeed;
int scattershotSprite;




//Global functions
//Store whether Link pressed A or B to use an item
int StoreInput;
void StoreInput(){
if(Link->InputA && !Link->InputB) StoreInput = 1;
else if(Link->InputB && !Link->InputA) StoreInput = 2;
else StoreInput = 0;
}

//Global script
global script Slot2{
void run(){
while(true){
//Call the ball and chain functions
if(BallChainUse) BallChain();
if(attack_delay>0)attack_delay--;
if(Link->InputB && fire3>0){
DoScattershot();
ladder(98);

Waitframe();
}
}
//The ball and chain functions
void BallChain(){
//Check whether the ball should still be going
if((StoreInput == 1 && Link->InputA) || (StoreInput == 2 && Link->InputB)){
//Draw the ball and chain
for(int i=1;i<=4;i++) DrawBall(BallChainCounter,i*8);

//Enemy damage routines
int ballX = Link->X+32*Cos(BallChainCounter);
int ballY = Link->Y+32*Sin(BallChainCounter);
for(int i=1;i<=Screen->NumNPCs();i++){
npc e = Screen->LoadNPC(i);
if(Abs(e->X-ballX) < 6 && Abs(e->Y-ballY) < 6) e->HP-=BallChainDamage;
}
//BallAndChain->Next routines
int loc = ComboAt(ballX+8,ballY+8);
if(Screen->ComboI[loc] == CF_BALLCHAIN || Screen->ComboF[loc] == CF_BALLCHAIN) Screen->ComboD[loc]++;

//Link's graphics
Link->Action = LA_CHARGING;
if(BallChainCounter >= 315 || BallChainCounter < 45) Link->Dir = DIR_RIGHT;
else if(BallChainCounter >= 225) Link->Dir = DIR_UP;
else if(BallChainCounter >= 130) Link->Dir = DIR_LEFT;
else if(BallChainCounter >= 45) Link->Dir = DIR_DOWN;

//Move the ball around the circle
BallChainCounter = (BallChainCounter%(360*BallChainSpeed))+BallChainS peed;
}else BallChainUse = false;
}
//The ball drawing functions
void DrawBall(int i,int r){
int x = Link->X+r*Cos(i); int y = Link->Y-2+r*Sin(i);
int tile = T_CHAIN;
if(r>30) tile = T_BALL;
Screen->DrawTile(3,x,y,tile,1,1,BallChainCSet,1,0,0,0,0,1, 128);
}
}

//Ball and Chain activiation script
item script BallChain{
void run(){
BallChainUse = true;
if(Link->Dir == DIR_RIGHT) BallChainCounter = 0;
else if(Link->Dir == DIR_DOWN) BallChainCounter = 90;
else if(Link->Dir == DIR_LEFT) BallChainCounter = 180;
else if(Link->Dir == DIR_UP) BallChainCounter = 270;
}
}

if(attack_delay==0){
attack_delay = 6;

lweapon laser = Screen->CreateLWeapon(LW_FIRE);

if(Link->Dir==0){laser->Dir=0;laser->X=lx;laser->Y=ly-16;}
else if(Link->Dir==1){laser->Dir=1;laser->X=lx;laser->Y=ly+16;}
else if(Link->Dir==2){laser->Dir=2;laser->X=lx-16;laser->Y=ly;}
else{ laser->Dir=3;laser->X=lx+16;laser->Y=ly;}
laser->Step=200;
laser->Damage=2;
laser->CSet=8;
Game->PlaySound(13);
}
}
else fire3=0;
}
}
}

void DoScattershot()
{
if(scattershotActive)
{
// Keep going?
if(Link->InputB && Link->MP>=scattershotMPCost)
{
Link->MP-=scattershotMPCost;
for(int i=0; i<scattershotNumShots; i++)
{
// Fire!
lweapon shot=Screen->CreateLWeapon(SCATTERSHOT_PROJECTILE_ID);
shot->UseSprite(scattershotSprite);
shot->X=Link->X;
shot->Y=Link->Y;
shot->Damage=scattershotDamage;
shot->Step=scattershotSpeed;
shot->Angular=true;
shot->Angle=Rand(31416)/5000;

// Set the shot's angle in case anything wants to block it.
if(shot->Angle<0.05 || shot->Angle>6.2782)
shot->Dir=DIR_RIGHT;
else if(shot->Angle<1.5658)
shot->Dir=DIR_RIGHTDOWN;
else if(shot->Angle<1.5758)
shot->Dir=DIR_DOWN;
else if(shot->Angle<3.1366)
shot->Dir=DIR_LEFTDOWN;
else if(shot->Angle<3.1466)
shot->Dir=DIR_LEFT;
else if(shot->Angle<4.7074)
shot->Dir=DIR_LEFTUP;
else if(shot->Angle<4.7174)
shot->Dir=DIR_UP;
else
shot->Dir=DIR_RIGHTUP;

}
}
// Let go of B or ran out of MP. Either way...
else
scattershotActive=false;
}
}


// Item script

item script Scattershot
{
void run(int numShots, int mpCost, int damage, int speed, int sprite)
{
scattershotNumShots=Max(1, numShots);
scattershotMPCost=mpCost;
scattershotDamage=damage;
scattershotSpeed=speed*100;
scattershotSprite=sprite;
scattershotActive=true;
}
}

global script ScattershotGlobal_slot3
{
void run()
{
scattershotActive=false;
}
}

//Courtesy of Saffith/beefster09
bool isSolid(int x, int y) {

if(x<0 || x>255 || y<0 || y>175) return false;
int mask=1111b;

if(x % 16 < 8)
mask &= 0011b;
else
mask &= 1100b;

if(y % 16 < 8)
mask &= 0101b;
else
mask &= 1010b;

int ret = Screen->ComboS[ComboAt(x, y)] & mask;
return (ret!=0);

}

void ladder(int f) {
int lc;

lc = ComboAt(Link->X+8, Link->Y+15); //for speed

if(Screen->ComboF[lc] == f || Screen->ComboI[lc] == f) {
if(!on_ladder) {
on_ladder = true;
has_hover = Link->Item[I_HOVERBOOTS];
Link->Item[I_HOVERBOOTS] = false;
}
Link->Jump = 0;
Link->Z = 0;
Link->Dir = DIR_UP;

if(Link->InputDown) {
Link->InputDown = false;
Link->Action = LA_WALKING;
if(!isSolid(Link->X, Link->Y + 16)) Link->Y += 1;
}
if(Link->InputUp) {
Link->InputUp = false;
Link->Action = LA_WALKING;
if(!isSolid(Link->X, Link->Y - 1)) Link->Y -= 1;
}
if(Link->InputLeft) {
Link->InputLeft = false;
Link->Action = LA_WALKING;
if(!isSolid(Link->X - 1 , Link->Y)) Link->X -= 1;
}
if(Link->InputRight) {
Link->InputRight = false;
Link->Action = LA_WALKING;
if(!isSolid(Link->X + 16, Link->Y)) Link->X += 1;
}
} else {
if(on_ladder) {
Link->Item[I_HOVERBOOTS] = has_hover;
on_ladder = false;
}
}
}
{
void run(){

int attack_delay;

while(true){

Waitframe();

int lx = Link->X; int ly = Link->Y;

if(attack_delay>0)attack_delay--;
if(Link->InputB && fire3>0){

if(attack_delay==0){
attack_delay = 6;

lweapon laser = Screen->CreateLWeapon(LW_FIRE);

if(Link->Dir==0){laser->Dir=0;laser->X=lx;laser->Y=ly-16;}
else if(Link->Dir==1){laser->Dir=1;laser->X=lx;laser->Y=ly+16;}
else if(Link->Dir==2){laser->Dir=2;laser->X=lx-16;laser->Y=ly;}
else{ laser->Dir=3;laser->X=lx+16;laser->Y=ly;}
laser->Step=200;
laser->Damage=2;
laser->CSet=8;
Game->PlaySound(13);
}
}
else fire3=0;
}
}
}

item script flamethrower_item{
void run(){
fire3=3;
}
}


item script wand_lv2{
void run(int tile){

int d = 2; // damage
int c = 7; // cset
int s = 300; // speed

int t = Link->Dir;

int lx = Link->X; int ly = Link->Y;

if(wand2>=0){
lweapon laser = Screen->CreateLWeapon(LW_MAGIC);

if(Link->Dir==0){laser->Dir=0;laser->X=lx;laser->Y=ly-16;}
else if(Link->Dir==1){laser->Dir=1;laser->X=lx;laser->Y=ly+16;}
else if(Link->Dir==2){laser->Dir=2;laser->X=lx-16;laser->Y=ly;}
else{ laser->Dir=3;laser->X=lx+16;laser->Y=ly;}
laser->Step=s;laser->Tile=tile+t;
laser->Damage=d;
laser->CSet=c;
Game->PlaySound(32);
}
if(wand2>=0){
lweapon laser = Screen->CreateLWeapon(LW_MAGIC);

if(Link->Dir==0){laser->Dir=0;laser->X=lx+8;laser->Y=ly-16;}
else if(Link->Dir==1){laser->Dir=1;laser->X=lx+8;laser->Y=ly+16;}
else if(Link->Dir==2){laser->Dir=2;laser->X=lx-16;laser->Y=ly+8;}
else{ laser->Dir=3;laser->X=lx+16;laser->Y=ly+8;}
laser->Step=s;laser->Tile=tile+t;
laser->Damage=d;
laser->CSet=c;
Game->PlaySound(32);
}
if(wand2>=0){
lweapon laser = Screen->CreateLWeapon(LW_MAGIC);

if(Link->Dir==0){laser->Dir=0;laser->X=lx-8;laser->Y=ly-16;}
else if(Link->Dir==1){laser->Dir=1;laser->X=lx-8;laser->Y=ly+16;}
else if(Link->Dir==2){laser->Dir=2;laser->X=lx-16;laser->Y=ly-8;}
else{ laser->Dir=3;laser->X=lx+16;laser->Y=ly-8;}
laser->Step=s;laser->Tile=tile+t;
laser->Damage=d;
laser->CSet=c;
Game->PlaySound(32);
}
if(wand2>=0){
lweapon laser = Screen->CreateLWeapon(LW_MAGIC);

if(Link->Dir==0){laser->Dir=1;laser->X=lx;laser->Y=ly+16;laser->Tile=tile+1;}
else if(Link->Dir==1){laser->Dir=0;laser->X=lx+8;laser->Y=ly-16;laser->Tile=tile;}
else if(Link->Dir==2){laser->Dir=3;laser->X=lx+16;laser->Y=ly;laser->Tile=tile+3;}
else{ laser->Dir=2;laser->X=lx-16;laser->Y=ly;laser->Tile=tile+2;}
laser->Step=s;
laser->Damage=d;
laser->CSet=c;
Game->PlaySound(32);
}
}
}


item script boomerang_multi{
void run(){

int s = 300; // b_rang speed
int c = 11;

lweapon fire1 = Screen->CreateLWeapon(LW_BRANG);
fire1->Step=s;
fire1->Damage=0;
fire1->CSet=c; // cset
Game->PlaySound(4);


if(Link->InputLeft && Link->InputUp){
fire1->X = Link->X - 16;
fire1->Y = Link->Y - 16;
fire1->Dir=4;
}
else if(Link->InputRight && Link->InputUp){
fire1->X = Link->X + 16;
fire1->Y = Link->Y - 16;
fire1->Dir=5;
}
else if(Link->InputLeft && Link->InputDown){
fire1->X = Link->X - 16;
fire1->Y = Link->Y + 16;
fire1->Dir=6;
}
else if(Link->InputRight && Link->InputDown){
fire1->X = Link->X + 16;
fire1->Y = Link->Y + 16;
fire1->Dir=7;
}
else{
if(Link->Dir == 0) {
fire1->X = Link->X;
fire1->Y = Link->Y - 16;
fire1->Dir=0;
}
if(Link->Dir == 1) {
fire1->X = Link->X;
fire1->Y = Link->Y + 16;
fire1->Dir=1;
}
if(Link->Dir == 2) {
fire1->X = Link->X - 16;
fire1->Y = Link->Y;
fire1->Dir=2;
}
if(Link->Dir == 3) {
fire1->X = Link->X + 16;
fire1->Y = Link->Y;
fire1->Dir=3;
}
}
}
}

Joe123
03-15-2009, 01:00 PM
'Unexpected LBrace' doesn't mean 'delete the LBrace'...

Start again, and make sure that your voids are between the RBrace at the end of 'DrawBall' and the one after that.

sps999
03-15-2009, 01:54 PM
Wait a second, that confuses me. Are you saying that intead of
...
}
//The ball drawing functions
void DrawBall(int i,int r){
...

I'm supposed to have

...
//The ball drawing functions
void DrawBall(int i,int r){
...
} //The very end

or what do you mean?

Besides, the problem starts right here:

//The ball and chain functions
void BallChain(){
//Check whether the ball should still be going
if((StoreInput == 1 && Link->InputA) || (StoreInput == 2 && Link->InputB)){
//Draw the ball and chain
for(int i=1;i<=4;i++) DrawBall(BallChainCounter,i*8);

Joe123
03-15-2009, 02:11 PM
void DrawBall(int i,int r){
int x = Link->X+r*Cos(i); int y = Link->Y-2+r*Sin(i);
int tile = T_CHAIN;
if(r>30) tile = T_BALL;
Screen->DrawTile(3,x,y,tile,1,1,BallChainCSet,1,0,0,0,0,1, 128);
}
//the other functions go here

//...some more functions

//etc.
}//end of script

sps999
03-15-2009, 04:27 PM
That ball and chain script seems to cause too much trouble, I think I'll just use the FFC version of it.