Finished base management for volumetric features. Code compiles, but this feature is not tested so far!

Made CVARs for volumetric features module.
Made trigger delay attribute for volumes, per player. Count down for n seconds after when a player enter. When leaving a volume trigger delay is aborted.
Made parameter parsing functions; paramtools.inc.
Made functions for setting and parsing generic volume attributes.
Updated header in files to volumetric features and paramtools.inc.
Removed unused knockback functions in zadmin.inc.
Made certain class functions into stock functions.
This commit is contained in:
richard
2009-05-30 04:17:01 +02:00
parent d466ab8b24
commit 433fd41ede
14 changed files with 1207 additions and 131 deletions

View File

@ -1,11 +1,26 @@
/*
* ============================================================================
*
* Zombie:Reloaded
* Zombie:Reloaded
*
* File: volanticamp.inc
* Type: Module
* Description: Anti-camp handler.
* File: volanticamp.inc
* Type: Module
* Description: Anti-camp handler.
*
* Copyright (C) 2009 Greyscale, Richard Helgeby
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ============================================================================
*/
@ -15,9 +30,37 @@
*/
enum VolTypeAnticamp
{
anticamp_damage,
anticamp_interval,
Handle:anticamp_timer
Float:anticamp_interval, /** How often to trigger an action. */
Handle:anticamp_timer, /** Action timer handle. */
VolAnticampAction:antivamp_action, /** What to do with players in anti-camp volumes */
Float:anticamp_amount, /** Amount depending on action type. Usually time in seconds or damage amount. */
VolAnticampeWarningType:anticamp_warning, /** How to warn the player. */
String:anticamp_message[256] /** Override warning message. Max 256 characters. */
}
/**
* Actions to do with players in anti-camp volumes.
*/
enum VolAnticampAction
{
anticamp_no_action, /** Do nothing but give a warning. */
anticamp_damage, /** Give damage to player. */
anticamp_slay, /** Slay player. */
anticamp_drug, /** Drug player. */
anticamp_fire /** Ignite player. */
}
/**
* Warning types.
*/
enum VolAnticampeWarningType
{
anticamp_no_warning, /** No warning messages. */
anticamp_chat, /** Print warning in chat area. */
anticamp_center, /** Print centered warning message. */
anticamp_menu /** Print a menu-like warning message with close option. */
}
/**

View File

@ -0,0 +1,225 @@
/*
* ============================================================================
*
* Zombie:Reloaded
*
* File: volcommands.inc
* Type: Module
* Description: Command handler for volumetric features.
*
* Copyright (C) 2009 Greyscale, Richard Helgeby
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ============================================================================
*/
/*
Add volume
------------
Syntax:
zr_vol_add <x1> <y1> <z1> <x2> <y2> <z2> <type> [params]
Parameters:
zn, yn, zn Max and min location.
type Feature type.
params A string with optional parameters:
team=all|humans|zombies
delay=0
effect=none|wireframe|smoke
effect_color=0,0,0
enabled=1
Example:
zr_vol_add 0 0 0 100 200 300 anticamp team=humans delay=5 effect=wireframe effect_color=255,0,0
*/
public Action:VolAddVolumeCommand(client, argc)
{
}
/**
* Creates a new volume with minimum parameters.
*
* Note: Extra volume attributes must be set using VolSetAttributes.
*
* @param locMin Minimum x, y and z values.
* @param locMax Maximum x, y and z values.
* @param volumeType Specifies the volumetric feature type.
* @param dataIndex Data index in remote array for feature data.
*
* @return The new volume index, or -1 if failed.
*/
VolAdd(Float:locMin[3], Float:locMax[3], VolumeFeatureTypes:volumeType, dataIndex)
{
new volumeIndex;
// Get a free volume index.
volumeIndex = VolGetFreeVolume();
// Validate index.
if (volumeIndex >= 0)
{
// Mark volume as enabled and in use.
Volumes[volumeIndex][vol_enabled] = true;
Volumes[volumeIndex][vol_in_use] = true;
// Set location data.
Volumes[volumeIndex][vol_x_min] = locMin[0];
Volumes[volumeIndex][vol_y_min] = locMin[1];
Volumes[volumeIndex][vol_z_min] = locMin[2];
Volumes[volumeIndex][vol_x_max] = locMax[0];
Volumes[volumeIndex][vol_y_max] = locMax[1];
Volumes[volumeIndex][vol_z_max] = locMax[2];
// Set type.
Volumes[volumeIndex][vol_type] = volumeType;
Volumes[volumeIndex][vol_data_index] = dataIndex;
// Return the new index.
return volumeIndex;
}
else
{
// No free volumes.
return -1;
}
}
/**
* Removes the specified volume.
*
* @param volumeIndex The volume index.
* @return True if successful, false otherwise.
*/
bool:VolRemove(volumeIndex)
{
// Validate index.
if (volumeIndex >= 0)
{
// Trigger event.
VolOnVolumeDisabled(volumeIndex);
// Mark volume as disabled and unused.
Volumes[volumeIndex][vol_enabled] = false;
Volumes[volumeIndex][vol_in_use] = false;
return true;
}
else
{
// Invalid index.
return false;
}
}
/**
* Sets extra attributes on a volume.
*
* @param volumeIndex The volume index.
* @param attributes A string with one or more attributes in key=value
* format.
* @return Number of successful attributes set, -1 on error.
*/
VolSetAttributes(volumeIndex, const String:attributes[])
{
new attribCount;
new successfulCount;
decl String:attribName[64];
decl String:attribValue[256];
// Validate volume index.
if (!VolIsValidIndex(volumeIndex))
{
return -1;
}
// Count attributes.
attribCount = GetParameterCount(attributes);
// Check if empty.
if (!attribCount)
{
return -1;
}
// Loop through all attributes.
for (new attrib = 0; attrib > attribCount; attrib++)
{
// Get attribute name.
GetParameterName(attribName, sizeof(attribName), attributes, attrib);
// Get attribute value.
GetParameterValue(attribValue, sizeof(attribValue), attributes, attribName);
// Check names and set volume attributes.
if (strcmp(attribName, "team", false))
{
// Parse team string value.
if (VolSetTeamString(volumeIndex, attribValue))
{
successfulCount++;
}
}
else if (strcmp(attribName, "delay", false))
{
// Parse delay string value.
if (VolSetDelayString(volumeIndex, attribValue))
{
successfulCount++;
}
}
else if (strcmp(attribName, "effect", false))
{
// Parse effect string value.
if (VolSetEffectString(volumeIndex, attribValue))
{
successfulCount++;
}
}
else if (strcmp(attribName, "effect_color", false))
{
// Parse effect color string value.
if (VolSetEffectColorString(volumeIndex, attribValue))
{
successfulCount++;
}
}
else if (strcmp(attribName, "enabled", false))
{
// Parse enabled string value.
if (VolSetEnabledString(volumeIndex, attribValue))
{
successfulCount++;
}
}
}
// Return number of successfully attributes set.
return successfulCount;
}
/**
* Creates commands for managing volumes.
*/
VolOnCommandsCreate()
{
RegAdminCmd("zr_vol_add", VolAddVolumeCommand, ADMFLAG_GENERIC, "Adds a new volume. Usage: zr_vol_add <x1> <y1> <z1> <x2> <y2> <z2> <type> [params]");
}

View File

@ -1,11 +1,26 @@
/*
* ============================================================================
*
* Zombie:Reloaded
* Zombie:Reloaded
*
* File: volevents.inc
* Type: Module
* Description: Handles volumetric feature events.
* File: volevents.inc
* Type: Module
* Description: Handles generic events for volumetric features.
*
* Copyright (C) 2009 Greyscale, Richard Helgeby
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ============================================================================
*/
@ -18,7 +33,12 @@
*/
VolOnPlayerEnter(client, volumeIndex)
{
// TODO: Check if volfeatures is enabled first.
// Check if volumetric features is enabled.
if (!VolEnabled)
{
// Volumetric features disabled.
return;
}
// Forward event to features.
// VolAnticampStart(client, volume);
@ -32,7 +52,12 @@ VolOnPlayerEnter(client, volumeIndex)
*/
VolOnPlayerLeave(client, volumeIndex)
{
// TODO: Check if volfeatures is enabled first.
// Check if volumetric features is enabled.
if (!VolEnabled)
{
// Volumetric features disabled.
return;
}
// Forward event to features.
// VolAnticampStop(client, volume);
@ -45,14 +70,40 @@ VolOnPlayerLeave(client, volumeIndex)
*/
VolOnPlayerSpawn(client)
{
// Check if volumetric features is enabled.
if (!VolEnabled)
{
// Volumetric features disabled.
return;
}
// Cache player location.
VolUpdatePlayerLocation(client);
}
/**
* Called when a player disconnects.
*
* @param client The client index.
*/
VolOnPlayerDisconnect(client)
{
// Disable trigger delay counters.
VolResetCountDown(client);
}
/**
* Called when the round starts. Main enable event for volumetric features.
*/
VolOnRoundStart()
{
// Check if volumetric features is enabled.
if (!VolEnabled)
{
// Volumetric features disabled.
return;
}
// Start main timer.
VolStartUpdateTimer();
}
@ -68,3 +119,23 @@ VolOnRoundEnd()
// Forward stop event to features.
// VolAnticampStop();
}
/**
* Called when a volume is disabled.
* @param volumeIndex The volume index.
*/
VolOnVolumeDisabled(volumeIndex)
{
// Forward stop event to features.
}
/**
* Called when a volume is enabled.
* @param volumeIndex The volume index.
*/
VolOnVolumeEnabled(volumeIndex)
{
// Forward start event to features.
}

View File

@ -1,11 +1,26 @@
/*
* ============================================================================
*
* Zombie:Reloaded
* Zombie:Reloaded
*
* File: volfeatures.inc
* Type: Module
* Description: Provides functions for managing volumetric features.
* File: volfeatures.inc
* Type: Module
* Description: Provides functions for managing volumetric features.
*
* Copyright (C) 2009 Greyscale, Richard Helgeby
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ============================================================================
*/
@ -21,23 +36,30 @@
enum VolumeAttributes
{
/* General */
bool:vol_enabled, /** Volume state. */
bool:vol_in_use, /** Marks if the volume is used. */
bool:vol_enabled, /** Volume state. */
bool:vol_in_use, /** Marks if the volume is used. */
/* Location */
Float:vol_x_min, /** Minimum x position. */
Float:vol_x_max, /** Maximum x position. */
Float:vol_x_min, /** Minimum x position. */
Float:vol_x_max, /** Maximum x position. */
Float:vol_y_min, /** Minimum y position. */
Float:vol_y_max, /** Maximum y position. */
Float:vol_y_min, /** Minimum y position. */
Float:vol_y_max, /** Maximum y position. */
Float:vol_z_min, /** Minimum z position. */
Float:vol_z_max, /** Maximum z position. */
Float:vol_z_min, /** Minimum z position. */
Float:vol_z_max, /** Maximum z position. */
/* Style */
VolumeEffects:vol_effect, /** Visual effect to apply on the volume. */
vol_effect_color[3], /** Render color of the effect. RGB colors. */
/* Data */
VolumeEffects:vol_effect, /** Visual effect to apply on the volume. */
VolumeFeatureTypes:vol_type, /** The volumetric feature type. */
vol_data_index /** Index in remote feature array. */
VolumeFeatureTypes:vol_type, /** The volumetric feature type. */
vol_data_index, /** Index in remote feature array. */
/* Behaviour */
VolumeTeamFilters:vol_team_filter, /** Team filtering. Trigger by certain teams, or all. */
Float:vol_trigger_delay /** Trigger delay. How many seconds players have to stay to trigger volume events. */
}
/**
@ -49,6 +71,9 @@ enum VolumeFeatureTypes
VolFeature_Knockback
}
/**
* Effects that can be applied on a volume. (Currently no effects.)
*/
enum VolumeEffects
{
VolEffect_None = 0,
@ -56,6 +81,16 @@ enum VolumeEffects
VolEffect_Smoke
}
/**
* Available team filter settings.
*/
enum VolumeTeamFilters
{
VolTeam_All = 0,
VolTeam_Humans,
VolTeam_Zombies
}
/**
* Volumes.
*/
@ -72,56 +107,95 @@ new VolumeCount;
new Float:VolPlayerLoc[MAXPLAYERS + 1][3];
/**
* Specifies whether the volumetric features module is enabled or not. To be
* synced with zr_volfeatures_enabled CVAR.
* Specifies whether the volumetric features module is enabled or not. Synced
* with zr_vol CVAR.
*/
new bool:VolEnabled;
/**
* Timer handle for timer that updates player locations. This is the main timer
* Counter for trigger delay.
*/
new Float:VolPlayerCountDown[MAXPLAYERS + 1][ZR_VOLUMES_MAX];
/**
* The handle for a timer that updates player locations. This is the main timer
* and any feature events can't be updated faster than this interval.
*
* Note: Some features may have its own timer.
*/
new Handle:hVolUpdateTimer;
/**
* The handle for a timer that do count down on trigger delays.
*/
new Handle:hVolTriggerTimer;
/**
* Cached interval value for trigger timer.
*/
new Float:VolTriggerInterval;
#include "zr/volfeatures/volevents"
#include "zr/volfeatures/volgenericattributes"
#include "zr/volfeatures/volcommands"
#include "zr/volfeatures/volanticamp"
/**
* Initialize volumetric features.
*/
VolLoad()
{
// Cache CVAR value.
VolEnabled = GetConVarBool(g_hCvarsList[CVAR_VOL]);
}
/**
* Function alias for fully stopping volumetric features.
*/
VolDisable()
{
VolEnabled = false;
VolStopUpdateTimer();
// TODO: Send disable/stop event to volumes with their own timers.
}
/**
* Starts the update timer.
*
* @return True if timer is started, false otherwise.
*/
bool:VolStartUpdateTimer()
{
// TODO: Read from CVAR (zr_volfeatures_enabled).
VolEnabled = true;
// Check if volumetric features is enabled.
if (!VolEnabled)
{
// Volumetric features disabled.
return false;
}
// TODO: Read from CVAR (zr_volfeatures_interval).
new Float:interval = 1.0;
// Stop timer if it exist.
VolStopUpdateTimer();
// Get update interval.
new Float:interval = GetConVarFloat(g_hCvarsList[CVAR_VOL_UPDATE_INTERVAL]);
// Validate interval.
if (interval > 0.0)
{
// Stop timer if it exist.
VolStopUpdateTimer();
// Create a new timer.
hVolUpdateTimer = CreateTimer(interval, Event_VolUpdateTimer, _, TIMER_REPEAT);
// Also start the trigger delay timer.
VolStartTriggerTimer();
// Volumetric features started.
return true;
}
else
{
// Volumetric features disabled. Do explicit stop.
VolStopUpdateTimer();
// Volumetric features disabled.
return false;
}
}
@ -137,6 +211,84 @@ VolStopUpdateTimer()
KillTimer(hVolUpdateTimer);
hVolUpdateTimer = INVALID_HANDLE;
}
// Also stop trigger delay timer.
VolStopTriggerTimer();
// Reset all trigger delay counters.
VolResetCountDown();
}
/**
* Starts the update timer if it exists.
*
* @return True if timer is started, false otherwise.
*/
bool:VolStartTriggerTimer()
{
// Make sure existing timer is killed.
VolStopTriggerTimer();
// Get trigger interval and cache it.
VolTriggerInterval = GetConVarFloat(g_hCvarsList[CVAR_VOL_TRIGGER_INTERVAL]);
// Validate interval.
if (VolTriggerInterval > 0.0)
{
// Start the timer.
hVolTriggerTimer = CreateTimer(VolTriggerInterval, Event_VolUpdateTimer, _, TIMER_REPEAT);
// Trigger timer started.
return true;
}
else
{
// Trigger timer not running. Either disabled or invalid interval.
return false;
}
}
/**
* Kills the trigger delay timer if it exists.
*/
VolStopTriggerTimer()
{
// Kill the timer if it's running.
if (hVolTriggerTimer != INVALID_HANDLE)
{
KillTimer(hVolTriggerTimer);
hVolTriggerTimer = INVALID_HANDLE;
}
}
/**
* Resets volume trigger delay counters on one or more players.
*
* @param client Optional. Specifies a single player to reset. Default is
* -1, all players.
*/
VolResetCountDown(client = -1)
{
// Check if a client is specified.
if (client > -1)
{
// Reset volume counters.
for (new volumeIndex = 0; volumeIndex < ZR_VOLUMES_MAX; volumeIndex++)
{
VolPlayerCountDown[client][volumeIndex] = -1.0;
}
}
else
{
// Reset all volume counters.
for (new clientIndex = 0; clientIndex <= MAXPLAYERS + 1; clientIndex++)
{
for (new volumeIndex = 0; volumeIndex < ZR_VOLUMES_MAX; volumeIndex++)
{
VolPlayerCountDown[clientIndex][volumeIndex] = -1.0;
}
}
}
}
/**
@ -157,7 +309,7 @@ VolUpdatePlayerLocation(client = -1)
}
else
{
for (new client = 1; client <= MaxClients; client++)
for (client = 1; client <= MaxClients; client++)
{
// Check if client is in game and alive.
if (!IsClientConnected(client) || !IsClientInGame(client) || !IsPlayerAlive(client))
@ -183,6 +335,9 @@ VolUpdatePlayerChanges()
new bool:newState;
new bool:oldState;
new Float:trigger_delay;
// Loop through all players.
for (new client = 1; client <= MaxClients; client++)
{
// Check if client is in game and alive.
@ -212,14 +367,33 @@ VolUpdatePlayerChanges()
// No change. Skip to next volume.
break;
}
// Check if client entered the volume.
else if (!newState && oldState)
{
// Client entered volume. Trigger event.
VolOnPlayerEnter(client, volumeIndex);
// Get trigger delay value.
trigger_delay = Volumes[volumeIndex][vol_trigger_delay];
// Check if the volume has a trigger delay.
if (trigger_delay > 0.0)
{
// Set count down value.
VolPlayerCountDown[client][volumeIndex] = trigger_delay;
}
else
{
// No trigger delay, trigger event instantly.
VolOnPlayerEnter(client, volumeIndex);
}
}
// Check if client left the volume.
else if (newState && !oldState)
{
// Client left the volume. Trigger event.
// Make sure count down value is reset.
VolPlayerCountDown[client][volumeIndex] = -1.0;
// Trigger event.
VolOnPlayerLeave(client, volumeIndex);
}
}
@ -264,6 +438,8 @@ bool:IsPositionInLocation(Float:pos[3], Float:min[3], Float:max[3])
/**
* Returns wether a volume is marked as in use.
*
* Note: Does not validate index.
*
* @param volumeIndex The volume index.
* @return True if in use, false otherwise.
*/
@ -272,6 +448,24 @@ bool:VolIsInUse(volumeIndex)
return Volumes[volumeIndex][vol_in_use];
}
/**
* Validates a volume index.
*
* @param volumeIndex The volume index.
* @return True if valid, false otherwise.
*/
bool:VolIsValidIndex(volumeIndex)
{
if (volumeIndex >= 0 && volumeIndex < ZR_VOLUMES_MAX)
{
return true;
}
else
{
return false;
}
}
/**
* Gets the first free volume index.
*
@ -354,3 +548,61 @@ public Action:Event_VolUpdateTimer(Handle:timer)
{
VolUpdatePlayerChanges();
}
/**
* Callback for trigger delay timer.
*/
public Action:Event_VolTriggerTimer(Handle:timer)
{
new Float:countDown;
// Loop through all players.
for (new client = 1; client <= MaxClients; client++)
{
// Loop through all volumes.
for (new volumeIndex = 0; volumeIndex < ZR_VOLUMES_MAX; volumeIndex++)
{
// Get count down value.
countDown = VolPlayerCountDown[client][volumeIndex];
// Check if volume trigger delay is enabled.
if (countDown > 0.0)
{
// Substract by trigger interval.
countDown -= VolTriggerInterval;
// Check if zero or below.
if (countDown <= 0.0)
{
// Trigger volume enter event.
VolOnPlayerEnter(client, volumeIndex);
// Reset count down value.
VolPlayerCountDown[client][volumeIndex] = -1.0;
}
}
}
}
}
/**
* Called when zr_vol CVAR is changed.
*/
public VolEnabledChanged(Handle:cvar, const String:oldvalue[], const String:newvalue[])
{
new bool:isEnabled = bool:StringToInt(newvalue);
if (isEnabled)
{
// Volumetric features is enabled.
VolEnabled = true;
// Start timers.
VolStartUpdateTimer();
}
else
{
// Volumetric features is disabled.
VolDisable();
}
}

View File

@ -0,0 +1,281 @@
/*
* ============================================================================
*
* Zombie:Reloaded
*
* File: volgenericattributes.inc
* Type: Module
* Description: Functions for getting or setting general volume attributes.
*
* Copyright (C) 2009 Greyscale, Richard Helgeby
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ============================================================================
*/
/**
* Parses a team string value and applies it to the specified volume.
*
* @param volumeIndex The volume index to apply to.
* @param team A team string value. Valid options: "all", "humans"
* and "zombies".
* @return True if successfully set, false otherwise.
*/
stock bool:VolSetTeamString(volumeIndex, const String:team[])
{
new VolumeTeamFilters:teamfilter;
// Check if string value is empty.
if (strlen(team) == 0)
{
return false;
}
// Convert value.
if (strcmp(team, "all", false))
{
teamfilter = VolTeam_All;
}
else if (strcmp(team, "humans", false))
{
teamfilter = VolTeam_Humans;
}
else if (strcmp(team, "zombies", false))
{
teamfilter = VolTeam_Zombies;
}
// Apply value.
Volumes[volumeIndex][vol_team_filter] = teamfilter;
return true;
}
/**
* Sets the feam filter attribute on a volume.
*
* @param volumeIndex The volume index to apply to.
* @param team The team filter value.
*/
stock VolSetTeam(volumeIndex, VolumeTeamFilters:team[])
{
Volumes[volumeIndex][vol_team_filter] = team;
}
/**
* Parses a delay string value and applies it to the specified volume.
*
* @param volumeIndex The volume index to apply to.
* @param delay The delay to apply. A floating point number formatted
* as a string.
* @return True if successfully set, false otherwise.
*/
stock bool:VolSetDelayString(volumeIndex, const String:delay[])
{
new Float:triggerdelay;
// Check if string value is empty.
if (strlen(delay) == 0)
{
return false;
}
// Convert value.
triggerdelay = StringToFloat(delay);
// Apply value.
Volumes[volumeIndex][vol_trigger_delay] = triggerdelay;
return true;
}
/**
* Sets the trigger delay attribute on a volume.
*
* @param volumeIndex The volume index to apply to.
* @param delay The trigger delay, in seconds.
*/
stock VolSetDelay(volumeIndex, Float:delay)
{
Volumes[volumeIndex][vol_trigger_delay] = delay;
}
/**
* Parses a effect string value and applies it to the specified volume.
*
* @param volumeIndex The volume index to apply to.
* @param effect A effect string value. Valid options: see VolumeEffects
* enumeration, exclude prefix.
* @return True if successfully set, false otherwise.
*/
stock bool:VolSetEffectString(volumeIndex, const String:effect[])
{
// Check if string value is empty.
if (strlen(effect) == 0)
{
return false;
}
// Check effect string values and apply them to the volume.
if (strcmp(effect, "none", false))
{
Volumes[volumeIndex][vol_effect] = VolEffect_None;
return true;
}
else if (strcmp(effect, "wireframe", false))
{
Volumes[volumeIndex][vol_effect] = VolEffect_Wireframe;
return true;
}
else if (strcmp(effect, "smoke", false))
{
Volumes[volumeIndex][vol_effect] = VolEffect_Smoke;
return true;
}
// The string value didn't match any valid effects.
return false;
}
/**
* Sets the effect attribute on a volume.
*
* @param volumeIndex The volume index to apply to.
* @param effect Specifies what effect to apply on the volume.
*/
stock VolSetEffect(volumeIndex, VolumeEffects:effect)
{
Volumes[volumeIndex][vol_effect] = effect;
}
/**
* Parses a effect color string value and applies it to the specified volume.
*
* @param volumeIndex The volume index to apply to.
* @param effect_color A effect color string value. No whitespace! Format
* (0-255): "red,green,blue".
* @return True if successfully set, false otherwise.
*/
stock bool:VolSetEffectColorString(volumeIndex, const String:effect_color[])
{
new String:colors[3][3];
new red, green, blue;
// Check if string value is empty.
if (strlen(effect_color) == 0)
{
return false;
}
// Split values into a string array.
ExplodeString(effect_color, ",", colors, 3, 3);
// Convert values.
red = StringToInt(colors[0]);
green = StringToInt(colors[1]);
blue = StringToInt(colors[2]);
// Apply values.
Volumes[volumeIndex][vol_effect_color][0] = red;
Volumes[volumeIndex][vol_effect_color][1] = green;
Volumes[volumeIndex][vol_effect_color][2] = blue;
return true;
}
/**
* Sets the effect color attribute on a volume.
*
* @param volumeIndex The volume index to apply to.
* @param red Amount of red color. 0 to 255.
* @param green Amount of green color. 0 to 255.
* @param blue Amount of blue color. 0 to 255.
*/
stock VolSetEffectColor(volumeIndex, red, green, blue)
{
Volumes[volumeIndex][vol_effect_color][0] = red;
Volumes[volumeIndex][vol_effect_color][1] = green;
Volumes[volumeIndex][vol_effect_color][2] = blue;
}
/**
* Parses a enabled string value and applies it to the specified volume.
*
* @param volumeIndex The volume index to apply to.
* @param enabled A enabled string value. Valid options: A number that
* evaluates to true or false, "yes" or "no".
* @return True if successfully set, false otherwise.
*/
stock bool:VolSetEnabledString(volumeIndex, const String:enabled[])
{
// Check if string value is empty.
if (strlen(enabled) == 0)
{
return false;
}
new bool:val = bool:StringToInt(enabled);
// Check yes or no values first.
if (strcmp(enabled, "yes", false) == 0)
{
val = true;
}
else if (strcmp(enabled, "no", false) == 0)
{
val = false;
}
// Check if the new value is different from the current.
if (Volumes[volumeIndex][vol_enabled] != val)
{
// Forward event.
if (val)
{
VolOnVolumeEnabled(volumeIndex);
}
else
{
VolOnVolumeDisabled(volumeIndex);
}
}
// Apply converted value.
Volumes[volumeIndex][vol_enabled] = val;
return true;
}
/**
* Sets the enabled attribute on a volume.
*
* @param volumeIndex The volume index to apply to.
* @param enabled Specifies if the volume should be enabled or not.
*/
stock VolSetEnabled(volumeIndex, bool:enabled)
{
// Check if the new value is different from the current.
if (Volumes[volumeIndex][vol_enabled] != enabled)
{
// Forward event.
if (enabled)
{
VolOnVolumeEnabled(volumeIndex);
}
else
{
VolOnVolumeDisabled(volumeIndex);
}
}
Volumes[volumeIndex][vol_enabled] = enabled;
}