mirror of
https://github.com/Jackzmc/sourcemod-plugins.git
synced 2025-05-06 14:13:20 +00:00
Extract cvar recorder to own inc
This commit is contained in:
parent
bd6526f85d
commit
57e922f1bc
2 changed files with 75 additions and 39 deletions
64
scripting/include/gamemodes/cvars.inc
Normal file
64
scripting/include/gamemodes/cvars.inc
Normal file
|
@ -0,0 +1,64 @@
|
|||
static char buffer[128];
|
||||
|
||||
methodmap GameConVarStorage < StringMap {
|
||||
public GameConVarStorage() {
|
||||
return view_as<GameConVarStorage>(new StringMap());
|
||||
}
|
||||
|
||||
public void Restore() {
|
||||
StringMapSnapshot snapshot = this.Snapshot();
|
||||
char key[32];
|
||||
#if defined DEBUG_GAME_CVAR_STORAGE
|
||||
PrintToServer("GameConVarStorage: Restoring %d saved convars", snapshot.Length);
|
||||
#endif
|
||||
for(int i = 0; i < snapshot.Length; i++) {
|
||||
snapshot.GetKey(i, key, sizeof(key));
|
||||
ConVar convar = FindConVar(key);
|
||||
if(convar != null) {
|
||||
float value;
|
||||
if(this.GetValue(key, value)) {
|
||||
convar.FloatValue = value;
|
||||
} else if(this.GetString(key, buffer, sizeof(buffer))) {
|
||||
convar.SetString(buffer);
|
||||
} else {
|
||||
LogError("GameConVarStorage: Cannot restore invalid cvar (\"%s\")", key);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.Clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
methodmap GameConVar < ConVar {
|
||||
public GameConVar(const char[] name) {
|
||||
return view_as<GameConVar>(FindConVar(name));
|
||||
}
|
||||
|
||||
public void RecordInt(int value, GameConVarStorage storage) {
|
||||
if(storage != null) {
|
||||
this.GetName(buffer, sizeof(buffer));
|
||||
storage.SetValue(buffer, float(value));
|
||||
}
|
||||
this.IntValue = value;
|
||||
}
|
||||
|
||||
public void RecordFloat(float value, GameConVarStorage storage) {
|
||||
if(storage != null) {
|
||||
this.GetName(buffer, sizeof(buffer));
|
||||
storage.SetValue(buffer, value);
|
||||
}
|
||||
this.FloatValue = value;
|
||||
}
|
||||
|
||||
public void RecordString(const char[] value, GameConVarStorage storage) {
|
||||
if(storage != null) {
|
||||
char prevValue[32];
|
||||
this.GetName(buffer, sizeof(buffer));
|
||||
this.GetString(prevValue, sizeof(prevValue));
|
||||
storage.SetString(buffer, prevValue);
|
||||
}
|
||||
this.SetString(value);
|
||||
}
|
||||
|
||||
}
|
|
@ -40,50 +40,15 @@ bool FindSpawnPosition(float pos[3], bool includePlayers = true) {
|
|||
return false;
|
||||
}
|
||||
|
||||
static char buffer[64];
|
||||
|
||||
methodmap GameConVar < ConVar {
|
||||
public GameConVar(const char[] name) {
|
||||
return view_as<GameConVar>(FindConVar(name));
|
||||
}
|
||||
|
||||
public void RecordInt(int value, bool record = false) {
|
||||
if(record) {
|
||||
this.GetName(buffer, sizeof(buffer));
|
||||
previousCvarValues.SetValue(buffer, float(value));
|
||||
}
|
||||
this.IntValue = value;
|
||||
}
|
||||
|
||||
public void RecordFloat(float value, bool record = false) {
|
||||
if(record) {
|
||||
this.GetName(buffer, sizeof(buffer));
|
||||
previousCvarValues.SetValue(buffer, value);
|
||||
}
|
||||
this.FloatValue = value;
|
||||
}
|
||||
|
||||
public void RecordString(const char[] value, bool record = false) {
|
||||
if(record) {
|
||||
char prevValue[32];
|
||||
this.GetName(buffer, sizeof(buffer));
|
||||
this.GetString(prevValue, sizeof(prevValue));
|
||||
previousCvarValues.SetString(buffer, prevValue);
|
||||
}
|
||||
this.SetString(value);
|
||||
}
|
||||
}
|
||||
|
||||
static char buffer[128];
|
||||
|
||||
methodmap GuessWhoGame {
|
||||
|
||||
property int Seeker {
|
||||
public get() {
|
||||
if(currentSeeker > 0 && IsClientConnected(currentSeeker)) {
|
||||
return currentSeeker;
|
||||
} else {
|
||||
return this._FindSeeker();
|
||||
}
|
||||
if(currentSeeker <= 0 || !IsClientConnected(currentSeeker))
|
||||
currentSeeker = this._FindSeeker();
|
||||
return currentSeeker;
|
||||
}
|
||||
public set(int client) {
|
||||
for(int i = 1; i <= MaxClients; i++) {
|
||||
|
@ -258,6 +223,13 @@ methodmap GuessWhoGame {
|
|||
}
|
||||
}
|
||||
|
||||
public void SetPoints(MovePoints points) {
|
||||
if(movePoints != null) {
|
||||
delete movePoints;
|
||||
}
|
||||
movePoints = points;
|
||||
}
|
||||
|
||||
// Ignores seeker
|
||||
property int AlivePlayers {
|
||||
public get() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue