This repository has been archived by the owner on Sep 8, 2022. It is now read-only.
forked from Franc1sco/sm-zombiereloaded-3-Franug-Edition
-
Notifications
You must be signed in to change notification settings - Fork 1
/
zr_classfix.sp
141 lines (117 loc) · 3.64 KB
/
zr_classfix.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
#include <sourcemod>
#include <sdktools>
#include <zombiereloaded>
public Plugin:myinfo =
{
name = "ZR Class Fix",
author = "Franc1sco franug",
description = "Class Fix",
version = "3.4",
url = "http://steamcommunity.com/id/franug"
};
new Handle:kv;
new Handle:hPlayerClasses, String:sClassPath[PLATFORM_MAX_PATH] = "configs/zr/playerclasses.txt";
new Handle:array_classes;
enum struct zrClasses
{
int Index;
int health;
char model[128];
}
public OnPluginStart()
{
array_classes = CreateArray(130);
RegConsoleCmd("sm_testzrfix", Test);
}
public Action:Test(client,args)
{
zrClasses Items;
for(new i=0;i<GetArraySize(array_classes);++i)
{
GetArrayArray(array_classes, i, Items);
ReplyToCommand(client, "Zombie Class index %i with health %i and model %s", Items.Index,Items.health,Items.model);
}
return Plugin_Handled;
}
public OnAllPluginsLoaded()
{
if (hPlayerClasses != INVALID_HANDLE)
{
UnhookConVarChange(hPlayerClasses, OnClassPathChange);
CloseHandle(hPlayerClasses);
}
if ((hPlayerClasses = FindConVar("zr_config_path_playerclasses")) == INVALID_HANDLE)
{
SetFailState("Zombie:Reloaded is not running on this server");
}
HookConVarChange(hPlayerClasses, OnClassPathChange);
}
public OnClassPathChange(Handle:convar, const String:oldValue[], const String:newValue[])
{
strcopy(sClassPath, sizeof(sClassPath), newValue);
OnConfigsExecuted();
}
public OnConfigsExecuted()
{
CreateTimer(0.2, OnConfigsExecutedPost);
}
public Action:OnConfigsExecutedPost(Handle:timer)
{
if (kv != INVALID_HANDLE)
{
CloseHandle(kv);
}
kv = CreateKeyValues("classes");
decl String:buffer[PLATFORM_MAX_PATH];
BuildPath(Path_SM, buffer, sizeof(buffer), "%s", sClassPath);
if (!FileToKeyValues(kv, buffer))
{
SetFailState("Class data file \"%s\" not found", buffer);
}
if (KvGotoFirstSubKey(kv))
{
ClearArray(array_classes);
decl String:name[64], String:enable[32], String:defaultclass[32], String:SMflags[32];
zrClasses Items;
do
{
KvGetString(kv, "enabled", enable, 32);
KvGetString(kv, "team_default", defaultclass, 32);
KvGetString(kv, "sm_flags", SMflags, 32);
// check if is a enabled zombie class and no admin class and it's default class
if(StrEqual(enable, "yes") && StrEqual(defaultclass, "yes") && KvGetNum(kv, "team") == 0 && KvGetNum(kv, "flags") == 0 && !SMflags[0])
{
KvGetString(kv, "name", name, sizeof(name));
Items.Index = ZR_GetClassByName(name);
Items.health = KvGetNum(kv, "health", 5000);
KvGetString(kv, "model_path", Items.model, 128);
PushArrayArray(array_classes, Items); // save all info in the array
}
} while (KvGotoNextKey(kv));
}
KvRewind(kv);
}
public ZR_OnClientInfected(client, attacker, bool:motherInfect, bool:respawnOverride, bool:respawn)
{
new vida = GetClientHealth(client);
if(vida < 300)
{
CreateTimer(0.5, Timer_SetDefaultClass, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
}
}
public Action:Timer_SetDefaultClass(Handle:timer, any:userid)
{
int client = GetClientOfUserId(userid);
if(client && IsClientInGame(client) && IsPlayerAlive(client) && ZR_IsClientZombie(client))
SetDefaultClass(client);
}
SetDefaultClass(client)
{
zrClasses Items;
new randomnum = GetRandomInt(0, GetArraySize(array_classes)-1); // random value in the array
GetArrayArray(array_classes, randomnum, Items); // get class info from the array
ZR_SelectClientClass(client, Items.Index, true, true); // set a valid class
SetEntityHealth(client, Items.health); // apply health of the class selected
if(strlen(Items.model) > 2 && IsModelPrecached(Items.model)) // check if model is valid and is precached
SetEntityModel(client, Items.model); // then apply it
}