-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrpg_job_gardener.sp
745 lines (651 loc) · 27.8 KB
/
rpg_job_gardener.sp
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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
/*
T-RP
Copyright (C) 2017 Christian Ziegler
This program 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/>.
*/
#pragma semicolon 1
#define PLUGIN_AUTHOR "Totenfluch"
#define PLUGIN_VERSION "1.00"
#include <sourcemod>
#include <sdktools>
#include <rpg_jobs_core>
#include <rpg_npc_core>
#include <devzones>
#include <multicolors>
#include <tConomy>
#include <rpg_inventory_core>
#include <rpg_perks>
#include <smlib>
#include <rpg_jail>
#include <rpg_job_police>
#include <tStocks>
#pragma newdecls required
#define MAX_ZONES 128
#define MAX_PLANTS 1024
#define TIME_TO_NEXT_STAGE 240
int g_iPlayerPrevButtons[MAXPLAYERS + 1];
bool g_bPlayerInGardenerZone[MAXPLAYERS + 1];
int g_iCollectedLoot[MAXPLAYERS + 1][MAX_ZONES];
int g_iPlayerZoneId[MAXPLAYERS + 1];
char g_cGardenerZones[MAX_ZONES][PLATFORM_MAX_PATH];
int g_iGardenerZoneCooldown[MAXPLAYERS + 1][MAX_ZONES];
int g_iLoadedZones = 0;
int g_iZoneCooldown = 400;
int MAX_COLLECT = 5;
char activeZone[MAXPLAYERS + 1][128];
char npctype[128] = "Gardener Recruiter";
char dbconfig[] = "gsxh_multiroot";
Database g_DB;
int g_iHarvestIndex[MAXPLAYERS + 1];
bool loaded = false;
enum plantProperties {
pEntRef,
String:pOwner[20],
String:pModel[128],
String:pCreatedTime[64],
pState,
pTime,
String:pFlags[64],
Float:pPos_x,
Float:pPos_y,
Float:pPos_z,
bool:pActive
}
int g_ePlayerPlants[MAX_PLANTS][plantProperties];
int g_iPlantsActive = 0;
public Plugin myinfo =
{
name = "[T-RP] Job: Gardener",
author = PLUGIN_AUTHOR,
description = "Adds mining to T-RP Jobs",
version = PLUGIN_VERSION,
url = "https://totenfluch.de"
};
public void OnPluginStart() {
jobs_registerJob("Gardener", "Mow grass and do gardening stuff", 20, 300, 2.11);
npc_registerNpcType(npctype);
RegConsoleCmd("sm_gstats", cmdOnGStats, "shows gardening stats");
HookEvent("round_start", onRoundStart);
char error[255];
g_DB = SQL_Connect(dbconfig, true, error, sizeof(error));
SQL_SetCharset(g_DB, "utf8");
char createTableQuery[2048];
Format(createTableQuery, sizeof(createTableQuery), "CREATE TABLE IF NOT EXISTS `t_rpg_gardener_plants` ( `Id` BIGINT NOT NULL AUTO_INCREMENT , `playerid` VARCHAR(20) NOT NULL , `plantName` VARCHAR(128) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL , `plantLevel` INT NOT NULL , `plantTime` INT NOT NULL , `plantCreated` VARCHAR(64) NOT NULL, `posX` FLOAT NOT NULL, `posY` FLOAT NOT NULL, `posZ` FLOAT NOT NULL, PRIMARY KEY (`Id`)) ENGINE = InnoDB;");
SQL_TQuery(g_DB, SQLErrorCheckCallback, createTableQuery);
}
public Action cmdOnGStats(int client, int args) {
PrintToChat(client, "InZone: %i Collected{0} %i Collected{1} %i ZoneID: %i Cd[1] %i Cd[1] %i", g_bPlayerInGardenerZone[client], g_iCollectedLoot[client][0], g_iCollectedLoot[client][1], g_iPlayerZoneId, g_iGardenerZoneCooldown[client][0], g_iGardenerZoneCooldown[client][1]);
return Plugin_Handled;
}
public void OnMapStart() {
CreateTimer(1.0, refreshTimer, _, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
inventory_addItemHandle("Eggplant Seeds", 1);
inventory_addItemHandle("Pumpkin Seeds", 1);
inventory_addItemHandle("Strawberry Seeds", 1);
PrecacheModel("models/custom_prop/ggc-plg-killzone/eggplant/eggplant_0.mdl");
PrecacheModel("models/custom_prop/ggc-plg-killzone/eggplant/eggplant_1.mdl");
PrecacheModel("models/custom_prop/ggc-plg-killzone/eggplant/eggplant_2.mdl");
PrecacheModel("models/custom_prop/ggc-plg-killzone/eggplant/eggplant_3.mdl");
PrecacheModel("models/custom_prop/ggc-plg-killzone/pumpkinplant/pumpkinplant_0.mdl");
PrecacheModel("models/custom_prop/ggc-plg-killzone/pumpkinplant/pumpkinplant_1.mdl");
PrecacheModel("models/custom_prop/ggc-plg-killzone/pumpkinplant/pumpkinplant_2.mdl");
PrecacheModel("models/custom_prop/ggc-plg-killzone/pumpkinplant/pumpkinplant_3.mdl");
PrecacheModel("models/custom_prop/ggc-plg-killzone/strawberryplant/strawberryplant_0.mdl");
PrecacheModel("models/custom_prop/ggc-plg-killzone/strawberryplant/strawberryplant_1.mdl");
PrecacheModel("models/custom_prop/ggc-plg-killzone/strawberryplant/strawberryplant_2.mdl");
PrecacheModel("models/custom_prop/ggc-plg-killzone/strawberryplant/strawberryplant_3.mdl");
}
public void inventory_onItemUsed(int client, char itemname[128], int weight, char category[64], char category2[64], int rarity, char timestamp[64], int slot) {
if (StrEqual(itemname, "Eggplant Seeds") || StrEqual(itemname, "Pumpkin Seeds") || StrEqual(itemname, "Strawberry Seeds")) {
Menu m = CreateMenu(plantSeedHandler);
char display[128];
Format(display, sizeof(display), "What to do with '%s' ?", itemname);
SetMenuTitle(m, display);
AddMenuItem(m, itemname, "Plant Seeds");
AddMenuItem(m, "throw", "Throw Away");
int amount = inventory_getPlayerItemAmount(client, itemname);
if (amount > 1) {
char displ[128];
Format(displ, sizeof(displ), "Throw all Away (%i)", amount);
AddMenuItem(m, "throwall", displ);
}
DisplayMenu(m, client, 60);
}
}
public int plantSeedHandler(Handle menu, MenuAction action, int client, int item) {
if (action == MenuAction_Select) {
char info[64];
char display[64];
int style = 0;
GetMenuItem(menu, item, info, sizeof(info), style, display, sizeof(display));
if (StrEqual(display, "Plant Seeds"))
plantSeeds(client, info);
}
if (action == MenuAction_End) {
delete menu;
}
}
public void plantSeeds(int client, char[] plantName) {
if (!jobs_isActiveJob(client, "Gardener")) {
CPrintToChat(client, "[-T-]{red} You are not a Gardener");
return;
}
if (getActivePlantsOfPlayerAmount(client) >= (2 + jobs_getLevel(client) / 2)) {
CPrintToChat(client, "[-T-]{red} You can not have more than %i active plants (%i Active)", (2 + jobs_getLevel(client) / 2), getActivePlantsOfPlayerAmount(client));
return;
}
if (jail_isInJail(client)) {
CPrintToChat(client, "[-T-]{red} You can't plant Plants in jail..");
return;
}
if (police_isPlayerCuffed(client)) {
CPrintToChat(client, "[-T-]{red} You can't plant Plants while cuffed...");
return;
}
if (!(GetEntityFlags(client) & FL_ONGROUND)) {
CPrintToChat(client, "[-T-]{red} You have to stand on the Ground to plant...");
return;
}
char item[128];
strcopy(item, sizeof(item), plantName);
char reason[256];
Format(reason, sizeof(reason), "Planted %s", item);
if (inventory_hasPlayerItem(client, item))
inventory_removePlayerItems(client, item, 1, reason);
else
return;
float pos[3];
GetClientAbsOrigin(client, pos);
char playerid[20];
GetClientAuthId(client, AuthId_Steam2, playerid, sizeof(playerid));
char plantTime[64];
int time = GetTime();
IntToString(time, plantTime, sizeof(plantTime));
char plantModel[128];
if (StrEqual(plantName, "Eggplant Seeds")) {
strcopy(plantModel, sizeof(plantModel), "models/custom_prop/ggc-plg-killzone/eggplant/eggplant_0.mdl");
} else if (StrEqual(plantName, "Pumpkin Seeds")) {
strcopy(plantModel, sizeof(plantModel), "models/custom_prop/ggc-plg-killzone/pumpkinplant/pumpkinplant_0.mdl");
} else if (StrEqual(plantName, "Strawberry Seeds")) {
strcopy(plantModel, sizeof(plantModel), "models/custom_prop/ggc-plg-killzone/strawberryplant/strawberryplant_0.mdl");
} else {
CPrintToChat(client, "[-T-]{red} Invalid Seeds (INTERNAL) report to an Admin");
return;
}
char createPlantQuery[512];
Format(createPlantQuery, sizeof(createPlantQuery), "INSERT INTO `t_rpg_gardener_plants` (`Id`, `playerid`, `plantName`, `plantLevel`, `plantTime`, `plantCreated`, `posX`, `posY`, `posZ`) VALUES (NULL, '%s', '%s', '0', '0', %s, '%.2f', '%.2f', '%.2f');", playerid, plantModel, plantTime, pos[0], pos[1], pos[2]);
SQL_TQuery(g_DB, SQLErrorCheckCallback, createPlantQuery);
spawnPlant(playerid, 0, 0, pos, plantTime, plantModel);
}
public void loadPlants() {
char loadPlantsQuery[512];
Format(loadPlantsQuery, sizeof(loadPlantsQuery), "SELECT plantCreated,plantLevel,plantName,plantTime,playerid,posX,posY,posZ FROM t_rpg_gardener_plants;");
SQL_TQuery(g_DB, SQLLoadPlantsQuery, loadPlantsQuery);
}
public void SQLLoadPlantsQuery(Handle owner, Handle hndl, const char[] error, any data) {
if (loaded)
return;
while (SQL_FetchRow(hndl)) {
char plantowner[20];
SQL_FetchStringByName(hndl, "playerid", plantowner, sizeof(plantowner));
int state = SQL_FetchIntByName(hndl, "plantLevel");
int time = SQL_FetchIntByName(hndl, "plantTime");
char creationTime[64];
SQL_FetchStringByName(hndl, "plantCreated", creationTime, sizeof(creationTime));
char plantModel[128];
SQL_FetchStringByName(hndl, "plantName", plantModel, sizeof(plantModel));
float pos[3];
pos[0] = SQL_FetchFloatByName(hndl, "posX");
pos[1] = SQL_FetchFloatByName(hndl, "posY");
pos[2] = SQL_FetchFloatByName(hndl, "posZ");
//PrintToChatAll("%s %i %i %.2f %.2f %.2f %i %s", plantowner, state, time, pos[0], pos[1], pos[2], creationTime, plantModel);
spawnPlant(plantowner, state, time, pos, creationTime, plantModel);
}
loaded = true;
}
public void spawnPlant(char owner[20], int state, int time, float pos[3], char creationTime[64], char model[128]) {
int plant = CreateEntityByName("prop_dynamic_override");
if (plant == -1)
return;
SetEntityModel(plant, model);
DispatchKeyValue(plant, "Solid", "6");
SetEntProp(plant, Prop_Send, "m_nSolidType", 6);
SetEntProp(plant, Prop_Data, "m_CollisionGroup", COLLISION_GROUP_PUSHAWAY);
DispatchSpawn(plant);
TeleportEntity(plant, pos, NULL_VECTOR, NULL_VECTOR);
Entity_SetGlobalName(plant, "Gardener Plant");
int whereToStore = findLowestUnusedPlantSlot();
g_ePlayerPlants[whereToStore][pEntRef] = EntIndexToEntRef(plant);
strcopy(g_ePlayerPlants[whereToStore][pOwner], 20, owner);
strcopy(g_ePlayerPlants[whereToStore][pCreatedTime], 64, creationTime);
strcopy(g_ePlayerPlants[whereToStore][pModel], 128, model);
g_ePlayerPlants[whereToStore][pState] = state;
g_ePlayerPlants[whereToStore][pTime] = time;
g_ePlayerPlants[whereToStore][pPos_x] = pos[0];
g_ePlayerPlants[whereToStore][pPos_y] = pos[1];
g_ePlayerPlants[whereToStore][pPos_z] = pos[2];
g_ePlayerPlants[whereToStore][pActive] = true;
if (g_iPlantsActive <= whereToStore)
g_iPlantsActive = whereToStore + 1;
}
public int findLowestUnusedPlantSlot() {
for (int i = 0; i < g_iPlantsActive; i++) {
if (!g_ePlayerPlants[i][pActive])
return i;
}
return g_iPlantsActive;
}
public int findPlantLoadedIdByIndex(int index) {
for (int i = 0; i < g_iPlantsActive; i++) {
if (!g_ePlayerPlants[i][pActive])
continue;
if (EntRefToEntIndex(g_ePlayerPlants[i][pEntRef]) == index)
return i;
}
return -1;
}
public int getActivePlantsOfPlayerAmount(int client) {
char playerid[20];
GetClientAuthId(client, AuthId_Steam2, playerid, sizeof(playerid));
int amount = 0;
for (int i = 0; i < MAX_PLANTS; i++) {
if (g_ePlayerPlants[i][pActive])
if (StrEqual(g_ePlayerPlants[i][pOwner], playerid))
amount++;
}
return amount;
}
public int getClientFromAuth2(char auth2[20]) {
for (int i = 1; i < MAXPLAYERS; i++) {
if (isValidClient(i)) {
char playerid[20];
GetClientAuthId(i, AuthId_Steam2, playerid, sizeof(playerid));
if (StrEqual(auth2, playerid)) {
return i;
}
}
}
return -1;
}
public Action refreshTimer(Handle Timer) {
for (int plant = 0; plant < MAX_PLANTS; plant++) {
if (g_ePlayerPlants[plant][pActive] && g_ePlayerPlants[plant][pState] < 4) {
g_ePlayerPlants[plant][pTime] += 1;
if (g_ePlayerPlants[plant][pTime] >= TIME_TO_NEXT_STAGE) {
if (g_ePlayerPlants[plant][pState] < 3) {
g_ePlayerPlants[plant][pState]++;
g_ePlayerPlants[plant][pTime] = 0;
evolvePlant(g_ePlayerPlants[plant][pEntRef], g_ePlayerPlants[plant][pState], plant);
} else if (g_ePlayerPlants[plant][pState] < 4 && g_ePlayerPlants[plant][pTime] >= TIME_TO_NEXT_STAGE * 10) {
deletePlant(EntRefToEntIndex(g_ePlayerPlants[plant][pEntRef]), plant);
}
}
updatePlant(plant);
}
}
for (int i = 1; i < MAXPLAYERS; i++) {
if (!isValidClient(i))
continue;
for (int x = 0; x < MAX_ZONES; x++) {
if (g_iGardenerZoneCooldown[i][x] > 0)
g_iGardenerZoneCooldown[i][x]--;
if (g_iGardenerZoneCooldown[i][x] == 0 && g_iCollectedLoot[i][x] == MAX_COLLECT)
g_iCollectedLoot[i][x] = 0;
}
}
}
public void evolvePlant(int entRef, int state, int plantId) {
if (state >= 0 && state < 4) {
int entity = EntRefToEntIndex(entRef);
if (!IsValidEntity(entity))
return;
char modelPath[128];
strcopy(modelPath, sizeof(modelPath), g_ePlayerPlants[plantId][pModel]);
char oldState[8];
IntToString(state - 1, oldState, sizeof(oldState));
char newState[8];
IntToString(state, newState, sizeof(newState));
ReplaceString(modelPath, sizeof(modelPath), oldState, newState);
SetEntityModel(entity, modelPath);
strcopy(g_ePlayerPlants[plantId][pModel], 128, modelPath);
}
}
public void deletePlant(int ent, int plantId) {
char deletePlantsQuery[512];
Format(deletePlantsQuery, sizeof(deletePlantsQuery), "DELETE FROM t_rpg_gardener_plants WHERE plantCreated = '%s' AND playerid = '%s';", g_ePlayerPlants[plantId][pCreatedTime], g_ePlayerPlants[plantId][pOwner]);
SQL_TQuery(g_DB, SQLErrorCheckCallback, deletePlantsQuery);
if (IsValidEntity(ent))
AcceptEntityInput(ent, "kill");
g_ePlayerPlants[plantId][pEntRef] = -1;
strcopy(g_ePlayerPlants[plantId][pOwner], 20, "");
g_ePlayerPlants[plantId][pState] = -1;
g_ePlayerPlants[plantId][pTime] = -1;
g_ePlayerPlants[plantId][pPos_x] = 0.0;
g_ePlayerPlants[plantId][pPos_y] = 0.0;
g_ePlayerPlants[plantId][pPos_z] = 0.0;
g_ePlayerPlants[plantId][pActive] = false;
}
public void updatePlant(int plantId) {
char updatePlantQuery[1024];
Format(updatePlantQuery, sizeof(updatePlantQuery), "UPDATE t_rpg_gardener_plants SET plantTime = %i, plantLevel = %i, plantName = '%s' WHERE plantCreated = '%s' AND playerid = '%s';", g_ePlayerPlants[plantId][pTime], g_ePlayerPlants[plantId][pState], g_ePlayerPlants[plantId][pModel], g_ePlayerPlants[plantId][pCreatedTime], g_ePlayerPlants[plantId][pOwner]);
SQL_TQuery(g_DB, SQLErrorCheckCallback, updatePlantQuery);
}
public void onRoundStart(Handle event, const char[] name, bool dontBroadcast) {
for (int i = 0; i < MAX_PLANTS; i++)
g_ePlayerPlants[i][pActive] = false;
g_iPlantsActive = 0;
loaded = false;
loadPlants();
}
public Action OnPlayerRunCmd(int client, int &iButtons, int &iImpulse, float fVelocity[3], float fAngles[3], int &iWeapon, int &tickcount) {
if (IsClientInGame(client) && IsPlayerAlive(client)) {
if (!(g_iPlayerPrevButtons[client] & IN_USE) && iButtons & IN_USE) {
int ent = getClientViewObject(client);
if (IsValidEntity(ent)) {
if (HasEntProp(ent, Prop_Data, "m_iName") && HasEntProp(ent, Prop_Data, "m_iGlobalname")) {
char entName[256];
Entity_GetGlobalName(ent, entName, sizeof(entName));
if (StrEqual(entName, "Gardener Plant")) {
if (findPlantLoadedIdByIndex(ent) == -1 || police_isPlayerCuffed(client)) {
g_iPlayerPrevButtons[client] = iButtons;
return Plugin_Continue;
}
float pos[3];
GetEntPropVector(ent, Prop_Data, "m_vecOrigin", pos);
float ppos[3];
GetClientAbsOrigin(client, ppos);
if (GetVectorDistance(ppos, pos) < 100.0) {
if (jobs_isActiveJob(client, "Gardener")) {
jobs_startProgressBar(client, 60, "Harvest Garden Plant");
g_iHarvestIndex[client] = ent;
} else {
CPrintToChat(client, "{red}You have to be a Gardener to harvest this Plant");
g_iPlayerPrevButtons[client] = iButtons;
return Plugin_Continue;
}
} else {
CPrintToChat(client, "{red}This Plant is too far away (%.2f/100.0)", GetVectorDistance(ppos, pos));
g_iPlayerPrevButtons[client] = iButtons;
return Plugin_Continue;
}
}
}
} else if (g_bPlayerInGardenerZone[client]) {
if (g_iCollectedLoot[client][g_iPlayerZoneId[client]] >= MAX_COLLECT || g_iGardenerZoneCooldown[client][g_iPlayerZoneId[client]] > 0) {
CPrintToChat(client, "{red}Gardening in this area is on cooldown");
g_iPlayerPrevButtons[client] = iButtons;
setInfo(client);
return Plugin_Continue;
}
if (!jobs_isActiveJob(client, "Gardener"))
return Plugin_Continue;
char infoString[64];
Format(infoString, sizeof(infoString), "Gardening (%i)", jobs_getLevel(client));
if (perks_hasPerk(client, "Gardener Speed Boost4"))
jobs_startProgressBar(client, 10, infoString);
else if (perks_hasPerk(client, "Gardener Speed Boost3"))
jobs_startProgressBar(client, 15, infoString);
else if (perks_hasPerk(client, "Gardener Speed Boost2"))
jobs_startProgressBar(client, 20, infoString);
else if (perks_hasPerk(client, "Gardener Speed Boost1"))
jobs_startProgressBar(client, 25, infoString);
else
jobs_startProgressBar(client, 30, infoString);
setInfo(client);
}
}
g_iPlayerPrevButtons[client] = iButtons;
}
return Plugin_Continue;
}
public void jobs_OnProgressBarFinished(int client, char info[64]) {
if (!jobs_isActiveJob(client, "Gardener"))
return;
if (StrContains(info, "Harvest Garden Plant") != -1) {
int plantId;
if ((plantId = findPlantLoadedIdByIndex(g_iHarvestIndex[client])) == -1)
return;
harvestPlant(client, g_iHarvestIndex[client], plantId, g_ePlayerPlants[plantId][pState]);
} else if (StrContains(info, "Gardening", false) != -1) {
if (g_iPlayerZoneId[client] == -1)
return;
if (++g_iCollectedLoot[client][g_iPlayerZoneId[client]] >= MAX_COLLECT)
g_iGardenerZoneCooldown[client][g_iPlayerZoneId[client]] = g_iZoneCooldown + GetRandomInt(0, 50);
char addCurrencyReason[256];
Format(addCurrencyReason, sizeof(addCurrencyReason), "Gardening (Level %i)", jobs_getLevel(client));
tConomy_addBankCurrency(client, 55 + jobs_getLevel(client) * 5, "Gardening");
if (perks_hasPerk(client, "Gardener XP Boost4"))
jobs_addExperience(client, 45, "Gardener");
else if (perks_hasPerk(client, "Gardener XP Boost3"))
jobs_addExperience(client, 40, "Gardener");
else if (perks_hasPerk(client, "Gardener XP Boost2"))
jobs_addExperience(client, 35, "Gardener");
else if (perks_hasPerk(client, "Gardener XP Boost1"))
jobs_addExperience(client, 30, "Gardener");
else
jobs_addExperience(client, 25, "Gardener");
setInfo(client);
}
}
public void harvestPlant(int client, int ent, int plantId, int state) {
jobs_addExperience(client, state * 150, "Gardener");
char resultItem[128];
if (StrContains(g_ePlayerPlants[plantId][pModel], "eggplant") != -1) {
strcopy(resultItem, sizeof(resultItem), "Eggplant");
} else if (StrContains(g_ePlayerPlants[plantId][pModel], "strawberry") != -1) {
strcopy(resultItem, sizeof(resultItem), "Strawberry");
} else if (StrContains(g_ePlayerPlants[plantId][pModel], "pumpkin") != -1) {
strcopy(resultItem, sizeof(resultItem), "Pumpkin");
}
if (state == 1) {
for (int i = 0; i < 1; i++) {
inventory_givePlayerItem(client, resultItem, 2, "", "Plant", "Gardener Item", 2, "Harvested Plant");
}
} else if (state == 2) {
for (int i = 0; i < 2; i++) {
inventory_givePlayerItem(client, resultItem, 2, "", "Plant", "Gardener Item", 2, "Harvested Plant");
}
} else if (state == 3) {
for (int i = 0; i < 5; i++) {
inventory_givePlayerItem(client, resultItem, 2, "", "Plant", "Gardener Item", 2, "Harvested Plant");
}
}
deletePlant(ent, plantId);
}
public void OnClientAuthorized(int client) {
g_bPlayerInGardenerZone[client] = false;
g_iPlayerZoneId[client] = -1;
for (int zones = 0; zones < MAX_ZONES; zones++) {
g_iGardenerZoneCooldown[client][zones] = g_iZoneCooldown;
g_iCollectedLoot[client][zones] = 0;
}
}
public void OnClientDisconnect(int client) {
g_bPlayerInGardenerZone[client] = false;
g_iPlayerZoneId[client] = -1;
for (int zones = 0; zones < MAX_ZONES; zones++) {
g_iGardenerZoneCooldown[client][zones] = 0;
g_iCollectedLoot[client][zones] = 0;
}
}
public int Zone_OnClientEntry(int client, char[] zone) {
strcopy(activeZone[client], sizeof(activeZone), zone);
if (StrContains(zone, "garden") != -1) {
addZone(zone);
g_bPlayerInGardenerZone[client] = true;
g_iPlayerZoneId[client] = getZoneId(zone);
} else {
g_bPlayerInGardenerZone[client] = false;
g_iPlayerZoneId[client] = -1;
}
setInfo(client);
}
public int Zone_OnClientLeave(int client, char[] zone) {
float pos[3];
GetClientAbsOrigin(client, pos);
if (Zone_isPositionInZone(activeZone[client], pos[0], pos[1], pos[2]))
return;
if (StrContains(zone, "garden", false) != -1) {
g_bPlayerInGardenerZone[client] = false;
g_iPlayerZoneId[client] = -1;
}
eraseInfo(client);
}
public void OnNpcInteract(int client, char npcType[64], char UniqueId[128], int entIndex) {
if (!StrEqual(npcType, npctype))
return;
char activeJob[128];
jobs_getActiveJob(client, activeJob);
Menu menu = CreateMenu(JobPanelHandler);
if (StrEqual(activeJob, "") || !jobs_isActiveJob(client, "Gardener")) {
SetMenuTitle(menu, "You already have a job! Want to quit it and becoma a Gardener?");
AddMenuItem(menu, "x", "No");
AddMenuItem(menu, "x", "Not now.");
AddMenuItem(menu, "givejob", "Yes");
} else if (jobs_isActiveJob(client, "Gardener")) {
SetMenuTitle(menu, "Welcome Gardener!");
AddMenuItem(menu, "x", "Are you having a nice day?", ITEMDRAW_DISABLED);
AddMenuItem(menu, "skin1", "First Gardener Skin [2](500$)", tConomy_getCurrency(client) >= 500 && jobs_getLevel(client) >= 2 ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED);
if (tConomy_getCurrency(client) >= 75 && jobs_isActiveJob(client, "Gardener") && jobs_getLevel(client) >= 3)
AddMenuItem(menu, "EggplantSeeds", "Buy a Eggplant Seed (75$)[3]");
else
AddMenuItem(menu, "x", "Buy a Eggplant Seed (75$)[3]", ITEMDRAW_DISABLED);
if (tConomy_getCurrency(client) >= 125 && jobs_isActiveJob(client, "Gardener") && jobs_getLevel(client) >= 5)
AddMenuItem(menu, "StawberrySeeds", "Buy a Stawberry Seed (125$)[5]");
else
AddMenuItem(menu, "x", "Buy a Stawberry Seed (125$)[5]", ITEMDRAW_DISABLED);
if (tConomy_getCurrency(client) >= 200 && jobs_isActiveJob(client, "Gardener") && jobs_getLevel(client) >= 11)
AddMenuItem(menu, "PumpkinSeeds", "Buy a Pumpkin Seed (200$)[11]");
else
AddMenuItem(menu, "x", "Buy a Pumpkin Seed (200$)[11]", ITEMDRAW_DISABLED);
if (inventory_hasPlayerItem(client, "Eggplant"))
AddMenuItem(menu, "sellEggplant", "Sell Eggplant");
if (inventory_getPlayerItemAmount(client, "Eggplant") > 1) {
char sellAll[256];
int itemamount = inventory_getPlayerItemAmount(client, "Eggplant");
Format(sellAll, sizeof(sellAll), "Sell %i Eggplant%s", itemamount, itemamount > 2 ? "s":"");
AddMenuItem(menu, "SellEggplants", sellAll);
}
if (inventory_hasPlayerItem(client, "Strawberry"))
AddMenuItem(menu, "sellStrawberry", "Sell Strawberry");
if (inventory_getPlayerItemAmount(client, "Strawberry") > 1) {
char sellAll[256];
int itemamount = inventory_getPlayerItemAmount(client, "Strawberry");
Format(sellAll, sizeof(sellAll), "Sell %i Strawberry%s", itemamount, itemamount > 2 ? "s":"");
AddMenuItem(menu, "SellStrawberrys", sellAll);
}
if (inventory_hasPlayerItem(client, "Pumpkin"))
AddMenuItem(menu, "sellPumpkin", "Sell Pumpkin");
if (inventory_getPlayerItemAmount(client, "Pumpkin") > 1) {
char sellAll[256];
int itemamount = inventory_getPlayerItemAmount(client, "Pumpkin");
Format(sellAll, sizeof(sellAll), "Sell %i Pumpkin%s", itemamount, itemamount > 2 ? "s":"");
AddMenuItem(menu, "SellPumpkins", sellAll);
}
}
DisplayMenu(menu, client, 60);
}
public int JobPanelHandler(Handle menu, MenuAction action, int client, int item) {
if (action == MenuAction_Select) {
char cValue[32];
GetMenuItem(menu, item, cValue, sizeof(cValue));
if (StrEqual(cValue, "givejob")) {
jobs_giveJob(client, "Gardener");
} else if (StrEqual(cValue, "skin1")) {
if (tConomy_getCurrency(client) >= 500 && jobs_getLevel(client) >= 2) {
tConomy_removeCurrency(client, 500, "Bought Gardener Skin");
inventory_givePlayerItem(client, "Gardener", 0, "", "Skin", "Skin", 1, "Bought from Gardener Recruiter");
}
} else if (StrEqual(cValue, "sellEggplant")) {
if (inventory_hasPlayerItem(client, "Eggplant")) {
tConomy_addCurrency(client, 100, "Sold Eggplant to Vendor");
inventory_removePlayerItems(client, "Eggplant", 1, "Sold to Vendor");
}
} else if (StrEqual(cValue, "SellEggplants")) {
int itemamount = inventory_getPlayerItemAmount(client, "Eggplant");
if (inventory_removePlayerItems(client, "Eggplant", itemamount, "Sold to Vendor (Mass Sell)"))
tConomy_addCurrency(client, 100 * itemamount, "Sold Eggplant to Vendor");
} else if (StrEqual(cValue, "sellStrawberry")) {
if (inventory_hasPlayerItem(client, "Strawberry")) {
tConomy_addCurrency(client, 125, "Sold Strawberry to Vendor");
inventory_removePlayerItems(client, "Strawberry", 1, "Sold to Vendor");
}
} else if (StrEqual(cValue, "SellStrawberrys")) {
int itemamount = inventory_getPlayerItemAmount(client, "Strawberry");
if (inventory_removePlayerItems(client, "Strawberry", itemamount, "Sold to Vendor (Mass Sell)"))
tConomy_addCurrency(client, 125 * itemamount, "Sold Strawberry to Vendor");
} else if (StrEqual(cValue, "sellPumpkin")) {
if (inventory_hasPlayerItem(client, "Pumpkin")) {
tConomy_addCurrency(client, 150, "Sold Pumpkin to Vendor");
inventory_removePlayerItems(client, "Pumpkin", 1, "Sold to Vendor");
}
} else if (StrEqual(cValue, "SellPumpkins")) {
int itemamount = inventory_getPlayerItemAmount(client, "Pumpkin");
if (inventory_removePlayerItems(client, "Pumpkin", itemamount, "Sold to Vendor (Mass Sell)"))
tConomy_addCurrency(client, 150 * itemamount, "Sold Pumpkin to Vendor");
} else if (StrEqual(cValue, "EggplantSeeds")) {
if (tConomy_getCurrency(client) >= 75) {
tConomy_removeCurrency(client, 75, "Bought Eggplant Seeds");
inventory_givePlayerItem(client, "Eggplant Seeds", 1, "", "Plant seeds", "Gardener Item", 1, "Bought from Vendor");
}
} else if (StrEqual(cValue, "StawberrySeeds")) {
if (tConomy_getCurrency(client) >= 125) {
tConomy_removeCurrency(client, 125, "Bought Eggplant Seeds");
inventory_givePlayerItem(client, "Strawberry Seeds", 1, "", "Plant seeds", "Gardener Item", 1, "Bought from Vendor");
}
} else if (StrEqual(cValue, "PumpkinSeeds")) {
if (tConomy_getCurrency(client) >= 200) {
tConomy_removeCurrency(client, 200, "Bought Pumpkin Seeds");
inventory_givePlayerItem(client, "Pumpkin Seeds", 1, "", "Plant seeds", "Gardener Item", 1, "Bought from Vendor");
}
}
}
if (action == MenuAction_End) {
delete menu;
}
}
public void addZone(char[] zone) {
if (StrContains(zone, "garden", false) != -1) {
for (int i = 0; i < g_iLoadedZones; i++) {
if (StrEqual(g_cGardenerZones[i], zone))
return;
}
strcopy(g_cGardenerZones[g_iLoadedZones], PLATFORM_MAX_PATH, zone);
g_iLoadedZones++;
}
}
public int getZoneId(char[] zone) {
for (int i = 0; i < g_iLoadedZones; i++) {
if (StrEqual(g_cGardenerZones[i], zone))
return i;
}
return -1;
}
public void setInfo(int client) {
if (!jobs_isActiveJob(client, "Gardener"))
return;
if (StrContains(activeZone[client], "garden", false) == -1)
return;
char info[128];
Format(info, sizeof(info), "%s: Gardened %i/%i (%is Cd)", activeZone[client], g_iCollectedLoot[client][g_iPlayerZoneId[client]], MAX_COLLECT, g_iGardenerZoneCooldown[client][g_iPlayerZoneId[client]]);
jobs_setCurrentInfo(client, info);
}
public void eraseInfo(int client) {
jobs_setCurrentInfo(client, "");
}
public void SQLErrorCheckCallback(Handle owner, Handle hndl, const char[] error, any data) {
if (!StrEqual(error, ""))
LogError(error);
}
public void jobs_OnProgressBarInterrupted(int client, char info[64]) {
g_iHarvestIndex[client] = -1;
}