Skip to content

Commit 445663c

Browse files
committed
API overhaul
- 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`
1 parent ac06f2f commit 445663c

File tree

18 files changed

+648
-319
lines changed

18 files changed

+648
-319
lines changed

.github/workflows/plugin.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ jobs:
6262
6363
- name: Create package
6464
run: |
65+
rm plugins/modelchooser_api_example.smx
6566
OUT="/tmp/build"
6667
SM="${OUT}/addons/sourcemod"
6768
mkdir -p $SM/configs

configs-bms/player_models.cfg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@
5959
"path" "models/example.ext"
6060
"path" "models/another.ext"
6161
}
62+
63+
// Extensibility support for plugin API
64+
"custom"
65+
{
66+
"key" "value"
67+
}
68+
6269
}
6370

6471
// ----------------------------------------------------------------------------------------

configs-hl2mp/player_models.cfg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@
7575
"path" "models/example.ext"
7676
"path" "models/another.ext"
7777
}
78+
79+
// Extensibility support for plugin API
80+
"custom"
81+
{
82+
"key" "value"
83+
}
84+
7885
}
7986

8087
// ----------------------------------------------------------------------------------------

scripting/include/model_chooser.inc

Lines changed: 0 additions & 43 deletions
This file was deleted.

scripting/include/model_chooser/natives.inc

Lines changed: 0 additions & 77 deletions
This file was deleted.

scripting/include/modelchooser.inc

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#if defined _model_chooser_included
2+
#endinput
3+
#endif
4+
#define _model_chooser_included
5+
6+
#define MODELCHOOSER_LIBRARY "ModelChooser"
7+
8+
public SharedPlugin __pl_model_chooser =
9+
{
10+
name = MODELCHOOSER_LIBRARY,
11+
file = "ultimate_modelchooser.smx",
12+
#if defined REQUIRE_PLUGIN
13+
required = 1,
14+
#else
15+
required = 0,
16+
#endif
17+
};
18+
19+
#if !defined REQUIRE_PLUGIN
20+
public void __pl_model_chooser_SetNTVOptional()
21+
{
22+
MarkNativeAsOptional("ModelChooser_GetCurrentModelName");
23+
MarkNativeAsOptional("ModelChooser_GetCurrentModelPath");
24+
MarkNativeAsOptional("ModelChooser_GetCurrentModelProperty");
25+
MarkNativeAsOptional("ModelChooser_UnlockModel");
26+
MarkNativeAsOptional("ModelChooser_LockModel");
27+
MarkNativeAsOptional("ModelChooser_SelectModel");
28+
MarkNativeAsOptional("ModelChooser_IsClientChoosing");
29+
MarkNativeAsOptional("ModelChooser_OpenChooser");
30+
MarkNativeAsOptional("ModelChooser_PlayRandomSound");
31+
MarkNativeAsOptional("ModelChooser_GetProperty");
32+
MarkNativeAsOptional("ModelChooser_GetModelList");
33+
MarkNativeAsOptional("ModelChooser_GetSoundMap");
34+
}
35+
#endif
36+
37+
/* Forwards */
38+
39+
forward void ModelChooser_OnConfigLoaded();
40+
41+
forward void ModelChooser_OnModelChanged(int client, const char[] modelName);
42+
43+
/* Natives */
44+
45+
native bool ModelChooser_GetCurrentModelName(int client, char[] modelName, int maxLength);
46+
47+
native bool ModelChooser_GetCurrentModelPath(int client, char[] modelPath, int maxLength);
48+
49+
native bool ModelChooser_GetCurrentModelProperty(int client, const char[] key, char[] value, int maxLength);
50+
51+
native bool ModelChooser_UnlockModel(int client, const char[] modelName, bool select = false);
52+
53+
native bool ModelChooser_LockModel(int client, const char[] modelName);
54+
55+
native bool ModelChooser_SelectModel(int client, const char[] modelName);
56+
57+
native bool ModelChooser_IsClientChoosing(int client);
58+
59+
native bool ModelChooser_OpenChooser(int client, bool printErrorMsg);
60+
61+
native bool ModelChooser_PlayRandomSound(int client, const char[] soundType, bool toAll = false, bool stopLast = true, int pitch = 100, float volume = 1.0);
62+
63+
native bool ModelChooser_GetProperty(const char[] modelName, const char[] key, char[] value, int maxLength);
64+
65+
#if defined MODELCHOOSER_RAWDOG_API
66+
67+
#include <sdktools>
68+
#include <clientprefs>
69+
#include <modelchooser/structs>
70+
71+
native ModelList ModelChooser_GetModelList();
72+
73+
native SoundMap ModelChooser_GetSoundMap();
74+
75+
#endif

scripting/include/model_chooser/anims.inc renamed to scripting/include/modelchooser/anims.inc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,8 @@ int GetCustomSequenceForAnim(int client, PLAYER_ANIM playerAnim, float &playback
6161
float time = GetGameTime();
6262
if (time > nextJumpSound[client])
6363
{
64-
{
65-
SoundPack soundPack;
66-
GetSoundPack(model, soundPack);
67-
PlayRandomSound(soundPack.jumpSounds, client, client, SNDCHAN_STATIC, true, JUMP_PITCH_MIN, JUMP_PITCH_MAX, JUMP_VOL);
68-
nextJumpSound[client] = time + model.jumpSndParams.cooldown.Rand();
69-
}
64+
PlayRandomSound(GetSoundPack(model).GetSoundList("jump"), client, client, SNDCHAN_STATIC, true, JUMP_PITCH_MIN, JUMP_PITCH_MAX, JUMP_VOL);
65+
nextJumpSound[client] = time + model.jumpSndParams.cooldown.Rand();
7066
}
7167
}
7268
else if (playerAnim == PLAYER_WALK)

scripting/include/model_chooser/commands.inc renamed to scripting/include/modelchooser/commands.inc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public Action Command_UnlockModel(int client, int args)
1818
return Plugin_Handled;
1919
}
2020

21-
char arg1[65], arg2[MAX_MODELNAME];
21+
char arg1[65], arg2[MODELCHOOSER_MAX_NAME];
2222
GetCmdArg(1, arg1, sizeof(arg1));
2323
GetCmdArg(2, arg2, sizeof(arg2));
2424

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

4343
String_ToUpper(arg2, arg2, sizeof(arg2));
4444

45-
PlayerModel model;
46-
if (modelList.FindByName(arg2, model) == -1)
45+
if (modelList.FindByName(arg2) == -1)
4746
{
4847
ReplyToCommand(client, "Model named %s doesn't exist!", arg2);
4948
return Plugin_Handled;
@@ -74,7 +73,7 @@ public Action Command_LockModel(int client, int args)
7473
return Plugin_Handled;
7574
}
7675

77-
char arg1[65], arg2[MAX_MODELNAME];
76+
char arg1[65], arg2[MODELCHOOSER_MAX_NAME];
7877
GetCmdArg(1, arg1, sizeof(arg1));
7978
GetCmdArg(2, arg2, sizeof(arg2));
8079

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

9998
String_ToUpper(arg2, arg2, sizeof(arg2));
10099

101-
PlayerModel model;
102-
if (modelList.FindByName(arg2, model) == -1)
100+
if (modelList.FindByName(arg2) == -1)
103101
{
104102
ReplyToCommand(client, "Model named %s doesn't exist!", arg2);
105103
return Plugin_Handled;

0 commit comments

Comments
 (0)