Гайд [RakSAMP Lite] Полезные сниппеты и функции

kyrtion

Известный
Автор темы
878
309
Данная тема создана специально для RakSAMP Lite.
Не следует путаться с темой MoonLoader.

Описание: *текст*
Пример использования:
Lua:
*code*
Код:
Lua:
*code*



Описание: возвращает ник с помощью ID игрока
Пример использования:
Lua:
local nick = sampGetPlayerNickname(int id)
Код:
Lua:
function sampGetPlayerNickname(id)
    local player = getPlayer(id)
    if player and player.nick then return player.nick end
end



Описание: возвращает ID игрока с помощью ник
Пример использования:
Lua:
local id = sampGetPlayerIdByNickname(string nick)
Код:
Lua:
function sampGetPlayerIdByNickname(nick)
    for id, player in pairs(getAllPlayers()) do
        if player and player.nick == nick then return id end
    end
end



Описание: возвращает максимальный ID игрока в стриме/на сервере
Пример использования:
Lua:
local count = sampGetMaxPlayerId(bool streamed)
Код:
Lua:
function sampGetMaxPlayerId(bool)
    local bool = bool and true or false
    local lastId = 0
    for id, player in pairs(getAllPlayers()) do
        if player and player.nick and player.exist == bool and lastId < id then lastId = id end
    end
    return lastId
end
 
Последнее редактирование:

whyega52

Гений, миллионер, плейбой, долбаеб
Модератор
2,769
2,592
Данная тема создана специально для RakSAMP Lite.
Не следует путаться с темой MoonLoader.

Описание: *текст*
Пример использования:
Lua:
*code*
Код:
Lua:
*code*



Описание: возвращает ID игрока с помощью ник
Пример использования:
Lua:
sampGetPlayerIdByNickname(string nick)
Код:
Lua:
function sampGetPlayerIdByNickname(nick)
    for id, player in pairs(getAllPlayers()) do
        if player and nick == player.nick then
            return id
        end
    end
end
Описание: возвращает максимальный ID игрока в стриме/на сервере
Пример использования:
Lua:
sampGetMaxPlayerId(bool steamed)
Код:
Lua:
function sampGetMaxPlayerId(bool)
    local lastId = 0
    if bool then
        for id, player in pairs(getAllPlayers()) do
            if player and player.nick and player.position and player.position.x then
                lastId = id
            end
        end
    else
        for id, player in pairs(getAllPlayers()) do
            if player and player.nick then
                lastId = id
            end
        end
    end
    return lastId
end
Описание: возвращает ник с помощью ID игрока
Пример использования:
Lua:
sampGetPlayerNickname(int id)
Код:
Lua:
function sampGetPlayerNickname(id)
    return getPlayer(id).nick
end
Описание: Получение дистанции на плоскости и в пространстве
Пример использования:
Lua:
local vec3d = {x = 300, y = 500, z = 25}
local vec3d = {x = -100, y = 400, z = 10}


local bx, by, bz = getBotPostion()
print(getDistanceBetweenCoords3d(vec3d.x, vec3d.y, vec3d.z, bx, by, bz))
print(getDistanceBetweenCoords2d(vec2d.x, vec2d.y, bx, by))


function getDistanceBetweenCoords3d(x1, y1, z1, x2, y2, z2)
    return math.sqrt(((x2 - x1)^2) + ((y2 - y1)^2) + ((z2 - z1)^2))
end

function getDistanceBetweenCoords2d(x1, y1, x2, y2)
    return math.sqrt(((x2 - x1)^2) + ((y2 - y1)^2))
end
Код:
Lua:
function getDistanceBetweenCoords3d(x1, y1, z1, x2, y2, z2)
    return math.sqrt(((x2 - x1)^2) + ((y2 - y1)^2) + ((z2 - z1)^2))
end

function getDistanceBetweenCoords2d(x1, y1, x2, y2)
    return math.sqrt(((x2 - x1)^2) + ((y2 - y1)^2))
end

Описание: Таблица с информацией о машинах (ID, модель, количество сидений). Спарсено с исходника RakSamp
Пример использования:
Lua:
local vehicle = {
    [400] = {model = "Landstalker", seats = 3},
    [401] = {model = "Bravura", seats = 1},
    [402] = {model = "Buffalo", seats = 1},
    [403] = {model = "Linerunner", seats = 1},
    [404] = {model = "Perennial", seats = 3},
    [405] = {model = "Sentinel", seats = 3},
    [406] = {model = "Dumper", seats = 0},
    [407] = {model = "FireTruck", seats = 1},
    [408] = {model = "Trashmaster", seats = 1},
    [409] = {model = "Stretch", seats = 3},
    [410] = {model = "Manana", seats = 1},
    [411] = {model = "Infernus", seats = 1},
    [412] = {model = "Voodoo", seats = 1},
    [413] = {model = "Pony", seats = 3},
    [414] = {model = "Mule", seats = 1},
    [415] = {model = "Cheetah", seats = 1},
    [416] = {model = "Ambulance", seats = 3},
    [417] = {model = "Leviathan", seats = 1},
    [418] = {model = "Moonbeam", seats = 3},
    [419] = {model = "Esperanto", seats = 1},
    [420] = {model = "Taxi", seats = 3},
    [421] = {model = "Washington", seats = 3},
    [422] = {model = "Bobcat", seats = 1},
    [423] = {model = "MrWhoopee", seats = 1},
    [424] = {model = "BFInjection", seats = 1},
    [425] = {model = "Hunter", seats = 0},
    [426] = {model = "Premier", seats = 3},
    [427] = {model = "Enforcer", seats = 3},
    [428] = {model = "Securicar", seats = 3},
    [429] = {model = "Banshee", seats = 1},
    [430] = {model = "Predator", seats = 0},
    [431] = {model = "Bus", seats = 7},
    [432] = {model = "Rhino", seats = 0},
    
    [433] = {model = "Barracks", seats = 1},
    [434] = {model = "Hotknife", seats = 1},
    [435] = {model = "ArtictTrailer", seats = 0},
    [436] = {model = "Previon", seats = 1},
    [437] = {model = "Coach", seats = 7},
    [438] = {model = "Cabbie", seats = 3},
    [439] = {model = "Stallion", seats = 1},
    [440] = {model = "Rumpo", seats = 3},
    [441] = {model = "RCBandit", seats = 0},
    [442] = {model = "Romero", seats = 1},
    [443] = {model = "Packer", seats = 1},
    [444] = {model = "Monster", seats = 1},
    [445] = {model = "Admiral", seats = 3},
    [446] = {model = "Squalo", seats = 0},
    [447] = {model = "Seasparrow", seats = 1},
    [448] = {model = "PizzaBoy", seats = 0},
    
    [449] = {model = "Trolly", seats = 1},
    
    [450] = {model = "ArtictTrailer2", seats = 0},
    [451] = {model = "Turismo", seats = 1},
    [452] = {model = "Speeder", seats = 0},
    [453] = {model = "Reefer", seats = 0},
    [454] = {model = "Tropic", seats = 0},
    [455] = {model = "Flatbed", seats = 1},
    [456] = {model = "Yankee", seats = 1},
    [457] = {model = "Caddy", seats = 1},
    [458] = {model = "Solair", seats = 3},
    [459] = {model = "BerkleysRCVan", seats = 3},
    [460] = {model = "Skimmer", seats = 1},
    [461] = {model = "PCJ600", seats = 1},
    [462] = {model = "Faggio", seats = 1},
    [463] = {model = "Freeway", seats = 1},
    [464] = {model = "RCBaron", seats = 0},
    [465] = {model = "RCRaider", seats = 0},
    [466] = {model = "Glendale", seats = 3},
    [467] = {model = "Oceanic", seats = 3},
    [468] = {model = "Sanchez", seats = 1},
    [469] = {model = "Sparrow", seats = 1},
    [470] = {model = "Patriot", seats = 3},
    [471] = {model = "Quadbike", seats = 1},
 
    
    [472] = {model = "Coastguard", seats = 0},
    [473] = {model = "Dinghy", seats = 0},
    [474] = {model = "Hermes", seats = 1},
    [475] = {model = "Sabre", seats = 1},
    [476] = {model = "Rustler", seats = 0},
    [477] = {model = "ZR350", seats = 1},
    [478] = {model = "Walton", seats = 1},
    [479] = {model = "Regina", seats = 3},
    [480] = {model = "Comet", seats = 1},
    [481] = {model = "BMX", seats = 0},
    [482] = {model = "Burrito", seats = 3},
    
    [483] = {model = "Camper", seats = 2},
    [484] = {model = "Marquis", seats = 0},
    [485] = {model = "Baggage", seats = 0},
    [486] = {model = "Dozer", seats = 0},
    [487] = {model = "Maverick", seats = 3},
    [488] = {model = "NewsChopper", seats = 1},
    [489] = {model = "Rancher", seats = 1},
    [490] = {model = "FBIRancher", seats = 3},
    [491] = {model = "Virgo", seats = 1},
    [492] = {model = "Greenwood", seats = 3},
    [493] = {model = "Jetmax", seats = 0},
    [494] = {model = "HotringRacer", seats = 1},
    [495] = {model = "Sandking", seats = 1},
    [496] = {model = "BlistaCompact", seats = 1},
    [497] = {model = "PoliceMaverick", seats = 3},
    [498] = {model = "Boxville", seats = 3},
    [499] = {model = "Benson", seats = 1},
    [500] = {model = "Mesa", seats = 1},
    [501] = {model = "RCGoblin", seats = 0},
    [502] = {model = "HotringRacer2", seats = 1},
    [503] = {model = "HotringRacer3", seats = 1},
    [504] = {model = "BloodringBanger", seats = 1},
    [505] = {model = "Rancher", seats = 1},
    [506] = {model = "SuperGT", seats = 1},
    [507] = {model = "Elegant", seats = 3},
    [508] = {model = "Journey", seats = 1},
    [509] = {model = "Bike", seats = 0},
    [510] = {model = "MountainBike", seats = 0},
    [511] = {model = "Beagle", seats = 1},
    [512] = {model = "Cropduster", seats = 0},
    [513] = {model = "Stuntplane", seats = 0},
    [514] = {model = "Tanker", seats = 1},
 
    [515] = {model = "Roadtrain", seats = 1},
    
    [516] = {model = "Nebula", seats = 3},
    [517] = {model = "Majestic", seats = 1},
    [518] = {model = "Buccaneer", seats = 1},
    [519] = {model = "Shamal", seats = 0},
    [520] = {model = "Hydra", seats = 0},
    [521] = {model = "FCR900", seats = 1},
    [522] = {model = "NRG500", seats = 1},
    [523] = {model = "HPV1000", seats = 1},
    [524] = {model = "CementTruck", seats = 1},
    [525] = {model = "Towtruck", seats = 1},
    [526] = {model = "Fortune", seats = 1},
    [527] = {model = "Cadrona", seats = 1},
    [528] = {model = "FBITruck", seats = 1},
    [529] = {model = "Willard", seats = 3},
    [530] = {model = "Forklift", seats = 0},
    [531] = {model = "Tractor", seats = 0},
    [532] = {model = "CombineHarvester", seats = 0},
    [533] = {model = "Feltzer", seats = 1},
    [534] = {model = "Remington", seats = 1},
    [535] = {model = "Slamvan", seats = 1},
    [536] = {model = "Blade", seats = 1},
    [537] = {model = "Freight", seats = 1},
 
    [538] = {model = "BrownStreakEngine", seats = 1},
 
    [539] = {model = "Vortex", seats = 0},
    [540] = {model = "Vincent", seats = 3},
    [541] = {model = "Bullet", seats = 1},
    [542] = {model = "Clover", seats = 1},
    [543] = {model = "Sadler", seats = 1},
    [544] = {model = "FireTruckwithladder", seats = 1},
    [545] = {model = "Hustler", seats = 1},
    [546] = {model = "Intruder", seats = 3},
    [547] = {model = "Primo", seats = 3},
    [548] = {model = "Cargobob", seats = 1},
    [549] = {model = "Tampa", seats = 1},
    [550] = {model = "Sunrise", seats = 3},
    [551] = {model = "Merit", seats = 3},
    [552] = {model = "UtilityVan", seats = 1},
    [553] = {model = "Nevada", seats = 0},
    [554] = {model = "Yosemite", seats = 1},
    [555] = {model = "Windsor", seats = 1},
    [556] = {model = "Monster2", seats = 1},
    [557] = {model = "Monster3", seats = 1},
    [558] = {model = "Uranus", seats = 1},
    [559] = {model = "Jester", seats = 1},
    [560] = {model = "Sultan", seats = 3},
    [561] = {model = "Stratum", seats = 3},
    [562] = {model = "Elegy", seats = 1},
    [563] = {model = "Raindance", seats = 1},
    [564] = {model = "RCTiger", seats = 0},
    [565] = {model = "Flash", seats = 1},
    [566] = {model = "Tahoma", seats = 3},
    [567] = {model = "Savanna", seats = 3},
    [568] = {model = "Bandito", seats = 0},
    [569] = {model = "FreightTrainFlatbed", seats = 0},
 
    [570] = {model = "BrownStreak", seats = 0},
 
    [571] = {model = "Kart", seats = 0},
    [572] = {model = "Mower", seats = 0},
    [573] = {model = "Dune", seats = 1},
    [574] = {model = "Sweeper", seats = 0},
    [575] = {model = "Broadway", seats = 1},
    [576] = {model = "Tornado", seats = 1},
    [577] = {model = "AT400", seats = 0},
    [578] = {model = "DFT30", seats = 1},
 
    [579] = {model = "Huntley", seats = 3},
    [580] = {model = "Stafford", seats = 1},
    [581] = {model = "BF400", seats = 1},
    [582] = {model = "NewsVan", seats = 3},
    [583] = {model = "Tug", seats = 0},
    [584] = {model = "PetrolTrailer", seats = 0},
    [585] = {model = "Emperor", seats = 3},
    [586] = {model = "Wayfarer", seats = 1},
    [587] = {model = "Euros", seats = 1},
    [588] = {model = "Hotdog", seats = 1},
    [589] = {model = "Club", seats = 1},
    [590] = {model = "FreightTrainBoxcar", seats = 0},
    
    [591] = {model = "ArtictTrailer3", seats = 0},
    [592] = {model = "Andromada", seats = 0},
    [593] = {model = "Dodo", seats = 1},
    [594] = {model = "RCCam", seats = 0},
    [595] = {model = "Launch", seats = 0},
    [596] = {model = "PoliceCarLS", seats = 3},
    [597] = {model = "PoliceCarSF", seats = 3},
    [598] = {model = "PoliceCarLV", seats = 3},
    [599] = {model = "PoliceRanger", seats = 1},
    [600] = {model = "Picador", seats = 1},
    [601] = {model = "SWAT", seats = 1},
    [602] = {model = "Alpha", seats = 1},
    [603] = {model = "Phoenix", seats = 1},
    [604] = {model = "DamagedGlendale", seats = 3},
    [605] = {model = "DamagedSadler", seats = 1},
    [606] = {model = "BaggageTrailer", seats = 0},
    [607] = {model = "BaggageTrailer2", seats = 0},
    [608] = {model = "TugStaircase", seats = 0},
    [609] = {model = "BlackBoxville", seats = 3},
    [610] = {model = "FarmTrailer", seats = 0},
    [611] = {model = "StreetSweeperTrailer", seats = 0}
}


local seats = vehicle[getAllVehicles()[getBotVehicle()].model].seats
local model = vehicle[getAllVehicles()[getBotVehicle()].model].model
print(model, seats)
Код:
Lua:
local vehicle = {
    [400] = {model = "Landstalker", seats = 3},
    [401] = {model = "Bravura", seats = 1},
    [402] = {model = "Buffalo", seats = 1},
    [403] = {model = "Linerunner", seats = 1},
    [404] = {model = "Perennial", seats = 3},
    [405] = {model = "Sentinel", seats = 3},
    [406] = {model = "Dumper", seats = 0},
    [407] = {model = "FireTruck", seats = 1},
    [408] = {model = "Trashmaster", seats = 1},
    [409] = {model = "Stretch", seats = 3},
    [410] = {model = "Manana", seats = 1},
    [411] = {model = "Infernus", seats = 1},
    [412] = {model = "Voodoo", seats = 1},
    [413] = {model = "Pony", seats = 3},
    [414] = {model = "Mule", seats = 1},
    [415] = {model = "Cheetah", seats = 1},
    [416] = {model = "Ambulance", seats = 3},
    [417] = {model = "Leviathan", seats = 1},
    [418] = {model = "Moonbeam", seats = 3},
    [419] = {model = "Esperanto", seats = 1},
    [420] = {model = "Taxi", seats = 3},
    [421] = {model = "Washington", seats = 3},
    [422] = {model = "Bobcat", seats = 1},
    [423] = {model = "MrWhoopee", seats = 1},
    [424] = {model = "BFInjection", seats = 1},
    [425] = {model = "Hunter", seats = 0},
    [426] = {model = "Premier", seats = 3},
    [427] = {model = "Enforcer", seats = 3},
    [428] = {model = "Securicar", seats = 3},
    [429] = {model = "Banshee", seats = 1},
    [430] = {model = "Predator", seats = 0},
    [431] = {model = "Bus", seats = 7},
    [432] = {model = "Rhino", seats = 0},
    
    [433] = {model = "Barracks", seats = 1},
    [434] = {model = "Hotknife", seats = 1},
    [435] = {model = "ArtictTrailer", seats = 0},
    [436] = {model = "Previon", seats = 1},
    [437] = {model = "Coach", seats = 7},
    [438] = {model = "Cabbie", seats = 3},
    [439] = {model = "Stallion", seats = 1},
    [440] = {model = "Rumpo", seats = 3},
    [441] = {model = "RCBandit", seats = 0},
    [442] = {model = "Romero", seats = 1},
    [443] = {model = "Packer", seats = 1},
    [444] = {model = "Monster", seats = 1},
    [445] = {model = "Admiral", seats = 3},
    [446] = {model = "Squalo", seats = 0},
    [447] = {model = "Seasparrow", seats = 1},
    [448] = {model = "PizzaBoy", seats = 0},
    
    [449] = {model = "Trolly", seats = 1},
    
    [450] = {model = "ArtictTrailer2", seats = 0},
    [451] = {model = "Turismo", seats = 1},
    [452] = {model = "Speeder", seats = 0},
    [453] = {model = "Reefer", seats = 0},
    [454] = {model = "Tropic", seats = 0},
    [455] = {model = "Flatbed", seats = 1},
    [456] = {model = "Yankee", seats = 1},
    [457] = {model = "Caddy", seats = 1},
    [458] = {model = "Solair", seats = 3},
    [459] = {model = "BerkleysRCVan", seats = 3},
    [460] = {model = "Skimmer", seats = 1},
    [461] = {model = "PCJ600", seats = 1},
    [462] = {model = "Faggio", seats = 1},
    [463] = {model = "Freeway", seats = 1},
    [464] = {model = "RCBaron", seats = 0},
    [465] = {model = "RCRaider", seats = 0},
    [466] = {model = "Glendale", seats = 3},
    [467] = {model = "Oceanic", seats = 3},
    [468] = {model = "Sanchez", seats = 1},
    [469] = {model = "Sparrow", seats = 1},
    [470] = {model = "Patriot", seats = 3},
    [471] = {model = "Quadbike", seats = 1},
 
    
    [472] = {model = "Coastguard", seats = 0},
    [473] = {model = "Dinghy", seats = 0},
    [474] = {model = "Hermes", seats = 1},
    [475] = {model = "Sabre", seats = 1},
    [476] = {model = "Rustler", seats = 0},
    [477] = {model = "ZR350", seats = 1},
    [478] = {model = "Walton", seats = 1},
    [479] = {model = "Regina", seats = 3},
    [480] = {model = "Comet", seats = 1},
    [481] = {model = "BMX", seats = 0},
    [482] = {model = "Burrito", seats = 3},
    
    [483] = {model = "Camper", seats = 2},
    [484] = {model = "Marquis", seats = 0},
    [485] = {model = "Baggage", seats = 0},
    [486] = {model = "Dozer", seats = 0},
    [487] = {model = "Maverick", seats = 3},
    [488] = {model = "NewsChopper", seats = 1},
    [489] = {model = "Rancher", seats = 1},
    [490] = {model = "FBIRancher", seats = 3},
    [491] = {model = "Virgo", seats = 1},
    [492] = {model = "Greenwood", seats = 3},
    [493] = {model = "Jetmax", seats = 0},
    [494] = {model = "HotringRacer", seats = 1},
    [495] = {model = "Sandking", seats = 1},
    [496] = {model = "BlistaCompact", seats = 1},
    [497] = {model = "PoliceMaverick", seats = 3},
    [498] = {model = "Boxville", seats = 3},
    [499] = {model = "Benson", seats = 1},
    [500] = {model = "Mesa", seats = 1},
    [501] = {model = "RCGoblin", seats = 0},
    [502] = {model = "HotringRacer2", seats = 1},
    [503] = {model = "HotringRacer3", seats = 1},
    [504] = {model = "BloodringBanger", seats = 1},
    [505] = {model = "Rancher", seats = 1},
    [506] = {model = "SuperGT", seats = 1},
    [507] = {model = "Elegant", seats = 3},
    [508] = {model = "Journey", seats = 1},
    [509] = {model = "Bike", seats = 0},
    [510] = {model = "MountainBike", seats = 0},
    [511] = {model = "Beagle", seats = 1},
    [512] = {model = "Cropduster", seats = 0},
    [513] = {model = "Stuntplane", seats = 0},
    [514] = {model = "Tanker", seats = 1},
 
    [515] = {model = "Roadtrain", seats = 1},
    
    [516] = {model = "Nebula", seats = 3},
    [517] = {model = "Majestic", seats = 1},
    [518] = {model = "Buccaneer", seats = 1},
    [519] = {model = "Shamal", seats = 0},
    [520] = {model = "Hydra", seats = 0},
    [521] = {model = "FCR900", seats = 1},
    [522] = {model = "NRG500", seats = 1},
    [523] = {model = "HPV1000", seats = 1},
    [524] = {model = "CementTruck", seats = 1},
    [525] = {model = "Towtruck", seats = 1},
    [526] = {model = "Fortune", seats = 1},
    [527] = {model = "Cadrona", seats = 1},
    [528] = {model = "FBITruck", seats = 1},
    [529] = {model = "Willard", seats = 3},
    [530] = {model = "Forklift", seats = 0},
    [531] = {model = "Tractor", seats = 0},
    [532] = {model = "CombineHarvester", seats = 0},
    [533] = {model = "Feltzer", seats = 1},
    [534] = {model = "Remington", seats = 1},
    [535] = {model = "Slamvan", seats = 1},
    [536] = {model = "Blade", seats = 1},
    [537] = {model = "Freight", seats = 1},
 
    [538] = {model = "BrownStreakEngine", seats = 1},
 
    [539] = {model = "Vortex", seats = 0},
    [540] = {model = "Vincent", seats = 3},
    [541] = {model = "Bullet", seats = 1},
    [542] = {model = "Clover", seats = 1},
    [543] = {model = "Sadler", seats = 1},
    [544] = {model = "FireTruckwithladder", seats = 1},
    [545] = {model = "Hustler", seats = 1},
    [546] = {model = "Intruder", seats = 3},
    [547] = {model = "Primo", seats = 3},
    [548] = {model = "Cargobob", seats = 1},
    [549] = {model = "Tampa", seats = 1},
    [550] = {model = "Sunrise", seats = 3},
    [551] = {model = "Merit", seats = 3},
    [552] = {model = "UtilityVan", seats = 1},
    [553] = {model = "Nevada", seats = 0},
    [554] = {model = "Yosemite", seats = 1},
    [555] = {model = "Windsor", seats = 1},
    [556] = {model = "Monster2", seats = 1},
    [557] = {model = "Monster3", seats = 1},
    [558] = {model = "Uranus", seats = 1},
    [559] = {model = "Jester", seats = 1},
    [560] = {model = "Sultan", seats = 3},
    [561] = {model = "Stratum", seats = 3},
    [562] = {model = "Elegy", seats = 1},
    [563] = {model = "Raindance", seats = 1},
    [564] = {model = "RCTiger", seats = 0},
    [565] = {model = "Flash", seats = 1},
    [566] = {model = "Tahoma", seats = 3},
    [567] = {model = "Savanna", seats = 3},
    [568] = {model = "Bandito", seats = 0},
    [569] = {model = "FreightTrainFlatbed", seats = 0},
 
    [570] = {model = "BrownStreak", seats = 0},
 
    [571] = {model = "Kart", seats = 0},
    [572] = {model = "Mower", seats = 0},
    [573] = {model = "Dune", seats = 1},
    [574] = {model = "Sweeper", seats = 0},
    [575] = {model = "Broadway", seats = 1},
    [576] = {model = "Tornado", seats = 1},
    [577] = {model = "AT400", seats = 0},
    [578] = {model = "DFT30", seats = 1},
 
    [579] = {model = "Huntley", seats = 3},
    [580] = {model = "Stafford", seats = 1},
    [581] = {model = "BF400", seats = 1},
    [582] = {model = "NewsVan", seats = 3},
    [583] = {model = "Tug", seats = 0},
    [584] = {model = "PetrolTrailer", seats = 0},
    [585] = {model = "Emperor", seats = 3},
    [586] = {model = "Wayfarer", seats = 1},
    [587] = {model = "Euros", seats = 1},
    [588] = {model = "Hotdog", seats = 1},
    [589] = {model = "Club", seats = 1},
    [590] = {model = "FreightTrainBoxcar", seats = 0},
    
    [591] = {model = "ArtictTrailer3", seats = 0},
    [592] = {model = "Andromada", seats = 0},
    [593] = {model = "Dodo", seats = 1},
    [594] = {model = "RCCam", seats = 0},
    [595] = {model = "Launch", seats = 0},
    [596] = {model = "PoliceCarLS", seats = 3},
    [597] = {model = "PoliceCarSF", seats = 3},
    [598] = {model = "PoliceCarLV", seats = 3},
    [599] = {model = "PoliceRanger", seats = 1},
    [600] = {model = "Picador", seats = 1},
    [601] = {model = "SWAT", seats = 1},
    [602] = {model = "Alpha", seats = 1},
    [603] = {model = "Phoenix", seats = 1},
    [604] = {model = "DamagedGlendale", seats = 3},
    [605] = {model = "DamagedSadler", seats = 1},
    [606] = {model = "BaggageTrailer", seats = 0},
    [607] = {model = "BaggageTrailer2", seats = 0},
    [608] = {model = "TugStaircase", seats = 0},
    [609] = {model = "BlackBoxville", seats = 3},
    [610] = {model = "FarmTrailer", seats = 0},
    [611] = {model = "StreetSweeperTrailer", seats = 0}
}
 
Последнее редактирование:
  • Нравится
Реакции: Rafinad и kyrtion

kyrtion

Известный
Автор темы
878
309
Описание: возвращает список игроков в стрим зоне
Пример использования:
Lua:
local list = sampGetPlayersInStreamZone()
Код:
Lua:
--[[sampGetPlayersInStreamZone() = {
   {
        string nick,
        int id, -- new!
        table position,
        float distance, -- new!
        int score,
        int ping,
        bool exist,
        int skin,
        int color,
    }
    ...
}]]

function sampGetPlayersInStreamZone()
    local list = {}
    local mX, mY, mZ = getBotPosition()
    for id, player in pairs(getAllPlayers()) do
        if player and player.nick and player.exist then
            player.id = id
            player.distance = math.sqrt(((mX-player.position.x)^2) + ((mY-player.position.y)^2) + ((mZ-player.position.z)^2))
            list[#list+1] = player
        end
    end
    return list
end
 
Последнее редактирование:

whyega52

Гений, миллионер, плейбой, долбаеб
Модератор
2,769
2,592
Lua:
        if player and player.position and player.position.x then
в структуре getAllPlayers существует поле для проверки на то, находится игрок в стриме или нет
1685770855080.png
 
  • Нравится
Реакции: kyrtion

Ulong

Диванный критик
Проверенный
64
368
Смысл темы если это просто калька уже существующих функций взятых с темы сниппетов под луа или других яп?
Только полный имбецил не сможет разобраться в апи который есть в основной теме. Короче говно

Описание: дисконнект при коннекте, теперь можно удалять тему
Код:
Lua:
function onReceivePacket(id, bs)
    if id == 34 then
        local bs_r = bitStream.new()
        bs_r:writeUInt8(32)  
        bs_r:sendPacket()
        bs_r:reset()
    end
end
 
Последнее редактирование:

mihagrom

Участник
98
88
Описание: возвращает таблицу с никами игроков, которые находятся в указанном радиусе.
Пример использования:
Lua:
for k, v in ipairs(getPlayersInRadius(100)) do
    print('Игрок '..v..' находится в указанном радиусе.')
end
Код:
Lua:
function getPlayersInRadius(radius)
    local players = {}
    local x, y, z = getBotPosition()
    for k, v in ipairs(getAllPlayers()) do  
        if getAllPlayers()[k].exist and getAllPlayers()[k].nick ~= getBotNick() and locateAnyMeans2d(x, y, getAllPlayers()[k].position.x, getAllPlayers()[k].position.y, radius) then
            table.insert(players, getAllPlayers()[k].nick)
        end
    end
    return players
end

function locateAnyMeans2d(x, y, ox, oy, radius)
    return (math.sqrt((x - ox)^2 + (y - oy)^2) <= radius)
end
 
Последнее редактирование:

xionerme

Потрачен
748
259
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Описание: Функция doesDirectoryExist используется для проверки существования директории (папки) в файловой системе. Она принимает путь к директории в качестве аргумента и возвращает булевое значение: true, если директория существует, и false, если она не существует.
Пример использования:
Lua:
local folder_name = 'raksamptop4ik'

if not doesDirectoryExist(folder_name) then
   os.execute('mkdir '..folder_name)
end
Код:
Lua:
function doesDirectoryExist(dirname)
    local ok, err, code = os.rename(dirname, dirname)
    if not ok then
        if code == 13 then
            return true
        end
        return false
    end
    return true
end
 

Parothn

Участник
4
11
Описание: Получение угла между двумя векторами (функция getHeadingFromVector2d). Извиняюсь за работу с арктангенсами, я в них 0, хотя учусь на физмате.
Пример использования:
Lua:
-- Нужно указывать просто координаты, координаты бота вычисляются внутри функции
local angle = getHeadingFromVector2d(x, y)
Код:
Lua:
function getHeadingFromVector2d(x, y)
    local mx, my, mz = getBotPosition()
    return (x - mx < 0 and 0 or (x - mx == 0 and 270 or 360)) - math.deg(math.atan2(x - mx, y - my))
end
 

whyega52

Гений, миллионер, плейбой, долбаеб
Модератор
2,769
2,592
Описание: Получение угла между двумя векторами (функция getHeadingFromVector2d). Извиняюсь за работу с арктангенсами, я в них 0, хотя учусь на физмате.
Пример использования:
Lua:
-- Нужно указывать просто координаты, координаты бота вычисляются внутри функции
local angle = getHeadingFromVector2d(x, y)
Код:
Lua:
function getHeadingFromVector2d(x, y)
    local mx, my, mz = getBotPosition()
    return (x - mx < 0 and 0 or (x - mx == 0 and 270 or 360)) - math.deg(math.atan2(x - mx, y - my))
end
другая реализация этой же функции:
Lua:
function getHeadingFromVector2d(x, y) 
    local angle = math.deg(math.atan2(y, x))
    if (angle < 0) then
        angle = (angle + 360)
    end
    angle = (angle - 90)
    if (angle < 0) then
        angle = (angle + 360)
    end
    return angle
end
 
  • Нравится
Реакции: kyrtion и Parothn

tfornik

Известный
325
260
Описание: Перезагрузка скриптов( нужен addon )
Пример использования:
Lua:
require('addon')

function onRunCommand(cmd)
    if cmd:find('!newreloadlua') then
        reload()
    end
end

function reload()
    local script_name = debug.getinfo(1, 'S').source:sub(2):gsub('\\\\', '\\')
    print(string.format('Script %s is reloaded!', debug.getinfo(1,'S').source:sub(2)))
    clearTasks()
    collectgarbage()
    dofile(script_name)
end

Код:
Lua:
function reload()
    local script_name = debug.getinfo(1, 'S').source:sub(2):gsub('\\\\', '\\')
    print(string.format('Script %s is reloaded!', debug.getinfo(1,'S').source:sub(2)))
    clearTasks()
    collectgarbage()
    dofile(script_name)
end
 
D

deleted-user-139653

Гость
Описание: Перезагрузка скриптов( нужен addon )
Пример использования:
Lua:
require('addon')

function onRunCommand(cmd)
    if cmd:find('!newreloadlua') then
        reload()
    end
end

function reload()
    local script_name = debug.getinfo(1, 'S').source:sub(2):gsub('\\\\', '\\')
    print(string.format('Script %s is reloaded!', debug.getinfo(1,'S').source:sub(2)))
    clearTasks()
    collectgarbage()
    dofile(script_name)
end

Код:
Lua:
function reload()
    local script_name = debug.getinfo(1, 'S').source:sub(2):gsub('\\\\', '\\')
    print(string.format('Script %s is reloaded!', debug.getinfo(1,'S').source:sub(2)))
    clearTasks()
    collectgarbage()
    dofile(script_name)
end
!reloadlua для тебя шутка?
 

cord

Хватит спать на мне
Проверенный
572
470
Описание: Запуск нового окна RakSAMP Lite с параметрами
Пример использования:
Lua:
runNewWindow("cord", "cheat.hackmysoftware.ru:7844")

Код:
Lua:
---@param playerNick string
---@param server string
---@param rconPassword string (опционально)
---@param serverPassword string (опционально)
---@param debug bool (опционально)
function runNewWindow(playerNick, server, rconPassword, serverPassword, debug)
    local PATH = getPath("RakSAMP Lite.exe")
    local playerNick = playerNick or "nick"
    local server = server or "127.0.0.1:7777"
    local rconPassword = rconPassword or ""
    local serverPassword = serverPassword or ""
    local debug = debug and "-d" or ""
    local ip, port = server:match("(.*):(.*)")
    os.execute(string.format('start "" "%s" -n %s -h %s -p %s -c %s -z %s %s', PATH, playerNick, ip, port, rconPassword, serverPassword, debug))
end