Easy difficulty system

Toranks

Active member
I would like to leave here a summary of how to create a difficulty mode that can be changed at any time, via globalvar, thanks to several fellow forum members, especially @Bloodbane

The idea is to create a progressive difficulty, that with greater difficulty, all the enemies of the previous difficulties appear plus the enemies of the current chosen difficulty. With a few small changes it is possible to create difficulties independent of each other, I will explain how in the end.

First you need any way of create and change values of some globalvars named "normal" and "hard", or similar (Note that the default difficulty does not need a globalvar assigned). I use a scripted visual menu that when choosing the preferred difficulty, the following script is activated (this is just a sample):

C#:
@script

    if (frame == 9)
    {
    setglobalvar("normal", 0);
    setglobalvar("hard", 0);
    }
    if (frame == 10)
    {
    setglobalvar("normal", 1);
    setglobalvar("hard", 0);
    }
    if (frame == 11)
    {
    setglobalvar("normal", 1);
    setglobalvar("hard", 1);
    }
@end_script

Depending on the frame where it is located (which represents the chosen option), the value of the chosen difficulty and the previous ones will change to 1. (If you want a complete sample of the menu code, write me)

AOF - 0084.pngAOF - 0085.png
Now you will need to insert two different codes to each enemy that will appear in each difficulty (remember that those of the chosen difficulty and all of the previous ones appear)

For normal (easy+hard):

C#:
spawn  biff
@script
  void main()
  {
    void self = getlocalvar("self");
    void difficulty = getglobalvar("normal");

    if(difficulty == 0){
      killentity(self);
    }
  }
@end_script
map     2
coords  650 340
at      100

For hard (easy+normal+hard):

C#:
spawn  rider1
@script
  void main()
  {
    void self = getlocalvar("self");
    void difficulty = getglobalvar("hard");

    if(difficulty == 0){
      killentity(self);
    }
  }
@end_script
coords  650 340
at      1520

Note that if the enemy already has a script, you must mix it up, not split it. For example if you previously have:

C#:
spawn  bash
@script
void main()
    {
    void self = getlocalvar("self");

    performattack(self, openborconstant("ANI_JUMP"));
    tossentity(self, 4, -4, 0);
    }
@end_script
map     1
coords  570 250
at      520

Need to be changed to:

C#:
spawn  bash
@script
void main()
    {
    void self = getlocalvar("self");
    void difficulty = getglobalvar("hard");

    performattack(self, openborconstant("ANI_JUMP"));
    tossentity(self, 4, -4, 0);
 
    if(difficulty == 0){
      killentity(self);
    }
}
@end_script
map     1
coords  570 250
at      520

And this is all! Every spawn verifies the corresponding difficulty is present. If not, kills the enemy, and continue with the next spawn.



If you need independent difficulties, make the following changes:

Use a generic globalvar named "difficulty" and set a value for normal and hard (for example 1 and 2).

C#:
setglobalvar("difficulty", 1);

or

C#:
setglobalvar("difficulty", 2);

And change the following line of the spawn code:

C#:
    void difficulty = getglobalvar("hard");

    if(difficulty == 0){

to

C#:
    void difficulty = getglobalvar("difficulty");

    if(difficulty != 1){

or

C#:
    void difficulty = getglobalvar("difficulty");

    if(difficulty != 2){

In this case, what the script will do is check if the difficulty is NOT the one corresponding to the enemy, and if so, it kills him.
 
Last edited:
This would have worked as a animation script i would recommend avoiding update scripts whenever possible.
 
This would have worked as a animation script i would recommend avoiding update scripts whenever possible.
You mean instead of:

C#:
spawn  biff
@script
  void main()
  {
    void self = getlocalvar("self");
    void difficulty = getglobalvar("normal");

    if(difficulty == 0){
      killentity(self);
    }
  }
@end_script
map     2
coords  650 340
at      100

Use that?:

C#:
spawn  biff
spawnscript data/scripts/spawnnormal.c
map     2
coords  650 340
at      100

And inside spawnnormal.c write the code above?
 
yes a spawnscript will work but the reason I said a animation script was because you can pass a parameter through with the script call so if you have 3 levels of difficulty some enemies can die if the difficulty is below 2 ( medium difficulty ) and other if its below 3 ( hard difficulty )
 
Last edited:
Back
Top Bottom