Servidor SA-MP/open.mp com scripting em Lua 5.4. Substitui completamente o Pawn por uma linguagem moderna, rápida e fácil de usar.
chmod +x nx-server start.sh
./start.shOu diretamente:
export LD_LIBRARY_PATH=".:./NexorixPlugins:$LD_LIBRARY_PATH"
./nx-server├── nx-server Executável do servidor
├── start.sh Script de inicialização
├── config.json Configuração do servidor
├── NexorixPlugins/ Plugins do servidor (não mexer)
│ └── Lua.so Plugin Lua (core + voice)
└── lua/
├── include/ Framework (compilado, não editável)
│ ├── nexorix.luac Core: hooks, comandos, constantes
│ └── nexorix_voice.luac API de voz
└── gamemode/
├── main.lua Ponto de entrada (edite aqui)
└── modulos/ Seus módulos
O servidor carrega lua/gamemode/main.lua automaticamente. Nele você faz require dos seus módulos:
require("include/nexorix") -- Framework (obrigatório)
require("include/nexorix_voice") -- Voice API (opcional)
require("gamemode/modulos/meu_modulo")
NX.Hook("OnGameModeInit", function()
nx_print("Servidor iniciado!")
end)NX.Hook("OnPlayerConnect", function(playerid)
nx_SendClientMessage(playerid, 0xFFFFFFFF, "Bem-vindo!")
end)
NX.Hook("OnPlayerDeath", function(playerid, killerid, reason)
-- lógica aqui
end)Eventos disponíveis:
OnGameModeInit,OnGameModeExitOnPlayerConnect,OnPlayerDisconnectOnPlayerSpawn,OnPlayerDeathOnPlayerText,OnPlayerCommandOnPlayerUpdate,OnPlayerKeyStateChangeOnPlayerEnterVehicle,OnPlayerExitVehicleOnPlayerStateChange,OnPlayerRequestClassOnDialogResponse,OnPlayerPickUpPickupOnPlayerClickMap,OnPlayerClickTextDrawOnTickOnPlayerVoiceConnect,OnPlayerVoiceDisconnectOnPlayerVoiceStart,OnPlayerVoiceStop
NX.RegisterCommand("teste", function(playerid, params)
nx_SendClientMessage(playerid, 0x00FF00FF, "Funciona! Params: " .. params)
end)O processador de comandos já vem embutido. Quando o player digita /teste algo, a função recebe playerid e "algo".
Todas as funções SA-MP estão disponíveis com prefixo nx_:
-- Player
nx_SetPlayerPos(playerid, x, y, z)
nx_GetPlayerPos(playerid) -- retorna x, y, z
nx_SetPlayerHealth(playerid, 100)
nx_GivePlayerWeapon(playerid, 31, 500) -- M4 com 500 balas
nx_SendClientMessage(playerid, cor, "texto")
nx_SendClientMessageToAll(cor, "texto")
nx_ShowPlayerDialog(playerid, id, style, titulo, corpo, btn1, btn2)
nx_Kick(playerid)
nx_IsPlayerConnected(playerid)
nx_GetPlayerName(playerid)
-- Veículo
nx_CreateVehicle(model, x, y, z, angle, cor1, cor2, respawn)
nx_DestroyVehicle(vehicleid)
nx_PutPlayerInVehicle(playerid, vehicleid, seat)
-- Mundo
nx_SetWorldTime(hora)
nx_SetWeather(weather)
nx_SetGravity(gravity)
-- Timer
local id = nx_SetTimer(function() ... end, intervalo_ms, repeating)
nx_KillTimer(id)require("include/nexorix_voice")
-- Criar stream de proximidade
local stream = NX.Voice.CreateProximityStream(50.0)
stream:AttachToPlayer(playerid)
stream:AddPlayer(listener_id)
-- Criar canal de rádio
local radio = NX.Voice.CreateChannel({
name = "Policia",
type = "global",
channel_index = 1,
})
radio:AddPlayer(playerid)
-- Efeitos
local effect = NX.Voice.CreateRadioEffect()
radio:SetEffect(effect)
-- Mute
NX.Voice.SetPlayerMuted(playerid, true)
-- Push-to-talk
NX.Voice.SetPushToTalkKey(playerid, 0x42, {0}) -- B key, channel 0-- Enviar mensagem para o Discord
Discord_SendMessage("Servidor online!")
Discord_SendEmbed("Titulo", "Descricao", 65280)
-- Comandos do Discord (!players, !status, !say)
-- Configurados automaticamente via config.jsonNota: O Discord bot requer OpenSSL. No Linux sem OpenSSL, o bot fica desabilitado automaticamente mas o resto do servidor funciona normalmente.
-- Abrir banco de dados
local db = nx_db_open("meu_banco.db")
-- Criar tabela
nx_db_exec(db, "CREATE TABLE IF NOT EXISTS players (id INTEGER PRIMARY KEY, nome TEXT, nivel INTEGER)")
-- Inserir com parâmetros (seguro contra SQL injection)
nx_db_exec(db, "INSERT INTO players (nome, nivel) VALUES (?, ?)", "Rick", 10)
-- Consultar
local rows = nx_db_query(db, "SELECT * FROM players WHERE nome = ?", "Rick")
for _, row in ipairs(rows) do
nx_print(row.id .. " | " .. row.nome .. " | Nivel: " .. row.nivel)
end
-- Último ID inserido
local id = nx_db_last_insert_id(db)
-- Linhas afetadas pelo último INSERT/UPDATE/DELETE
local changes = nx_db_changes(db)
-- Fechar banco
nx_db_close(db)Funções disponíveis:
nx_db_open(path)— Abre/cria banco SQLitenx_db_close(db)— Fecha o banconx_db_exec(db, sql, ...)— Executa INSERT/UPDATE/DELETE/CREATEnx_db_query(db, sql, ...)— Executa SELECT, retorna tabela de rowsnx_db_last_insert_id(db)— Último rowid inseridonx_db_changes(db)— Linhas afetadasnx_db_prepare(db, sql)— Prepared statementnx_db_bind(stmt, index, value)— Bind valor ao statementnx_db_step(stmt)— Executa step ("row"/"done"/"error")nx_db_column(stmt, index)— Lê coluna (0-based)nx_db_reset(stmt)— Reset statement para reusarnx_db_finalize(stmt)— Libera statement
{
"name": "Meu Servidor",
"max_players": 100,
"network": { "port": 7777 },
"lua": { "entry": "lua/gamemode" },
"discord": {
"enabled": true,
"token": "SEU_TOKEN",
"channel_id": "SEU_CHANNEL"
},
"voice": {
"enabled": true,
"port": 2020
}
}NX.COLOR.WHITE -- 0xFFFFFFFF
NX.COLOR.RED -- 0xFF4444FF
NX.COLOR.GREEN -- 0x44FF44FF
NX.COLOR.YELLOW -- 0xFFFF44FF
NX.COLOR.BLUE -- 0x4488FFFF
NX.INVALID_PLAYER_ID -- 0xFFFF
NX.MAX_PLAYERS -- 1000- Ubuntu 18.04+ / Debian 10+
- Arquitetura x86 (32-bit libs necessárias)
- Porta 7777 (jogo) e 2020 (voice) abertas
# Se necessário instalar libs 32-bit:
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install libc6:i386 libstdc++6:i386- Organize seu código em módulos na pasta
gamemode/modulos/ - Use
nx_print("msg")para logs no console - Hooks suportam prioridade:
NX.Hook("evento", fn, NX.HOOK_PRIORITY.HIGH) - O framework é thread-safe e otimizado para performance
- Voice requer o client SampVoice instalado nos players
O framework suporta recarregamento de módulos em tempo real sem reiniciar o servidor.
/reload — Recarrega todos os módulos automaticamente
/reload commands — Recarrega um módulo específico
/modules — Lista todos os módulos detectados
- Escaneia recursivamente
gamemode/modulos/einclude/ - Limpa o cache
package.loadeddo módulo - Re-executa o arquivo com
loadfile+pcall - Hooks e comandos são re-registrados automaticamente
- Edite
gamemode/modulos/commands.luae adicione um novo comando - No jogo, digite
/reload commands - O novo comando já está disponível sem reiniciar
Requer admin nível 4+ (Gerente). Configure no sistema admin.
Nota: O reload funciona para a maioria dos casos. Se algo não atualizar, reinicie o servidor.
Nexorix Framework — Desenvolvido por Rick_Spooky