Skip to content

Commit

Permalink
API overhaul
Browse files Browse the repository at this point in the history
- Added api example plugin
- Sound types are no longer hardcoded, extend as you wish
- Added custom per-model properties support
- Added forward `ModelChooser_OnConfigLoaded`
- Added natives `ModelChooser_GetCurrentModelProperty`, `ModelChooser_OpenChooser`, `ModelChooser_PlayRandomSound`
`ModelChooser_GetProperty`, `ModelChooser_GetModelList`, `ModelChooser_GetSoundMap`
  • Loading branch information
Alienmario committed Dec 15, 2024
1 parent ac06f2f commit 445663c
Show file tree
Hide file tree
Showing 18 changed files with 648 additions and 319 deletions.
1 change: 1 addition & 0 deletions .github/workflows/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ jobs:
- name: Create package
run: |
rm plugins/modelchooser_api_example.smx
OUT="/tmp/build"
SM="${OUT}/addons/sourcemod"
mkdir -p $SM/configs
Expand Down
7 changes: 7 additions & 0 deletions configs-bms/player_models.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@
"path" "models/example.ext"
"path" "models/another.ext"
}

// Extensibility support for plugin API
"custom"
{
"key" "value"
}

}

// ----------------------------------------------------------------------------------------
Expand Down
7 changes: 7 additions & 0 deletions configs-hl2mp/player_models.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@
"path" "models/example.ext"
"path" "models/another.ext"
}

// Extensibility support for plugin API
"custom"
{
"key" "value"
}

}

// ----------------------------------------------------------------------------------------
Expand Down
43 changes: 0 additions & 43 deletions scripting/include/model_chooser.inc

This file was deleted.

77 changes: 0 additions & 77 deletions scripting/include/model_chooser/natives.inc

This file was deleted.

75 changes: 75 additions & 0 deletions scripting/include/modelchooser.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#if defined _model_chooser_included
#endinput
#endif
#define _model_chooser_included

#define MODELCHOOSER_LIBRARY "ModelChooser"

public SharedPlugin __pl_model_chooser =
{
name = MODELCHOOSER_LIBRARY,
file = "ultimate_modelchooser.smx",
#if defined REQUIRE_PLUGIN
required = 1,
#else
required = 0,
#endif
};

#if !defined REQUIRE_PLUGIN
public void __pl_model_chooser_SetNTVOptional()
{
MarkNativeAsOptional("ModelChooser_GetCurrentModelName");
MarkNativeAsOptional("ModelChooser_GetCurrentModelPath");
MarkNativeAsOptional("ModelChooser_GetCurrentModelProperty");
MarkNativeAsOptional("ModelChooser_UnlockModel");
MarkNativeAsOptional("ModelChooser_LockModel");
MarkNativeAsOptional("ModelChooser_SelectModel");
MarkNativeAsOptional("ModelChooser_IsClientChoosing");
MarkNativeAsOptional("ModelChooser_OpenChooser");
MarkNativeAsOptional("ModelChooser_PlayRandomSound");
MarkNativeAsOptional("ModelChooser_GetProperty");
MarkNativeAsOptional("ModelChooser_GetModelList");
MarkNativeAsOptional("ModelChooser_GetSoundMap");
}
#endif

/* Forwards */

forward void ModelChooser_OnConfigLoaded();

forward void ModelChooser_OnModelChanged(int client, const char[] modelName);

/* Natives */

native bool ModelChooser_GetCurrentModelName(int client, char[] modelName, int maxLength);

native bool ModelChooser_GetCurrentModelPath(int client, char[] modelPath, int maxLength);

native bool ModelChooser_GetCurrentModelProperty(int client, const char[] key, char[] value, int maxLength);

native bool ModelChooser_UnlockModel(int client, const char[] modelName, bool select = false);

native bool ModelChooser_LockModel(int client, const char[] modelName);

native bool ModelChooser_SelectModel(int client, const char[] modelName);

native bool ModelChooser_IsClientChoosing(int client);

native bool ModelChooser_OpenChooser(int client, bool printErrorMsg);

native bool ModelChooser_PlayRandomSound(int client, const char[] soundType, bool toAll = false, bool stopLast = true, int pitch = 100, float volume = 1.0);

native bool ModelChooser_GetProperty(const char[] modelName, const char[] key, char[] value, int maxLength);

#if defined MODELCHOOSER_RAWDOG_API

#include <sdktools>
#include <clientprefs>
#include <modelchooser/structs>

native ModelList ModelChooser_GetModelList();

native SoundMap ModelChooser_GetSoundMap();

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,8 @@ int GetCustomSequenceForAnim(int client, PLAYER_ANIM playerAnim, float &playback
float time = GetGameTime();
if (time > nextJumpSound[client])
{
{
SoundPack soundPack;
GetSoundPack(model, soundPack);
PlayRandomSound(soundPack.jumpSounds, client, client, SNDCHAN_STATIC, true, JUMP_PITCH_MIN, JUMP_PITCH_MAX, JUMP_VOL);
nextJumpSound[client] = time + model.jumpSndParams.cooldown.Rand();
}
PlayRandomSound(GetSoundPack(model).GetSoundList("jump"), client, client, SNDCHAN_STATIC, true, JUMP_PITCH_MIN, JUMP_PITCH_MAX, JUMP_VOL);
nextJumpSound[client] = time + model.jumpSndParams.cooldown.Rand();
}
}
else if (playerAnim == PLAYER_WALK)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public Action Command_UnlockModel(int client, int args)
return Plugin_Handled;
}

char arg1[65], arg2[MAX_MODELNAME];
char arg1[65], arg2[MODELCHOOSER_MAX_NAME];
GetCmdArg(1, arg1, sizeof(arg1));
GetCmdArg(2, arg2, sizeof(arg2));

Expand All @@ -42,8 +42,7 @@ public Action Command_UnlockModel(int client, int args)

String_ToUpper(arg2, arg2, sizeof(arg2));

PlayerModel model;
if (modelList.FindByName(arg2, model) == -1)
if (modelList.FindByName(arg2) == -1)
{
ReplyToCommand(client, "Model named %s doesn't exist!", arg2);
return Plugin_Handled;
Expand Down Expand Up @@ -74,7 +73,7 @@ public Action Command_LockModel(int client, int args)
return Plugin_Handled;
}

char arg1[65], arg2[MAX_MODELNAME];
char arg1[65], arg2[MODELCHOOSER_MAX_NAME];
GetCmdArg(1, arg1, sizeof(arg1));
GetCmdArg(2, arg2, sizeof(arg2));

Expand All @@ -98,8 +97,7 @@ public Action Command_LockModel(int client, int args)

String_ToUpper(arg2, arg2, sizeof(arg2));

PlayerModel model;
if (modelList.FindByName(arg2, model) == -1)
if (modelList.FindByName(arg2) == -1)
{
ReplyToCommand(client, "Model named %s doesn't exist!", arg2);
return Plugin_Handled;
Expand Down
Loading

0 comments on commit 445663c

Please sign in to comment.