AMXX-BG.INFO text.inc Raw include

text.inc

Original include source with line numbers.

Back Download .inc
1 #if defined _text_included
2 #endinput
3 #endif
4 #define _text_included
5
6 /*
7 String functions by Zefir<[email protected]>
8 developed for Cerberus project
9 http://cerberus.cstrike.in.ua/
10 5 January 2010 (c) Zefir
11 */
12
13 #include <fakemeta>
14
15
16
17 // Allocate memory for string
18 // Used for store parameters between call of set_task and other callbacks
19 #define get_ptr_to_str(%1) engfunc(EngFunc_AllocString, %1)
20 #define get_str_from_ptr(%1,%2,%3) global_get(glb_pStringBase, %1, %2, %3)
21 #define free_ptr_to_str(%1) %1 = 0
22
23 // simple copy with autodetected size of recive buffer
24 #define scopy(%1,%2) copy(%1, sizeof(%1) - 1, %2)
25
26 /*
27 For create sub formatted string
28
29 Example:
30
31 #include <amxmodx>
32 #include <text>
33
34 public plugin_init() {
35 register_plugin("Dinamic Hostname", "1.0", "Zefir")
36 register_cvar("amx_hostname", "CS Server (next map: #m; timeleft: #t)")
37 set_task(1.0, "set_hostname", 0, _, _, "b")
38 }
39
40 public set_hostname() {
41 static hostname[64]
42
43 get_cvar_string("amx_hostname", hostname, charsmax(hostname))
44
45 static time_string[32], next_map[32]
46 static h,m,s
47
48 if (!get_cvar_float("mp_timelimit"))
49 formatex(time_string, charsmax(time_string), "Never")
50 else {
51 s = get_timeleft()
52 m = s/60
53 h = m/60
54 s = s-m*60
55 m = m-h*60
56 if(h)
57 formatex(time_string, charsmax(time_string), "%d:%02d:%02d", h, m, s)
58 else
59 formatex(time_string, charsmax(time_string), "%d:%02d", m, s)
60 }
61 replace_all_format(hostname, charsmax(hostname), 't', time_string)
62
63 get_cvar_string("amx_nextmap", next_map, charsmax(next_map))
64 replace_all_format(hostname, charsmax(hostname), 'm', next_map)
65
66 set_cvar_string("hostname", hostname)
67 }
68
69
70 */
71 stock replace_all_format(string[], len, const format_char, const with[]) {
72
73 static total, format_str[3]
74 total = 0
75 formatex(format_str, 2, "#%c", format_char)
76
77 while (replace(string, len, format_str, "%s") != 0) {
78 format(string, len, string, with)
79 total++;
80 }
81
82 return total;
83 }
84
85