Skip to content

Commit

Permalink
Deprecate "id" config property
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikusch committed Oct 24, 2021
1 parent 3bef3ae commit e560faa
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 90 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ the [Vehicle Scripts for Source](https://steamcommunity.com/sharedfiles/filedeta
```
"Vehicles"
{
"0"
"example_vehicle"
{
"id" "example_vehicle"
"name" "#Vehicle_ExampleVehicle"
"model" "models/vehicles/example_vehicle.mdl"
"script" "scripts/vehicles/example_vehicle.txt"
Expand Down
16 changes: 6 additions & 10 deletions addons/sourcemod/configs/vehicles/vehicles.cfg
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
//
// VEHICLE CONFIGURATION:
// Allows you to configure your own vehicles.
// Some attributes are <required> while others are [optional].
// Some properties are <required> while others are [optional].
//
// Attributes:
// <id> - Unique identifier of the vehicle
// <name> - Human-readable name of the vehicle (defined in vehicles.phrases.txt)
// Properties:
// <name> - Translation key for the human-readable name of the vehicle (defined in vehicles.phrases.txt)
// <model> - Vehicle model
// <script> - Vehicle script path
// <type> - Vehicle type
Expand All @@ -20,9 +19,8 @@
//
"Vehicles"
{
"0"
"hl2_jeep"
{
"id" "hl2_jeep"
"name" "#Vehicle_HL2_Jeep"
"model" "models/buggy.mdl"
"script" "scripts/vehicles/jeep_test.txt"
Expand All @@ -31,9 +29,8 @@
"key_hint" "#Hint_VehicleKeys_Car"
}

"1"
"hl2_airboat"
{
"id" "hl2_airboat"
"name" "#Vehicle_HL2_Airboat"
"model" "models/airboat.mdl"
"script" "scripts/vehicles/airboat.txt"
Expand All @@ -44,9 +41,8 @@
//
// Example: (do not put // in front of real lines, as // means 'comment')
//
// "0"
// "example_vehicle"
// {
// "id" "example_vehicle"
// "name" "#Vehicle_ExampleVehicle"
// "model" "models/vehicles/example_vehicle.mdl"
// "script" "scripts/vehicles/example_vehicle.txt"
Expand Down
167 changes: 89 additions & 78 deletions addons/sourcemod/scripting/vehicles.sp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ enum VehicleType
VEHICLE_TYPE_CAR_WHEELS = (1 << 0),
VEHICLE_TYPE_CAR_RAYCAST = (1 << 1),
VEHICLE_TYPE_JETSKI_RAYCAST = (1 << 2),
VEHICLE_TYPE_AIRBOAT_RAYCAST = (1 << 3)
VEHICLE_TYPE_AIRBOAT_RAYCAST = (1 << 3),
}

bool g_LoadSoundscript;
Expand Down Expand Up @@ -108,98 +108,109 @@ enum struct VehicleConfig

void ReadConfig(KeyValues kv)
{
kv.GetString("id", this.id, 256, this.id);
kv.GetString("name", this.name, 256, this.name);
kv.GetString("model", this.model, PLATFORM_MAX_PATH, this.model);
kv.GetString("script", this.script, PLATFORM_MAX_PATH, this.script);

char type[32];
kv.GetString("type", type, sizeof(type));
if (StrEqual(type, "car_wheels"))
this.type = VEHICLE_TYPE_CAR_WHEELS;
else if (StrEqual(type, "car_raycast"))
this.type = VEHICLE_TYPE_CAR_RAYCAST;
else if (StrEqual(type, "jetski_raycast"))
this.type = VEHICLE_TYPE_JETSKI_RAYCAST;
else if (StrEqual(type, "airboat_raycast"))
this.type = VEHICLE_TYPE_AIRBOAT_RAYCAST;
else if (type[0] != '\0')
LogError("%s: Invalid vehicle type '%s'", this.id, type);

kv.GetString("soundscript", this.soundscript, PLATFORM_MAX_PATH, this.soundscript);
if (this.soundscript[0] != '\0')
if (kv.GetSectionName(this.id, 256))
{
if (g_LoadSoundscript)
//TODO: Remove deprecated code (deprecated since: 2.3.1)
char id[256];
kv.GetString("id", id, sizeof(id));
if (id[0] != '\0')
{
#if defined _loadsoundscript_included
SoundScript soundscript = LoadSoundScript(this.soundscript);
for (int i = 0; i < soundscript.Count; i++)
strcopy(this.id, 256, id);
LogMessage("%s: The 'id' property is deprecated and is subject for removal in a future version, use the root section for the vehicle identifier", this.id);
}

kv.GetString("name", this.name, 256);
kv.GetString("model", this.model, PLATFORM_MAX_PATH);
kv.GetString("script", this.script, PLATFORM_MAX_PATH);

char type[32];
kv.GetString("type", type, sizeof(type));
if (StrEqual(type, "car_wheels"))
this.type = VEHICLE_TYPE_CAR_WHEELS;
else if (StrEqual(type, "car_raycast"))
this.type = VEHICLE_TYPE_CAR_RAYCAST;
else if (StrEqual(type, "jetski_raycast"))
this.type = VEHICLE_TYPE_JETSKI_RAYCAST;
else if (StrEqual(type, "airboat_raycast"))
this.type = VEHICLE_TYPE_AIRBOAT_RAYCAST;
else if (type[0] != '\0')
LogError("%s: Invalid vehicle type '%s'", this.id, type);

kv.GetString("soundscript", this.soundscript, PLATFORM_MAX_PATH);
if (this.soundscript[0] != '\0')
{
if (g_LoadSoundscript)
{
SoundEntry entry = soundscript.GetSound(i);
char soundname[256];
entry.GetName(soundname, sizeof(soundname));
PrecacheScriptSound(soundname);
}
#if defined _loadsoundscript_included
SoundScript soundscript = LoadSoundScript(this.soundscript);
for (int i = 0; i < soundscript.Count; i++)
{
SoundEntry entry = soundscript.GetSound(i);
char soundname[256];
entry.GetName(soundname, sizeof(soundname));
PrecacheScriptSound(soundname);
}
#else
LogMessage("%s: Failed to load vehicle soundscript '%s' because the plugin was compiled without the LoadSoundscript include", this.id, this.soundscript);
LogMessage("%s: Failed to load vehicle soundscript '%s' because the plugin was compiled without the LoadSoundscript include", this.id, this.soundscript);
#endif
}
else
{
LogMessage("%s: Failed to load vehicle soundscript '%s' because the LoadSoundscript extension could not be found", this.id, this.soundscript);
}
}
else
{
LogMessage("%s: Failed to load vehicle soundscript '%s' because the LoadSoundscript extension could not be found", this.id, this.soundscript);
}
}

this.skins = new ArrayList();

char skins[128];
kv.GetString("skins", skins, sizeof(skins), "0");

char split[32][4];
int retrieved = ExplodeString(skins, ",", split, sizeof(split), sizeof(split[]));
for (int i = 0; i < retrieved; i++)
{
int skin;
if (TrimString(split[i]) > 0 && StringToIntEx(split[i], skin) > 0)
this.skins.Push(skin);
}

this.lock_speed = kv.GetFloat("lock_speed", 10.0);
kv.GetString("key_hint", this.key_hint, 256);
this.is_passenger_visible = view_as<bool>(kv.GetNum("is_passenger_visible", true));

kv.GetString("horn_sound", this.horn_sound, PLATFORM_MAX_PATH);
if (this.horn_sound[0] != '\0')
{
char filepath[PLATFORM_MAX_PATH];
Format(filepath, sizeof(filepath), "sound/%s", this.horn_sound);
if (FileExists(filepath, true))

this.skins = new ArrayList();

char skins[128];
kv.GetString("skins", skins, sizeof(skins), "0");

char split[32][4];
int retrieved = ExplodeString(skins, ",", split, sizeof(split), sizeof(split[]));
for (int i = 0; i < retrieved; i++)
{
AddFileToDownloadsTable(filepath);
Format(this.horn_sound, PLATFORM_MAX_PATH, ")%s", this.horn_sound);
PrecacheSound(this.horn_sound);
int skin;
if (TrimString(split[i]) > 0 && StringToIntEx(split[i], skin) > 0)
this.skins.Push(skin);
}
else

this.lock_speed = kv.GetFloat("lock_speed", 10.0);
kv.GetString("key_hint", this.key_hint, 256);
this.is_passenger_visible = view_as<bool>(kv.GetNum("is_passenger_visible", true));

kv.GetString("horn_sound", this.horn_sound, PLATFORM_MAX_PATH);
if (this.horn_sound[0] != '\0')
{
LogError("%s: The file '%s' does not exist", this.id, filepath);
this.horn_sound[0] = '\0';
char filepath[PLATFORM_MAX_PATH];
Format(filepath, sizeof(filepath), "sound/%s", this.horn_sound);
if (FileExists(filepath, true))
{
AddFileToDownloadsTable(filepath);
Format(this.horn_sound, PLATFORM_MAX_PATH, ")%s", this.horn_sound);
PrecacheSound(this.horn_sound);
}
else
{
LogError("%s: The file '%s' does not exist", this.id, filepath);
this.horn_sound[0] = '\0';
}
}
}

if (kv.JumpToKey("downloads"))
{
if (kv.GotoFirstSubKey(false))

if (kv.JumpToKey("downloads"))
{
do
if (kv.GotoFirstSubKey(false))
{
char filename[PLATFORM_MAX_PATH];
kv.GetString(NULL_STRING, filename, sizeof(filename));
AddFileToDownloadsTable(filename);
do
{
char filename[PLATFORM_MAX_PATH];
kv.GetString(NULL_STRING, filename, sizeof(filename));
AddFileToDownloadsTable(filename);
}
while (kv.GotoNextKey(false));
kv.GoBack();
}
while (kv.GotoNextKey(false));
kv.GoBack();
}
kv.GoBack();
}
}
}
Expand Down

0 comments on commit e560faa

Please sign in to comment.