-
Notifications
You must be signed in to change notification settings - Fork 8
/
modelrandomizer.sp
71 lines (58 loc) · 1.78 KB
/
modelrandomizer.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
#include <sdktools>
#include <sdkhooks>
#include <tf2items>
int stringTable;
public Plugin myinfo =
{
name = "[TF2] Model Randomizer",
author = "Pelipoika",
description = "",
version = "-1.0",
url = "Nah"
};
public void OnPluginStart()
{
stringTable = FindStringTable("modelprecache");
}
public void OnEntityCreated(int entity, const char[] classname)
{
if(entity > MaxClients)
SDKHook(entity, SDKHook_SpawnPost, OnEntitySpawn);
}
public void OnEntitySpawn(int entity)
{
int numStrings = GetStringTableNumStrings(stringTable);
int mindex = GetRandomInt(0, numStrings);
char strModel[PLATFORM_MAX_PATH];
ReadStringTable(stringTable, mindex, strModel, PLATFORM_MAX_PATH);
PrintToServer("%i -> %s", entity, strModel);
SetEntProp(entity, Prop_Data, "m_nModelIndexOverrides", mindex);
SetEntProp(entity, Prop_Data, "m_nModelIndex", mindex);
// RequestFrame(OnSpawnSpawn, EntIndexToEntRef(entity));
}
public void OnSpawnSpawn(int iRef)
{
int iEnt = EntRefToEntIndex(iRef);
if(iEnt != INVALID_ENT_REFERENCE)
{
RequestFrame(OnSpawnSpawnSpawn, EntIndexToEntRef(iEnt));
}
}
public void OnSpawnSpawnSpawn(int iRef)
{
int iEnt = EntRefToEntIndex(iRef);
if(iEnt != INVALID_ENT_REFERENCE)
{
int numStrings = GetStringTableNumStrings(stringTable);
int mindex = GetRandomInt(0, numStrings);
SetEntProp(iEnt, Prop_Data, "m_nModelIndexOverrides", mindex);
SetEntProp(iEnt, Prop_Data, "m_nModelIndex", mindex);
}
}
/*
public int TF2Items_OnGiveNamedItem_Post(int client, char[] classname, int index, int level, int quality, int entity)
{
int numStrings = GetStringTableNumStrings(stringTable);
int mindex = GetRandomInt(0, numStrings);
SetEntProp(entity, Prop_Data, "m_nModelIndexOverrides", mindex);
}*/