Ads keep us online. Without them, we wouldn't exist. We don't have paywalls or sell mods - we never will. But every month we have large bills and running ads is our only way to cover them. Please consider unblocking us. Thank you from GameBanana <3

Precache Management

A Config Script for Counter-Strike 1.6

No ads for members. Membership is 100% free. Sign up!
144 3 kb Raw Code
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
/* AMX Mod X Plugin
*
* (c) Copyright 2008, ConnorMcLeod
* This file is provided as is (no warranties).
*
*/


#include <amxmodx>
#include <fakemeta>

#define MAX_PRECACHE    812
#define MAX_FILE_LENGHT    128

new g_iCounter

new g_szPrecachedFiles[MAX_PRECACHE+1][MAX_FILE_LENGHT+1]
new g_szCustomFiles[MAX_PRECACHE+1][MAX_FILE_LENGHT+1]

new g_iForwardsIds[3]

public plugin_precache()
{
    register_plugin("Precache Management", "1.0.0", "ConnorMcLeod")

    g_iForwardsIds[0] = register_forward(FM_PrecacheModel, "Precache_Post", 1)
    g_iForwardsIds[1] = register_forward(FM_PrecacheSound, "Precache_Post", 1)
    g_iForwardsIds[2] = register_forward(FM_PrecacheGeneric, "Precache_Post", 1)
}

public plugin_natives()
{
    register_library("precache")
    register_native("can_precache","native_can_precache")
    register_native("PrecacheModel","native_PrecacheModel")
    register_native("PrecacheSound","native_PrecacheSound")
    register_native("PrecacheGeneric","native_PrecacheGeneric")
}

public plugin_init()
{
    unregister_forward(FM_PrecacheModel, g_iForwardsIds[0], 1)
    unregister_forward(FM_PrecacheSound, g_iForwardsIds[1], 1)
    unregister_forward(FM_PrecacheGeneric, g_iForwardsIds[2], 1)

    new const szLogFile[] = "PrecacheList.log"
    new const szLogFile2[] = "PrecacheListCust.log"
    for(new i=1; i<=MAX_PRECACHE; i++)
    {
        if(g_szPrecachedFiles[i][0])
        {
            log_to_file(szLogFile, "<%d><%s>", i, g_szPrecachedFiles[i])
        }
        if(g_szCustomFiles[i][0])
        {
            log_to_file(szLogFile2, "<%d><%s>", i, g_szCustomFiles[i])
        }
    }
    log_to_file(szLogFile, "%i files precached", g_iCounter)
    pause("ad")
}

public Precache_Post(const szFile[])
{
    static iVal
    iVal = get_orig_retval()
    update_counter(iVal)

    if( !g_szPrecachedFiles[iVal][0] )
    {
        formatex(g_szPrecachedFiles[iVal], MAX_FILE_LENGHT, szFile)
    }
}

update_counter(iVal)
{
    if( iVal > g_iCounter )
    {
        g_iCounter = iVal
        return 1
    }
    return 0
}

public native_can_precache(iPlugin, iParams)
{
    return (g_iCounter < MAX_PRECACHE)
}

public native_PrecacheModel(iPlugin, iParams)
{
    if(iParams != 1)
        return -1

    static szFile[MAX_FILE_LENGHT], iVal
    get_string(1, szFile, MAX_FILE_LENGHT-1)

    iVal = engfunc(EngFunc_PrecacheModel, szFile)

    update_counter( iVal )
    if( !g_szCustomFiles[iVal][0] )
    {
        formatex(g_szCustomFiles[iVal], MAX_FILE_LENGHT, szFile)
    }

    return iVal
}

public native_PrecacheSound(iPlugin, iParams)
{
    if(iParams != 1)
        return -1

    static szFile[MAX_FILE_LENGHT], iVal
    get_string(1, szFile, MAX_FILE_LENGHT-1)

    iVal = engfunc(EngFunc_PrecacheSound, szFile)

    update_counter( iVal )
    if( !g_szCustomFiles[iVal][0] )
    {
        formatex(g_szCustomFiles[iVal], MAX_FILE_LENGHT, szFile)
    }

    return iVal
}

public native_PrecacheGeneric(iPlugin, iParams)
{
    if(iParams != 1)
        return -1

    static szFile[MAX_FILE_LENGHT], iVal
    get_string(1, szFile, MAX_FILE_LENGHT-1)

    iVal = engfunc(EngFunc_PrecacheGeneric, szFile)

    update_counter( iVal )
    if( !g_szCustomFiles[iVal][0] )
    {
        formatex(g_szCustomFiles[iVal], MAX_FILE_LENGHT, szFile)
    }

    return iVal
}

Updates

v1.0 26d
  • - Increase the "MAX_PRECACHE" to 812
Here's the updated code, you can see that custom files have indexes that are not related to game files indexes, so it would be difficult to count the exact files number, considering that a file can be both precached by the game and by amxx
Sign up to access this!

No comments yet

Embed

Share banner
Image URL
HTML embed code
BB embed code
Markdown embed code

Credits

ConnorMcLeod
ConnorMcLeod
Scripter

Submitter

Rainbowdash98 avatar
Rainbowdash98 Joined 4y ago
Offline
2,398 points Ranked 20320th
9 medals 1 rare
  • Returned 1000 times Medal icon
  • One month a member Medal icon
  • Returned 100 times Medal icon
  • 6 months a member Medal icon
  • 1 year a member Medal icon
  • 2 years a member Medal icon
Rainbowdash98
Redistributor
Are you the owner? Request Ownership
Sign up to access this!
Sign up to access this!
Sign up to access this!

Game

Sign up to access this!

Category

License

Share

  • Share on Reddit
  • Share on Twitter
  • Share on Facebook
  • 1
  • 413
  • 26d
  • 26d

More from Submitter

More AMX/X Scripts Scripts