summaryrefslogblamecommitdiff
path: root/npc/other/Global_Functions.txt
blob: aef48a489cc91368c2a544b716a433b6ce98f256 (plain) (tree)

































                                                                           
                    
                                                                           
                             







                                                                           
            
                                                                        

                                                                            
                                                                           
                                         


                                       
 

                                        
 




                                                                                           


                      

                                                            

                                                 




                           
                                                 





                                                                     
                       
                     
                                                  





                                                   
                                                  






                                   
                           




                             




                                         
                                                                     

                                                                                           
                                                                 

                             
                                                         
                              

                                                                   
 
                                  
                      
 
                                       








                          
 
                                                     

                                       
 


               
                                                            
                          
                                         
                                                             



                                                                             



                                                                                 

                                           

 

                                                            
                                                                                  



                                         

                                                            
                                 
                                                                                           

 

                                                            
                                 
                                                                                                                        

 
                                                            
                                    




                                                       

                                                                        
                                         
                     
                                          

                              



                                                         

                           




                                                   

                                                               

 

                                                            
                                                 
                                  
                                  

                                                              

                                  

                                                                



               

                                                            

                                         
                                       
                                                                    
         
                                


               

                                                            

                                         
                                        
                                                                       
         
                                 
               
 
 

                                                            




























                                                                        

                                                            















                                                                            
 
                                                            
                            
                                         
                                                 
 





                                        
 
                     
                        
                                              
                             
                                             

                         
                                                
                              
                                               

                           
                                                    
                                
                                                   
 
                                                 
                                                    
                                   
                                                   
 

                       




























                                                                                             
//================= Hercules Script =======================================
//=       _   _                     _
//=      | | | |                   | |
//=      | |_| | ___ _ __ ___ _   _| | ___  ___
//=      |  _  |/ _ \ '__/ __| | | | |/ _ \/ __|
//=      | | | |  __/ | | (__| |_| | |  __/\__ \
//=      \_| |_/\___|_|  \___|\__,_|_|\___||___/
//================= License ===============================================
//= This file is part of Hercules.
//= http://herc.ws - http://github.com/HerculesWS/Hercules
//=
//= Copyright (C) 2012-2015  Hercules Dev Team
//= Copyright (C)  AnnieRuru
//= Copyright (C)  Emistry
//= Copyright (C)  Euphy
//= Copyright (C)  Paradox924X
//= Copyright (C)  L0ne_W0lf
//= Copyright (C)  Evera
//= Copyright (C)  kobra_k88
//= Copyright (C)  Lupus
//=
//= Hercules is free software: you can redistribute it and/or modify
//= it under the terms of the GNU General Public License as published by
//= the Free Software Foundation, either version 3 of the License, or
//= (at your option) any later version.
//=
//= This program is distributed in the hope that it will be useful,
//= but WITHOUT ANY WARRANTY; without even the implied warranty of
//= MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//= GNU General Public License for more details.
//=
//= You should have received a copy of the GNU General Public License
//= along with this program.  If not, see <http://www.gnu.org/licenses/>.
//=========================================================================
//= Global Functions
//================= Description ===========================================
//= General script functions.
//================= Current Version =======================================
//= 2.20
//=========================================================================

//== Function F_InsertComma ================================
// Returns a number with commas based on precision of digits and custom
// separator.
// callfunc "F_InsertComma",<number>{,<precision>,<separator>}
// Examples:
//    callfunc("F_InsertComma",7777777)           // returns "7,777,777"
//    callfunc("F_InsertComma",1000000000,3,","}) // returns "1,000,000,000"
//    callfunc("F_InsertComma",1000000000,3,"_"}) // returns "1_000_000_000"
//    callfunc("F_InsertComma",1000000000,4)      // returns "10,0000,0000"
function	script	F_InsertComma	{
	.@value = getarg(0);
	.@precision = getarg(1,3);
	.@separator$ = getarg( 2,"," );

	.@str$ = ""+.@value;
	.@is_negative = ( .@value < 0 );

	.@length = getstrlen( .@str$ ) - .@precision - .@is_negative;
	while ( .@length > 0 ) {
		.@str$ = insertchar( .@str$, .@separator$ , ( .@length + .@is_negative ) );
		.@length -= .@precision;
	}
	return .@str$;
}

//== Function F_ClearJobVar ================================
// Clears job quest variables
function	script	F_ClearJobVar	{
	// Misc ---------------------------------
	JBLVL = 0;
	FIRSTAID = 0;
	PLAYDEAD = 0;
	got_bandage = 0;
	got_novnametag = 0;
	// First Class Jobs ---------------------
	job_acolyte_q = 0; job_acolyte_q2 = 0;
	job_archer_q = 0;
	job_magician_q = 0;
	job_merchant_q = 0; job_merchant_q2 = 0; job_merchant_q3 = 0;
	job_sword_q = 0; SWTEST = 0;
	job_thief_q = 0;
	// Super Novice
	SUPNOV_Q = 0;
	// 2-1 Jobs ------------------------------
	ASSIN_Q = 0; ASSIN_Q2 = 0; ASSIN_Q3 = 0;
	BSMITH_Q = 0; BSMITH_Q2 = 0;
	HNTR_Q = 0; HNTR_Q2 = 0;
	KNIGHT_Q = 0; KNIGHT_Q2 = 0;
	PRIEST_Q = 0; PRIEST_Q2 = 0; PRIEST_Q3 = 0;
	WIZ_Q = 0; WIZ_Q2 = 0;
	// 2-2 Jobs ------------------------------
	ROGUE_Q = 0; ROGUE_Q2 = 0;
	ALCH_Q = 0; ALCH_Q2 = 0;
	CRUS_Q = 0;
	MONK_Q = 0; JOB_MONK_C = 0;
	SAGE_Q = 0; SAGE_Q2 = 0;
	DANC_Q = 0;
	BARD_Q = 0;
	// Extended Classes
	TAEK_Q = 0; TK_Q = 0;
	STGL_Q = 0;
	SOUL_Q = 0;
	GUNS_Q = 0;
	NINJ_Q = 0;
	return;
}

function	script	F_ClearGarbage	{
	// Clear outdated global VARS
	//Clear TURTLE var if the Turtle Islans Quest is already done
		if(TURTLE==20) MISC_QUEST |= 65536;
		if(MISC_QUEST & 65536) TURTLE = 0; //now clear the var if the quest is over
	//Clear previously saved Quest Skills (now it isn't used)
		ADV_QSK = 0;
		ADV_QSK2 = 0;
	//Old Seset Skill Event used to use RES_SKILL var
		RES_SKILL = 0;
	//Here you put outdated variables from your outdated EVENTS
	//e.g. Is XMAS done? Add the EVENT var clearing code here.

	//due to bugs in BS quest:
	wizard_m2 = 0;

	// Old Novice Ground Variables.
	NEW_MES_FLAG0 = 0;
	NEW_MES_FLAG1 = 0;
	NEW_MES_FLAG2 = 0;
	NEW_MES_FLAG3 = 0;
	NEW_MES_FLAG4 = 0;
	NEW_MES_FLAG5 = 0;
	NEW_LVUP0 = 0;
	NEW_LVUP1 = 0;
	NEW_JOBLVUP = 0;

	// Old DTS variables that are no longer used.
	dtseligible = 0;
	MISC_QUEST = MISC_QUEST & ~128;

	return;
}

//== Function Job_Change ===================================
// Used in REBIRTH scripts
function	script	Job_Change	{
	jobchange getarg(0),Upper; //Jobchange based on Upper
	logmes "CLASS CHANGE: " +strcharinfo(0)+ " become a "+jobname(Class);
	return;
}

//== Function F_Rand =======================================
// Returns a random argument
// Example: (see also F_Bye or F_Hi functions)
// .@itemIDfromList = callfunc("F_Rand",1129,1222,1163,1357,1360,1522,1811,1410);
function	script	F_Rand	{
	return getarg(rand(getargcount()));
}

//== Function F_Sex ========================================
// Returns 1st argument if female, 2nd argument otherwise
// Example: mes callfunc("F_Sex","What a beautiful lady!","What a handsome man!");
function	script	F_SexMes	{
	return getarg(Sex);
}

//== Function F_Hi =========================================
// Returns random HELLO message
function	script	F_Hi	{
	return callfunc("F_Rand","Hi!","Hello!","Good day!","How are you?","Hello there.");
}

//== Function F_Bye ========================================
// Returns random BYE message
function	script	F_Bye	{
	return callfunc("F_Rand","Bye. See you again.","Later.","Goodbye.","Good luck!","Have a nice day!","Byebye!!!");
}

//== Function F_ItemName ===================================
// Returns expanded item name string
// Arguments:
// - 0 - Item ID
// - 1 - Element N (0=none,1=Ice,2=Earth,3=Fire,4=Wind)
// - 2 - VVS meter 0...3
// - 3 - Refine
// Example: mes "Show me your "+callfunc("F_ItemName",1201,1,2,5)+"...";
//  is equal to: mes "Show me your ^000090 +5 VVS Fire Knife ^000000..."
function	script	F_ItemName	{
	if(getarg(3))
		.@t$ += "+"+getarg(3)+" ";
	switch(getarg(2)) {
		case 0: break;
		case 1: .@t$ += "VS "; break;
		case 2: .@t$ += "VVS "; break;
		case 3: .@t$ += "VVVS "; break;
		default: .@t$ += getarg(2)+"xVS "; break;
	}
	switch(getarg(1)) {
		case 1: .@t$ += "Ice "; break;
		case 2: .@t$ += "Earth "; break;
		case 3: .@t$ += "Fire "; break;
		case 4: .@t$ += "Wind "; break;
		default: .@t$ += "Strange "; break;
	}
	return "^000090"+.@t$+getitemname(getarg(0))+"^000000";
}

//== Function F_SaveQuestSkills ============================
// Stores learned quest skills
function	script	F_SaveQuestSkills	{
	ADV_QSK = 0; ADV_QSK2 = 0;
	//1st classes quest skills
	for (.@i = 0; .@i < 14; ++.@i) {
		if(getskilllv(144+.@i)) ADV_QSK |= pow(2,.@i);
	}
	//2nd classes quest skills
	for (.@i = 0; .@i < 19; ++.@i) {
		if(getskilllv(1001+.@i)) ADV_QSK2 |= pow(2,.@i);
	}
	return;
}

//== Function F_Load1Skills ================================
// Restores learned 1st class quest skills
function	script	F_Load1Skills	{
	//1st classes quest skills
	for(.@i = 0; .@i < 14; ++.@i) {
		if(ADV_QSK|pow(2,.@i) == ADV_QSK) skill 144+.@i,1,0;
	}
	ADV_QSK = 0; //Clear var
	return;
}

//== Function F_Load2Skills ================================
// Restores learned 2nd class quest skills
function	script	F_Load2Skills	{
	//2nd classes quest skills
	for (.@i = 0; .@i < 19; ++.@i) {
		if(ADV_QSK2|pow(2,.@i) == ADV_QSK2) skill 1001+.@i,1,0;
	}
	ADV_QSK2 = 0; //Clear var
	return;
}

//== Function F_GetWeaponType ==============================
// Determines weapon type by view
function	script	F_GetWeaponType	{
	switch(getiteminfo(getarg(0),11)) {
		case 1: return "Dagger"; break;
		case 2: return "One-handed Sword"; break;
		case 3: return "Two-handed Sword"; break;
		case 4: return "One-handed Spear"; break;
		case 5: return "Two-handed Spear"; break;
		case 6: return "One-handed Axe"; break;
		case 7: return "Two-handed Axe"; break;
		case 8: return "Mace"; break;
		//case 9: return "Unused"; break;
		case 10: return "Staff"; break;
		case 11: return "Bow"; break;
		case 12: return "Knuckle"; break;
		case 13: return "Instrument"; break;
		case 14: return "Whip"; break;
		case 15: return "Book"; break;
		case 16: return "Katar"; break;
		case 17: return "Revolver"; break;
		case 18: return "Rifle"; break;
		case 19: return "Gatling gun"; break;
		case 20: return "Shotgun"; break;
		case 21: return "Grenade Launcher"; break;
		case 22: return "Shuriken"; break;
		default: return "Unable to Determine Equip Type"; break;
	}
	end;
}

//== Function F_GetArmorType ===============================
// Determines equipment type by equip location
function	script	F_GetArmorType	{
	switch(getiteminfo(getarg(0),5)) {
		case 001: return "Lower Headgear"; break;
		case 2: return "Weapon"; break;
		case 4: return "Garment"; break;
		case 8: return "Accessory"; break;
		case 16: return "Armor"; break;
		case 32: return "Shield"; break;
		case 64: return "Shoes"; break;
		case 128: return "Accessory"; break;
		case 256: return "Upper Headgear"; break;
		case 512: return "Middle Headgear"; break;
		default: return "Unable to Determine Equip Location"; break;
	}
	end;
}

//== Function Time2Str =====================================
// Time calculation Function
function	script	Time2Str	{
	.@time_left = getarg(0) - gettimetick(2);

	.@Days = .@time_left / 86400;
	.@time_left -= (.@Days * 86400);
	.@Hours = .@time_left / 3600;
	.@time_left -= (.@Hours * 3600);
	.@Minutes = .@time_left / 60;
	.@time_left -= (.@Minutes * 60);

	.@Time$ = "";
	if( .@Days > 1 )
		.@Time$ += .@Days + " days, ";
	else if( .@Days > 0 )
		.@Time$ += .@Days + " day, ";

	if( .@Hours > 1 )
		.@Time$ += .@Hours + " hours, ";
	else if( .@Hours > 0 )
		.@Time$ += .@Hours + " hour, ";

	if( .@Minutes > 1 )
		.@Time$ += .@Minutes + " minutes, ";
	else if( .@Minutes > 0 )
		.@Time$ += .@Minutes + " minute, ";

	if( .@time_left > 1 || .@time_left == 0 )
		.@Time$ += .@time_left + " seconds";
	else if( .@time_left == 1 )
		.@Time$ += .@time_left + " second";

	return .@Time$;
}

//////////////////////////////////////////////////////////////////////////////////
// *** Function "F_ShuffleNumbers":
// Generate a set of numbers in random order that the numbers are not repeated
// --- callfunc "F_ShuffleNumbers",<start num>,<last num>,<output array>{,<count>};
// Examples: 
//    callfunc("F_ShuffleNumbers", 0, 5, .@output)      // possible output 4,1,3,2,0,5
//    callfunc("F_ShuffleNumbers", -5, 1, .@output)     // possible output -3,-5,-4,-2,-1,1,0
//    callfunc("F_ShuffleNumbers", 0, 100, .@output, 5) // possible output 9,55,27,84,33
// Reminder: Use *freeloop command when appropriate !
//////////////////////////////////////////////////////////////////////////////////
function	script	F_ShuffleNumbers	{
	deletearray getarg(2);
	.@static = getarg(0);
	.@range = getarg(1) +1 - .@static;
	.@count = getarg(3, .@range);
	if (.@range <= 0 || .@count <= 0)
		return 0;
	if (.@count > .@range)
		.@count = .@range;
	for (.@i = 0; .@i < .@range; ++.@i)
		.@temparray[.@i] = .@i;
	for (.@i = 0; .@i < .@count; ++.@i) {
		.@rand = rand(.@range);
		set getelementofarray( getarg(2), .@i ), .@temparray[.@rand] + .@static;
		.@temparray[.@rand] = .@temparray[--.@range];
	}
	return .@count;
}