- 6
- 0
- Версия SA-MP
-
- Любая
Особо нет навыка в кодинге, пытался че та сделать, но безуспешно, суть в чем, есть скрипт, взят на БХ, в нем можно создать актеров (нпс) но в нем нет сохранение данных, то есть я создал там 5 НПС, расставил в нужные точки и после перезахода их нет, то есть они активны до релога, можете помочь реализовать сохранение в ini или json, cfg, не важно, главное чтобы нпс сохранялись и после перезахода они были в местах где я поставил, вот code скрипта:
Actor:
local imgui = require("imgui")
local encoding = require ("encoding")
encoding.default = "CP1251"
u8 = encoding.UTF8
local selected_obj = -1
local animation = {
file = imgui.ImBuffer(128),
name = imgui.ImBuffer(128),
time = imgui.ImInt(-1),
lockXY = imgui.ImBool(false),
lockF = imgui.ImBool(false),
loop = imgui.ImBool(false),
speed = imgui.ImFloat(3),
}
local drive = {
speed = imgui.ImFloat(30),
ride_type = imgui.ImInt(0),
drive_type = imgui.ImInt(7),
carid = imgui.ImInt(0)
}
local acterSettings = {
botName = imgui.ImBuffer(24),
textActer = imgui.ImBuffer(128),
skinID = imgui.ImInt(0),
rot = imgui.ImInt(0),
DraweNickName = imgui.ImInt(0),
aimTime = imgui.ImFloat(5),
weap = imgui.ImInt(1),
nickName = imgui.ImBool(false),
}
local objectSettings = {
objIDD = imgui.ImInt(0),
objName = imgui.ImBuffer(24),
rot = imgui.ImInt(0),
pos = {x = 0, y = 0, z = 0}
}
local posititon = {
pos = {x = imgui.ImFloat(0), y = imgui.ImFloat(0), z = imgui.ImFloat(0)},
blip = {x = imgui.ImFloat(0), y = imgui.ImFloat(0), z = imgui.ImFloat(0)},
mypos = {x = imgui.ImFloat(0), y = imgui.ImFloat(0), z = imgui.ImFloat(0)},
object = {x = imgui.ImFloat(0), y = imgui.ImFloat(0), z = imgui.ImFloat(0)},
}
local quaternion = {
char = {x = imgui.ImFloat(0), y = imgui.ImFloat(0), z = imgui.ImFloat(0), w = imgui.ImFloat(0)},
object = {x = imgui.ImFloat(0), y = imgui.ImFloat(0), z = imgui.ImFloat(0), w = imgui.ImFloat(0)}
}
local vcar = {
pos = {x = imgui.ImFloat(0), y = imgui.ImFloat(0), z = imgui.ImFloat(0)},
rotate = 0,
gm = imgui.ImBool(false),
id = imgui.ImInt(411),
color = imgui.ImInt(0),
color2 = imgui.ImInt(0),
handle = {}
}
local handle = 0
local obj = {}
local bots = {}
local selected = -1
local window = imgui.ImBool(false)
font_flag = require("moonloader").font_flag
font = renderCreateFont("Tahoma", 10, font_flag.BOLD + font_flag.BORDER)
local weapons = {
[0] = '##',
[1] = 'Brass Knuckles',
[2] = 'Golf Club',
[3] = 'Nightstick',
[4] = 'Knife',
[5] = 'Baseball Bat ',
[6] = 'Shovel',
[7] = 'Pool Cue',
[8] = 'Katana',
[9] = 'Chainsaw',
[10] = 'Purple Dildo',
[11] = 'Dildo',
[12] = 'Vibrator',
[13] = 'Silver Vibrator',
[14] = 'Flowers',
[15] = 'Cane',
[16] = 'Grenade',
[17] = 'Tear Gas',
[18] = 'Molotov Cocktail',
[19] = '##',
[20] = '##',
[21] = '##',
[22] = 'Pistol',
[23] = 'Silent Pistol',
[24] = 'Desert Eagle',
[25] = 'Shotgun',
[26] = 'Sawnoff Shotgun',
[27] = 'Combat Shotgun',
[28] = 'Micro SMG/Uzi',
[29] = 'MP5',
[30] = 'AK-47',
[31] = 'M4',
[32] = 'Tec-9',
[33] = 'Contry Riffle',
[34] = 'Sniper Riffle',
[35] = 'RPG',
[36] = 'HS Rocket',
[37] = 'Flame Thrower',
[38] = 'Minigun',
[39] = 'Satchel charge',
[40] = 'Detonator',
[41] = 'Spraycan',
[42] = 'Fire Extiguisher',
[43] = 'Camera',
[44] = 'Nigh Vision Goggles',
[45] = 'Thermal Goggles',
[46] = 'Parachute'
}
function main()
while not isSampAvailable() do wait(200) end
animation.name.v = "BIKED_BACK"
animation.file.v = "BIKED"
sampRegisterChatCommand("acter",function()
window.v = not window.v
end)
while true do
wait(0)
if #bots > 0 then
if acterSettings.nickName.v then
for i = 1, #bots do
if bots[i].spawn then
local player_pos = {getCharCoordinates(bots[i].h)}
player_pos[3] = player_pos[3] + 1
local xx,yy = convert3DCoordsToScreen(player_pos[1],player_pos[2],player_pos[3])
if isPointOnScreen(player_pos[1],player_pos[2],player_pos[3]) then
renderFontDrawText(font, bots[i].name, xx, yy, 0xFFFFFFFF)
end
end
end
end
end
imgui.Process = window.v
end
end
function imgui.OnDrawFrame()
if window.v then
local resX, resY = getScreenResolution()
local sizeX, sizeY = 910, 620
imgui.SetNextWindowPos(imgui.ImVec2(resX / 2 - sizeX / 2, resY / 2 - sizeY / 2), imgui.Cond.FirstUseEver)
imgui.SetNextWindowSize(imgui.ImVec2(sizeX, 310), imgui.Cond.FirstUseEver)
imgui.Begin("Create your own scene", window, imgui.WindowFlags.NoResize)
imgui.BeginChild("bots", imgui.ImVec2(150, 0), true)
if #bots > 0 then
for i = 1, #bots, 1 do
if imgui.Selectable(u8(bots[i].name), selected == i and true or false) then
selected = selected == -1 and i or i == selected and -1 or i or -1
end
end
end
imgui.EndChild()
imgui.SameLine()
imgui.BeginChild("panel", imgui.ImVec2(550, 0), true)
if selected == -1 then
imgui.PushItemWidth(150)
imgui.InputText(u8"Имя актера", acterSettings.botName)
imgui.PopItemWidth()
if imgui.Button(u8"Создать актера") then
if #acterSettings.botName.v < 3 then
sampAddChatMessage("Имя должно быть от 3 символов", -1)
else
acterSettings.nickName.v = false
table.insert(bots, {spawn = false,h = 0, name = acterSettings.botName.v, pos = {x = 0,y = 0,z = 0}, weap = 0, rot = acterSettings.rot.v,skin = acterSettings.skinID.v })
end
end
else
if select_menu == 1 then
imgui.Text(u8"Имя актера: "..bots[selected].name)
imgui.Text(u8 "задать скина") imgui.SameLine() imgui.PushItemWidth(150) imgui.InputInt(u8'Index', acterSettings.skinID, 1) imgui.PopItemWidth()
imgui.Text(u8 "Задать угол поворота") imgui.SameLine() imgui.PushItemWidth(150) if imgui.SliderInt(u8 "Градус",acterSettings.rot,0,360) then setCharHeading(bots[selected].h,acterSettings.rot.v) end imgui.PopItemWidth()
imgui.Text(u8 "Задать оружие") imgui.SameLine() if imgui.Combo(u8'##weapons', acterSettings.weap, weapons) then giveWeapToActor(bots[selected].h,acterSettings.weap.v) end
if imgui.Button(u8 'Целиться с оружия') then taskAimGunAtChar(bots[selected].h, 1, acterSettings.aimTime.v * 1000) end imgui.SameLine() imgui.PushItemWidth(150) imgui.SliderFloat(u8 'time', acterSettings.aimTime,1,20)imgui.PopItemWidth()
if imgui.CollapsingHeader(u8 'set quaternion') then
if imgui.SliderFloat(u8 'cord X ##8', quaternion.char.x,-1.00000000, 1.00000000) then setCharQuaternion(bots[selected].h, quaternion.char.x.v,quaternion.char.y.v,quaternion.char.z.v,quaternion.char.w.v) end
if imgui.SliderFloat(u8 'cord Y ##9', quaternion.char.y,-1.00000000, 1.00000000) then setCharQuaternion(bots[selected].h, quaternion.char.x.v,quaternion.char.y.v,quaternion.char.z.v,quaternion.char.w.v) end
if imgui.SliderFloat(u8 'cord Z ##10', quaternion.char.z,-1.00000000, 1.00000000) then setCharQuaternion(bots[selected].h, quaternion.char.x.v,quaternion.char.y.v,quaternion.char.z.v,quaternion.char.w.v) end
if imgui.SliderFloat(u8 'cord W ##11', quaternion.char.w,-1.00000000, 1.00000000) then setCharQuaternion(bots[selected].h, quaternion.char.x.v,quaternion.char.y.v,quaternion.char.z.v,quaternion.char.w.v) end
end
imgui.Text(u8 "Задать позицию") imgui.SameLine() imgui.PushItemWidth(100) imgui.InputFloat(u8'##3 POS X', posititon.pos.x, 1) imgui.SameLine() imgui.InputFloat(u8'##3 POS Y', posititon.pos.y, 1) imgui.SameLine() imgui.InputFloat(u8'##3 POS Z', posititon.pos.z, 1) imgui.PopItemWidth()
if imgui.Button("Get my position") then
local x,y,z = getCharCoordinates(1)
posititon.pos.x.v, posititon.pos.y.v, posititon.pos.z.v = tonumber(x), tonumber(y), tonumber(z)
end
imgui.PushItemWidth(100)
imgui.InputText(u8 'текст от лица актера', acterSettings.textActer) imgui.SameLine()
if imgui.Button(u8 "Сказать") then
taskPlayAnim(bots[selected].h, "IDLE_CHAT", "PED", 3.0, false, false, false, true, -1)
lua_thread.create(function()
local x, y, z = getCharCoordinates(bots[selected].h)
text = sampCreate3dText(u8:decode(acterSettings.textActer.v), 0xFFFFFFFF, x, y, z + 1.2,20, false, -1,-1)
wait(10000)
sampDestroy3dText(text)
clearCharTasksImmediately(bots[selected].h)
end)
end
imgui.SameLine()
if imgui.Button(u8 "TP acter") then if bots[selected].h ~= nil and bots[selected].spawn then setCharCoordinates(bots[selected].h, posititon.pos.x.v, posititon.pos.y.v, posititon.pos.z.v) end end
imgui.Checkbox(u8"Рисовать ник бота", acterSettings.nickName)
if imgui.Button(u8 "Spawn", imgui.ImVec2(-1,0)) then
spawnCharFunc(acterSettings.skinID.v)
bots[selected].spawn = true
end
if imgui.Button(u8 "ReSpawn", imgui.ImVec2(-1,0)) then
deleteChar(bots[selected].h)
respawnActor(bots[selected].h)
end
if imgui.Button(u8 "Delete", imgui.ImVec2(-1,0)) then
deleteChar(bots[selected].h)
table.remove(bots, selected)
selected = bots[selected] ~= nil and selected or -1
end
elseif select_menu == 2 then
imgui.Text(u8 "Задать анимацию")
if bots[selected].spawn then
imgui.PushItemWidth(150)
imgui.InputText("name anim",animation.name)
imgui.InputText("file anim",animation.file)
imgui.SliderFloat("speed anim", animation.speed, 0, 10)
imgui.Checkbox("repetition", animation.loop)
if imgui.Button("Play") then
taskPlayAnim(bots[selected].h, animation.name.v, animation.file.v, animation.speed.v, animation.loop.v, false, false, -1)
end
imgui.SameLine()
if imgui.Button("Stop Anim") then
clearCharTasksImmediately(bots[selected].h)
end
imgui.PopItemWidth()
end
end
end
imgui.EndChild()
imgui.SameLine()
imgui.BeginChild("bots3", imgui.ImVec2(160, 0), true)
if imgui.Button(u8"Настройка бота",imgui.ImVec2(-1, 37)) then
select_menu = 1
end
if imgui.Button(u8"Настройка анимации",imgui.ImVec2(-1, 37)) then
select_menu = 2
end
imgui.EndChild()
imgui.SameLine()
imgui.End()
end
end
function getTargetBlipCoordinatesFixed()
local bool, x, y, z = getTargetBlipCoordinates(); if not bool then return false end
requestCollision(x, y); loadScene(x, y, z)
local bool, x, y, z = getTargetBlipCoordinates()
return bool, x, y, z
end
function join_argb(a, r, g, b)
local argb = b -- b
argb = bit.bor(argb, bit.lshift(g, 8)) -- g
argb = bit.bor(argb, bit.lshift(r, 16)) -- r
argb = bit.bor(argb, bit.lshift(a, 24)) -- a
return argb
end
function imgui.TextQuestion(text)
local war = u8'Подсказка:'
if imgui.IsItemHovered() then
imgui.BeginTooltip()
imgui.PushTextWrapPos(450)
imgui.Text(u8'Подсказка:'..text)
imgui.PopTextWrapPos()
imgui.EndTooltip()
end
end
function spawnCharFunc(modelID)
if bots[selected].h == 0 then
requestModel(modelID)
loadAllModelsNow()
local han = createChar(4, modelID, posititon.pos.x.v, posititon.pos.y.v, posititon.pos.z.v)
bots[selected].h = han
markModelAsNoLongerNeeded(modelID)
else
sampAddChatMessage("Такой актёр уже заспавнен",-1)
end
end
function respawnActor(handle)
if handle ~= 0 then
deleteChar(handle)
requestModel(acterSettings.skinID.v)
loadAllModelsNow()
local han = createChar(4, acterSettings.skinID.v, posititon.pos.x.v, posititon.pos.y.v, posititon.pos.z.v)
bots[selected].h = han
markModelAsNoLongerNeeded(acterSettings.skinID.v)
end
end
function giveWeapToActor(handle, weap)
local model = getWeapontypeModel(weap)
requestModel(model)
loadAllModelsNow()
giveWeaponToChar(handle, weap, 5000)
markModelAsNoLongerNeeded(model)
end
function onScriptTerminate(script, quitGame)
if script == thisScript() then
for i = 1, #bots do
deleteChar(bots[i].h)
end
end
end
function apply_custom_style()
imgui.SwitchContext()
local style = imgui.GetStyle()-- BY IvAn Code-- BY IvAn Code
local colors = style.Colors
local clr = imgui.Col
local ImVec4 = imgui.ImVec4
local ImVec2 = imgui.ImVec2
style.WindowPadding = ImVec2(15, 15)
style.WindowRounding = 15.0
style.FramePadding = ImVec2(5, 5)
style.ItemSpacing = ImVec2(12, 8)
style.ItemInnerSpacing = ImVec2(8, 6)
style.IndentSpacing = 25.0
style.ScrollbarSize = 15.0
style.ScrollbarRounding = 15.0
style.GrabMinSize = 15.0
style.GrabRounding = 7.0
style.ChildWindowRounding = 8.0
style.FrameRounding = 6.0
-- BY IvAn Code
colors[clr.Text] = ImVec4(0.95, 0.96, 0.98, 1.00)
colors[clr.TextDisabled] = ImVec4(0.36, 0.42, 0.47, 1.00)
colors[clr.WindowBg] = ImVec4(0.11, 0.15, 0.17, 1.00)
colors[clr.ChildWindowBg] = ImVec4(0.15, 0.18, 0.22, 1.00)
colors[clr.PopupBg] = ImVec4(0.08, 0.08, 0.08, 0.94)
colors[clr.Border] = ImVec4(0.43, 0.43, 0.50, 0.50)
colors[clr.BorderShadow] = ImVec4(0.00, 0.00, 0.00, 0.00)
colors[clr.FrameBg] = ImVec4(0.20, 0.25, 0.29, 1.00)
colors[clr.FrameBgHovered] = ImVec4(0.12, 0.20, 0.28, 1.00)
colors[clr.FrameBgActive] = ImVec4(0.09, 0.12, 0.14, 1.00)
colors[clr.TitleBg] = ImVec4(0.09, 0.12, 0.14, 0.65)
colors[clr.TitleBgCollapsed] = ImVec4(0.00, 0.00, 0.00, 0.51)
colors[clr.TitleBgActive] = ImVec4(0.08, 0.10, 0.12, 1.00)
colors[clr.MenuBarBg] = ImVec4(0.15, 0.18, 0.22, 1.00)
colors[clr.ScrollbarBg] = ImVec4(0.02, 0.02, 0.02, 0.39)
colors[clr.ScrollbarGrab] = ImVec4(0.20, 0.25, 0.29, 1.00)
colors[clr.ScrollbarGrabHovered] = ImVec4(0.18, 0.22, 0.25, 1.00)
colors[clr.ScrollbarGrabActive] = ImVec4(0.09, 0.21, 0.31, 1.00)
colors[clr.ComboBg] = ImVec4(0.20, 0.25, 0.29, 1.00)
colors[clr.CheckMark] = ImVec4(0.28, 0.56, 1.00, 1.00)-- BY IvAn Code
colors[clr.SliderGrab] = ImVec4(0.28, 0.56, 1.00, 1.00)
colors[clr.SliderGrabActive] = ImVec4(0.37, 0.61, 1.00, 1.00)
colors[clr.Button] = ImVec4(0.20, 0.25, 0.29, 1.00)
colors[clr.ButtonHovered] = ImVec4(0.28, 0.56, 1.00, 1.00)
colors[clr.ButtonActive] = ImVec4(0.06, 0.53, 0.98, 1.00)
colors[clr.Header] = ImVec4(0.20, 0.25, 0.29, 0.55)
colors[clr.HeaderHovered] = ImVec4(0.26, 0.59, 0.98, 0.80)
colors[clr.HeaderActive] = ImVec4(0.26, 0.59, 0.98, 1.00)
colors[clr.ResizeGrip] = ImVec4(0.26, 0.59, 0.98, 0.25)
colors[clr.ResizeGripHovered] = ImVec4(0.26, 0.59, 0.98, 0.67)
colors[clr.ResizeGripActive] = ImVec4(0.06, 0.05, 0.07, 1.00)
colors[clr.CloseButton] = ImVec4(0.40, 0.39, 0.38, 0.16)
colors[clr.CloseButtonHovered] = ImVec4(0.40, 0.39, 0.38, 0.39)
colors[clr.CloseButtonActive] = ImVec4(0.40, 0.39, 0.38, 1.00)
colors[clr.PlotLines] = ImVec4(0.61, 0.61, 0.61, 1.00)
colors[clr.PlotLinesHovered] = ImVec4(1.00, 0.43, 0.35, 1.00)
colors[clr.PlotHistogram] = ImVec4(0.90, 0.70, 0.00, 1.00)
colors[clr.PlotHistogramHovered] = ImVec4(1.00, 0.60, 0.00, 1.00)
colors[clr.TextSelectedBg] = ImVec4(0.25, 1.00, 0.00, 0.43)
colors[clr.ModalWindowDarkening] = ImVec4(1.00, 0.98, 0.95, 0.73)
end
apply_custom_style()
Последнее редактирование: