Jump to content

Recommended Posts

Posted

Script Name: Package Item Trader

Description: This script allows you to make the NPC to require multiple items and give multiple items.

Version: 1.0

Syntax: callsub(ADD_PACKAGE,"Reward",<itemid,quantity,{itemid,quantity}...>,"Required",<itemid,quantity,{itemid,quantity}...>,"Zeny",zeny,PACKAGETITLE,CATEGORY);

Keywords:

  • Reward - this is an indicator that your adding items that the npc will give to the player
  • Required - this is an indicator that your adding items that the player must give to the npc
  • Zeny - this is an indicator that your requiring a zeny payment set the zeny to 0 if your dont want to require zeny payment.


//Script Name: Package Item Trader
//Developer: JayPee Mateo
//Description:  This is package item trade is where you can set the NPC to require multiple items and give multiple items also.
//Version: 1.0
//Some Explanation:
//LABEL or CALLSUB FUNCTION NAME: ADD_PACKAGE
//Zeny Payment: If you dont want to not require a zeny set it to Zero (0)
//PACKAGETITLE - what do you want to call that Package
//CATEGORY - on what group does it belong just to be cleaner 

//Syntax:callsub(ADD_PACKAGE,"Reward",<itemid,quantity,{itemid,quantity}...>,"Required",<itemid,quantity,{itemid,quantity}...>,"Zeny",zeny,PACKAGETITLE,CATEGORY);

//Script
royal_room3,84,136,5 script Item Trader 70,{
//Initialized Variables:
set .npcName$,"^FF3300[ Trader ]^000000";
set @ctr_id,1;
set @selected,0;

//Clear Values
deletearray @selected_ctrid[0],128;
deletearray .@tmp_CatArr$[0],128;

//Initialized Packages 
//You must initialize the item packages after the clearing and intialization of the variables 
//Example 1: 
//Reward or Item to give:Rice Cake Stick(2 pcs), Traditional Rice Cake (1pc) and Neatly Sliced Rice Cake(3 pcs)
//Item Requirements: Shining Stone (1)
//Zeny Payment: 1z
//Title is Example 1
//Category is Category1
callsub(ADD_PACKAGE,"Reward",555,1,556,2,557,3,"Required",640,1,"Zeny",1,"Example 1","Category1");

//Example 2: 
//Reward or Items the npc will give: Level 1 Frost Diver
//Item Requirements: Rice Cake Stick(2 pcs), Traditional Rice Cake (1pc) and Neatly Sliced Rice Cake(3 pcs)
//Zeny Payment: 0z or no required zeny
//Title is Example 2
//Category is Category2 
callsub(ADD_PACKAGE,"Reward",700,1,"Required",555,1,556,2,557,3,"Zeny",0,"Example 2","Category2");



set .@makeString$,"";
for(set .@i,1; .@i<@ctr_id; set .@i,.@i+1)
{
set .@tmp_cat$,getd("."+.@i+"_category$");
if(.@makeString$ == "")
{
setarray .@tmp_CatArr$[getarraysize(.@tmp_CatArr$)],.@tmp_cat$;
set .@makeString$,.@tmp_cat$;
}
else
{
if(compare(.@makeString$,.@tmp_cat$)==0)
{ 
setarray .@tmp_CatArr$[getarraysize(.@tmp_CatArr$)],.@tmp_cat$;
set .@makeString$,.@makeString$+":"+.@tmp_cat$;
} 
}
}
mes .npcName$;
mes "Please choose the ^FF0000item category^000000:";
set @selected,select(.@makeString$);
set .@tmp_cat$,.@tmp_CatArr$[@selected-1];
set .@hasValue,callsub(getCTRIDByCAT,.@tmp_cat$,@ctr_id);
if(.@hasValue==1)
{
goto LIST_TITLES;
}
else
mes "Weird....Nothing found!";
close;

LIST_TITLES:
next;
mes .npcName$;
mes "Kindly choose the ^FF0000item package^000000:";
set .@makeString$,"";
for(set .@i,0; .@i<getarraysize(@selected_ctrid); set .@i,.@i+1)
{ 
if(.@makeString$ == "")
{
set .@tmp_cat$,getd("."+@selected_ctrid[.@i]+"_title$");
set .@makeString$,.@tmp_cat$; 
}
else
{
set .@tmp_cat$,getd("."+@selected_ctrid[.@i]+"_title$");
set .@makeString$,.@makeString$+":"+.@tmp_cat$; 
}
}
set @selected,select(.@makeString$)-1;
set .@tmp_cat$,getd("."+@selected_ctrid[@selected]+"_title$");
goto LIST_INFO;
end;

LIST_INFO:
set .@tmp_CTRID,@selected_ctrid[@selected];

next;
mes "^FF3300"+.@tmp_cat$+" Information^000000";
//List rewards
mes "Reward:";
for(set .@i,0; .@i<getd("."+.@tmp_CTRID+"_rew_size"); set .@i,.@i+1)
{
set .@tmp_name$,getitemname(getd("."+.@tmp_CTRID+"_item_rew_id["+.@i+"]"));
set .@tmp_quantity,getd("."+.@tmp_CTRID+"_item_rew_quantity["+.@i+"]");
mes "* "+.@tmp_name$+" - "+.@tmp_quantity+" pc(s).";
}
mes "\n";
//List requirements
mes "Requirements:";
for(set .@i,0; .@i<getd("."+.@tmp_CTRID+"_req_size"); set .@i,.@i+1)
{
set .@tmp_itemid,getd("."+.@tmp_CTRID+"_item_req_id["+.@i+"]");
set .@tmp_name$,getitemname(.@tmp_itemid);
set .@tmp_quantity,getd("."+.@tmp_CTRID+"_item_req_quantity["+.@i+"]");

if(countitem(.@tmp_itemid)<.@tmp_quantity)
setarray .@errors$[getarraysize(.@errors$)],.@tmp_name$+" -[ "+countitem(.@tmp_itemid)+" / "+.@tmp_quantity+" ]";

mes "* "+.@tmp_name$+" - "+.@tmp_quantity+" pc(s).";
}

set .@tmp_zeny_req,getd("."+.@tmp_CTRID+"_zeny_req");

//Check if there is a zeny requirements
if(.@tmp_zeny_req>0)
mes "* Zeny - "+.@tmp_zeny_req+" z.";

//Zenny Requirements: it will skip the zeny requirements if set to 0
if(Zeny<.@tmp_zeny_req && .@tmp_zeny_req>0)
setarray .@errors$[ getarraysize(.@errors$)],"Zenny - ["+Zeny+"/ "+.@tmp_zeny_req+" ]";

switch(select("Claim Reward:I'll be back"))
{
case 1:
next;
mes "^FF3300"+.npcName$+" - Claim Reward^000000";
if(getarraysize(.@errors$)>0)
{
mes "You dont have all the required items:";
for(set .@i,0; .@i<getarraysize(.@errors$); set .@i,.@i+1)
{
mes (.@i+1)+".] "+.@errors$[.@i];
}
close;
} 
else
{ 
//Consuming all the requirements
for(set .@i,0; .@i<getd("."+.@tmp_CTRID+"_req_size"); set .@i,.@i+1)
{
set .@tmp_itemid,getd("."+.@tmp_CTRID+"_item_req_id["+.@i+"]");
set .@tmp_quantity,getd("."+.@tmp_CTRID+"_item_req_quantity["+.@i+"]");

delitem .@tmp_itemid,.@tmp_quantity;
}

//Consuming the zeny
if(.@tmp_zeny_req>0)
set Zeny,Zeny-.@tmp_zeny_req+" z.";

//Giving all the rewards
mes "Rewards Given:";
for(set .@i,0; .@i<getd("."+.@tmp_CTRID+"_rew_size"); set .@i,.@i+1)
{
set .@tmp_itemid,getd("."+.@tmp_CTRID+"_item_rew_id["+.@i+"]");
set .@tmp_quantity,getd("."+.@tmp_CTRID+"_item_rew_quantity["+.@i+"]");
mes "* "+getitemname(.@tmp_itemid)+" - "+.@tmp_quantity+" pc(s).";
getitem .@tmp_itemid,.@tmp_quantity;
} 

} 
mes "Here you go! Hope you enjoy the reward";
close;
case 2:
next;
mes "^FF3300"+.npcName$+"^000000";
mes "Okay, bye!";
close;
}
end;

ADD_PACKAGE:
set .@keywordFinder,0; //This is the indicator if the keyword has been found
set .@shift,0; //This is for itemid and quantity
set .@pairChecker,0; //Checks if there are missing arguments example: itemid itemid quantity
//Important Keywords
//Reward = for the reward items
//Required = for the required items
//Zeny  = if you want to specify a zenny

//Returned Variables: 
//@ctr_id - is the number of packages produced
//@ctr_id_rew_size = arraysize of the reward array;
//@ctr_id_req_size = arraysize of the required array;
//@ctr_id_item_rew_id[index] = arrayvariable of rewards itemid
//@ctr_id_item_rew_quantity[index] = arrayvariable of rewards quantity
//@ctr_id_item_req_id[index] = arrayvariable of required itemid
//@ctr_id_item_req_quantity[index] = array variable of the required quantity
//@ctr_id_zeny_req = zeny requirements this is not an array
//@ctr_id_title$ = title of the package
//@ctr_id_category$ = name of the group of the package

//Check if the Reward keyword is found else report error
if(""+getarg(0)!="Reward")
{
debugmes "The first argument for ADD_ITEM callsub function must be Reward. Error occur at counter id: "+@ctr_id;
return 0;
}

//This will be use in the array index
set .@tmp_loopctr,0;

//Loop all the initialize requirements
for(set .@add,1; .@add<getargcount(); set .@add,.@add+1)
{
//If Required keyword has been found break loop
if(""+getarg(.@add)=="Required")
{
//Store the number value where the Required keyword has been found
set .@keywordFinder,.@add; 
break;
}

if(.@shift==0)
{
if(getarg(.@add)==0)
{
debugmes "The item id for Reward and Requirements cannot be zero. Error occur at counter id: "+@ctr_id;
end;
}
setd "."+@ctr_id+"_item_rew_id["+(.@tmp_loopctr)+"]",getarg(.@add);
set .@shift,1;
}
else
{
if(getarg(.@add)==0)
{
debugmes "The quantity for items Reward and Requirements cannot be zero. Error occur at counter id: "+@ctr_id;
end;
}
setd "."+@ctr_id+"_item_rew_quantity["+(.@tmp_loopctr)+"]",getarg(.@add);
set .@tmp_loopctr,.@tmp_loopctr+1;
set .@shift,0;
}
set .@pairChecker,.@pairChecker+1;
}
setd "."+@ctr_id+"_rew_size",.@pairChecker/2; //Store the arraysize of the Reward Items

//If there are missing arguments in Rewards its either quantity or itemid
//Check if the itemid and quantity match.
//Error Example: 1100,111,111
//Right Example: 1100,111,1101,111
if(.@pairChecker%2==1)
{
debugmes "Missing arguments in Reward. Error Occured at counter id: "+@ctr_id;
end; 
}

//If Required Keyword has been found
//it must not be equal to zero to verify that required keyword has been found
if(.@keywordFinder == 0)
{
debugmes "No Required Keyword Found. Error occured at counter id: "+@ctr_id;
end; 
}

//Required Keyword
set .@pairChecker,0; //Reset the pair checker
set .@tmp_keywordFinder,.@keywordFinder; //Store the last keywordfinder value to a temporary variable
set .@shift,0; //For itemid and quantity shifting

//This will be use as the array index/key
set .@tmp_loopctr,0;

//Get all the Required Items
for(set .@add,.@keywordFinder+1; .@add<getargcount(); set .@add,.@add+1)
{

//Check if the Zeny Keyword has been found else continue looping
if(""+getarg(.@add)=="Zeny")
{
//Store the number value where the Required keyword has been found
set .@keywordFinder,.@add; 
break;
}

if(.@shift == 0)
{
if(getarg(.@add)==0)
{
debugmes "The item id for Reward and Requirements cannot be zero. Error occur at counter id: "+@ctr_id;
end;
}
setd "."+@ctr_id+"_item_req_id["+(.@tmp_loopctr)+"]",getarg(.@add);
set .@shift,1;
}
else
{
if(getarg(.@add)==0)
{
debugmes "The quantity for items Reward and Requirements cannot be zero. Error occur at counter id: "+@ctr_id;
end;
}
setd "."+@ctr_id+"_item_req_quantity["+(.@tmp_loopctr)+"]",getarg(.@add);
set .@tmp_loopctr,.@tmp_loopctr+1;
set .@shift,0;
} 
set .@pairChecker,.@pairChecker+1;
}
setd "."+@ctr_id+"_req_size",.@pairChecker/2; //Array size of the required items

//If there are missing arguments in Rewards its either quantity or itemid
if(.@pairChecker%2==1)
{
debugmes "Missing arguments in Required Keyword. Error Occured at counter id: "+@ctr_id;
end; 
}

//If reward has not been found
if(.@keywordFinder == .@tmp_keywordFinder)
{
debugmes "No Zeny Keyword Found. Error occured at counter id: "+@ctr_id;
end; 
}

//Zeny Keyword
if(getarg(.@keywordFinder+1)<0)
{
debugmes "Negative Zeny Requirments Not Allowed. Error occured at counter id: "+@ctr_id;
end; 
}

setd "."+@ctr_id+"_zeny_req",getarg(.@keywordFinder+1);

//Title
if(""+getarg(.@keywordFinder+2)==""+0)
{
debugmes "Title Required. Error occured at counter id: "+@ctr_id;
end; 
}
setd "."+@ctr_id+"_title$",getarg(.@keywordFinder+2);

//Category
if(""+getarg(.@keywordFinder+3)==""+0)
setd "."+@ctr_id+"_category$","Uncategorized"; 
else
setd "."+@ctr_id+"_category$",getarg(.@keywordFinder+3);

set @ctr_id,@ctr_id+1;
return 1; //Return a 1 if success 
end; 


getCTRIDByCAT:
//Getting the CTR ID's related to the assigned to a category
//getarg(0) - is the category
//getarg(1) - is the total ctr id

set .@tmp_ctr,0;
for(set .@i,1; .@i<getarg(1); set .@i,.@i+1)
{
set .@tmp_strcat$,getd("."+.@i+"_category$");
if(.@tmp_strcat$ == getarg(0))
{
setarray @selected_ctrid[.@tmp_ctr],.@i;
set .@tmp_ctr,.@tmp_ctr+1;
}
}
if(getarraysize(@selected_ctrid)>0)
return 1; //Return 1 if there is a CTRID's found
return 0;
end;

}

  • Upvote 2

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...