Jump to content
JayPee

Package Item Trader

Recommended Posts

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 [email protected]_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 [email protected]$,"";
for(set [email protected],1; [email protected]<@ctr_id; set [email protected],[email protected]+1)
{
set [email protected]_cat$,getd("."[email protected]+"_category$");
if([email protected]$ == "")
{
setarray [email protected]_CatArr$[getarraysize([email protected]_CatArr$)],[email protected]_cat$;
set [email protected]$,[email protected]_cat$;
}
else
{
if(compare([email protected]$,[email protected]_cat$)==0)
{ 
setarray [email protected]_CatArr$[getarraysize([email protected]_CatArr$)],[email protected]_cat$;
set [email protected]$,[email protected]$+":"[email protected]_cat$;
} 
}
}
mes .npcName$;
mes "Please choose the ^FF0000item category^000000:";
set @selected,select([email protected]$);
set [email protected]_cat$,[email protected]_CatArr$[@selected-1];
set [email protected],callsub(getCTRIDByCAT,[email protected]_cat$,@ctr_id);
if([email protected]==1)
{
goto LIST_TITLES;
}
else
mes "Weird....Nothing found!";
close;

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

LIST_INFO:
set [email protected]_CTRID,@selected_ctrid[@selected];

next;
mes "^FF3300"[email protected]_cat$+" Information^000000";
//List rewards
mes "Reward:";
for(set [email protected],0; [email protected]<getd("."[email protected]_CTRID+"_rew_size"); set [email protected],[email protected]+1)
{
set [email protected]_name$,getitemname(getd("."[email protected]_CTRID+"_item_rew_id["[email protected]+"]"));
set [email protected]_quantity,getd("."[email protected]_CTRID+"_item_rew_quantity["[email protected]+"]");
mes "* "[email protected]_name$+" - "[email protected]_quantity+" pc(s).";
}
mes "\n";
//List requirements
mes "Requirements:";
for(set [email protected],0; [email protected]<getd("."[email protected]_CTRID+"_req_size"); set [email protected],[email protected]+1)
{
set [email protected]_itemid,getd("."[email protected]_CTRID+"_item_req_id["[email protected]+"]");
set [email protected]_name$,getitemname([email protected]_itemid);
set [email protected]_quantity,getd("."[email protected]_CTRID+"_item_req_quantity["[email protected]+"]");

if(countitem([email protected]_itemid)<[email protected]_quantity)
setarray [email protected]$[getarraysize([email protected]$)],[email protected]_name$+" -[ "+countitem([email protected]_itemid)+" / "[email protected]_quantity+" ]";

mes "* "[email protected]_name$+" - "[email protected]_quantity+" pc(s).";
}

set [email protected]_zeny_req,getd("."[email protected]_CTRID+"_zeny_req");

//Check if there is a zeny requirements
if([email protected]_zeny_req>0)
mes "* Zeny - "[email protected]_zeny_req+" z.";

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

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

delitem [email protected]_itemid,[email protected]_quantity;
}

//Consuming the zeny
if([email protected]_zeny_req>0)
set Zeny,[email protected]_zeny_req+" z.";

//Giving all the rewards
mes "Rewards Given:";
for(set [email protected],0; [email protected]<getd("."[email protected]_CTRID+"_rew_size"); set [email protected],[email protected]+1)
{
set [email protected]_itemid,getd("."[email protected]_CTRID+"_item_rew_id["[email protected]+"]");
set [email protected]_quantity,getd("."[email protected]_CTRID+"_item_rew_quantity["[email protected]+"]");
mes "* "+getitemname([email protected]_itemid)+" - "[email protected]_quantity+" pc(s).";
getitem [email protected]_itemid,[email protected]_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 [email protected],0; //This is the indicator if the keyword has been found
set [email protected],0; //This is for itemid and quantity
set [email protected],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: "[email protected]_id;
return 0;
}

//This will be use in the array index
set [email protected]_loopctr,0;

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

if([email protected]==0)
{
if(getarg([email protected])==0)
{
debugmes "The item id for Reward and Requirements cannot be zero. Error occur at counter id: "[email protected]_id;
end;
}
setd "."[email protected]_id+"_item_rew_id["+([email protected]_loopctr)+"]",getarg([email protected]);
set [email protected],1;
}
else
{
if(getarg([email protected])==0)
{
debugmes "The quantity for items Reward and Requirements cannot be zero. Error occur at counter id: "[email protected]_id;
end;
}
setd "."[email protected]_id+"_item_rew_quantity["+([email protected]_loopctr)+"]",getarg([email protected]);
set [email protected]_loopctr,[email protected]_loopctr+1;
set [email protected],0;
}
set [email protected],[email protected]+1;
}
setd "."[email protected]_id+"_rew_size",[email protected]/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([email protected]%2==1)
{
debugmes "Missing arguments in Reward. Error Occured at counter id: "[email protected]_id;
end; 
}

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

//Required Keyword
set [email protected],0; //Reset the pair checker
set [email protected]_keywordFinder,[email protected]; //Store the last keywordfinder value to a temporary variable
set [email protected],0; //For itemid and quantity shifting

//This will be use as the array index/key
set [email protected]_loopctr,0;

//Get all the Required Items
for(set [email protected],[email protected]+1; [email protected]<getargcount(); set [email protected],[email protected]+1)
{

//Check if the Zeny Keyword has been found else continue looping
if(""+getarg([email protected])=="Zeny")
{
//Store the number value where the Required keyword has been found
set [email protected],[email protected]; 
break;
}

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

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

//If reward has not been found
if([email protected] == [email protected]_keywordFinder)
{
debugmes "No Zeny Keyword Found. Error occured at counter id: "[email protected]_id;
end; 
}

//Zeny Keyword
if(getarg([email protected]+1)<0)
{
debugmes "Negative Zeny Requirments Not Allowed. Error occured at counter id: "[email protected]_id;
end; 
}

setd "."[email protected]_id+"_zeny_req",getarg([email protected]+1);

//Title
if(""+getarg([email protected]+2)==""+0)
{
debugmes "Title Required. Error occured at counter id: "[email protected]_id;
end; 
}
setd "."[email protected]_id+"_title$",getarg([email protected]+2);

//Category
if(""+getarg([email protected]+3)==""+0)
setd "."[email protected]_id+"_category$","Uncategorized"; 
else
setd "."[email protected]_id+"_category$",getarg([email protected]+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 [email protected]_ctr,0;
for(set [email protected],1; [email protected]<getarg(1); set [email protected],[email protected]+1)
{
set [email protected]_strcat$,getd("."[email protected]+"_category$");
if([email protected]_strcat$ == getarg(0))
{
setarray @selected_ctrid[[email protected]_ctr],[email protected];
set [email protected]_ctr,[email protected]_ctr+1;
}
}
if(getarraysize(@selected_ctrid)>0)
return 1; //Return 1 if there is a CTRID's found
return 0;
end;

}

  • Upvote 2
Link to comment
Share on other sites

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.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.