Jump to content

Photo

Small script request.


  • Please log in to reply
19 replies to this topic

#1 Cereal Guy

Cereal Guy

    Senior

  • Members
  • Location:Concepción, CHL

Posted 18 July 2016 - 12:12 PM

Well, my idea principally is this:

 

· If an specific enemy touches an item the item disappear, and when the item disappear -> Play a certain SFX

 

 

 I need this :( please I need help. :(


Edited by Cereal Guy, 18 July 2016 - 12:13 PM.


#2 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 18 July 2016 - 12:34 PM

Try this:

D0: NPC ID for enemy that can steal items.
D1: Sound effect for stealing.
D2: The time that the npc carries item around before hey vanish, in seconds.
Accepts decimal values, so 1.250 is 1.25 seconds.
 

const int NPC_MISC_HOLDING_ITEM = 12; 

ffc script BasicStealItem{
	void run(int npc_ID, int stealsfx, float dragdur){
		npc n; item i; int q; int w; int e; int r; itemdata it;
		if ( !dragdur ) dragdur = 1; 
		int itemlist[]={	IC_RUPEE, IC_HEART, IC_ARROWAMMO, IC_MAGIC, IC_BOMBAMMO};
		while(true){
			for ( w = 1; w <= Screen->NumItems(); w++){
				for ( q = 1; q <= Screen->NumNPCs(); q++) {
					n = Screen->LoadNPC(q);
					if ( n->isValid() )	{
						if ( n->ID == npc_ID && !n->Misc[NPC_MISC_HOLDING_ITEM]) {
							i = Screen->LoadItem(w);
							if ( i->isValid() ) {
								if ( __DistX(n,i,4) && __DistY(n,i,4) ){
								
									it = Game->LoadItemData(i->ID);
									for ( e = 0; e < SizeOfArray(itemlist); e++){
										if ( it->Family == itemlist[e] ) {
											n->Misc[NPC_MISC_HOLDING_ITEM] = 1; 
											for ( r = 0; r < (dragdur * 60); r ++ ) {
												i->X = n->X;
												i->Y = n->Y;
												Waitframe();
											}
											Game->PlaySound(stealsfx);
											Remove(i);
											n->Misc[NPC_MISC_HOLDING_ITEM] = 0;
										}
									}									
								}
							}
						}
					}
				}
			}
			Waitframe();
		}
	}
	bool __DistX(npc a, item b, int distance) {
		int dist;
		if ( a->X > b->X ) dist = a->X - b->X;
		else dist = b->X - a->X;
		return ( dist <= distance );
	} 
	bool __DistY(npc a, item b, int distance) {
		int dist;
		if ( a->Y > b->Y ) dist = a->Y - b->Y;
		else dist = b->Y - a->Y;
		return ( dist <= distance );
	} 

}

AutoGhost version

 

const int NPC_MISC_HOLDING_ITEM = 12;
const int GHOST_STEALITEM_HOLDING_ITEM = 3;
const int GHOST_STEALITEM_STEAL_SFX = 43;
const float GHOST_STEALITEM_DRAGDUR = 1.5;

ffc script AutoghostBasicThief{
    void run(int enemyid){
        npc ghost = Ghost_InitAutoGhost(this, enemyid);
        item i; itemdata it;
        int a[4];
        int itemlist[]={ IC_RUPEE, IC_HEART, IC_ARROWAMMO, IC_MAGIC, IC_BOMBAMMO };
        while(true){
            for ( a[0] = 1; a[0] <= Screen->NumItems(); a[0]++){
                if ( !a[GHOST_STEALITEM_HOLDING_ITEM] ) {
                    i = Screen->LoadItem( a[0] );
                    it = Game->LoadItemData(i->ID);
                    for ( a[1] = 0; a[1] < SizeOfArray(itemlist); a[1]++){
                        if ( it->Family == itemlist[ a[1] ] ) {
                            if ( __DistX(ghost,i,4) && __DistY(ghost,i,4) ){
                                a[GHOST_STEALITEM_HOLDING_ITEM] = 1;
                                for ( a[2] = 0; a[2] < (GHOST_STEALITEM_DRAGDUR * 60); a[2]++ ) {
                                    i->X = ghost->X;
                                    i->Y = ghost->Y;
                                    Ghost_Waitframe2(this,ghost);
                                }
                                Game->PlaySound(GHOST_STEALITEM_STEAL_SFX);
                                Remove(i);
                                a[GHOST_STEALITEM_HOLDING_ITEM] = 0;
                            }
                        }
                    }
                }
            }
            Ghost_Waitframe2(this,ghost);
        }
    }
    bool __DistX(npc a, item b, int distance) {
        int dist;
        if ( a->X > b->X ) dist = a->X - b->X;
        else dist = b->X - a->X;
        return ( dist <= distance );
    }
    bool __DistY(npc a, item b, int distance) {
        int dist;
        if ( a->Y > b->Y ) dist = a->Y - b->Y;
        else dist = b->Y - a->Y;
        return ( dist <= distance );
    }

}

Edited by ZoriaRPG, 24 July 2016 - 06:58 AM.


#3 Cereal Guy

Cereal Guy

    Senior

  • Members
  • Location:Concepción, CHL

Posted 18 July 2016 - 02:34 PM

Unexpected identifier, on token npc id

 

:(


Edited by Cereal Guy, 18 July 2016 - 02:35 PM.


#4 judasrising

judasrising

    I play guitar

  • Members
  • Location:Sweden but born in Finland

Posted 18 July 2016 - 02:40 PM

Unexpected identifier, on token npc id

 

:(

Replace it with int npc_ID



#5 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 18 July 2016 - 03:08 PM

Replace it with int npc_ID


No... I forgot to declare the param as an int.

Edited by ZoriaRPG, 24 July 2016 - 01:01 AM.


#6 Cereal Guy

Cereal Guy

    Senior

  • Members
  • Location:Concepción, CHL

Posted 19 July 2016 - 12:31 AM

Error T29: 'That pointer type does not have a variable isValid 

 

:shiver:



#7 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 19 July 2016 - 11:54 AM

Updated above.

Edited by ZoriaRPG, 24 July 2016 - 01:02 AM.


#8 Cereal Guy

Cereal Guy

    Senior

  • Members
  • Location:Concepción, CHL

Posted 19 July 2016 - 08:01 PM

Another error now on the line 9 :(  "That pointer type does not have a FUNCTION isValid" D:



#9 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 21 July 2016 - 03:15 AM

I see what I did there. I had the casing right originally, but forgot the parens.

Edited by ZoriaRPG, 24 July 2016 - 01:02 AM.


#10 Cereal Guy

Cereal Guy

    Senior

  • Members
  • Location:Concepción, CHL

Posted 21 July 2016 - 11:00 PM

error t29: that pointer type does not have a variable class.

 

Oggg :(



#11 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 22 July 2016 - 05:12 AM

Fixed above.

#12 Lejes

Lejes

    Seeker of Runes

  • Members
  • Location:Flying High Above Monsteropolis

Posted 22 July 2016 - 11:57 AM

Items also don't have a Type variable. The IC_ constants are meant for item families, which you'll have to load itemdata for.

#13 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 22 July 2016 - 12:26 PM

Items also don't have a Type variable. The IC_ constants are meant for item families, which you'll have to load itemdata for.

Sigh. Another inconsistent thing for me to fix in ZScript. There is no reason whatever, that item->Type shouldn't be a thing, and pointer->Class should exist too, as that's how ZC defines them in the editor, which is why when I was making these--on me phone--I used that.

Life tip: Don't become old, and senile. I very rarely use the class of objects to do...anythibg. I typically use object->ID, as my applications are far less generic. This [i]should[i] be done now, and if it isn't, it's going to wait until I can sit in front of a laptop.

The main reason that I used item classes here, is so that CerealGuy didn't need to make a huge list of all the items to affect. I originally wrote it with item->ID, and then decided that the set-up would be too much work for him; and I set it to the common drops, instead of single items, instead.

It also shortens the for loop quite a lot.

Edited by ZoriaRPG, 22 July 2016 - 12:29 PM.


#14 Cereal Guy

Cereal Guy

    Senior

  • Members
  • Location:Concepción, CHL

Posted 22 July 2016 - 04:40 PM

Syntax error, unexpected identifier, expecting semicolon or or, on token it  :augh:  

npc n; item i; int q; int w; int e; itemclass it;

Edited by Cereal Guy, 22 July 2016 - 04:41 PM.


#15 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 22 July 2016 - 09:35 PM

Syntax error, unexpected identifier, expecting semicolon or or, on token it :augh:

npc n; item i; int q; int w; int e; itemclass it;
Change itemclass to itemdata, and then I'll shoot meself in the foot again. Fixed above.

ZASM uses 'itemclass', by the by. Been staring at that too much lately, apparently. Thinking about it, that's probably why item->Class/item->Type isn't a thing, as itemdata began life, as itemclass.

Edited by ZoriaRPG, 22 July 2016 - 09:39 PM.



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users