samp.directory
← Scripts e bibliotecas

derrick0930/Custom-Vehicle-Samp

Custom vehicle models for SA-MP 0.3.7: server plugin, client ASI and Pawn include.

Plugin★ 41atualizado há 3 diasMITC++
Abrir no GitHub
Testar no compilador Pawn →

Adiciona os arquivos de include dele, com as bibliotecas de que depende, ao compilador Pawn no seu navegador, prontos para incluir num script.

README.md

Custom Vehicle Skin

Server-delivered custom vehicle models for all SA-MP versions.

Table of contents

Preview

Overview

ComponentOutputPurpose
Server plugin (server/)cvs.dll / cvs.soRegisters and validates models (.dff, .txd, .ifp, model.ini folders), serves them over HTTP, coordinates OnPlayerConnect gating, and tracks download completion
Client plugin (client/)vehskin.asiWaits for OnPlayerConnect, renders a modern ImGui-style download table overlay, caches models, applies custom models/wheels/mudguards/lights, and swaps custom .ifp animations
Gamemode include (example/)cvs.incPawn API used to gate OnPlayerConnect before login, create/track custom vehicles, and fire OnPlayerCVSDownloadFinish

Key features:

  • Custom vehicle appearance with the handling and physics of a standard base vehicle (model IDs 400 to 611).
  • Built-in HTTP file server that shares the same port number as the game server, so no extra port is needed.
  • Download-once caching on the client, keyed by server address and port, with fast metadata verification (.meta) so returning players skip the download screen and go straight to login.
  • Modern client-side download table overlay (Direct3D9 + GDI+): clean dark rounded card with TYPE, FILE, PROGRESS (0%–100%), speed (KB/s), and overall progress bar — no intrusive DIALOG_STYLE_TABLIST_HEADERS dialog.
  • Built-in Custom Models panel (F3 hotkey directly in vehskin.asi for all SA-MP versions): unlocks a free mouse cursor, supports mouse wheel / Up/Down scrolling, top-right X close button, and displays every registered custom model ID, file name, base ID, total size, and READY/MISSING status.
  • OnPlayerConnect synchronization: the download overlay appears only after OnPlayerConnect fires (not during the SA-MP loading screen), and server login/account systems can wait for OnPlayerCVSDownloadFinish.
  • Per-vehicle application, so custom and standard vehicles can coexist freely.
  • Custom animations: an optional .ifp file per model (GTA: SA ANP3 format) replaces the rider animations of custom motorbikes.
  • Model folders: each model can live in its own models/<id>/ folder described by a model.ini file, loaded in one call with CVS_LoadModels.
  • Per-model tuning in model.ini: headlight, taillight, and wheel/mudguard position offsets.
  • Pure Pawn API with a single include file, plus a ready-to-run example gamemode.

How it works

  1. The gamemode registers each custom model, either with CVS_AddModel (custom ID, base vehicle ID and a pair of files in the server models/ folder) or in bulk with CVS_LoadModels, which reads models/<id>/model.ini folders. An optional .ifp animation file is attached with CVS_SetModelAnim or the IFP key of model.ini.
  2. CVS_Start starts the HTTP file server on the game server's TCP port. The server exposes /connect, /manifest, /vehicles, /files/<name>, and /progress.
  3. When a player joins, OnPlayerConnect calls CVS_StartPlayerDownload(playerid) at the very top (before login/account systems). vehskin.asi polls /connect so nothing appears during the SA-MP loading screen; as soon as OnPlayerConnect signals ready, the client fetches /manifest, displays the modern download table overlay, downloads any missing or changed files (.dff, .txd, .ifp), and notifies /progress when done so OnPlayerCVSDownloadFinish(playerid) runs the login flow.
  4. Vehicles created with CVS_CreateVehicle are spawned using the base vehicle ID. The plugin keeps track of their custom model and position, and the client swaps in the custom model for those vehicles only. If the model has an .ifp, the client also swaps in the custom rider animations while the player is on, or next to, that vehicle.

Repository structure

CustomVehicle/
|-- client/
|   |-- main.cpp          Client plugin source (vehskin.asi)
|   `-- build.ps1         Legacy build script
|-- server/
|   |-- main.cpp          Server plugin source (cvs.dll / cvs.so)
|   `-- sdk/              SA-MP plugin SDK headers and sources
|-- example/
|   |-- cvs.inc           Pawn include (copy to pawno/include)
|   `-- example.pwn       Example gamemode with the /vehmodel command
|-- docs/                 Images used by this README
|-- models/               Place your .dff, .txd and .ifp files here (ignored by Git)
|-- dist/                 Build output (ignored by Git)
|-- build-windows.sh      Builds cvs.dll and vehskin.asi into dist/ (clang, Windows)
|-- build-linux.sh        Builds cvs.so into dist/ (Zig, Linux)
|-- .gitattributes
|-- .gitignore
`-- README.md

Requirements

Build tools (Windows)

These are needed for build-windows.sh, which builds cvs.dll and vehskin.asi.

RequirementNotes
Windows 10 or laterRequired to build the Windows plugins and to run the client
Git for WindowsProvides git and Git Bash, which runs build-windows.sh (an MSYS2 shell also works)
Clang (clang++) or MinGW-w64 g++Must target 32-bit i686-w64-windows-gnu / i686-w64-mingw32. Both SA-MP and GTA: San Andreas are 32-bit, so a 64-bit target will not work
MinGW-w64 runtime for i686Headers, import libraries (winhttp, d3d9, gdi32, gdiplus, ws2_32) and static winpthread
SA-MP server packageSupplies pawno (the Pawn compiler) for the example gamemode
zcmd.incOnly needed to compile example/example.pwn

Confirm that the compiler is available:

clang++ --version

Build tools (Linux / cross-compile)

These are needed for build-linux.sh (or compiling cvs.so from Windows with Zig). The client plugin (vehskin.asi) is Windows only.

RequirementNotes
Linux (x86-64 or x86) or WindowsThe 32-bit ELF target is cross-compiled by Zig, so no 32-bit system libraries are needed
ZigVersion 0.11 or newer, from https://ziglang.org/download/. zig must be in PATH. Zig bundles its own clang, libc headers and libc++, so no separate gcc, clang or multilib packages are required
BashRuns build-linux.sh

Confirm that Zig is available:

zig version

Runtime

SideRequirement
ServerSA-MP server (all versions) for Windows (cvs.dll), or Linux (cvs.so, beta)
ClientSA-MP (all versions) with GTA: San Andreas 1.0 (US) and an ASI loader, such as Ultimate ASI Loader
NetworkThe game server port must be open for both UDP (game traffic) and TCP (model downloads)

Building

The build is split into one script per platform. Both write their output to dist/.

ScriptPlatformCompilerOutput
build-windows.shWindows (Git Bash or MSYS2)clang++dist/cvs.dll, dist/vehskin.asi
build-linux.shLinux (or Windows with Zig)zig c++dist/cvs.so

Windows

build-windows.sh compiles the server plugin and the client plugin in one go.

  1. Install the build tools listed under Build tools (Windows), including Git for Windows.

  2. Open Git Bash and download the project:

    git clone https://github.com/derrick0930/Costum-Vehicle-Samp.git
    cd Costum-Vehicle-Samp
    

    If you downloaded a ZIP instead, extract it and run cd into the extracted folder (for example cd CustomVehicle).

  3. Check that the compiler is found:

    clang++ --version
    
  4. Run the build script:

    ./build-windows.sh
    

    If the script is not executable on your system, run bash build-windows.sh instead. From PowerShell, use bash .\build-windows.sh. Note that vehskin.asi links -lwinhttp -ld3d9 -lgdi32 -lgdiplus.

  5. Collect the results from the dist/ folder:

    FileGoes to
    dist/cvs.dllThe plugins/ folder of your SA-MP server
    dist/vehskin.asiThe GTA: San Andreas folder on each player's PC
CommandAction
./build-windows.shBuilds the server plugin and the client plugin
./build-windows.sh serverBuilds only dist/cvs.dll
./build-windows.sh clientBuilds only dist/vehskin.asi
./build-windows.sh cleanRemoves cvs.dll and vehskin.asi from dist/

The script stops at the first error. To use a different compiler, set CXX, for example CXX=/c/llvm/bin/clang++ ./build-windows.sh.

Linux

build-linux.sh builds the 32-bit SA-MP server plugin with Zig.

  1. Install Zig as described under Build tools (Linux) and check it with zig version.

  2. From the project folder, run:

    ./build-linux.sh
    

    If the script is not executable, run bash build-linux.sh instead.

  3. Copy dist/cvs.so to the plugins/ folder of your SA-MP Linux server.

CommandAction
./build-linux.shBuilds dist/cvs.so (same as ./build-linux.sh build)
./build-linux.sh cleanRemoves dist/cvs.so

The script stops at the first error. It reads two optional environment variables:

VariableDefaultPurpose
ZIGzigPath to the Zig executable, for example ZIG=/opt/zig/zig ./build-linux.sh
TARGETx86-linux-gnu.2.17Zig target triple. The .2.17 suffix sets the minimum glibc version, so the plugin also loads on older distributions. Raise or lower it if your server needs a different glibc

To verify the result:

file dist/cvs.so                      # should say: ELF 32-bit LSB shared object, Intel 80386
readelf -d dist/cvs.so | grep NEEDED  # should not list libstdc++.so.6

Installation

Server

  1. Copy dist/cvs.dll to the plugins/ folder of your SA-MP server.

  2. Add the plugin to server.cfg:

    plugins cvs
    
  3. Copy example/cvs.inc to pawno/include/.

  4. Create a models/ folder in the server root (next to samp-server.exe) and place your .dff, .txd and optional .ifp files in it, either directly or in models/<id>/ sub-folders (see Model folders and model.ini).

  5. Open the game port for TCP as well as UDP in your firewall.

Linux server (beta)

A .so build of the server plugin is released for SA-MP Linux servers. It is still in beta. If you find an error, please open an issue (see Reporting issues).

  1. Download cvs.so from the Releases page, or build it yourself with ./build-linux.sh (see Building), and copy it to the plugins/ folder of your server.

  2. Add the plugin to server.cfg:

    plugins cvs.so
    
  3. Follow steps 3 to 5 of the Server section. The models/ folder goes in the server root (note that Linux file names are case-sensitive), and players still use vehskin.asi.

Client

  1. Copy dist/vehskin.asi to the GTA: San Andreas installation folder, next to gta_sa.exe.
  2. Make sure an ASI loader is installed.
  3. Connect through the SA-MP launcher. The client reads the server address and port from the launcher arguments, so connecting through unusual methods that skip them is not supported.

Cached files (.dff, .txd and .ifp) are stored in Documents\GTA San Andreas User Files\SAMP\cvs_cache\, in one sub-folder per server address and port. A file is downloaded again only when its size or checksum differs from the server's.

Usage

Register models and start the file server in OnGameModeInit, then create vehicles with CVS_CreateVehicle:

#include <a_samp>
#include "cvs"

public OnGameModeInit()
{
    CVS_AddModel(20001, 411, "infernus_red.dff", "infernus_red.txd");
    CVS_AddModel(20002, 451, "turismo_gold.dff", "turismo_gold.txd");
    CVS_Start();
    return 1;
}

Create and remove vehicles:

new vehicleid = CVS_CreateVehicle(20001, x, y, z, angle);
CVS_DestroyVehicle(vehicleid);

The file names passed to CVS_AddModel are resolved inside the server models/ folder. The .dff, .txd and .ifp names must be plain file names (no paths) and must differ from each other. Files are looked up by name when a client downloads them, so every file name must be unique across all models: two models cannot both use a file called model.dff.

Model folders and model.ini

Instead of one CVS_AddModel call per model, put each model in its own folder named after its custom ID and call CVS_LoadModels() once, before CVS_Start:

models/
|-- 20001/
|   |-- model.ini
|   |-- huracan.dff
|   `-- huracan.txd
`-- 20003/
    |-- model.ini
    |-- chopper.dff
    |-- chopper.txd
    `-- chopper.ifp

model.ini:

[Model]
Name=Chopper
VisualBase=463
DFF=chopper.dff
TXD=chopper.txd
IFP=chopper.ifp

[Lighting]
HeadlightOffsetX=0.0
HeadlightOffsetY=0.0
HeadlightOffsetZ=0.0
TaillightOffsetX=0.0
TaillightOffsetY=0.0
TaillightOffsetZ=0.0

[Offsets]
FrontWheelOffsetY=0.0
FrontWheelOffsetZ=0.0
RearWheelOffsetY=0.0
RearWheelOffsetZ=0.0
KeyMeaning
NameDisplay name of the model (informational)
VisualBase (or Base)Base vehicle ID, 400 to 611. The vehicle keeps this vehicle's handling and physics
DFF, TXDModel and texture file names, in the same folder
IFPOptional animation file in the same folder. If it is missing or unreadable, the model loads without it
HeadlightOffset*, TaillightOffset*Added to the headlight and taillight positions of the base vehicle
FrontWheelOffsetY/Z, RearWheelOffsetY/ZAdded to the front wheel (and mudguard on bikes) and rear wheel positions of the base vehicle

Lines starting with # or ; are comments and every offset defaults to 0.0. The folder name is the custom ID (20001 to 30000). A folder is skipped, and a message is written to the server log, when model.ini is missing, the base or file names are invalid, or the .dff or .txd is not found. A model that was already registered with CVS_AddModel is not replaced. CVS_LoadModels returns the number of models loaded.

Custom animations (IFP)

A model can ship a custom .ifp animation file. Attach it in model.ini with the IFP key, or in Pawn after registering the model:

CVS_AddModel(20003, 463, "chopper.dff", "chopper.txd");
CVS_SetModelAnim(20003, "chopper.ifp");

Requirements and behaviour:

  • The file must be a GTA: San Andreas ANP3 animation file placed in the server models/ folder (or the model's folder). Files in another format are ignored and a message is written to the client log.
  • Animations are matched by name against the originals, so the .ifp should contain animations with the same names as the standard bike animations it replaces.
  • The custom animations replace the rider animations of the bike groups (bike* and choppa) via CAnimBlendStaticAssociation::Init, preserving the original sequence arrays when restored. They are active while the player is on a custom vehicle that has an .ifp, or standing within about 4 metres of one (for mounting/dismounting), and the default animations are restored afterwards.
  • The .ifp is downloaded and cached like the .dff and .txd.

Download progress overlay and login flow

When a player connects, the client renders a modern ImGui-style download table overlay directly in-game (showing TYPE, FILE, PROGRESS 0%–100%, download speed in KB/s, and an overall progress bar). DIALOG_STYLE_TABLIST_HEADERS is no longer shown.

To ensure the overlay only appears on OnPlayerConnect (not during the SA-MP loading screen) and that model downloads finish before your login/account system runs:

public OnPlayerConnect(playerid)
{
    if (IsPlayerNPC(playerid)) return 1;

    // Gate login/server systems until model download or cache check finishes
    CVS_StartPlayerDownload(playerid);
    TogglePlayerSpectating(playerid, true);
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    CVS_ClearPlayerDownload(playerid);
    return 1;
}

forward OnPlayerCVSDownloadFinish(playerid);
public OnPlayerCVSDownloadFinish(playerid)
{
    // Start your account check / login dialog here
    return 1;
}

CVS_StartPlayerDownload(playerid) records the player's initial connection name (so CVS_ClearPlayerDownload(playerid) still cleans it up properly even if your login system renames the player to a roleplay character name). If all models are already cached on the client, the download table is skipped and OnPlayerCVSDownloadFinish(playerid) fires immediately.

Players can press F3 at any time in-game (handled directly by vehskin.asi across all SA-MP versions, no Pawn script required) to toggle the interactive Custom Models panel showing each model's ID, file name, base ID, size, and READY status. While open, the cursor is unlocked so you can scroll with the mouse wheel (or Up/Down) and close via the top-right X button or by pressing F3 again.

Example gamemode

example/example.pwn registers sample models, loads any models/<id>/model.ini folders, integrates CVS_StartPlayerDownload / CVS_ClearPlayerDownload / OnPlayerCVSDownloadFinish, and provides test commands:

Command / KeyResult
/vehmodel 411Spawns a standard Infernus with its original model
/vehmodel 20001Spawns the custom model 20001, using Infernus (411) as its base
F3Opens or closes the interactive Custom Models panel

Compile it with pawno after placing zcmd.inc and cvs.inc in pawno/include/.

API reference

Ler o resto no GitHub

asifilterscriptfilterscriptspawnpluginpluginssa-mpsa-mp-developmentsa-mp-pluginsamp

Esta página é montada com o que o GitHub publica sobre o repositório. O samp.directory não hospeda o código. Avisar de um problema com esta página

derrick0930/Custom-Vehicle-Samp: Plugin de SA-MP | samp.directory