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
|
#pragma semicolon 1
#include <sourcemod>
#include <clientprefs>
#include <smlib>
#define PLUGIN_VERSION "0.1"
/* Handles */
new Handle:g_hCVEnable;
new Handle:g_hCVPopupTimer;
new g_iEnable;
new Float:g_fTimer;
/* Cookie settings */
new Handle:g_hCookieWantPanel = INVALID_HANDLE;
new bool:g_bClientWantsPanel[MAXPLAYERS+1] = {true,...};
public Plugin:myinfo =
{
name = "rtdpopup",
author = "fluxX'",
description = "",
version = PLUGIN_VERSION,
url = "WCFAN.de"
}
public OnPluginStart()
{
new Handle:hVersion = CreateConVar("sm_rtdpopup_version", PLUGIN_VERSION, "RtdPopup Version", FCVAR_PLUGIN|FCVAR_NOTIFY|FCVAR_REPLICATED|FCVAR_DONTRECORD);
if(hVersion != INVALID_HANDLE)
SetConVarString(hVersion, PLUGIN_VERSION);
g_hCVEnable = CreateConVar("sm_rtdpopup_enable", "1", "Plugin RtdPopup (0 = Disabled, 1 = Enabled).", FCVAR_PLUGIN);
g_hCVPopupTimer = CreateConVar("sm_rtdpopup_time", "300", "Time in seconds to display the RtdPopup-Menu.", FCVAR_PLUGIN);
g_iEnable = GetConVarInt(g_hCVEnable);
g_fTimer = GetConVarFloat(g_hCVPopupTimer);
// Settings Panel
g_hCookieWantPanel = RegClientCookie("sm_rtdpopup", "Pop-up a menu after x seconds to ask a player if he wants to roll the dice", CookieAccess_Protected);
SetCookieMenuItem(Cookie_SelectPanel, 0, "Want to get the roll the dice Pop-up Menu?");
// ConVarChange
HookConVarChange(g_hCVEnable, OnConVarChange);
HookConVarChange(g_hCVPopupTimer, OnConVarChange);
}
public OnMapStart()
{
if(!g_iEnable)
return;
CreateTimer(g_fTimer, RtdPopupMenu, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}
public OnConVarChange(Handle:hCvar, const String:oldValue[], const String:newValue[])
{
if(hCvar == g_hCVEnable)
g_iEnable = GetConVarInt(g_hCVEnable);
if(hCvar == g_hCVPopupTimer)
g_fTimer = GetConVarFloat(g_hCVPopupTimer);
}
public Action:RtdPopupMenu(Handle:timer, any:userid)
{
//PrintToChatAll("Debug: Send RTD Popup-Menu");
for(new i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i) && IsPlayerAlive(i))
{
if(g_bClientWantsPanel[i])
// Display the Popup to the client
DisplayRtdPopupMenu(i);
else
return;
}
}
}
public OnClientCookiesCached(client)
{
decl String:sBuffer[256];
GetClientCookie(client, g_hCookieWantPanel, sBuffer, sizeof(sBuffer));
if(strlen(sBuffer) == 0 || StrEqual(sBuffer, "Yes"))
g_bClientWantsPanel[client] = true;
else
g_bClientWantsPanel[client] = false;
// Set default value
if(strlen(sBuffer) == 0)
SetClientCookie(client, g_hCookieWantPanel, "Yes");
}
// Cache the changed value
public Cookie_SelectPanel(client, CookieMenuAction:action, any:info, String:buffer[], maxlen)
{
if (action == CookieMenuAction_DisplayOption)
{
decl String:status[10];
if (g_bClientWantsPanel[client])
{
Format(status, sizeof(status), "On");
}
else
{
Format(status, sizeof(status), "Off");
}
Format(buffer, maxlen, "RTD Panel: %s", status);
}
else if(action == CookieMenuAction_SelectOption)
{
// Toggle the setting
decl String:sCookieValue[7];
GetClientCookie(client, g_hCookieWantPanel, sCookieValue, sizeof(sCookieValue));
if(StrEqual(sCookieValue, "Yes"))
{
SetClientCookie(client, g_hCookieWantPanel, "No");
// Remove panel directly
Client_PrintKeyHintText(client, "");
}
else
SetClientCookie(client, g_hCookieWantPanel, "Yes");
g_bClientWantsPanel[client] = !g_bClientWantsPanel[client];
// Reshow the !settings menu
ShowCookieMenu(client);
}
}
DisplayRtdPopupMenu(client)
{
new Handle:hMenu = CreateMenu(Menu_HandlerRtdPopupMenu);
decl String:title[100];
Format(title, sizeof(title), "Want to roll the dice?");
SetMenuTitle(hMenu, title);
SetMenuExitButton(hMenu, true);
AddMenuItem(hMenu, "yes", "Yes");
AddMenuItem(hMenu, "no", "No");
// Show the menu to the client
DisplayMenu(hMenu, client, 20);
}
public Menu_HandlerRtdPopupMenu(Handle:menu, MenuAction:action, param1, param2)
{
/* If an option was selected, tell the client about the item. */
if (action == MenuAction_Select)
{
new String:sInfo[32];
GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
if(StrEqual(sInfo, "yes"))
{
// yes, send him the other menu
FakeClientCommand(param1,"say rtd");
}
else if(StrEqual(sInfo, "no"))
{
}
}
/* If the menu has ended, destroy it */
else if (action == MenuAction_End)
{
CloseHandle(menu);
}
}
|