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
|
// The Mana World Script
//
// Author: Jesusalva <jesusalva@tmw2.org>
//
// Magic Script Core Functions
//
// Imported from Moubootaur Legends
//
// Important Variables:
// MAGIC_EXP
// Current mana magic experience
// LAST_SKILL
// Last Skill used (array)
// MAGIC_LVL
// Maximum tier of usable magic, capped by something
// MAGIC_PTS
// Amount of used Magic Skill Points (bad logic)
// MAGIC_CLU
// Array of (skill ID, Level) for sk_canlevelup
// PLACEHOLDER
function script getskillname {
return getarg(0);
}
// This function will add MAGIC_EXP
// And manage last skills used memory
// GetManaExp(SkillID, EXP Points)
function script GetManaExp {
.@sk=getarg(0);
.@pt=getarg(1);
if (LAST_SKILL == .@sk) {
.@pt=cap_value(.@pt/3, 0, 1);
.@bonus=0;
} else {
// Update skill memory
LAST_SKILL[4]=LAST_SKILL[3];
LAST_SKILL[3]=LAST_SKILL[2];
LAST_SKILL[2]=LAST_SKILL[1];
LAST_SKILL[1]=LAST_SKILL[0];
LAST_SKILL[0]=.@sk;
}
// Update Magic EXP
MAGIC_EXP=MAGIC_EXP+.@pt;
return;
}
// sk_maxpoints() → Max Magic Skill Points you may use
// Returns how many points you can use
// Could be tweaked to read a variable instead
function script sk_maxpoints {
// 2 points per magic level
.@val=(MAGIC_LVL)*2;
// 1 point every twice magic level
.@val+=(MAGIC_LVL/2);
// Excluding first 15, 1 point every 12 job levels (Up to JL 75)
.@val+=min(5, ((JobLevel-15)/12));
// 1 point per being a player
.@val+=1;
// 2 points per Rebirth
.@val+=(REBIRTH*2);
return .@val;
}
// Returns how many points you can allocate
// Could be tweaked to NOT use MAGIC_PTS this way
function script sk_points {
return sk_maxpoints()-MAGIC_PTS;
}
// Returns true if a skill can be leveled up.
// It checks the MSP
// sk_canlvup( {cost=1} )
function script sk_canlvup {
return ((MAGIC_PTS+getarg(0,1)) <= sk_maxpoints());
}
// Level up a skill in 1 level (internal function)
// TODO: Return the point if leveling about Max Level
// sk_lvup( sk{, cost=0} )
function script sk_lvup {
.@lvl=MAGIC_CLU[getarg(0)];
getexp 0, 50*(.@lvl+1);
skill(getarg(0), .@lvl+1, 0);
if (getarg(1,0)) {
MAGIC_PTS+=getarg(1, 0);
}
MAGIC_CLU[getarg(0)]=.@lvl+1;
return;
}
// Internal Magic School Learning Interface
// mlearn( skill, MAX_LV, MSP cost, item, amount{, GP cost} )
// returns false if cheater; DO NOT USE IN SCRIPTS
function script mlearn {
.@sk=getarg(0);
.@ff=getarg(1);
.@msp=getarg(2);
.@it=getarg(3);
.@am=getarg(4);
.@gp=getarg(5, 0);
// Max level reached
if (getskilllv(.@sk) >= .@ff) {
return true;
}
// Not enough items
if (countitem(.@it) < .@am)
return false;
// Not enough MSP
if (!sk_canlvup(.@msp))
return false;
// Not enough GP
if (Zeny < .@gp) {
return false;
}
// Payment
delitem .@it, .@am;
Zeny-=.@gp;
// Level up
sk_lvup(.@sk, .@msp);
return true;
}
// NEW Magic School Learning Interface
// learn_magic(Skill)
function script learn_magic {
.@ski=getarg(0);
.@learn$=l("Learning");
// Check if skill is valid
.@mlv=$@MSK_MAXLV[.@ski];
if (.@mlv < 1) {
return false;//Exception("ERROR: The skill "+.@ski+" is not valid!");
}
// Load a few temporary variables
.@pre=$@MSK_PREREQ[.@ski];
.@it=$@MSK_ITEM[.@ski];
.@am=$@MSK_AMOUNT[.@ski];
.@msp=$@MSK_MSPCOST[.@ski];
.@gp=$@MSK_COST[.@ski];
// Pre-requisite check
if (.@pre) {
if (getskilllv(.@pre) < 1) {
mesc l("Pre-requisites not met!"), 1;
mesc l("The following skill is needed: %s%s (Lv. %d)",
"##9", getskillname(.@pre), 1), 1;
return false;
}
}
// Max level reached
if (getskilllv(.@ski) >= .@mlv) {
mesc l("You've reached the maximum level for this skill."), 1;
return true;
}
// Skill level check
if (getskilllv(.@sk)) {
.@msp=1;
.@learn$=l("Upgrading");
}
mesc l("%s %s will require:", .@learn$, getskillname(.@ski));
mes l("* %d/%d MSP (Magic Skill Points)", .@msp, sk_points());
mes l("* %d/%d E (Esperins)", .@gp, Zeny);
mes l("* %d/%d %s", .@am, countitem(.@it), getitemlink(.@it));
mes "";
mesc l("Really learn this skill?");
if (askyesno() == ASK_NO)
return false;
return mlearn(.@ski, .@mlv, .@msp, .@it, .@am, .@gp);
}
// transcheck( {item 1, amount 1}, {item 2, amount 2}... )
// returns true upon success
function script transcheck {
if (getargcount() < 2 || getargcount() % 2 != 0)
return false;//Exception("Faulty learning skill command invoked - error");
// Count items
for (.@i=0;.@i < getargcount(); .@i++) {
if (countitem(getarg(.@i)) < getarg(.@i+1))
return false;
.@i++;
}
// Delete Items
for (.@i=0;.@i < getargcount(); .@i++) {
delitem getarg(.@i), getarg(.@i+1);
.@i++;
}
return true;
}
// Returns a value defining your current magic control (affects success ratio, higher is better)
// A value of '5' means perfect control, and a value of '0' means overwhelm.
// abizit()
function script abizit {
.@lv=MAGIC_LVL+1;
if (.@lv < 1) return 0;
.@base=((.@lv*2)**3);
return min(MAGIC_EXP/.@base, 5);
}
// Reimplementation of abizit()
// Internal helper
// mescordialog(text, color, {dialog=1})
function script mescordialog {
if (getarg(2, true))
mesc getarg(0), getarg(1);
else
dispbottom col(getarg(0), getarg(1));
return;
}
// Reimplementation of abizit()
// It will show abizit in dialog box or in a floating message
// ShowAbizit({dialog=1})
function script ShowAbizit {
.@dial=getarg(0, true);
if (.@dial)
mesn l("Current Magic Control");
.@lv=MAGIC_LVL+1;
.@val=MAGIC_EXP+rand(-.@lv*5, .@lv*5);
.@base=((.@lv*2)**3);
if (.@val > .@base*5)
mescordialog l("You are perfectly in control of your magic."), 3, .@dial;
else if (.@val > .@base*4)
mescordialog l("You are mostly in control of your magic."), 2, .@dial;
else if (.@val > .@base*3)
mescordialog l("You are somewhat in control of your magic."), 4, .@dial;
else if (.@val > .@base*2)
mescordialog l("Your magic is more powerful than you, but you can control."), 7, .@dial;
else if (.@val > .@base)
mescordialog l("You still are overwhelmed by your magic."), 6, .@dial;
else
mescordialog l("You are completly overwhelmed by your magic."), 1, .@dial;
return;
}
/////////////////////////////////////////
// RegisterMagic(MSP, Skill, MaxLv, Item, Amount, Class, Cost, {PreReq, PostReq})
function script RegisterMagic {
.@msp=getarg(0);
.@ski=getarg(1);
.@max=getarg(2);
.@ite=getarg(3);
.@amo=getarg(4);
.@cla=getarg(5);
.@cos=getarg(6);
.@pre=getarg(7, false);
.@pos=getarg(8, false);
$@MSK_MSPCOST[.@ski]=.@msp;
$@MSK_MAXLV[.@ski]=.@max;
$@MSK_ITEM[.@ski]=.@ite;
$@MSK_AMOUNT[.@ski]=.@amo;
$@MSK_COST[.@ski]=.@cos;
$@MSK_PREREQ[.@ski]=.@pre;
$@MSK_POSTREQ[.@ski]=.@pos;
//array_push($@MSK_CLASS[.@cla], .@ski); // 3D Arrays are not supported
array_push($@MSK_MAGIC, .@ski);
return;
}
- script Magic Load NPC_HIDDEN,{
OnInit:
/* RegisterMagic(MSP, Skill, MaxLv, Item, Amount,
Class, Cost, {PreReq, PostReq}) */
//////////////////////// Other: Misc
// Monster Identify
RegisterMagic(0, EVOL_MONSTER_IDENTIFY, 1, Beer, 1,
CLASS_OTHER, 5000);
end;
}
|