Jump to content

Photo

achievement system

achievement counter enemies

  • Please log in to reply
11 replies to this topic

#1 accela2me

accela2me

    Illustrious

  • Members
  • Real Name:Juliano
  • Location:Minas Gerais, Brazil

Posted 20 December 2013 - 09:35 PM

hello, people!

I'm making an achievement system for my quest and one of the tasks is to kill a certain number of enemies (300, for example). so, I need a script to create a counter of defeated enemies and display a message when the total number of enemies is reached.

can someone help me with this? :)

 



#2 MoscowModder

MoscowModder

    Sometimes lurking. Rarely posting.

  • Members
  • Location:Wisconsin

Posted 20 December 2013 - 10:08 PM

I made this to support multiple achievements in one script. Adding more achievements should be relatively simple. In theory.

int achievementCounters[1]; //All achievement counters

//Achievement counter indices
const int AC_KILLS = 0;

//Achievement items
const int I_KILLS300 = 0; //Item to give for 300 kills

const int HP_DEAD = -999;

global script active{
    void run(){
        while(true){
            //Kill tracking
            for(int i = 1; i <= Screen->NumNPCs(); i++){
                npc enem = Screen->LoadNPC(i);
                if(enem->HP <= 0 && enem->HP > HP_DEAD){
                    achievementCounters[AC_KILLS]++;
                    enem->HP = HP_DEAD;
                    if(achievementCounters[AC_KILLS] == 300)
                        Link->Item[I_KILLS300] = true;
                }
            }
            Waitframe();
        }
    }
}

Edited by MoscowModder, 21 December 2013 - 01:32 PM.
Edited script


#3 accela2me

accela2me

    Illustrious

  • Members
  • Real Name:Juliano
  • Location:Minas Gerais, Brazil

Posted 21 December 2013 - 11:43 AM

Dude, I tested the script with my current quest, but the item didn't appear in the subscreen.

And in another test, I created a new game using only the script that you made ​​and the game crashed.

What could be wrong? :/

 

Here the test file:

https://dl.dropboxus...72/testfile.rar

 

EDIT: I found the problem to the 1st test: the script works only with enemies that have only 1 point of HP.


Edited by accela2me, 21 December 2013 - 12:05 PM.


#4 MoscowModder

MoscowModder

    Sometimes lurking. Rarely posting.

  • Members
  • Location:Wisconsin

Posted 21 December 2013 - 01:11 PM

Dang it! Forgot the old Waitframe(). I also forgot to set the enemies' HP to HP_DEAD. Fixed both above. ^^



#5 Saffith

Saffith

    IPv7 user

  • Members

Posted 21 December 2013 - 01:13 PM

Also, that should be enem->HP <= 0

#6 Avaro

Avaro

    >w<

  • Members

Posted 21 December 2013 - 01:39 PM

So, enemies that have 0 or less HP disappear after one frame, right?



#7 accela2me

accela2me

    Illustrious

  • Members
  • Real Name:Juliano
  • Location:Minas Gerais, Brazil

Posted 21 December 2013 - 01:48 PM

Now is working very well!

Thanks so much, guys! :)



#8 accela2me

accela2me

    Illustrious

  • Members
  • Real Name:Juliano
  • Location:Minas Gerais, Brazil

Posted 12 September 2015 - 04:23 PM

I'll use this topic again, because I need another achievement to add to my quest:

Now I don't know how to create an achievement that is unlocked if you collect 999 rupees (since the amount of rupees is always changing.)



#9 MoscowModder

MoscowModder

    Sometimes lurking. Rarely posting.

  • Members
  • Location:Wisconsin

Posted 12 September 2015 - 04:36 PM

Boom.

int achievementCounters[1]; //All achievement counters

//Achievement counter indices
const int AC_KILLS = 0;

//Achievement items
const int I_KILLS300 = 0; //Item to give for 300 kills
const int I_RUPEES999 = 0; // Item to give for 999 rupees

const int HP_DEAD = -999;

global script active{
    void run(){
        while(true){
            //Kill tracking
            for(int i = 1; i <= Screen->NumNPCs(); i++){
                npc enem = Screen->LoadNPC(i);
                if(enem->HP <= 0 && enem->HP > HP_DEAD){
                    achievementCounters[AC_KILLS]++;
                    enem->HP = HP_DEAD;
                    if(achievementCounters[AC_KILLS] == 300)
                        Link->Item[I_KILLS300] = true;
                }
            }
            // 999 rupees
            if(!Link->Item[I_RUPEES999] && Game->Counter[CR_RUPEES] >= 999)
                Link->Item[I_RUPEES999] = true;
            Waitframe();
        }
    }
}


#10 accela2me

accela2me

    Illustrious

  • Members
  • Real Name:Juliano
  • Location:Minas Gerais, Brazil

Posted 12 September 2015 - 05:54 PM

Thanks, dude! :)



#11 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 18 September 2015 - 02:46 AM

So, enemies that have 0 or less HP disappear after one frame, right?


Pointers are cleared the frame after they become invalid; so, aye, that's what happens. This is also true for objects (NPCs, weapons, and the like) removed with the Remove() function: They aren't removed until the next frame.

 

Further, don't do Remove() with Lanmolas in 2.50.0, as that will crash ZC. (You can safely do it in 2.50.1.)



#12 elektriktoad

elektriktoad

    Initiate

  • Members

Posted 28 September 2015 - 12:40 PM

I'll use this topic again, because I need another achievement to add to my quest:

Now I don't know how to create an achievement that is unlocked if you collect 999 rupees (since the amount of rupees is always changing.)

 

Do you mean "unlock achievement once your wallet contains 999 rupees" (which is what MoscowModder's script does), or "unlock achievement after collecting 999 rupees, even if you've spent some in the meantime"? For the latter, you could attach a pickup script to all rupee items that increases a Cumulative Rupee counter and check that counter in the global script to unlock the achievement. Alternatively, a global script could continuously compare your rupee counter to the amount from the previous frame, and increment a Cumulative Rupee variable as needed. I don't have the time to implement that at the moment, but I could get to it later this week if no one else does it first.

 

I like these achievement ideas. It would be neat if the achievement item that you acquire can be equipped/unequipped to give you different 'hats,' using Link Tile Modifiers.





Also tagged with one or more of these keywords: achievement, counter, enemies

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users