Changed model config to key/value format and improved model module features. Model access isn't tested yet, but base stuff works. Minior fixes.

Added more random model selection presets: public, admins, hidden and mother zombies.
Simplified ClassFlagFilterMatch logic.
This commit is contained in:
richard
2009-11-17 08:47:39 +01:00
parent 8c1a549239
commit 66ed43dd48
8 changed files with 824 additions and 309 deletions

View File

@ -77,24 +77,64 @@ bool:ClassApplyAttributes(client, bool:improved = false)
*/
bool:ClassApplyModel(client, classindex, cachetype = ZR_CLASS_CACHE_PLAYER)
{
new bool:isAttributePreset = false;
decl String:modelpath[PLATFORM_MAX_PATH];
new index;
new ModelTeam:team;
new access;
new model;
// Get the model path from the specified cache.
// Get correct index according to cache type.
if (cachetype == ZR_CLASS_CACHE_PLAYER)
{
ClassGetModelPath(client, modelpath, sizeof(modelpath), cachetype);
index = client;
}
else
{
ClassGetModelPath(classindex, modelpath, sizeof(modelpath), cachetype);
index = classindex;
}
// Check if the user specified a pre-defined model setting.
// Get the model path from the specified cache.
ClassGetModelPath(index, modelpath, sizeof(modelpath), cachetype);
// Get model team setting from the specified cache.
team = ModelsTeamIdToTeam(ClassGetTeamID(index, cachetype));
// Check if the user specified a pre-defined model setting. If so, setup
// model filter settings.
if (StrEqual(modelpath, "random", false))
{
// TODO: Make a function that gets a random model from the specified team.
ModelsGetRandomModelIndex(modelpath, sizeof(modelpath), false, true);
Format(modelpath, sizeof(modelpath), "%s.mdl", modelpath);
// Set access filter flags.
access = MODEL_ACCESS_PUBLIC | MODEL_ACCESS_ADMINS;
// Specify client for including admin models if client is admin.
index = client;
isAttributePreset = true;
}
else if (StrEqual(modelpath, "random_public", false))
{
access = MODEL_ACCESS_PUBLIC;
index = -1;
isAttributePreset = true;
}
else if (StrEqual(modelpath, "random_hidden", false))
{
access = MODEL_ACCESS_HIDDEN;
index = -1;
isAttributePreset = true;
}
else if (StrEqual(modelpath, "random_admin", false))
{
access = MODEL_ACCESS_ADMINS;
index = -1;
isAttributePreset = true;
}
else if (StrEqual(modelpath, "random_mother_zombie", false))
{
access = MODEL_ACCESS_MOTHER_ZOMBIES;
index = -1;
isAttributePreset = true;
}
else if (StrEqual(modelpath, "default", false))
{
@ -112,12 +152,33 @@ bool:ClassApplyModel(client, classindex, cachetype = ZR_CLASS_CACHE_PLAYER)
return true;
}
}
else if (StrEqual(modelpath, "nochange", false))
else if (StrEqual(modelpath, "no_change", false))
{
// Do nothing.
return true;
}
// Check if model setting is a attribute preset.
if (isAttributePreset)
{
// Get model based on filter settings set up earlier.
model = ModelsGetRandomModel(index, team, access);
// Check if found.
if (model >= 0)
{
// Get model path.
ModelsGetFullPath(model, modelpath, sizeof(modelpath));
}
else
{
// Couldn't find any models based on filter. Fall back to a random
// public model. Then get its path.
model = ModelsGetRandomModel(-1, team, MODEL_ACCESS_PUBLIC);
ModelsGetFullPath(model, modelpath, sizeof(modelpath));
}
}
SetEntityModel(client, modelpath);
return true;
}

View File

@ -162,8 +162,12 @@ stock ClassValidateAttributes(classindex)
}
else
{
// Check if a model different from a pre-defined setting.
// Validate only if not a pre-defined setting.
if (!StrEqual(model_path, "random", false) &&
!StrEqual(model_path, "random_public", false) &&
!StrEqual(model_path, "random_hidden", false) &&
!StrEqual(model_path, "random_admins", false) &&
!StrEqual(model_path, "random_mother_zombies", false) &&
!StrEqual(model_path, "default", false) &&
!StrEqual(model_path, "nochange", false))
{
@ -172,7 +176,7 @@ stock ClassValidateAttributes(classindex)
{
flags += ZR_CLASS_MODEL_PATH;
}
}
}
}
// Alpha, initial.
@ -705,8 +709,8 @@ stock bool:ClassFilterMatch(index, filter[ClassFilter], cachetype = ZR_CLASS_CAC
stock bool:ClassFlagFilterMatch(index, require, deny, cachetype)
{
new flags;
new bool:requirepassed;
new bool:denypassed;
new bool:requirepassed = false;
new bool:denypassed = false;
// Do quick check for optimization reasons: Check if no flags are specified.
if (require == 0 && deny == 0)
@ -723,11 +727,6 @@ stock bool:ClassFlagFilterMatch(index, require, deny, cachetype)
// All required flags are set.
requirepassed = true;
}
else
{
// Not all required flags are set.
requirepassed = false;
}
// Match deny filter.
if (deny == 0 || !(flags & deny))
@ -735,11 +734,6 @@ stock bool:ClassFlagFilterMatch(index, require, deny, cachetype)
// No denied flags are set.
denypassed = true;
}
else
{
// It has denied flags set.
denypassed = false;
}
// Check if required and denied flags passed the filter.
if (requirepassed && denypassed)
@ -747,11 +741,9 @@ stock bool:ClassFlagFilterMatch(index, require, deny, cachetype)
// The class pass the filter.
return true;
}
else
{
// The class didn't pass the filter.
return false;
}
// The class didn't pass the filter.
return false;
}
/**

View File

@ -376,11 +376,6 @@ new ClassNoFilter[ClassFilter];
*/
new ClassNoSpecialClasses[ClassFilter] = {false, 0, ZR_CLASS_SPECIALFLAGS, -1};
/**
* Keyvalue handle to store class data.
*/
new Handle:kvClassData = INVALID_HANDLE;
/**
* The original class data. This array only changed when class data is loaded.
* ZR_CLASS_CACHE_ORIGINAL is the cache type to this array.
@ -413,7 +408,7 @@ new Float:ClassMultiplierCache[ZR_CLASS_TEAMCOUNT][ClassMultipliers];
new ClassCount;
/**
* Specifies wether the class team requirement and attributes are valid or not.
* Specifies whether the class team requirements and attributes are valid or not.
* Used to block events that happend before the module is done loading.
*/
new bool:ClassValidated;
@ -485,11 +480,9 @@ ClassLoad()
// Register config file.
ConfigRegisterConfig(File_Classes, Structure_Keyvalue, CONFIG_FILE_ALIAS_CLASSES);
new Handle:kvClassData;
// Make sure kvClassData is ready to use.
if (kvClassData != INVALID_HANDLE)
{
CloseHandle(kvClassData);
}
kvClassData = CreateKeyValues(CONFIG_FILE_ALIAS_CLASSES);
// Get weapons config path.