Expose optional default values for the GetEvent* SP functions.

This commit is contained in:
Ryan Stecker 2014-09-12 16:39:21 -05:00
parent 570570f7a0
commit 3ffd4cd835
2 changed files with 36 additions and 8 deletions

View File

@ -207,7 +207,13 @@ static cell_t sm_GetEventBool(IPluginContext *pContext, const cell_t *params)
char *key; char *key;
pContext->LocalToString(params[2], &key); pContext->LocalToString(params[2], &key);
return pInfo->pEvent->GetBool(key); bool defValue = false;
if (params[0] > 2)
{
defValue = !!params[3];
}
return pInfo->pEvent->GetBool(key, defValue);
} }
static cell_t sm_GetEventInt(IPluginContext *pContext, const cell_t *params) static cell_t sm_GetEventInt(IPluginContext *pContext, const cell_t *params)
@ -226,7 +232,13 @@ static cell_t sm_GetEventInt(IPluginContext *pContext, const cell_t *params)
char *key; char *key;
pContext->LocalToString(params[2], &key); pContext->LocalToString(params[2], &key);
return pInfo->pEvent->GetInt(key); int defValue = 0;
if (params[0] > 2)
{
defValue = params[3];
}
return pInfo->pEvent->GetInt(key, defValue);
} }
static cell_t sm_GetEventFloat(IPluginContext *pContext, const cell_t *params) static cell_t sm_GetEventFloat(IPluginContext *pContext, const cell_t *params)
@ -245,7 +257,13 @@ static cell_t sm_GetEventFloat(IPluginContext *pContext, const cell_t *params)
char *key; char *key;
pContext->LocalToString(params[2], &key); pContext->LocalToString(params[2], &key);
float value = pInfo->pEvent->GetFloat(key); float defValue = 0.0f;
if (params[0] > 2)
{
defValue = sp_ctof(params[3]);
}
float value = pInfo->pEvent->GetFloat(key, defValue);
return sp_ftoc(value); return sp_ftoc(value);
} }
@ -266,7 +284,13 @@ static cell_t sm_GetEventString(IPluginContext *pContext, const cell_t *params)
char *key; char *key;
pContext->LocalToString(params[2], &key); pContext->LocalToString(params[2], &key);
pContext->StringToLocalUTF8(params[3], params[4], pInfo->pEvent->GetString(key), NULL); char *defValue = "";
if (params[0] > 4)
{
pContext->LocalToString(params[5], &defValue);
}
pContext->StringToLocalUTF8(params[3], params[4], pInfo->pEvent->GetString(key, defValue), NULL);
return 1; return 1;
} }

View File

@ -145,10 +145,11 @@ native CancelCreatedEvent(Handle:event);
* *
* @param event Handle to the event. * @param event Handle to the event.
* @param key Name of event key. * @param key Name of event key.
* @param defValue Optional default value to use if the key is not found.
* @return The boolean value of the specfied event key. * @return The boolean value of the specfied event key.
* @error Invalid or corrupt Handle. * @error Invalid or corrupt Handle.
*/ */
native bool:GetEventBool(Handle:event, const String:key[]); native bool:GetEventBool(Handle:event, const String:key[], bool:defValue=false);
/** /**
* Sets the boolean value of a game event's key. * Sets the boolean value of a game event's key.
@ -166,10 +167,11 @@ native SetEventBool(Handle:event, const String:key[], bool:value);
* *
* @param event Handle to the event. * @param event Handle to the event.
* @param key Name of event key. * @param key Name of event key.
* @param defValue Optional default value to use if the key is not found.
* @return The integer value of the specfied event key. * @return The integer value of the specfied event key.
* @error Invalid or corrupt Handle. * @error Invalid or corrupt Handle.
*/ */
native GetEventInt(Handle:event, const String:key[]); native GetEventInt(Handle:event, const String:key[], defValue=0);
/** /**
* Sets the integer value of a game event's key. * Sets the integer value of a game event's key.
@ -192,10 +194,11 @@ native SetEventInt(Handle:event, const String:key[], value);
* *
* @param event Handle to the event. * @param event Handle to the event.
* @param key Name of event key. * @param key Name of event key.
* @param defValue Optional default value to use if the key is not found.
* @return The floating point value of the specfied event key. * @return The floating point value of the specfied event key.
* @error Invalid or corrupt Handle. * @error Invalid or corrupt Handle.
*/ */
native Float:GetEventFloat(Handle:event, const String:key[]); native Float:GetEventFloat(Handle:event, const String:key[], Float:defValue=0.0);
/** /**
* Sets the floating point value of a game event's key. * Sets the floating point value of a game event's key.
@ -215,10 +218,11 @@ native SetEventFloat(Handle:event, const String:key[], Float:value);
* @param key Name of event key. * @param key Name of event key.
* @param value Buffer to store the value of the specified event key. * @param value Buffer to store the value of the specified event key.
* @param maxlength Maximum length of string buffer. * @param maxlength Maximum length of string buffer.
* @param defValue Optional default value to use if the key is not found.
* @noreturn * @noreturn
* @error Invalid or corrupt Handle. * @error Invalid or corrupt Handle.
*/ */
native GetEventString(Handle:event, const String:key[], String:value[], maxlength); native GetEventString(Handle:event, const String:key[], String:value[], maxlength, const String:defvalue[]="");
/** /**
* Sets the string value of a game event's key. * Sets the string value of a game event's key.