Jump to content

iAxel

Members
  • Posts

    160
  • Joined

  • Last visited

Everything posted by iAxel

  1. iAxel

    [HELP] DxScroll

    Help me please with function moving the scrollbar with mouse To do this I will need the features OnClientKey OnClientCursorMove But I have no idea how to do it Please help me and thanks in advance
  2. iAxel

    [HELP] DxScroll

    Solved: helped dxCreateRenderTarget.
  3. Спасибо помогло. dxSetRenderTarget(rBox, true) for i = 1, 10 do dxDrawRectangle(0, mX-224+65*i-offset, 309, 60, tocolor(50, 50, 50, 235)) dxDrawImage(0, mX-224+65*i-offset, 60, 60, ':guieditor/images/plus.png') dxDrawText('Backpack '..i, mX-89.5, mX-203+65*i-offset) dxDrawText(i..'/35', mX+115.5, mX-224+65*i-offset) end dxSetRenderTarget() dxDrawRectangle(bW+191, bH-280, 319, 560, tocolor(0, 0, 0, 70)) dxDrawImage(bW+191, bH-280, 319, 560, rBox) dxDrawLine(bW+500, bH-280, bW+500, bH+279, tocolor(200, 200, 200, 100), 1) Можете помочь сделать scrollbar так чтобы его размер менялся смотря на количество объектов внутри, заранее благодарен --Scrollbar dxDrawLine(bW+502, bH-280+offset, bW+502, bH-109+offset, tocolor(200, 200, 200, 100), 1) dxDrawLine(bW+508, bH-280+offset, bW+502, bH-280+offset, tocolor(200, 200, 200, 100), 1) dxDrawLine(bW+502, bH-109+offset, bW+508, bH-109+offset, tocolor(200, 200, 200, 100), 1) dxDrawLine(bW+508, bH-109+offset, bW+508, bH-280+offset, tocolor(200, 200, 200, 100), 1) Ну как в браузере
  4. Да в сервер-браузере Перечитай первый вопрос. В сервер-браузере, который встроенный в МТА ? Именно там
  5. Привет всем! Решил сделать DxScroll, ну вроде получилось не плохо. Но проблема в том что не как не могу ограничить видимость вещей внутри Rectangle. Скриншоты Код local sW, sH = guiGetScreenSize() local bW, bH = (sW/2), (sH/2) local offset = 0 -- addEventHandler('onClientRender', root, function () if (isLogged(localPlayer)) then dxDrawRectangle(bW+190, bH-300, 320, 20, tocolor(0, 0, 0, 255)) dxDrawText('INVENTORY', bW+195, bH-300, bW+510, bH-280, tocolor(160, 160, 160, 255), 1, 'default', 'left', 'center', false, false, true, false, false) --Box dxDrawLine(bW+190, bH-281, bW+190, bH+280, tocolor(200, 200, 200, 100), 1) dxDrawLine(bW+510, bH-281, bW+190, bH-281, tocolor(200, 200, 200, 100), 1) dxDrawLine(bW+190, bH+280, bW+510, bH+280, tocolor(200, 200, 200, 100), 1) dxDrawLine(bW+510, bH+280, bW+510, bH-281, tocolor(200, 200, 200, 100), 1) dxDrawRectangle(bW+191, bH-280, 319, 560, tocolor(0, 0, 0, 70)) dxDrawLine(bW+500, bH-280, bW+500, bH+279, tocolor(200, 200, 200, 100), 1) --Scrollbar dxDrawLine(bW+502, bH-280+offset, bW+502, bH-109+offset, tocolor(200, 200, 200, 100), 1) dxDrawLine(bW+508, bH-280+offset, bW+502, bH-280+offset, tocolor(200, 200, 200, 100), 1) dxDrawLine(bW+502, bH-109+offset, bW+508, bH-109+offset, tocolor(200, 200, 200, 100), 1) dxDrawLine(bW+508, bH-109+offset, bW+508, bH-280+offset, tocolor(200, 200, 200, 100), 1) dxDrawRectangle(bW+503, bH-279+offset, 5, 170, tocolor(0, 0, 0, 0)) --Items for i = 1, 10 do dxDrawRectangle(bW+191, bH-345+65*i-offset, 309, 60, tocolor(100, 100, 100, 200)) dxDrawImage(bW+191, bH-345+65*i-offset, 60, 60, ':guieditor/images/plus.png', 0, 0, 0, tocolor(255, 255, 255, 255)) dxDrawText('Backpack '..i, bW+261, bH-326+65*i-offset, bW+499, bH-306+65*i-offset, tocolor(255, 255, 255, 255), 1, 'default-bold', 'left', 'center', false, false, true, false, false) dxDrawText('0/'..i, bW+451, bH-346+65*i-offset, bW+499, bH-326+65*i-offset, tocolor(255, 255, 255, 255), 1, 'default-bold', 'right', 'center', false, false, true, false, false) end end end end ) -- function Scroll(key, state) if (isLogged(localPlayer)) then if (state == 'down') then if (key == 'mouse_wheel_up') then if (offset > 0) then offset = offset-97 else offset = 0 end elseif (key == 'mouse_wheel_down') then if (offset < 388) then offset = offset+97 else offset = 388 end end end end end bindKey('mouse_wheel_up', 'down', Scroll) bindKey('mouse_wheel_down', 'down', Scroll) Конечно можно ограничить видимость с помощью offset и Y координат, но не у всех одинаковый монитор Помогите решить проблему
  6. Hello guys! A few days ago did DxScroll, but can not seem to solve one problem How to limit the visibility of items, as in the gui Scroll Namely thus Screenshots: Code: local sW, sH = guiGetScreenSize() local bW, bH = (sW/2), (sH/2) local offset = 0 -- addEventHandler('onClientRender', root, function () if (isLogged(localPlayer)) then dxDrawRectangle(bW+190, bH-300, 320, 20, tocolor(0, 0, 0, 255)) dxDrawText('INVENTORY', bW+195, bH-300, bW+510, bH-280, tocolor(160, 160, 160, 255), 1, 'default', 'left', 'center', false, false, true, false, false) --Box dxDrawLine(bW+190, bH-281, bW+190, bH+280, tocolor(200, 200, 200, 100), 1) dxDrawLine(bW+510, bH-281, bW+190, bH-281, tocolor(200, 200, 200, 100), 1) dxDrawLine(bW+190, bH+280, bW+510, bH+280, tocolor(200, 200, 200, 100), 1) dxDrawLine(bW+510, bH+280, bW+510, bH-281, tocolor(200, 200, 200, 100), 1) dxDrawRectangle(bW+191, bH-280, 319, 560, tocolor(0, 0, 0, 70)) dxDrawLine(bW+500, bH-280, bW+500, bH+279, tocolor(200, 200, 200, 100), 1) --Scrollbar dxDrawLine(bW+502, bH-280+offset, bW+502, bH-109+offset, tocolor(200, 200, 200, 100), 1) dxDrawLine(bW+508, bH-280+offset, bW+502, bH-280+offset, tocolor(200, 200, 200, 100), 1) dxDrawLine(bW+502, bH-109+offset, bW+508, bH-109+offset, tocolor(200, 200, 200, 100), 1) dxDrawLine(bW+508, bH-109+offset, bW+508, bH-280+offset, tocolor(200, 200, 200, 100), 1) dxDrawRectangle(bW+503, bH-279+offset, 5, 170, tocolor(0, 0, 0, 0)) --Items for i = 1, 10 do dxDrawRectangle(bW+191, bH-345+65*i-offset, 309, 60, tocolor(100, 100, 100, 200)) dxDrawImage(bW+191, bH-345+65*i-offset, 60, 60, ':guieditor/images/plus.png', 0, 0, 0, tocolor(255, 255, 255, 255)) dxDrawText('Backpack '..i, bW+261, bH-326+65*i-offset, bW+499, bH-306+65*i-offset, tocolor(255, 255, 255, 255), 1, 'default-bold', 'left', 'center', false, false, true, false, false) dxDrawText('0/'..i, bW+451, bH-346+65*i-offset, bW+499, bH-326+65*i-offset, tocolor(255, 255, 255, 255), 1, 'default-bold', 'right', 'center', false, false, true, false, false) end end end end ) -- function Scroll(key, state) if (isLogged(localPlayer)) then if (state == 'down') then if (key == 'mouse_wheel_up') then if (offset > 0) then offset = offset-97 else offset = 0 end elseif (key == 'mouse_wheel_down') then if (offset < 388) then offset = offset+97 else offset = 388 end end end end end bindKey('mouse_wheel_up', 'down', Scroll) bindKey('mouse_wheel_down', 'down', Scroll) Help solve the problem Thanks in advance to all
  7. iAxel

    [HELP] Tables

    Okay, thank you very much
  8. Подтяните в коде... Какой метод лучше использовать? Логическое function isLogged(element) if (not element) or (element:getType() ~= 'player') then return end local elementData = element:getData('logged') return elementData and true or false end IF ELSE function isLogged(element) if (not element) or (element:getType() ~= 'player') then return end if (element:getData('logged') == true) return true else return false end end
  9. iAxel

    [HELP] Tables

    See if the backpack is created so function Backpack:create(player, slots) if (Backpack.list[player]) then return Backpack.list[player] end local new = { items = {}, slots = slots or 100, owner = player } setmetatable(new, {__index = Backpack}) Backpack.list[player] = new return new end And thus is deleted function Backpack:delete(player) Backpack.list[player] = nil return true end Maybe I should null and self.items = nil self.slots = nil self.owner = nil --or destroyElement(self.items) destroyElement(self.slots) destroyElement(self.owner) --or destroyElement(self) And thus should delete the backpack? function Backpack:delete(player) self = nil --or destroyElement(self) Backpack.list[player] = nil return true end
  10. iAxel

    [HELP] Tables

    So Much? function BackPack:delete(player) Backpack.list[player] = nil return true end
  11. iAxel

    [HELP] Tables

    In your code is a function of creating a backpack But do not have delete function backpack Help with function delete backpack Example function BackPack:delete(player) Backpack.list[player] = nil setmetatable(self, self) return true end I did the right function?
  12. iAxel

    [HELP] Tables

    Thank you very much!
  13. iAxel

    [HELP] Tables

    I can not know a slot backpack addCommandHandler('backpack', function (player) for name, amount in pairs(items) do player:outputChat(name..': '..amount) end player:outputChat('Slot '..Backpack:getSlots()) end ) [2015-01-13 00:29:40] ERROR: [new_project]\project\inventory\backpack.lua:56: attempt to concatenate a nil value
  14. iAxel

    [HELP] Tables

    I mean that's such functions Backpack = {} function Backpack:create(slot) local new = { slots = slot, items = {} } return setmetatable(new, {__index = Backpack}) end function Backpack:getSlots() local slot = (self.slots) return slot end Backpack:create(8) But then an error
  15. iAxel

    [HELP] Tables

    Please Add features such as: That when creating the backpack could set the slot. Function Backpack:getSlot(). Function destroy the backpack. Function how busy slots. Thanks in advance to you p.s I`m noob, I beg you
  16. Как правильно задать значение? Backpack = {} function Backpack:create(slot) local new = { slots = slot, items = {} } return setmetatable(new, {__index = Backpack}) end function Backpack:getSlots() local slot = (self.slots) return slot end Backpack:create(8) source:outputChat('Slots: '..Backpack:getSlots()) Проблема в том что не могу узнать слот
  17. iAxel

    [HELP] Table

    Thank you very much, I do not use SQLite, I use MySQL for him and not to used setAccountData. Data is saved to check the serial
  18. iAxel

    [HELP] Table

    Variant 1 for i, data in ipairs(Table.need) do source:setData(data[1], data[2]) end for i, data in ipairs(Table.stat) do source:setData(data[1], data[2]) end for i, data in ipairs(Table.item) do source:setData(data[1], data[2]) end Variant 2 for _, v in pairs(Table) do for _, v2 in pairs(v) do source:setData(v2[1], v2[2]) end end 2 variant mean effective than 1? I did not understand, but if you talk about the connection to the database or save data local connect = nil local db = { type = 'mysql', base = 'mta', host = '127.0.0.1', name = 'root', pass = '' } -- function getDB() if (not reconnect) then return connect else Timer(getDB, 150, 1) end end -- addEventHandler('onResourceStart', resourceRoot, function () connect = Connection(db.type, 'dbname='..db.base..';host='..db.host, db.name, db.pass) if (not connect) then outputServerLog('MySQL connection is not established!') else outputServerLog('MySQL connection is established!') end end ) -- addEventHandler('onResourceStop', resourceRoot, function () for i, player in ipairs(getElementsByType('player')) do if (isLogged(player)) then onSave(player) end end for i, vehicle in ipairs(getElementsByType('vehicle')) do if (isVehicle(vehicle)) then onVehSave(vehicle) end end if (isElement(connect)) then connect:destroy() end end ) Save function onSave(player) local serial = player:getSerial() local name = player:getName() local health = player:getHealth() local x, y, z = getElementPosition(player) local pos = toJSON({x, y, z}) local needs, status, items = {}, {}, {} for k, v in pairs(Table) do for i, data in pairs(v) do if (k == 'need') then needs[i] = player:getData(data[1]) elseif (k == 'stat') then status[i] = player:getData(data[1]) elseif (k == 'item') then items[i] = player:getData(data[1]) end end end player:setData('logged', false) needs, status, items = toJSON(needs), toJSON(status), toJSON(items) getDB():exec('UPDATE `accounts` SET `login` = ?, `health` = ?, `pos` = ?, `needs` = ?, `status` = ?, `items` = ?, `lastdate` = NOW() WHERE `serial` = ? LIMIT 1', name, health, pos, needs, status, items, serial) outputServerLog('Account Name: '..name..' was saved automatically.') end If there is an error please correct it, I'm still a noob, I'm just learning) And thank you for the answer, then if not strange ignore or remain silent
  19. iAxel

    [HELP] Table

    Thank you so much, but all the same table used in the loop is not effective? And can a couple of examples of optimization
  20. iAxel

    [HELP] Table

    Himself solved the problem for k, v in pairs(Table) do for i, data in pairs(v) do if (k == 'need') then player:setData(data[1], needs[i]) elseif (k == 'stat') then player:setData(data[1], status[i]) elseif (k == 'item') then player:setData(data[1], items[i]) end end end The next question is - It's not like will not affect the performance? P.S Answer at least this time ...
  21. Так же привел простой тест local data = { values = {} } for i = 1, 10000 do table.insert(data.values, i) end function simpleForTest() local j local t = getTickCount() for k = 1, 100 do for i = 1, #data.values do j = data.values[i] end end outputServerLog('~~~# '..getTickCount() - t) end function pairsTest() local j local t = getTickCount() for k = 1, 100 do for i, val in pairs(data.values) do j = val end end outputServerLog('~~~pairs '..getTickCount() - t) end function ipairsTest() local j local t = getTickCount() for k = 1, 100 do for i, val in ipairs(data.values) do j = val end end outputServerLog('~~~ipairs '..getTickCount() - t) end for i = 1, 10 do simpleForTest() pairsTest() ipairsTest() end ~~~# 147.99999999988 ~~~pairs 223.99999999988 ~~~ipairs 242 ~~~# 163.00000000012 ~~~pairs 226.99999999988 ~~~ipairs 240 ~~~# 152.00000000012 ~~~pairs 222.99999999988 ~~~ipairs 237 ~~~# 148 ~~~pairs 223 ~~~ipairs 236 ~~~# 148 ~~~pairs 223 ~~~ipairs 237 ~~~# 150 ~~~pairs 221 ~~~ipairs 235.00000000012 ~~~# 149 ~~~pairs 222 ~~~ipairs 239 ~~~# 150 ~~~pairs 222.00000000012 ~~~ipairs 236.99999999988 То есть «некрасивый» код работает в два раза быстрее «красивого». Вот так.
×
×
  • Create New...