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
|
// TMW2 Script
// Evol functions.
// Authors:
// gumi
// omatt
// Travolta
// Jesusalva
// Description:
// Fishing functions.
// Variable
// .dir
// DOWN Never try or pulled too late
// UP Bait dropped
// LEFT Fish bite bait
//
// player log on .dir is DOWN, start by choose bait menu
// player chooses bait, script addtimer in npc .dir is UP
// if player pulls before signal npc, bait is lost, set .bait to DOWN goto choose bait
// if player pulls after pull delay max, bait is lost, set .bait to DOWN goto choose bait
// npc signal .dir is LEFT
// player pulls between npc signal and pulls delay max, got the fish, set .dir to DOWN goto choose bait
function script fishing_cleanup {
.@npc$ = getarg(0, "");
if (.@npc$ == "") end;
set getvariableofnpc(.char_id, .@npc$), 0; // clean acc id
set getvariableofnpc(.account_id, .@npc$), 0; // clean char id
set getvariableofnpc(.last_used, .@npc$), gettimetick(2); // set last used time
setnpcdir .@npc$, DOWN; // reset direction
return;
}
- script global fishing handler 32767,{
end;
OnBite:
if (ispcdead()) end;
if (getnpcdir(@fishing_spot$) != UP)
end;
setnpcdir @fishing_spot$, LEFT;
@fishing_tick = gettimetick(0);
.@bite_fx=getvariableofnpc(.bite_fx, @fishing_spot$);
specialeffect(.@bite_fx ? .@bite_fx : 30, SELF, playerattached());
end;
OnCleanUp:
dispbottom l("You waited too long and lost the bait...");
specialeffect(getvariableofnpc(.failure_fx, @fishing_spot$), SELF, playerattached()); // event fail
OnPCLogoutEvent:
fishing_cleanup @fishing_spot$;
@fishing_spot$ = ""; // unbind fishing npc
end;
}
// Syntax: fishing()
// Syntax: fishing ( OFFSET, COMMON FISHES, RARE FISHES )
// OFFSET: How many fishes are common
function script fishing {
///////////////////////////////////////////
// Var initialization
if (getarg(0, 0) == 0) {
setarray .@common_fish,
CommonCarp;
setarray .@rare_fish,
GrassCarp;
} else {
.@i=0;
freeloop(true);
for (.@i=1; .@i < getargcount(); .@i++) {
if (.@i <= getarg(0)) {
.@common_fish[.@i-1]=getarg(.@i);
} else {
.@rare_fish[.@i-1-getarg(0)]=getarg(.@i);
}
};
freeloop(false);
}
//debugmes("[FISH] Initialized with %d common and %d rare fishes", getarraysize(.@common_fish), getarraysize(.@rare_fish));
.@npc$ = strnpcinfo(0); // the full name of the fishing spot
.@account_id = getvariableofnpc(.account_id, .@npc$); // the account id of the player using the fishing spot
.@char_id = getvariableofnpc(.char_id, .@npc$); // the char id of the player using the fishing spot
.@dir = getnpcdir(.@npc$); // direction of the fishing spot
.@last_used = getvariableofnpc(.last_used, .@npc$); // when this fishing spot was last used
.@baits = getvariableofnpc(.baits, .@npc$); // bait count
.@rod = getvariableofnpc(.fishing_rod, .@npc$); // the fishing rod required for this spot
.@rod = (.@rod ? .@rod : FishingRod);
.@net_ratio = getvariableofnpc(.net_ratio, .@npc$); // How many fishes and baits are required?
.@net_ratio = max(1, (.@net_ratio ? .@net_ratio : 1));
.@regen_time = getvariableofnpc(.cooldown, .@npc$); // cooldown for the fishing spot
.@regen_time = (.@regen_time ? .@regen_time : 20);
.@bp_chance = getvariableofnpc(.bp_chance, .@npc$); // Blueprint chance
.@bp_chance = (.@bp_chance ? .@bp_chance : 1);
.@success_fx = getvariableofnpc(.success_fx, .@npc$); // effect to show on success
.@success_fx = (.@success_fx ? .@success_fx : FX_SUCCESS);
.@failure_fx = getvariableofnpc(.failure_fx, .@npc$); // effect to show on failure
if (.@failure_fx < 1)
{
.@failure_fx = FX_FAILURE;
set getvariableofnpc(.failure_fx, .@npc$), .@failure_fx; // needed by global handler
}
.@initial_fx = getvariableofnpc(.initial_fx, .@npc$); // effect to show when throwing the bait
.@initial_fx = (.@initial_fx ? .@initial_fx : 29);
.@bite_fx = getvariableofnpc(.bite_fx, .@npc$); // effect to show when something bites
if (.@bite_fx < 1)
{
.@bite_fx = 30;
set getvariableofnpc(.bite_fx, .@npc$), .@bite_fx; // needed by global handler
}
.@wait_time_min = getvariableofnpc(.wait_time_min, .@npc$); // min amount of time to wait for the line to sink
.@wait_time_min = (.@wait_time_min ? .@wait_time_min : 4000);
.@wait_time_max = getvariableofnpc(.wait_time_max, .@npc$); // max amount of time to wait for the line to sink
.@wait_time_max = (.@wait_time_max ? .@wait_time_max : 18000);
// During night time there are more fishes, and therefore, it is easier to fish
// This will make they reply at most 30% faster. Default is a 6 second max delay gain
if (is_night())
.@wait_time_max = min(.@wait_time_min, .@wait_time_max*7/10);
.@catch_time = getvariableofnpc(.catch_time, .@npc$); // the player must catch the fish within X ms after the line sinks
.@catch_time = (.@catch_time ? .@catch_time : 5000);
.@pull_rand_max = getvariableofnpc(.pull_rand_max, .@npc$);
.@pull_rand_max = (.@pull_rand_max ? .@pull_rand_max : 1100);
.@fish_id = CommonCarp; // failsafe
if (getvariableofnpc(.bait_ids[0], .@npc$) < 1)
{
// default baits (bait, chance booster) rand(0, 100)
setarray getvariableofnpc(.bait_ids[0], .@npc$),
SmallTentacles, 4,
Bread, 4,
Aquada, 8,
Tentacles, 10,
BugLeg, 2,
CaveSnakeTongue, 6,
LettuceLeaf, 1,
Cheese, 3,
RoastedMaggot, 6;
}
if (.@baits < 1)
{
// only count it once
.@baits = getarraysize(getvariableofnpc(.bait_ids[0], .@npc$));
set getvariableofnpc(.baits, .@npc$), .@baits;
}
///////////////////////////////////////////
// Logic below
if (countitem(.@rod) < 1)
{
dispbottom l("You don't have any @@.", getitemlink(.@rod));
return -1;
}
if (.@account_id > 0 && !isloggedin(.@account_id, .@char_id))
{
fishing_cleanup .@npc$; // reset
.@dir = DOWN;
}
if (.@char_id != getcharid(CHAR_ID_CHAR) && .@dir != DOWN)
{
dispbottom l("This fishing spot is already being used!");
return -2;
}
// pull too soon
if (.@dir == UP)
{
deltimer "global fishing handler::OnCleanUp"; // cancel auto cleanup
deltimer "global fishing handler::OnBite";
specialeffect(.@failure_fx, SELF, playerattached()); // event fail
fishing_cleanup .@npc$; // do it manually instead
dispbottom l("You pulled too soon and lost the bait.");
return -3;
}
// pull maybe on time
else if (.@dir == LEFT)
{
deltimer "global fishing handler::OnCleanUp"; // cancel auto cleanup
fishing_cleanup .@npc$; // do it manually instead
getmapxy .@mapbis$, .@xbis, .@ybis, UNITTYPE_PC; // get current char location
// Leave spot, lost the bait
if (.@mapbis$ != @fishing_loc$[0] || .@xbis != @fishing_loc[0] || .@ybis != @fishing_loc[1] || @fishing_spot$ != .@npc$)
{
dispbottom l("You left your fishing spot!");
return -4;
}
// RNG to obtain a fish
if (rand2(gettimetick(0) - @fishing_tick) <= .@pull_rand_max)
{
for (.@i=0 ; .@i < .@net_ratio ; .@i++) {
// RNG to obtain a rare fish or common fish
// Luck can increase up to 5% when it is at 100.
// Level can increase up to 10% when it is at 100.
.@boost=(readparam2(bLuk)/20)+(BaseLevel/10);
.@bai=getvariableofnpc(.bait_ids[@bait_d+1], .@npc$);
// Ancient Blueprint: 0.05% per bait bonus (no luck)
if (rand2(2000) < .@bp_chance*.@bai) {
.@fish_id = AncientBlueprint;
} else if (rand2(0, 100) < .@bai+.@boost) {
.@fish_id = any_of(.@rare_fish);
} else {
.@fish_id = any_of(.@common_fish);
}
specialeffect(.@success_fx, SELF, playerattached());
getexp getvariableofnpc(.bait_ids[@bait_d+1], .@npc$)+(BaseLevel/10), 4+getvariableofnpc(.bait_ids[@bait_d+1], .@npc$); // xp gain is equivalent to bait rarity + BaseLevel boost
// MobPt gain is equivalent to bait rarity.
if (MPQUEST)
Mobpt+=.@bai*limit(1, BaseLevel/10, 10);
if(!checkweight(.@fish_id, 1)) {
dispbottom l("You caught a @@ but had no room in your inventory to carry it.", getitemlink(.@fish_id));
makeitem .@fish_id, 1, .@mapbis$, .@xbis, .@ybis; // drop on the ground
return 0;
}
getitem .@fish_id, 1;
// Catch the Golden Fish Event
if ($EVENT$ == "Fishing")
FYE_Fishing();
}
}
else
{
dispbottom l("You pulled too late and lost the bait...");
specialeffect(.@failure_fx, SELF, playerattached()); // event fail
.@fish_id = 0;
getexp 0, 5;
}
@fishing_spot$="";
return .@fish_id;
}
if (gettimetick(2) - .@last_used < .@regen_time)
{
dispbottom l("This fishing spot has just been used, give it a rest.");
return -5;
}
// This "hack" will prevent you from fishing at two spots (buggy)
// It'll cancel the previous fishing too, per logical rule.
if (@fishing_spot$ != "") {
deltimer "global fishing handler::OnCleanUp"; // cancel auto cleanup
deltimer "global fishing handler::OnBite";
fishing_cleanup(@fishing_spot$); // clean up manually
@fishing_spot$="";
dispbottom l("You left your fishing spot!");
return -4;
}
// begin fishing
narrator S_LAST_NEXT,
l("You see some fish reflecting the sun on the surface of the water."),
(.@net_ratio == 1 ? l("What will be the bait for the fish?") : l("You need @@ units of bait for this fishing spot. What will you use?", .@net_ratio));
if (GSET_FISHING_BAIT > 1) {
.@bait = GSET_FISHING_BAIT;
mesc l("Maybe a %s?", getitemlink(GSET_FISHING_BAIT));
} else {
mes "##B" + l("Drag and drop an item from your inventory.") + "##b";
.@bait = requestitem();
if (.@bait > 1 && GSET_FISHING_BAIT)
GSET_FISHING_BAIT = .@bait;
}
if (.@bait < .@net_ratio) {
narrator S_FIRST_BLANK_LINE,
l("You take your @@ and leave.", getitemlink(.@rod));
return -6;
}
if (countitem(.@bait) < .@net_ratio) {
mesc l("You do not have enough bait for fishing here.");
return -6;
}
.@bait_c = false;
for (.@i = 0; .@i < .@baits; .@i += 2) {
if (getvariableofnpc(.bait_ids[.@i], .@npc$) == .@bait)
{
.@bait_c = true;
@bait_d = .@i;
break;
}
}
if (.@bait_c != true)
{
narrator S_FIRST_BLANK_LINE,
l("This item cannot be used as bait here.");
return -6;
}
if (getvariableofnpc(.char_id, .@npc$) > 0)
{
narrator S_FIRST_BLANK_LINE,
l("Somebody took your place on this spot!"),
l("You take your fishing rod and leave.");
return -8;
}
@fishing_spot$ = .@npc$; // bind player to fishing spot
set getvariableofnpc(.account_id, .@npc$), getcharid(CHAR_ID_ACCOUNT); // record account id
set getvariableofnpc(.char_id, .@npc$), getcharid(CHAR_ID_CHAR); // record char id
set getvariableofnpc(.last_used, .@npc$), gettimetick(2);
getmapxy(@fishing_loc$[0], @fishing_loc[0], @fishing_loc[1], 0); // record char pos
delitem .@bait, .@net_ratio;
// The player uses this spot, his bait is ready, he just has to wait for the signal.
closedialog;
specialeffect(.@initial_fx, SELF); // throw the bait
sleep2 800; // wait 0.8s for synchronize the sound of "plop" in water with the npc dir UP.
setnpcdir .@npc$, UP;
dispbottom l("Wait for the bait to sink underwater.");
.@delay = rand(.@wait_time_min, .@wait_time_max);
addtimer .@delay, "global fishing handler::OnBite"; // bite logic
addtimer (.@delay + .@catch_time), "global fishing handler::OnCleanUp"; // auto clean up
return 0;
}
|