Coder Social home page Coder Social logo

mikusch / source-vehicles Goto Github PK

View Code? Open in Web Editor NEW
30.0 8.0 5.0 118 KB

Driveable vehicles based on prop_vehicle_driveable for TF2, CS:S, and more

License: GNU General Public License v3.0

SourcePawn 100.00%
tf2 vehicles sourcemod sourcepawn vehicle team-fortress-2 driveable-vehicles counter-strike-source css black-mesa

source-vehicles's Introduction

Driveable Vehicles for Source Engine Multiplayer

This is a SourceMod plugin that allows spawning driveable vehicles based on prop_vehicle_driveable in Source engine multiplayer games.

List of supported games:

  • Team Fortress 2
  • Counter-Strike: Source
  • Black Mesa
  • Half-life 2: Deathmatch

This plugin bundles the required entity fixes, and a few configurable nice-to-have features.

Features

  • Fully functioning driveable vehicles based on prop_vehicle_driveable
  • Vehicle sounds
  • Entry and exit animations (experimental)
  • Physics collisions and damage against other players
  • High customizability through plugin configuration and ConVars

Dependencies

Installation

  1. Download the latest version from the releases page
  2. Extract the contents of the ZIP file into your server's game directory
  3. Restart your server or type sm plugins load vehicles into your server console

Usage

The easiest way to spawn vehicles is using the sm_vehicle command. This requires vehicles to be added to the vehicle configuration.

If you have access to ent_create, you can spawn vehicle entities without having to add them to the configuration. The plugin automatically detects and hooks any vehicle spawned into the map. If a configuration entry matches both the vehicle model and vehicle script, its properties will be applied accordingly.

Example:

ent_create prop_vehicle_driveable model "models/buggy.mdl" VehicleScript "scripts/vehicles/jeep_test.txt"

To enter a vehicle, look at it and use the +use console command.

Configuration

The vehicle configuration allows you to add custom vehicles. Each vehicle requires at least a name, model, vehicle script, and vehicle type. More documentation and examples can be found in the default configuration.

To learn how to create custom vehicle models and scripts, check out the Vehicle Scripts for Source guide on Steam.

Example Configuration

"Vehicles"
{
	"example_vehicle"
	{
		"name"					"#Vehicle_ExampleVehicle"
		"model"					"models/vehicles/example_vehicle.mdl"
		"script"				"scripts/vehicles/example_vehicle.txt"
		"type"					"car_wheels"
		"soundscript"				"scripts/example_soundscript.txt"
		"skins"					"0,1,2"
		"key_hint"				"#Hint_VehicleKeys_Car"
		"lock_speed"				"10.0"
		"is_passenger_visible"			"1"
		"horn_sound"				"sounds/vehicles/example_horn.wav"
		"downloads"
		{
			"0"	"models/vehicles/example_vehicle.dx80.vtx"
			"1"	"models/vehicles/example_vehicle.dx90.vtx"
			"2"	"models/vehicles/example_vehicle.mdl"
			"3"	"models/vehicles/example_vehicle.phy"
			"4"	"models/vehicles/example_vehicle.sw.vtx"
			"5"	"models/vehicles/example_vehicle.vvd"
			"6"	"materials/models/vehicles/example_vehicle.vmt"
			"7"	"materials/models/vehicles/example_vehicle.vtf"
		}
	}
}

ConVars

The plugin creates the following console variables:

  • vehicle_config_path ( def. "configs/vehicles/vehicles.cfg" ) - Path to vehicle configuration file, relative to the SourceMod folder
  • vehicle_physics_damage_modifier ( def. "1.0" ) - Modifier of impact-based physics damage against other players
  • vehicle_passenger_damage_modifier ( def. "1.0" ) - Modifier of damage dealt to vehicle passengers
  • vehicle_enable_entry_exit_anims ( def. "0" ) - If set to 1, enables entry and exit animations (experimental)
  • vehicle_enable_horns ( def. "1" ) - If set to 1, enables vehicle horns

Entry and Exit Animations

Most vehicles have entry and exit animations that make the player transition between the vehicle and the entry/exit points. The plugin fully supports these animations.

However, since Valve never intended prop_vehicle_driveable to be used outside Half-Life 2, there is code that does not function properly in a multiplayer environment and can even cause client crashes.

Because of that, entry and exit animations on all vehicles are disabled by default and have to be manually enabled by setting vehicle_enable_entry_exit_anims to 1. If you intend to use this plugin on a public server, it is highly recommended to keep the animations disabled.

source-vehicles's People

Contributors

alienmario avatar batfoxkid avatar blueberryy avatar dispenz0r avatar jagflax avatar mikusch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

source-vehicles's Issues

[Error] I can't load materials for vehicles, even if i write them in "download" line in vehicles.cfg.

So I installed your plugin for my TF2 Server. It worked very well. My friends told me to add more vehicles. I unzip addons from Garry's Mod and add to my server folder. Then write code for them. They work fine, but I can't load textures for them. I thought, what I missed the "material" line. But nope. I even put all materials to "download" line, but they just don't load. Please help me!
Here's my example code for vehicle:
"Sniper's Camper Van"
{
"name" "#Vehicle_CamperVan"
"model" "models/vehicles/camper.mdl"
"script" "scripts/vehicles/farcryhumvee_hl2.txt"
"type" "car_wheels"
"soundscript" ""
"key_hint" ""
"downloads"
{
"0" "models/vehicles/camper.dx80.vtx"
"1" "models/vehicles/camper.dx90.vtx"
"2" "models/vehicles/camper.mdl"
"3" "models/vehicles/camper.phy"
"4" "models/vehicles/camper.sw.vtx"
"5" "models/vehicles/camper.vvd"
"6" "materials/models/vehicles/camper.vmt"
"7" "materials/models/vehicles/camper.vtf"
"8" "materials/models/vehicles/camper_exp.vtf"
"9" "materials/models/vehicles/camper_normal.vtf"
"10" "materials/models/vehicles/citizen_body.vmt"
"11" "materials/models/vehicles/citizen_body.vtf"
"12" "materials/models/vehicles/citizen_head.vmt"
"13" "materials/models/vehicles/citizen_head.vtf"
"14" "materials/models/vehicles/details.vmt"
"15" "materials/models/vehicles/details.vtf"
"16" "materials/models/vehicles/interior.vmt"
"17" "materials/models/vehicles/interior.vtf"
"18" "materials/models/vehicles/interior_exp.vtf"
"19" "materials/models/vehicles/interior_normal.vtf"
"20" "materials/models/vehicles/body.vmt"
"21" "materials/models/vehicles/body.vtf"
"22" "materials/models/vehicles/body_exp.vtf"
"23" "materials/models/vehicles/body_height.vtf"
"24" "materials/models/vehicles/body_normal.vtf"
"25" "materials/models/vehicles/rear_sticker.vmt"
"26" "materials/models/vehicles/rear_sticker.vtf"
"27" "materials/models/vehicles/w_sniperrifle01.vmt"
"28" "materials/models/vehicles/w_sniperrifle01.vtf"
"29" "materials/models/vehicles/w_sniperrifle_normal.vtf"
"30" "materials/models/vehicles/weapon_lightwarp.vtf"
"31" "materials/models/vehicles/wheels.vmt"
"32" "materials/models/vehicles/wheels.vtf"
"33" "materials/models/vehicles/wheels_exp.vtf"
"34" "materials/models/vehicles/wheels_normal.vtf"
"35" "materials/models/vehicles/windshield.vmt"
"36" "materials/models/vehicles/windshield.vtf"
"37" "materials/models/vehicles/windshield_normal.vtf"
}
}

Individual vehicle behavior

Right now, we treat all vehicles the same, regardless of vehicle type, vehicle model or any other factors. Similar to the virtual functions defined by the IServerVehicle class, a vehicle should be able to define its own behavior.

For example, some vehicles may not want to have the player be visible at all times, so instead of always returning true for CBaseServerVehicle::IsPassengerVisible, we could have a callback function defined in the config:

"callback_is_passenger_visible"	"IsPassengerVisible"

Then we implement said function in our plugin:

public bool IsPassengerVisible(int vehicle, PassengerRole role)
{
	//This is the default behavior and can be overridden!
	return true;
}

Possible callbacks:

  • bool IsPassengerVisible(int vehicle, PassengerRole role)
  • bool PassengerShouldReceiveDamage(int vehicle, TakeDamageInfo...)
  • float PassengerDamageModifier(int vehicle, TakeDamageInfo...)
  • void OnTakeDamage(int vehicle, TakeDamageInfo...) (to allow disrupting the vehicle or passing damage to the driver)
  • void PreExitVehicle(int client, PassengerRole role)

There are probably many more functions that can be added to this list. This seems like a massive change so it would warrant bumping the version to 2.0.0 if it gets implemented.

Problems:
To call the right functions we will need to map a vehicle entity to its related config entry. Right now we have no way to fetch the config entry for a vehicle entity without relying on model or vehicle script. This is acceptable for map vehicles since they are arbitrarily matched to a config entry based on those two factors already but for player-spawned vehicles we will need to remember which entity belongs to which config.
Additionally, for a few functions, we need to fetch the entity index for a m_pServerVehicle address but that should be as simple as doing an SDKCall to CBaseServerVehicle::GetVehicleEnt.

Entering a vehicle will snap the view angle of nearby players

Entering a vehicle will cause nearby player's view angles to snap to different coordinates. This is related to the entry animation, which will snap the driver's view angle to the angle of the vehicle. From our testing, the view snapping will continue happening if the sequence never finishes, but while the entry animation is still running. This seems to only happen if you are within a certain range of the vehicle.

There is a function in shared code called SharedVehicleViewSmoothing which handles the view snapping, however from my knowledge that only ever gets executed for the player that actually entered the vehicle, and also contains some CLIENT_DLL stuff. Will need to investigate further, and determine if it is even possible to fix this.

Disable entry and exit animations

Entry and exit animations cause a wide range of issues. Most of them can be traced back to a function called SharedVehicleViewSmoothing and can unfortunately not be fixed due to client-side function calls (thanks Valve).

Known issues:

  • View snapping for EVERY player on entry animation finish due to a CEngineClient::SetViewAngles call
    • In CLIENT_DLL define, unfixable
  • Random client crashes on exit animation finish with multiple players on the server
    • Haven't figured out why or where exactly this happens
  • Players getting stuck on entry of some custom vehicles due to broken or missing animations

In short, the animations do not work in a multiplayer environment.

We need to prevent the call to SharedVehicleViewSmoothing at all costs, or at the very least prevent it from running its multiplayer-unfriendly code. This can only be done by forcing the vehicle to not start the entry and exit animations.
For exit animations, this should be as simple as detouring CBaseServerVehicle::GetExitAnimToUse and returning ACTIVITY_NOT_AVAILABLE. Setting bExitAnimOn to false is not enough! Entry animations might be a bit trickier to block as there is a fallback.

An additional problem that may arise is immediately exiting the vehicle after entering when using +use. Entry animations would normally prevent that. We need to add something that removes the IN_USE button (preferable) or add a delay between vehicle entry and vehicle exit.

The current animation behavior should still be available by setting a convar tf_vehicle_use_entry_exit_anims to 1, but should definitely be disabled by default (perhaps even print a warning if enabled with multiple players on the server).

not working in TF2?

Hey there im currently running the latest version of tf2 and it doesnt seem to work. It adjusts the camera correctly as of the vehicle but it doesnt actually put you into the state of driving. Trying to enter the vehicle afterwards will do nothing

1 Issue and a question.

While the Buggy sounds seem to work fine, Airboat is silent as an owl, I'm gonna guess the TF2's hl2 files doesn't provide sounds for the airboat right?

Another very specific issue happens in cp_dustbowl but could also be affecting other maps that use breakable props or something of the sort, players phase through those breakable barrels which doesn't happen when I disable the plugin so its affecting their "solid" state somehow.

Black Mesa

[SM] Unable to load plugin "vehicles.smx": Native "SoundScript.Count.get" was not found

  SourceMod Version Information:
    SourceMod Version: 1.11.0.6888
    SourcePawn Engine: 1.11.0.6888, jit-x86 (build 1.11.0.6888)
    SourcePawn API: v1 = 5, v2 = 16
    Compiled on: Jun  6 2022 12:45:32
    Built from: https://github.com/alliedmodders/sourcemod/commit/5c0ae11a
    Build ID: 6888:5c0ae11a

[Feature Request] Third person mode

Hello, I would like to request a feature to have a configurable ability to use third person mode in vehicles. Typing thirdperson looks pretty good already.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.