Jump to content

  •  





Basic Floating Rates Script

Posted by GmOcean, in 1. Beginner Scripts 25 November 2014 · 1500 views

Basic Floating Rates Script ( 2 Parts )
Here we will create an npc that will adjust the base & job experience rates.

Part 1
Alright, so we're going to start off by making a floating npc header. It's similar to a normal npc header with the exception of replacing the <map_name>,<x>,<y>,<facing> with a simply hyphen ( - ), and the <sprite_id> with -1.

So let's make our floating npc header and call our npc floating_rates:
-    script    floating_rates    -1,{

Alright, since this is our third script in the beginner's series, we're going to speed things up a bit by not taking so much time to explain things ( this sentence & mandatory explanations being the exception ).
Now, since we want our script to activate everyday of the week, and change daily, we are going to use a label called: OnClock<hour><minute>: The time we are going to use is 0000:
OnClock0000:

Okay, now it's time to start adding in where we change the experience rates, but first we need to set 2 variables to a random value between 150 & 200.
To do so we use this command: rand(<number>{,<number>}); We're going to use scope variables, and we're going to call them base_exp & job_exp.
So go ahead and add that beneath our OnClock label:
    .@base_exp = rand(150,200);
    .@job_exp = rand(150,200);

We got that taken care of. Now we are going to actually change the base & job experience rates. To do that we need to use this command: setbattleflag "<battle flag>",<value>;
A list of battle flags can be found in the files listed here: Battle Flags. But we are only going to be using the following flags: base_exp_rate & job_exp_rate
    setbattleflag "base_exp_rate", .@base_exp;
    setbattleflag "job_exp_rate", .@job_exp;

Alright, that's everything we need to do. So let's end the script and close it up:
    end;
}

When you're done, your script should look something like this:
-	script	floating_rates	-1,{
OnClock0000:
    .@base_exp = rand(150,200);
    .@job_exp = rand(150,200);
    setbattleflag "base_exp_rate", .@base_exp;
    setbattleflag "job_exp_rate", .@job_exp;
    end;
}
And, now whenever your players kill a monster they will get that modified experience rate, that changes everyday at midnight.

Part 2
Okay, so last lesson we made a very basic floating rates npc that changes the rates everyday. However, now we are going to change that npc to only change rates during weekends.

Let's start by opening up our script:
-	script	floating_rates	-1,{
OnClock0000:
    .@base_exp = rand(150,200);
    .@job_exp = rand(150,200);
    setbattleflag "base_exp_rate", .@base_exp;
    setbattleflag "job_exp_rate", .@job_exp;
    end;
}

So, to make it only work for Friday, Saturday and Sunday, we are going to change our label OnClock0000: to this label: On<weekday><hour><minute>:.
So let's change it for Firday same time:
OnFri0000:

Okay now that we got that taken care of, rates will change to a new random amount every Friday. However we want this to only last for the weekend, so we need to change them back starting Monday. That's right you guessed it, very similar setup but this time we'll be setting the rates back to normal so let's do it:
OnMon0000:
    setbattleflag "base_exp_rate", 100;
    setbattleflag "job_exp_rate", 100;
    end;

Right now your script should look something like this:
-	script	floating_rates	-1,{
OnFri0000:
    .@base_exp = rand(150,200);
    .@job_exp = rand(150,200);
    setbattleflag "base_exp_rate", .@base_exp;
    setbattleflag "job_exp_rate", .@job_exp;
    end;
OnMon0000:
    setbattleflag "base_exp_rate", 100;
    setbattleflag "job_exp_rate", 100;
    end;
}

As of right now it's almost done. Let's just edit it a bit, so that we let player's know when the experience rates change and what they changed to.
To do that we are going to use this command: announce "<text>",<flag>{,<fontColor>{,<fontType>{,<fontSize>{,<fontAlign>{,<fontY>}}}}}; in combination with this command: getbattleflag("<battle flag>")
The announcement_flag we'll be using is bc_all with 0x00FFFF as the color. For other flags look here: Broadcast Flags. Additionally, you can use other hex color codes for the broadcast color in this format: 0xRRGGBB
Now then let's add 1 announcement when we increase the rates:
announce "Bonus Experience Weekend has just started! Base Exp: +"+ (getbattleflag("base_exp_rate") - 100) +"% | Job Exp: +"+ (getbattleflag("job_exp_rate") - 100) +"% !!",bc_all,0x00FFFF;

And 1 announcement when we set the rates back:
announce "Bonus Experience Weekend has ended.",bc_all,0x00FFFF;

Make sure you added those announcements under the correct label, if you got them backwards you'll be confusing your players. Although, we are almost done so let's finish this.
The last thing we're going to do is add 1 more announcement that occurs every hour, to let player's know it is bonus exp weeked.
To do that we're going to use the label: OnMinute<minute>: and we are going to use 00 as the minute, additionally we need to use this command: gettime(<type>) so we can find out the day.
Mainly we need to check if it's Friday, Saturday or Sunday. So let's add it in:
OnMinute00:
    if (!gettime(4) || gettime(4) >= 5){
	announce "Bonus Experience Weekend in progress! Base Exp: +"+ (getbattleflag("base_exp_rate") - 100) +"% | Job Exp: +"+ (getbattleflag("job_exp_rate") - 100) +"% !!",bc_all,0x00FFFF;
    }
    end;

When you're all done your script should look like this:
-	script	floating_rates	-1,{
OnFri0000:
    .@base_exp = rand(150,200);
    .@job_exp = rand(150,200);
    setbattleflag "base_exp_rate", .@base_exp;
    setbattleflag "job_exp_rate", .@job_exp;
    announce "Bonus Experience Weekend has just started! Base Exp: +"+ (getbattleflag("base_exp_rate") - 100) +"% | Job Exp: +"+ (getbattleflag("job_exp_rate") - 100) +"% !!",bc_all,0x00FFFF;
    end;
OnMon0000:
    setbattleflag "base_exp_rate", 100;
    setbattleflag "job_exp_rate", 100;
    announce "Bonus Experience Weekend has ended.",bc_all,0x00FFFF;
    end;
	
OnMinute00:
    if (!gettime(4) || gettime(4) >= 5){
        announce "Bonus Experience Weekend in progress! Base Exp: +"+ (getbattleflag("base_exp_rate") - 100) +"% | Job Exp: +"+ (getbattleflag("job_exp_rate") - 100) +"% !!",bc_all,0x00FFFF;
	}
    end;
}
Save it and we are done. You just finished creating a Floating Rates NPC.