Jump to content

freeroam problem


Chaos

Recommended Posts

hi,

i have problem with freeroam can you help me to fix it ?

ux89.jpg

g_gridListContents = {}   -- info about binded gridlists 
g_openedWindows = {}      -- {window1table = true, window2table = true, ...}
 
GRIDLIST_UPDATE_CHUNK_SIZE = 10
 
classInfo = {
    wnd = {className = 'Window', padding = {25, 10, 10, 10}, isContainer = true},
    tbp = {className = 'TabPanel'},
    tab = {className = 'Tab', padding = 10, isContainer = true},
    lbl = {className = 'Label', height = 20},
    btn = {className = 'Button', height = 20, padding = {0, 4}},
    chk = {className = 'CheckBox', height = 20, padding = {0, 6}},
    rad = {className = 'RadioButton', height = 20, padding = {0, 10}},
    txt = {className = 'Edit', width=100, height = 24},
    lst = {className = 'GridList', width = 250, height = 400},
    img = {className = 'StaticImage'}
}
 
function getTextWidth(text)
    return 8*text:len()
end
 
function createWindow(wnd, rebuild)
    if wnd.element then
        if rebuild then
            destroyElement(wnd.element)
        else
            guiSetVisible(wnd.element, true)
            guiBringToFront(wnd.element)
            g_openedWindows[wnd] = true
            if wnd.oncreate then
                wnd.oncreate()
            end
            return
        end
    end
   
    _planWindow(wnd)
    _buildWindow(wnd)
end
 
function _planWindow(wnd, baseWnd, parentWnd, x, y, maxHeightInLine)
    -- simulate building a window to get the proper height
    local wndClass = wnd[1]
   
    if not maxHeightInLine then
        maxHeightInLine = LINE_HEIGHT
    end
   
    local text, padding, parentPadding
    if wndClass ~= 'br' then
        padding = classInfo[wndClass].padding
        if type(padding) == 'number' then
            padding = table.rep(padding, 4)
            classInfo[wndClass].padding = padding
        elseif type(padding) == 'table' then
            if #padding == 1 then
                padding = table.rep(padding[1], 4)
                classInfo[wndClass].padding = padding
            elseif #padding == 2 then
                padding = table.flatten(table.rep(padding, 2))
                classInfo[wndClass].padding = padding
            elseif #padding == 3 then
                table.insert(padding, padding[2])
                classInfo[wndClass].padding = padding
            end
        elseif not padding then
            padding = table.rep(0, 4)
            classInfo[wndClass].padding = padding
        end
       
        text = wnd.text or wnd.id or ''
        if not wnd.width then
            wnd.width = (classInfo[wndClass].width or getTextWidth(text)) +
                (not classInfo[wndClass].isContainer and (padding[2] + padding[4]) or 0)
        end
        if not wnd.height and not classInfo[wndClass].isContainer then
            wnd.height = (classInfo[wndClass].height or LINE_HEIGHT) + padding[1] + padding[3]
        end
    end
    parentPadding = parentWnd and classInfo[parentWnd[1]].padding
   
    if wndClass == 'br' or (not classInfo[wndClass].isContainer and x + wnd.width > parentWnd.width - parentPadding[2]) then
        -- line wrap
        x = parentPadding[4]
        y = y + maxHeightInLine + LINE_MARGIN
 
        maxHeightInLine = LINE_HEIGHT
        if wndClass == 'br' then
            return nil, x, y, maxHeightInLine
        end
    end
    if not wnd.x then
        wnd.x = x
    end
    if not wnd.y then
        wnd.y = y
    end
    wnd.parent = parentWnd
   
    if wnd.controls then
        local childX, childY = padding[4], padding[1]
        local childMaxHeightInLine = LINE_HEIGHT
        local control
        for id, controlwnd in pairs(wnd.controls) do
            control, childX, childY, childMaxHeightInLine = _planWindow(controlwnd, baseWnd or wnd, wnd, childX, childY, childMaxHeightInLine)
        end
        if classInfo[wndClass].isContainer then
            wnd.height = childY + childMaxHeightInLine + padding[3]
        end
    end
   
    if wnd.tabs then
        local maxTabHeight = 0
        for id, tab in pairs(wnd.tabs) do
            tab[1] = 'tab'
            tab.width = wnd.width
            _planWindow(tab, baseWnd, wnd)
            if tab.height > maxTabHeight then
                maxTabHeight = tab.height
            end
        end
        wnd.height = maxTabHeight
    end
   
    if classInfo[wndClass].isContainer then
        return elem
    else
        if wnd.height > maxHeightInLine then
            maxHeightInLine = wnd.height
        end
        return elem, x + wnd.width + CONTROL_MARGIN_RIGHT, y, maxHeightInLine
    end
end
 
function _buildWindow(wnd, baseWnd, parentWnd)
    local wndClass = wnd[1]
    if wndClass == 'br' then
        return
    end
   
    local relX, relY, relWidth, relHeight
    if parentWnd then
        if wnd.x and wnd.y then
            relX = wnd.x/parentWnd.width
            relY = wnd.y/parentWnd.height
        end
        relWidth = wnd.width / parentWnd.width
        relHeight = wnd.height / parentWnd.height
    end
   
    local elem
    if wndClass == 'wnd' then
        local screenWidth, screenHeight = guiGetScreenSize()
        if not wnd.x then
            wnd.x = screenWidth/2 - wnd.width/2
        else
            local i, f = math.modf(wnd.x)
            if f ~= 0 then
                wnd.x = screenWidth * wnd.x
            end
            if wnd.x < 0 then
                wnd.x = screenWidth - math.abs(wnd.x) - wnd.width
            end
        end
        if not wnd.y then
            wnd.y = screenHeight/2 - wnd.height/2
        else
            local i, f = math.modf(wnd.y)
            if f ~= 0 then
                wnd.y = screenHeight * wnd.y
            end
            if wnd.y < 0 then
                wnd.y = screenHeight - math.abs(wnd.y) - wnd.height
            end
        end
        elem = guiCreateWindow(wnd.x, wnd.y, wnd.width, wnd.height, wnd.text, false)
        guiWindowSetSizable(elem, false)
        guiBringToFront(elem)
        g_openedWindows[wnd] = true
    elseif wndClass == 'chk' then
        elem = guiCreateCheckBox(relX, relY, relWidth, relHeight, wnd.text or wnd.id or '', false, true, parentWnd.element)
    elseif wndClass == 'tbp' then
        elem = guiCreateTabPanel(relX, relY, relWidth, relHeight, true, parentWnd.element)
    elseif wndClass == 'tab' then
        elem = guiCreateTab(text, parentWnd.element)
    elseif wndClass == 'lst' then
        elem = guiCreateGridList(relX, relY, relWidth, relHeight, true, parentWnd.element)
        if wnd.columns then
            guiGridListSetSortingEnabled(elem, false)
            for i, column in ipairs(wnd.columns) do
                guiGridListAddColumn(elem, column.text or column.attr or '', column.width or 0.9)
            end
        end
    elseif wndClass == 'img' then
        elem = guiCreateStaticImage(relX, relY, relWidth, relHeight, wnd.src or '', true, parentWnd.element)
    else
        elem = _G['guiCreate' .. classInfo[wndClass].className](relX, relY, relWidth, relHeight, wnd.text or wnd.id or '', true, parentWnd.element)
        if wnd.align and wndClass == 'lbl' then
            guiLabelSetHorizontalAlign(elem, wnd.align, true)
        end
    end
    wnd.element = elem
   
    if wnd.controls then
        for id, controlwnd in pairs(wnd.controls) do
            _buildWindow(controlwnd, baseWnd or wnd, wnd)
        end
    end
 
    if wnd.tabs then
        for id, tab in pairs(wnd.tabs) do
            _buildWindow(tab, baseWnd, wnd)
        end
    end
   
    if wnd.rows then
        if wnd.rows.xml then
            -- get rows from xml
            bindGridListToTable(wnd, not gridListHasCache(wnd) and xmlToTable(wnd.rows.xml, wnd.rows.attrs) or false,
                wnd.expandlastlevel or wnd.expandlastlevel == nil)
        else
            -- rows hardcoded in window definition
            bindGridListToTable(wnd, not gridListHasCache(wnd) and wnd.rows or false, false)
        end
    end
   
    local clickhandler = nil
    if wnd.onclick then
        if wndClass == 'img' then
            clickhandler = function(btn, state, x, y)
                local imgX, imgY = getControlScreenPos(wnd)
                wnd.onclick((x - imgX)/wnd.width, (y - imgY)/wnd.height, btn)
            end
        else
            clickhandler = function() wnd.onclick() end
        end
    elseif wnd.window then
        clickhandler = function() toggleWindow(wnd.window) end
    elseif wnd.inputbox then
        clickhandler = function()
            wndInput = {
                'wnd',
                width = 170,
                height = 60,
                controls = {
                    {'txt', id='input', text='', width=60},
                    {'btn', id='ok', onclick=function() wnd.inputbox.callback(getControlText(wndInput, 'input')) closeWindow(wndInput) end},
                    {'btn', id='cancel', closeswindow=true}
                }
            }
           
Link to comment
g_gridListContents = {}   -- info about binded gridlists 
g_openedWindows = {}      -- {window1table = true, window2table = true, ...}
 
GRIDLIST_UPDATE_CHUNK_SIZE = 10
 
classInfo = {
    wnd = {className = 'Window', padding = {25, 10, 10, 10}, isContainer = true},
    tbp = {className = 'TabPanel'},
    tab = {className = 'Tab', padding = 10, isContainer = true},
    lbl = {className = 'Label', height = 20},
    btn = {className = 'Button', height = 20, padding = {0, 4}},
    chk = {className = 'CheckBox', height = 20, padding = {0, 6}},
    rad = {className = 'RadioButton', height = 20, padding = {0, 10}},
    txt = {className = 'Edit', width=100, height = 24},
    lst = {className = 'GridList', width = 250, height = 400},
    img = {className = 'StaticImage'}
}
 
function getTextWidth(text)
    return 8*text:len()
end
 
function createWindow(wnd, rebuild)
    if wnd.element then
        if rebuild then
            destroyElement(wnd.element)
        else
            guiSetVisible(wnd.element, true)
            guiBringToFront(wnd.element)
            g_openedWindows[wnd] = true
            if wnd.oncreate then
                wnd.oncreate()
            end
            return
        end
    end
   
    _planWindow(wnd)
    _buildWindow(wnd)
end
 
function _planWindow(wnd, baseWnd, parentWnd, x, y, maxHeightInLine)
    -- simulate building a window to get the proper height
    local wndClass = wnd[1]
   
    if not maxHeightInLine then
        maxHeightInLine = LINE_HEIGHT
    end
   
    local text, padding, parentPadding
    if wndClass ~= 'br' then
        padding = classInfo[wndClass].padding
        if type(padding) == 'number' then
            padding = table.rep(padding, 4)
            classInfo[wndClass].padding = padding
        elseif type(padding) == 'table' then
            if #padding == 1 then
                padding = table.rep(padding[1], 4)
                classInfo[wndClass].padding = padding
            elseif #padding == 2 then
                padding = table.flatten(table.rep(padding, 2))
                classInfo[wndClass].padding = padding
            elseif #padding == 3 then
                table.insert(padding, padding[2])
                classInfo[wndClass].padding = padding
            end
        elseif not padding then
            padding = table.rep(0, 4)
            classInfo[wndClass].padding = padding
        end
       
        text = wnd.text or wnd.id or ''
        if not wnd.width then
            wnd.width = (classInfo[wndClass].width or getTextWidth(text)) +
                (not classInfo[wndClass].isContainer and (padding[2] + padding[4]) or 0)
        end
        if not wnd.height and not classInfo[wndClass].isContainer then
            wnd.height = (classInfo[wndClass].height or LINE_HEIGHT) + padding[1] + padding[3]
        end
    end
    parentPadding = parentWnd and classInfo[parentWnd[1]].padding
   
    if wndClass == 'br' or (not classInfo[wndClass].isContainer and x + wnd.width > parentWnd.width - parentPadding[2]) then
        -- line wrap
        x = parentPadding[4]
        y = y + maxHeightInLine + LINE_MARGIN
 
        maxHeightInLine = LINE_HEIGHT
        if wndClass == 'br' then
            return nil, x, y, maxHeightInLine
        end
    end
    if not wnd.x then
        wnd.x = x
    end
    if not wnd.y then
        wnd.y = y
    end
    wnd.parent = parentWnd
   
    if wnd.controls then
        local childX, childY = padding[4], padding[1]
        local childMaxHeightInLine = LINE_HEIGHT
        local control
        for id, controlwnd in pairs(wnd.controls) do
            control, childX, childY, childMaxHeightInLine = _planWindow(controlwnd, baseWnd or wnd, wnd, childX, childY, childMaxHeightInLine)
        end
        if classInfo[wndClass].isContainer then
            wnd.height = childY + childMaxHeightInLine + padding[3]
        end
    end
   
    if wnd.tabs then
        local maxTabHeight = 0
        for id, tab in pairs(wnd.tabs) do
            tab[1] = 'tab'
            tab.width = wnd.width
            _planWindow(tab, baseWnd, wnd)
            if tab.height > maxTabHeight then
                maxTabHeight = tab.height
            end
        end
        wnd.height = maxTabHeight
    end
   
    if classInfo[wndClass].isContainer then
        return elem
    else
        if wnd.height > maxHeightInLine then
            maxHeightInLine = wnd.height
        end
        return elem, x + wnd.width + CONTROL_MARGIN_RIGHT, y, maxHeightInLine
    end
end
 
function _buildWindow(wnd, baseWnd, parentWnd)
    local wndClass = wnd[1]
    if wndClass == 'br' then
        return
    end
   
    local relX, relY, relWidth, relHeight
    if parentWnd then
        if wnd.x and wnd.y then
            relX = wnd.x/parentWnd.width
            relY = wnd.y/parentWnd.height
        end
        relWidth = wnd.width / parentWnd.width
        relHeight = wnd.height / parentWnd.height
    end
   
    local elem
    if wndClass == 'wnd' then
        local screenWidth, screenHeight = guiGetScreenSize()
        if not wnd.x then
            wnd.x = screenWidth/2 - wnd.width/2
        else
            local i, f = math.modf(wnd.x)
            if f ~= 0 then
                wnd.x = screenWidth * wnd.x
            end
            if wnd.x < 0 then
                wnd.x = screenWidth - math.abs(wnd.x) - wnd.width
            end
        end
        if not wnd.y then
            wnd.y = screenHeight/2 - wnd.height/2
        else
            local i, f = math.modf(wnd.y)
            if f ~= 0 then
                wnd.y = screenHeight * wnd.y
            end
            if wnd.y < 0 then
                wnd.y = screenHeight - math.abs(wnd.y) - wnd.height
            end
        end
        elem = guiCreateWindow(wnd.x, wnd.y, wnd.width, wnd.height, wnd.text, false)
        guiWindowSetSizable(elem, false)
        guiBringToFront(elem)
        g_openedWindows[wnd] = true
    elseif wndClass == 'chk' then
        elem = guiCreateCheckBox(relX, relY, relWidth, relHeight, wnd.text or wnd.id or '', false, true, parentWnd.element)
    elseif wndClass == 'tbp' then
        elem = guiCreateTabPanel(relX, relY, relWidth, relHeight, true, parentWnd.element)
    elseif wndClass == 'tab' then
        elem = guiCreateTab(text, parentWnd.element)
    elseif wndClass == 'lst' then
        elem = guiCreateGridList(relX, relY, relWidth, relHeight, true, parentWnd.element)
        if wnd.columns then
            guiGridListSetSortingEnabled(elem, false)
            for i, column in ipairs(wnd.columns) do
                guiGridListAddColumn(elem, column.text or column.attr or '', column.width or 0.9)
            end
        end
    elseif wndClass == 'img' then
        elem = guiCreateStaticImage(relX, relY, relWidth, relHeight, wnd.src or '', true, parentWnd.element)
    else
        elem = _G['guiCreate' .. classInfo[wndClass].className](relX, relY, relWidth, relHeight, wnd.text or wnd.id or '', true, parentWnd.element)
        if wnd.align and wndClass == 'lbl' then
            guiLabelSetHorizontalAlign(elem, wnd.align, true)
        end
    end
    wnd.element = elem
   
    if wnd.controls then
        for id, controlwnd in pairs(wnd.controls) do
            _buildWindow(controlwnd, baseWnd or wnd, wnd)
        end
    end
 
    if wnd.tabs then
        for id, tab in pairs(wnd.tabs) do
            _buildWindow(tab, baseWnd, wnd)
        end
    end
   
    if wnd.rows then
        if wnd.rows.xml then
            -- get rows from xml
            bindGridListToTable(wnd, not gridListHasCache(wnd) and xmlToTable(wnd.rows.xml, wnd.rows.attrs) or false,
                wnd.expandlastlevel or wnd.expandlastlevel == nil)
        else
            -- rows hardcoded in window definition
            bindGridListToTable(wnd, not gridListHasCache(wnd) and wnd.rows or false, false)
        end
    end
   
    local clickhandler = nil
    if wnd.onclick then
        if wndClass == 'img' then
            clickhandler = function(btn, state, x, y)
                local imgX, imgY = getControlScreenPos(wnd)
                wnd.onclick((x - imgX)/wnd.width, (y - imgY)/wnd.height, btn)
            end
        else
            clickhandler = function() wnd.onclick() end
        end
    elseif wnd.window then
        clickhandler = function() toggleWindow(wnd.window) end
    elseif wnd.inputbox then
        clickhandler = function()
            wndInput = {
                'wnd',
                width = 170,
                height = 60,
                controls = {
                    {'txt', id='input', text='', width=60},
                    {'btn', id='ok', onclick=function() wnd.inputbox.callback(getControlText(wndInput, 'input')) closeWindow(wndInput) end},
                    {'btn', id='cancel', closeswindow=true}
                }
            }
           
Link to comment

yes i modified it before

CONTROL_MARGIN_RIGHT = 5 
LINE_MARGIN = 5
LINE_HEIGHT = 16
 
g_Root = getRootElement()
g_ResRoot = getResourceRootElement(getThisResource())
g_Me = getLocalPlayer()
server = createServerCallInterface()
guiSetInputMode("no_binds_when_editing")
 
---------------------------
-- Set skin window
---------------------------
 
 
---------------------------
--- Set animation window
---------------------------
 
function applyAnimation(leaf)
    if type(leaf) ~= 'table' then
        leaf = getSelectedGridListLeaf(wndAnim, 'animlist')
        if not leaf then
            return
        end
    end
    server.setPedAnimation(g_Me, leaf.parent.name, leaf.name, true, true)
end
 
function stopAnimation()
    server.setPedAnimation(g_Me, false)
end
 
wndAnim = {
    'wnd',
    text = 'Set animation',
    width = 250,
    x = -20,
    y = 0.3,
    controls = {
        {
            'lst',
            id='animlist',
            width=230,
            height=290,
            columns={
                {text='Animation', attr='name'}
            },
            rows={xml='animations.xml', attrs={'name'}},
            expandlastlevel=false,
            onitemdoubleclick=applyAnimation
        },
        {'btn', id='set', onclick=applyAnimation},
        {'btn', id='stop', onclick=stopAnimation},
        {'btn', id='close', closeswindow=true}
    }
}
 
addCommandHandler('anim',
    function(command, lib, name)
        server.setPedAnimation(g_Me, lib, name, true, true)
    end
)
 
---------------------------
-- Weapon window
---------------------------
 
---------------------------
-- Fighting style
---------------------------
 
---------------------------
-- Clothes window
---------------------------
function clothesInit()
    if getElementModel(g_Me) ~= 0 then
        errMsg('You must have the CJ skin set in order to apply clothes.')
        closeWindow(wndClothes)
        return
    end
    if not g_Clothes then
        triggerServerEvent('onClothesInit', g_Me)
    end
end
 
addEvent('onClientClothesInit', true)
addEventHandler('onClientClothesInit', g_Root,
    function(clothes)
        g_Clothes = clothes.allClothes
        for i,typeGroup in ipairs(g_Clothes) do
            for j,cloth in ipairs(typeGroup.children) do
                if not cloth.name then
                    cloth.name = cloth.model .. ' - ' .. cloth.texture
                end
                cloth.wearing =
                    clothes.playerClothes[typeGroup.type] and
                    clothes.playerClothes[typeGroup.type].texture == cloth.texture and
                    clothes.playerClothes[typeGroup.type].model == cloth.model
                    or false
            end
            table.sort(typeGroup.children, function(a, b) return a.name < b.name end)
        end
        bindGridListToTable(wndClothes, 'clothes', g_Clothes, false)
    end
)
 
function clothListClick(cloth)
    setControlText(wndClothes, 'addremove', cloth.wearing and 'remove' or 'add')
end
 
function applyClothes(cloth)
    if not cloth then
        cloth = getSelectedGridListLeaf(wndClothes, 'clothes')
        if not cloth then
            return
        end
    end
    if cloth.wearing then
        cloth.wearing = false
        setControlText(wndClothes, 'addremove', 'add')
        server.removePlayerClothes(g_Me, cloth.parent.type)
    else
        local prevClothIndex = table.find(cloth.siblings, 'wearing', true)
        if prevClothIndex then
            cloth.siblings[prevClothIndex].wearing = false
        end
        cloth.wearing = true
        setControlText(wndClothes, 'addremove', 'remove')
        server.addPedClothes(g_Me, cloth.texture, cloth.model, cloth.parent.type)
    end
end
 
wndClothes = {
    'wnd',
    text = 'Clothes',
    x = -20,
    y = 0.3,
    width = 350,
    controls = {
        {
            'lst',
            id='clothes',
            width=330,
            height=390,
            columns={
                {text='Clothes', attr='name', width=0.6},
                {text='Wearing', attr='wearing', enablemodify=true, width=0.3}
            },
            rows={
                {name='Retrieving clothes list...'}
            },
            onitemclick=clothListClick,
            onitemdoubleclick=applyClothes
        },
        {'br'},
        {'btn', text='add', id='addremove', width=60, onclick=applyClothes},
        {'btn', id='close', closeswindow=true}
    },
    oncreate = clothesInit
}
 
function addClothesCommand(cmd, type, model, texture)
    type = type and tonumber(type)
    if type and model and texture then
        server.addPedClothes(g_Me, texture, model, type)
    end
end
addCommandHandler('addclothes', addClothesCommand)
addCommandHandler('ac', addClothesCommand)
 
function removeClothesCommand(cmd, type)
    type = type and tonumber(type)
    if type then
        server.removePlayerClothes(g_Me, type)
    end
end
addCommandHandler('removeclothes', removeClothesCommand)
addCommandHandler('rc', removeClothesCommand)
---------------------------
-- Player gravity window
---------------------------
 
---------------------------
-- Warp to player window
---------------------------
 
---------------------------
-- Stats window
---------------------------
 
---------------------------
-- Bookmarks window
---------------------------
 
 
---------------------------
-- Jetpack toggle
---------------------------
 
 
---------------------------
-- Fall off bike toggle
---------------------------
function toggleFallOffBike()
    setPedCanBeKnockedOffBike(g_Me, guiCheckBoxGetSelected(getControl(wndMain, 'falloff')))
end
 
---------------------------
-- Set position window
---------------------------
 
---------------------------
-- Spawn map window
---------------------------
 
 
---------------------------
-- Interior window
---------------------------
 
---------------------------
-- Create vehicle window
---------------------------
 
   
---------------------------
-- Repair vehicle
---------------------------
function repairVehicle()
    local vehicle = getPedOccupiedVehicle(g_Me)
    if vehicle then
        server.fixVehicle(vehicle)
    end
end
 
addCommandHandler('repair', repairVehicle)
addCommandHandler('rp', repairVehicle)
 
---------------------------
-- Flip vehicle
---------------------------
function flipVehicle()
    local vehicle = getPedOccupiedVehicle(g_Me)
    if vehicle then
        local rX, rY, rZ = getElementRotation(vehicle)
        server['set' .. 'VehicleRotation'](vehicle, 0, 0, (rX > 90 and rX < 270) and (rZ + 180) or rZ)
    end
end
 
Link to comment

see it

    CONTROL_MARGIN_RIGHT = 5 
    LINE_MARGIN = 5
    LINE_HEIGHT = 16
     
    g_Root = getRootElement()
    g_ResRoot = getResourceRootElement(getThisResource())
    g_Me = getLocalPlayer()
    server = createServerCallInterface()
    guiSetInputMode("no_binds_when_editing")
     
    ---------------------------
    -- Set skin window
    ---------------------------
     
     
    ---------------------------
    --- Set animation window
    ---------------------------
     
    function applyAnimation(leaf)
        if type(leaf) ~= 'table' then
            leaf = getSelectedGridListLeaf(wndAnim, 'animlist')
            if not leaf then
                return
            end
        end
        server.setPedAnimation(g_Me, leaf.parent.name, leaf.name, true, true)
    end
     
    function stopAnimation()
        server.setPedAnimation(g_Me, false)
    end
     
    wndAnim = {
        'wnd',
        text = 'Set animation',
        width = 250,
        x = -20,
        y = 0.3,
        controls = {
            {
                'lst',
                id='animlist',
                width=230,
                height=290,
                columns={
                    {text='Animation', attr='name'}
                },
                rows={xml='animations.xml', attrs={'name'}},
                expandlastlevel=false,
                onitemdoubleclick=applyAnimation
            },
            {'btn', id='set', onclick=applyAnimation},
            {'btn', id='stop', onclick=stopAnimation},
            {'btn', id='close', closeswindow=true}
        }
    }
     
    addCommandHandler('anim',
        function(command, lib, name)
            server.setPedAnimation(g_Me, lib, name, true, true)
        end
    )
     
    ---------------------------
    -- Weapon window
    ---------------------------
     
    ---------------------------
    -- Fighting style
    ---------------------------
     
    ---------------------------
    -- Clothes window
    ---------------------------
    function clothesInit()
        if getElementModel(g_Me) ~= 0 then
            errMsg('You must have the CJ skin set in order to apply clothes.')
            closeWindow(wndClothes)
            return
        end
        if not g_Clothes then
            triggerServerEvent('onClothesInit', g_Me)
        end
    end
     
    addEvent('onClientClothesInit', true)
    addEventHandler('onClientClothesInit', g_Root,
        function(clothes)
            g_Clothes = clothes.allClothes
            for i,typeGroup in ipairs(g_Clothes) do
                for j,cloth in ipairs(typeGroup.children) do
                    if not cloth.name then
                        cloth.name = cloth.model .. ' - ' .. cloth.texture
                    end
                    cloth.wearing =
                        clothes.playerClothes[typeGroup.type] and
                        clothes.playerClothes[typeGroup.type].texture == cloth.texture and
                        clothes.playerClothes[typeGroup.type].model == cloth.model
                        or false
                end
                table.sort(typeGroup.children, function(a, b) return a.name < b.name end)
            end
            bindGridListToTable(wndClothes, 'clothes', g_Clothes, false)
        end
    )
     
    function clothListClick(cloth)
        setControlText(wndClothes, 'addremove', cloth.wearing and 'remove' or 'add')
    end
     
    function applyClothes(cloth)
        if not cloth then
            cloth = getSelectedGridListLeaf(wndClothes, 'clothes')
            if not cloth then
                return
            end
        end
        if cloth.wearing then
            cloth.wearing = false
            setControlText(wndClothes, 'addremove', 'add')
            server.removePlayerClothes(g_Me, cloth.parent.type)
        else
            local prevClothIndex = table.find(cloth.siblings, 'wearing', true)
            if prevClothIndex then
                cloth.siblings[prevClothIndex].wearing = false
            end
            cloth.wearing = true
            setControlText(wndClothes, 'addremove', 'remove')
            server.addPedClothes(g_Me, cloth.texture, cloth.model, cloth.parent.type)
        end
    end
     
    wndClothes = {
        'wnd',
        text = 'Clothes',
        x = -20,
        y = 0.3,
        width = 350,
        controls = {
            {
                'lst',
                id='clothes',
                width=330,
                height=390,
                columns={
                    {text='Clothes', attr='name', width=0.6},
                    {text='Wearing', attr='wearing', enablemodify=true, width=0.3}
                },
                rows={
                    {name='Retrieving clothes list...'}
                },
                onitemclick=clothListClick,
                onitemdoubleclick=applyClothes
            },
            {'br'},
            {'btn', text='add', id='addremove', width=60, onclick=applyClothes},
            {'btn', id='close', closeswindow=true}
        },
        oncreate = clothesInit
    }
     
    function addClothesCommand(cmd, type, model, texture)
        type = type and tonumber(type)
        if type and model and texture then
            server.addPedClothes(g_Me, texture, model, type)
        end
    end
    addCommandHandler('addclothes', addClothesCommand)
    addCommandHandler('ac', addClothesCommand)
     
    function removeClothesCommand(cmd, type)
        type = type and tonumber(type)
        if type then
            server.removePlayerClothes(g_Me, type)
        end
    end
    addCommandHandler('removeclothes', removeClothesCommand)
    addCommandHandler('rc', removeClothesCommand)
    ---------------------------
    -- Player gravity window
    ---------------------------
     
    ---------------------------
    -- Warp to player window
    ---------------------------
     
    ---------------------------
    -- Stats window
    ---------------------------
     
    ---------------------------
    -- Bookmarks window
    ---------------------------
     
     
    ---------------------------
    -- Jetpack toggle
    ---------------------------
     
     
    ---------------------------
    -- Fall off bike toggle
    ---------------------------
    function toggleFallOffBike()
        setPedCanBeKnockedOffBike(g_Me, guiCheckBoxGetSelected(getControl(wndMain, 'falloff')))
    end
     
    ---------------------------
    -- Set position window
    ---------------------------
     
    ---------------------------
    -- Spawn map window
    ---------------------------
     
     
    ---------------------------
    -- Interior window
    ---------------------------
     
    ---------------------------
    -- Create vehicle window
    ---------------------------
     
       
    ---------------------------
    -- Repair vehicle
    ---------------------------
    function repairVehicle()
        local vehicle = getPedOccupiedVehicle(g_Me)
        if vehicle then
            server.fixVehicle(vehicle)
        end
    end
     
    addCommandHandler('repair', repairVehicle)
    addCommandHandler('rp', repairVehicle)
     
    ---------------------------
    -- Flip vehicle
    ---------------------------
    function flipVehicle()
        local vehicle = getPedOccupiedVehicle(g_Me)
        if vehicle then
            local rX, rY, rZ = getElementRotation(vehicle)
            server['set' .. 'VehicleRotation'](vehicle, 0, 0, (rX > 90 and rX < 270) and (rZ + 180) or rZ)
        end
    end
     
   
Link to comment
  • Scripting Moderators
CONTROL_MARGIN_RIGHT = 5 
LINE_MARGIN = 5
LINE_HEIGHT = 16
 
g_Root = getRootElement()
g_ResRoot = getResourceRootElement(getThisResource())
g_Me = getLocalPlayer()
server = createServerCallInterface()
guiSetInputMode("no_binds_when_editing")
 
---------------------------
-- Set skin window
---------------------------
 
 
---------------------------
--- Set animation window
---------------------------
 
function applyAnimation(leaf)
    if type(leaf) ~= 'table' then
        leaf = getSelectedGridListLeaf(wndAnim, 'animlist')
        if not leaf then
            return
        end
    end
    server.setPedAnimation(g_Me, leaf.parent.name, leaf.name, true, true)
end
 
function stopAnimation()
    server.setPedAnimation(g_Me, false)
end
 
wndAnim = {
    'wnd',
    text = 'Set animation',
    width = 250,
    x = -20,
    y = 0.3,
    controls = {
        {
            'lst',
            id='animlist',
            width=230,
            height=290,
            columns={
                {text='Animation', attr='name'}
            },
            rows={xml='animations.xml', attrs={'name'}},
            expandlastlevel=false,
            onitemdoubleclick=applyAnimation
        },
        {'btn', id='set', onclick=applyAnimation},
        {'btn', id='stop', onclick=stopAnimation},
        {'btn', id='close', closeswindow=true}
    }
}
 
addCommandHandler('anim',
    function(command, lib, name)
        server.setPedAnimation(g_Me, lib, name, true, true)
    end
)
 
---------------------------
-- Weapon window
---------------------------
 
---------------------------
-- Fighting style
---------------------------
 
---------------------------
-- Clothes window
---------------------------
function clothesInit()
    if getElementModel(g_Me) ~= 0 then
        errMsg('You must have the CJ skin set in order to apply clothes.')
        closeWindow(wndClothes)
        return
    end
    if not g_Clothes then
        triggerServerEvent('onClothesInit', g_Me)
    end
end
 
addEvent('onClientClothesInit', true)
addEventHandler('onClientClothesInit', g_Root,
    function(clothes)
        g_Clothes = clothes.allClothes
        for i,typeGroup in ipairs(g_Clothes) do
            for j,cloth in ipairs(typeGroup.children) do
                if not cloth.name then
                    cloth.name = cloth.model .. ' - ' .. cloth.texture
                end
                cloth.wearing =
                    clothes.playerClothes[typeGroup.type] and
                    clothes.playerClothes[typeGroup.type].texture == cloth.texture and
                    clothes.playerClothes[typeGroup.type].model == cloth.model
                    or false
            end
            table.sort(typeGroup.children, function(a, b) return a.name < b.name end)
        end
        bindGridListToTable(wndClothes, 'clothes', g_Clothes, false)
    end
)
 
function clothListClick(cloth)
    setControlText(wndClothes, 'addremove', cloth.wearing and 'remove' or 'add')
end
 
function applyClothes(cloth)
    if not cloth then
        cloth = getSelectedGridListLeaf(wndClothes, 'clothes')
        if not cloth then
            return
        end
    end
    if cloth.wearing then
        cloth.wearing = false
        setControlText(wndClothes, 'addremove', 'add')
        server.removePlayerClothes(g_Me, cloth.parent.type)
    else
        local prevClothIndex = table.find(cloth.siblings, 'wearing', true)
        if prevClothIndex then
            cloth.siblings[prevClothIndex].wearing = false
        end
        cloth.wearing = true
        setControlText(wndClothes, 'addremove', 'remove')
        server.addPedClothes(g_Me, cloth.texture, cloth.model, cloth.parent.type)
    end
end
 
wndClothes = {
    'wnd',
    text = 'Clothes',
    x = -20,
    y = 0.3,
    width = 350,
    controls = {
        {
            'lst',
            id='clothes',
            width=330,
            height=390,
            columns={
                {text='Clothes', attr='name', width=0.6},
                {text='Wearing', attr='wearing', enablemodify=true, width=0.3}
            },
            rows={
                {name='Retrieving clothes list...'}
            },
            onitemclick=clothListClick,
            onitemdoubleclick=applyClothes
        },
        {'br'},
        {'btn', text='add', id='addremove', width=60, onclick=applyClothes},
        {'btn', id='close', closeswindow=true}
    },
    oncreate = clothesInit
}
 
function addClothesCommand(cmd, type, model, texture)
    type = type and tonumber(type)
    if type and model and texture then
        server.addPedClothes(g_Me, texture, model, type)
    end
end
addCommandHandler('addclothes', addClothesCommand)
addCommandHandler('ac', addClothesCommand)
 
function removeClothesCommand(cmd, type)
    type = type and tonumber(type)
    if type then
        server.removePlayerClothes(g_Me, type)
    end
end
addCommandHandler('removeclothes', removeClothesCommand)
addCommandHandler('rc', removeClothesCommand)
---------------------------
-- Player gravity window
---------------------------
 
---------------------------
-- Warp to player window
---------------------------
 
---------------------------
-- Stats window
---------------------------
 
---------------------------
-- Bookmarks window
---------------------------
 
 
---------------------------
-- Jetpack toggle
---------------------------
 
 
---------------------------
-- Fall off bike toggle
---------------------------
function toggleFallOffBike()
    setPedCanBeKnockedOffBike(g_Me, guiCheckBoxGetSelected(getControl(wndMain, 'falloff')))
end
 
---------------------------
-- Set position window
---------------------------
 
---------------------------
-- Spawn map window
---------------------------
 
 
---------------------------
-- Interior window
---------------------------
 
---------------------------
-- Create vehicle window
---------------------------
 
   
---------------------------
-- Repair vehicle
---------------------------
function repairVehicle()
    local vehicle = getPedOccupiedVehicle(g_Me)
    if vehicle then
        server.fixVehicle(vehicle)
    end
end
 
addCommandHandler('repair', repairVehicle)
addCommandHandler('rp', repairVehicle)
 
---------------------------
-- Flip vehicle
---------------------------
function flipVehicle()
    local vehicle = getPedOccupiedVehicle(g_Me)
    if vehicle then
        local rX, rY, rZ = getElementRotation(vehicle)
        server['set' .. 'VehicleRotation'](
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...