Environment variables (.env) plugin for SA-MP and Open Multiplayer, written in Rust. Loads a .env file at startup and exposes the values to Pawn through a single typed native.
Designed to eliminate hardcoded credentials in Pawn code, keeping secrets out of version control and centralized in a single configuration file.
The same .so / .dll runs on SA-MP and on Open Multiplayer — natively as a component (recommended) or via legacy mode.
Full documentation lives at https://env-samp.nullsablex.com/:
The Markdown sources are in docs/ — mkdocs serve from the repo root for a local preview.
- examples/example.pwn — minimal gamemode using
Envfor string/int/float/bool andEnvCount. - examples/env — annotated
.envcovering every syntax feature the parser accepts (quoting, escapes, inline comments, duplicates, etc.). Copy it to.envat the server root and edit the values.
#include <a_samp>
#include <env_samp>
public OnGameModeInit()
{
new host[64];
if (Env("MYSQL_HOST", host))
{
printf("[env_samp] MYSQL_HOST=%s", host);
}
new port;
if (Env("MYSQL_PORT", port, ENV_INT))
{
printf("[env_samp] MYSQL_PORT=%d", port);
}
return 1;
}Run the example .env alongside your server and call this from OnGameModeInit.
Requires Rust stable with the 32-bit targets installed. On Linux:
./scripts/build-linux.sh # builds .so + .dll into dist/On Windows (Git Bash):
./scripts/build-windows.shBoth scripts read PLUGIN_NAME from Cargo.toml, install missing rustup targets and produce dist/env_samp.so and dist/env_samp.dll.
- The
.envis read once at startup. No runtime reload. - Values are never logged. Only error/warning messages about the file itself are emitted.
- Files larger than 1 MiB are rejected.
- Add
.envto.gitignore. Never commit credentials. - Use examples/env as a public template without real values.
This project is distributed under the GNU Affero General Public License v3.0 or later.
You can use, modify and redistribute it freely, provided that derivative works are released under the same license with source code available. Because it is AGPL, modifications used on servers accessible over the network must also have their source offered to the users interacting with that instance.