For scripts that keep repeating the same thing over and over but only have minor changes based on scenario, functions are the way to go.
/* Function to check that the player has the requisite item, then accept multiple args to control the rest of the function.
* @param {int} rental_item - The item id to check for.
* @param {int} second_item - The item id to check for.
* @param {int} give_item - The item id to give the player when the function is finished.
* @syntax callfunc "F_Gather",40005,40008,40023;
*/
function script F_Gather {
.@rental_item = getarg(0);
.@second_item = getarg(1);
.@give_item = getarg(2);
clear;
if(rentalcountitem(.@rental_item) < 1){
mes "You don't have a "+ getitemname(.@rental_item) +"."; // You don't have a Stone Knife.
close;
}
if(countitem(.@second_item) == 1){
mes "Gathering in progress.", "Do not move or gathering", "progress will be cancelled.";
soundeffect "gathering.wav",0;
addtimer 2,strnpcinfo(0)+"::OnTest";
progressbar "0x00ff00",2;
next;
mes "Gathering Completed.";
soundeffect "menu.wav",0;
gathering_points += 1;
dispbottom "Gained +1 Gathering Points";
getitem .@give_item,1;
close3;
}
}
- script Green Tree FAKE_NPC,{
soundeffect "menu.wav",0;
mes "What do you want to do ?";
switch(select("- Gather Branch:- Gather Log:- Gather Tree Sap:- Cancel")){
case 1:
switch(select("- Use Stone Knife:- Cancel")){
case 1:
// Rental item needed, Second item needed, Item to give
callfunc "F_Gather", 40005, 40008, 40023;
case 2:
break;
}
break;
case 2:
switch(select("- Use Makeshift Axe:- Cancel")){
case 1:
callfunc "F_Gather",40029,40008,40027;
case 2:
break;
}
break;
case 3:
switch(select("- Use Stone Knife:- Cancel")){
case 1:
callfunc "F_Gather",40005,40008,40190;
case 2:
break;
}
case 4:
break;
}
OnTest:
end;
}
// DUPLICATE
//=================================================================
new_1-3,92,63,6 duplicate(Green Tree) Green Tree#1000 11000
new_1-3,96,65,6 duplicate(Green Tree) Green Tree#1001 11000