- 6
- 0
local ffi = require("ffi")
ffi.cdef([[
typedef struct {
const char* state;
const char* details;
int64_t startTimestamp;
int64_t endTimestamp;
const char* largeImageKey;
const char* largeImageText;
const char* smallImageKey;
const char* smallImageText;
const char* partyId;
int partySize;
int partyMax;
const char* matchSecret;
const char* joinSecret;
const char* spectateSecret;
int8_t instance;
} DiscordRichPresence;
void Discord_Initialize(const char* applicationId,
int handlers,
int autoRegister,
const char* optionalSteamId);
void...
если я ничего не путаю, то данная функция возвращает только ip (лень смотреть в вики, но вроде так)
Возвращает IP и порт.если я ничего не путаю, то данная функция возвращает только ip (лень смотреть в вики, но вроде так)
Не подскажешь как решить? Вроде вызывается с функцией main.Возвращает IP и порт.
А по делу, скорее всего пытаешься вызвать функцию до инициализации сампа
Не подскажешь как решить? Вроде вызывается с функцией main.
function main()
while not isSampAvailable() and not isSampfuncsLoaded() do wait(100) return end
--и тут уже проверка IP адреса и прочий код
end
function main()
if not isSampLoaded() or not isSampfuncsLoaded() then return end
while not isSampAvailable() do wait(100) end
while sampGetCurrentServerName() == 'SA-MP' do wait(10) end
local ip, port = sampGetCurrentServerAdress()
-- if ip == blablabla then
-- blablabla
-- end
while true do wait(0) end
end
local ffi = require("ffi")
ffi.cdef([[
typedef struct {
const char* state;
const char* details;
int64_t startTimestamp;
int64_t endTimestamp;
const char* largeImageKey;
const char* largeImageText;
const char* smallImageKey;
const char* smallImageText;
const char* partyId;
int partySize;
int partyMax;
const char* matchSecret;
const char* joinSecret;
const char* spectateSecret;
int8_t instance;
} DiscordRichPresence;
void Discord_Initialize(const char* applicationId,
int handlers,
int autoRegister,
const char* optionalSteamId);
void Discord_UpdatePresence(const DiscordRichPresence* presence);
]])
local drpc = ffi.load("moonloader/lib/discord-rpc.dll")
local rpc = ffi.new("DiscordRichPresence")
function main()
while not isSampAvailable() do wait(0) end
while true do
wait(0)
serverName = sampGetCurrentServerName()
serverIp, serverPort = sampGetCurrentServerAddress()
if string.find(serverName, 'SA-MP') then
rpc.largeImageKey = 'sa_connecting'
rpc.details = 'Connecting to '..serverIp..':'..serverPort
elseif string.find(serverName, 'TRAINING') then
rpc.largeImageKey = 'sa_training'
elseif string.find(serverName, 'TRAINING') then
rpc.largeImageKey = 'sa_gambit'
elseif string.find(serverName, 'HackMySoftware') then
rpc.largeImageKey = 'sa_hms'
end
end
end
if sampGetGamestate() == 5 then
serverName = sampGetCurrentServerName()
serverIp, serverPort = sampGetCurrentServerAddress()
rpc.largeImageKey = 'connecting'
rpc.details = 'Connecting to '
rpc.state = serverIp..':'..serverPort
elseif sampGetGamestate() == 3 then
if sampIsLocalPlayerSpawned() then
serverName = sampGetCurrentServerName()
serverIp, serverPort = sampGetCurrentServerAddress()
if string.find(serverName, 'Arizona') then
rpc.largeImageKey = 'srv_arz'
elseif string.find(serverName, 'Diamond') then
rpc.largeImageKey = 'srv_drp'
elseif string.find(serverName, 'Evolve') then
rpc.largeImageKey = 'srv_erp'
elseif string.find(serverName, 'HackMySoftware') then
rpc.largeImageKey = 'srv_hms'
else
rpc.largeImageKey = 'large'
end
rpc.largeImageText = u8'Играет на: '..serverName..'\n'..serverIp..':'..serverPort
end
end
Может и не проще, человеку надо через IP - пусть делает через IPа не проще через название сервера?
Lua:local ffi = require("ffi") ffi.cdef([[ typedef struct { const char* state; const char* details; int64_t startTimestamp; int64_t endTimestamp; const char* largeImageKey; const char* largeImageText; const char* smallImageKey; const char* smallImageText; const char* partyId; int partySize; int partyMax; const char* matchSecret; const char* joinSecret; const char* spectateSecret; int8_t instance; } DiscordRichPresence; void Discord_Initialize(const char* applicationId, int handlers, int autoRegister, const char* optionalSteamId); void Discord_UpdatePresence(const DiscordRichPresence* presence); ]]) local drpc = ffi.load("moonloader/lib/discord-rpc.dll") local rpc = ffi.new("DiscordRichPresence") function main() while not isSampAvailable() do wait(0) end while true do wait(0) serverName = sampGetCurrentServerName() serverIp, serverPort = sampGetCurrentServerAddress() if string.find(serverName, 'SA-MP') then rpc.largeImageKey = 'sa_connecting' rpc.details = 'Connecting to '..serverIp..':'..serverPort elseif string.find(serverName, 'TRAINING') then rpc.largeImageKey = 'sa_training' elseif string.find(serverName, 'TRAINING') then rpc.largeImageKey = 'sa_gambit' elseif string.find(serverName, 'HackMySoftware') then rpc.largeImageKey = 'sa_hms' end end end
лично я делал так:
Lua:if sampGetGamestate() == 5 then serverName = sampGetCurrentServerName() serverIp, serverPort = sampGetCurrentServerAddress() rpc.largeImageKey = 'connecting' rpc.details = 'Connecting to ' rpc.state = serverIp..':'..serverPort elseif sampGetGamestate() == 3 then if sampIsLocalPlayerSpawned() then serverName = sampGetCurrentServerName() serverIp, serverPort = sampGetCurrentServerAddress() if string.find(serverName, 'Arizona') then rpc.largeImageKey = 'srv_arz' elseif string.find(serverName, 'Diamond') then rpc.largeImageKey = 'srv_drp' elseif string.find(serverName, 'Evolve') then rpc.largeImageKey = 'srv_erp' elseif string.find(serverName, 'HackMySoftware') then rpc.largeImageKey = 'srv_hms' else rpc.largeImageKey = 'large' end rpc.largeImageText = u8'Играет на: '..serverName..'\n'..serverIp..':'..serverPort end end
Так string.find будет работать и когда название сервера "Gambit rpg 228 1337 eshkere" и когда "Gambit RP"Может и не проще, человеку надо через IP - пусть делает через IP
Может там название сервера меняется каждую секунду, м?
Это то понятное делоТак string.find будет работать и когда название сервера "Gambit rpg 228 1337 eshkere" и когда "Gambit RP"
С такой же логикой можно сказать, что нубо рп очень часто переезжают с ip на ip.Это то понятное дело
Не помню какой проект, но есть такие проекты (нубо рп), которые меняют свое название по кд и у них не всегда есть название сервера типа "Nubo RP" в тайтле, так сказать