A GTA SAMP plugin for Chat Bot communication.
It works for both SA-MP 0.3.7/0.3.DL and open.mp.
The following Chat Bots API are implemented:
This plugin can permit arbitrary model and system instruction choise using natives in runtime.
Refer to this wiki for pawn implementation.
Before choosing a Chat Bot API remember:
- GPT is not free to use, check pricing;
- Gemini is free to use in certain countries;
- LLAMA is free on groq.com everywhere and has some premium features (LLAMA hasn't any official API);
- Doubao performs better in Chinese;
- DeepSeek is not free to use, check pricing.
#include <a_samp>
#include <core>
#include <float>
#include <samp-chatbot>
#include <Pawn.CMD>
#include <sscanf2>
#define COLOR_RED 0xFF0000FF
#define COLOR_MAGENTA 0xFF00FFFF
#define CHATBOT_DIALOG 10
#define API_KEY "MY_API_KEY"
#define GLOBAL_REQUEST -1
#pragma tabsize 0
new lastResponses[MAX_PLAYERS][1024];
new lastGlobalResponse[1024];
main()
{
SetChatBotEncoding(W1252);
SelectChatBot(LLAMA);
SetModel("llama3-70b-8192");
SetAPIKey(API_KEY);
SetSystemPrompt("You are an assistant inside GTA SAMP");
SetChatBotTimeout(10000);
SetChatBotDebugMode(CHATBOT_DEBUG_ERRORS);
}
CMD:clearmemory(playerid, params[])
{
new id;
if(sscanf(params, "d", id))
return SendClientMessage(playerid, COLOR_RED, "/clearmemory <id>");
ClearMemory(id);
return 1;
}
CMD:disablesysprompt(playerid, params[])
{
SetSystemPrompt("");
return 1;
}
CMD:sysprompt(playerid, params[])
{
new sysPrompt[512];
if(sscanf(params, "s[512]", sysPrompt))
return SendClientMessage(playerid, COLOR_RED, "/sysprompt <system_prompt>");
SetSystemPrompt(sysPrompt);
return 1;
}
CMD:bot(playerid, params[])
{
new prompt[512];
if(sscanf(params, "s[512]", prompt))
return SendClientMessage(playerid, COLOR_RED, "/bot <prompt>");
RequestToChatBot(prompt, playerid);
return 1;
}
CMD:botglobal(playerid, params[])
{
new prompt[512];
if(sscanf(params, "s[512]", prompt))
return SendClientMessage(playerid, COLOR_RED, "/botglobal <prompt>");
RequestToChatBot(prompt, GLOBAL_REQUEST);
return 1;
}
CMD:lastresponse(playerid, params[])
{
ShowPlayerDialog(playerid, CHATBOT_DIALOG, DIALOG_STYLE_MSGBOX, "Chat Bot Answer", lastResponses[playerid], "Ok", "");
return 1;
}
public OnChatBotResponse(prompt[], response[], id)
{
//from a player
if(id >= 0 && id < MAX_PLAYERS)
{
format(lastResponses[id], 1024, "%s", response);
SendClientMessage(id, COLOR_MAGENTA, "Chat Bot Responded! Check it with /lastresponse.");
}
else if(id == GLOBAL_REQUEST) //global
{
format(lastGlobalResponse, 2048, "%s", response);
SendClientMessageToAll(COLOR_MAGENTA, "Chat Bot Responded Globally! Check it with /lastglobalresponse.");
}
}
public OnChatBotError(id, const error[])
{
printf("[ChatBot ERROR] | ID: %d | Message: %s", id, error);
return 1;
}
- Download the last Release.
- Put
samp-chatbot.incinsidepawno/includefolder.
- Put
samp-chatbot.dllinsidepluginsfolder; - Put
libcurl.dll libcrypto-3.dll libss-3.dllinside the root server folder.
- Put
samp-chatbot.soinsidepluginsfolder.
Compiling on Windows is pretty simple, it requires Visual Studio 2022 with the latest C++ Windows SDK, libcurl is already provided.
In Linux (I only tried on Debian based systems) you need to do make clean and make inside the main folder, libcurl libssl libcrypto are already provided.
If you want to compile curl and openssl yourself you will need to cross-compile them in 32 bit on 64 bit machine.
Steps:
- remove libcurl and OpenSSL if it's already install and update with
ldconfigotherwise it will create conflicts! - install cross-platform multilib:
sudo apt install gcc-multilib g++-multilib - download OpenSSL 3.3.1 and extract it
- go inside OpenSSL folder and configure on x86:
setarch i386 ./config -m32 - compile and install OpenSSL
makeandsudo make install - download libcurl 8.8.0 and extract it
- configure libcurl by doing:
./configure --host=i686-pc-linux-gnu --with-openssl CFLAGS=-m32 CC=/usr/bin/gcc - compile libcurl
makeand install itcd lib/andsudo make install - find and copy
libcurl.a libcrypto.a libssl.ainsidesamp-chatbot-root-folder/lib - now you should have everything ready for compilation!
For compiling the samp-chatbot do make clean and make inside the main folder, binaries are inside bin/linux/Release.
This project is licensed under the MIT License - see the LICENSE file for details
Project structure inspired from: