summaryrefslogtreecommitdiff
path: root/npc/other/Global_Functions.txt
blob: cb41abcd7a1984b448e7f8f6cb2e38d401194c15 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
//================= 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(PC_NAME)+ " 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_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 |= (2 ** .@i);
	}
	//2nd classes quest skills
	for (.@i = 0; .@i < 19; ++.@i) {
		if(getskilllv(1001+.@i)) ADV_QSK2 |= (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|(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|(2 ** .@i) == ADV_QSK2) skill 1001+.@i,1,0;
	}
	ADV_QSK2 = 0; //Clear var
	return;
}

//== Function F_GetWeaponType ==============================
// Determines weapon type by subtype
function	script	F_GetWeaponType	{
	switch (getiteminfo(getarg(0), ITEMINFO_SUBTYPE)) {
		case W_DAGGER: return "Dagger"; break;
		case W_1HSWORD: return "One-handed Sword"; break;
		case W_2HSWORD: return "Two-handed Sword"; break;
		case W_1HSPEAR: return "One-handed Spear"; break;
		case W_2HSPEAR: return "Two-handed Spear"; break;
		case W_1HAXE: return "One-handed Axe"; break;
		case W_2HAXE: return "Two-handed Axe"; break;
		case W_MACE: return "Mace"; break;
		//case W_2HMACE: return "Two-handed Mace"; break; // Unused
		case W_STAFF: return "Staff"; break;
		case W_BOW: return "Bow"; break;
		case W_KNUCKLE: return "Knuckle"; break;
		case W_MUSICAL: return "Instrument"; break;
		case W_WHIP: return "Whip"; break;
		case W_BOOK: return "Book"; break;
		case W_KATAR: return "Katar"; break;
		case W_REVOLVER: return "Revolver"; break;
		case W_RIFLE: return "Rifle"; break;
		case W_GATLING: return "Gatling gun"; break;
		case W_SHOTGUN: return "Shotgun"; break;
		case W_GRENADE: return "Grenade Launcher"; break;
		case W_HUUMA: 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), ITEMINFO_LOC)) {
		// FIXME
		case EQP_HEAD_LOW: return "Lower Headgear"; break;
		case EQP_HAND_R: return callfunc("F_GetWeaponType", getarg(0)); break;
		case EQP_GARMENT: return "Garment"; break;
		case EQP_ACC_L: return "Accessory"; break;
		case EQP_ARMOR: return "Armor"; break;
		case EQP_HAND_L: return "Shield"; break;
		case EQP_SHOES: return "Shoes"; break;
		case EQP_ACC_R: return "Accessory"; break;
		case EQP_ACC: return "Accessory"; break;
		case EQP_HEAD_TOP: return "Upper Headgear"; break;
		case EQP_HEAD_MID: return "Middle Headgear"; break;
		case EQP_COSTUME_HEAD_TOP: return "Costume Upper Headgear"; break;
		case EQP_COSTUME_HEAD_MID: return "Costume Middle Headgear"; break;
		case EQP_COSTUME_HEAD_LOW: return "Costume Lower Headgear"; break;
		case EQP_COSTUME_GARMENT: return "Costume Garment"; break;
		case EQP_AMMO: return "Ammo"; break;
		case EQP_SHADOW_ARMOR: return "Shadow Armor"; break;
		case EQP_SHADOW_WEAPON: return "Shadow Weapon"; break;
		case EQP_SHADOW_SHIELD: return "Shadow Shield"; break;
		case EQP_SHADOW_SHOES: return "Shadow Shoes"; break;
		case EQP_SHADOW_ACC_R: return "Shadow Accessory"; break;
		case EQP_SHADOW_ACC_L: return "Shadow Accessory"; break;
		case EQP_SHADOW_ACC: return "Shadow Accessory"; break;
		default: return "Unknown Equip Type"; 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;
}

//== Function F_MesColor ===================================
// Function to colorize npc dialog without having to memorize the color code
// Examples:
//    mes callfunc("F_MesColor", C_BLUE) +"This message is now in BLUE";
function	script	F_MesColor	{
	return sprintf("^%06X", min(getarg(0), 0xFFFFFF));
}