Jump to content

freeroam weapons dimension


Dany Alex

Recommended Posts

How to make weapons can be taken in one dimension only?

--------------------------- 
-- Weapon window 
--------------------------- 
  
function addWeapon(leaf, amount) 
    if type(leaf) ~= 'table' then 
        leaf = getSelectedGridListLeaf(wndWeapon, 'weaplist') 
        amount = getControlNumber(wndWeapon, 'amount') 
        if not amount or not leaf then 
            return 
        end 
    end 
    server.giveMeWeapon(leaf.id, amount) 
end 
  
wndWeapon = { 
    'wnd', 
    text = 'Give weapon', 
    width = 250, 
    controls = { 
        { 
            'lst', 
            id='weaplist', 
            width=230, 
            height=280, 
            columns={ 
                {text='Weapon', attr='name'} 
            }, 
            rows={xml='weapons.xml', attrs={'id', 'name'}}, 
            onitemdoubleclick=function(leaf) addWeapon(leaf, 500) end 
        }, 
        {'br'}, 
        {'txt', id='amount', text='500', width=60}, 
        {'btn', id='add', onclick=addWeapon}, 
        {'btn', id='close', closeswindow=true} 
    } 
} 
  
function giveWeaponCommand(cmd, weapon, amount) 
    weapon = tonumber(weapon) or getWeaponIDFromName(weapon) 
    if not weapon then 
        return 
    end 
    amount = amount and tonumber(amount) or 500 
    server.giveMeWeapon(math.floor(weapon), amount) 
end 
addCommandHandler('give', giveWeaponCommand) 
addCommandHandler('wp', giveWeaponCommand) 

Link to comment

Use getElementDimension to check if player is in right dimension.

Change the dimension to whatever you need.

function addWeapon(leaf, amount) 
    if (getElementDimension(localPlayer) == 2) then 
        if type(leaf) ~= 'table' then 
            leaf = getSelectedGridListLeaf(wndWeapon, 'weaplist') 
            amount = getControlNumber(wndWeapon, 'amount') 
            if not amount or not leaf then 
                return 
            end 
        end 
        server.giveMeWeapon(leaf.id, amount) 
    else 
        -- outputChatBox("You need to be at right dimension to get weapons!") 
    end  
end 
  
function giveWeaponCommand(cmd, weapon, amount) 
    if (getElementDimension(localPlayer) == 2) then 
        weapon = tonumber(weapon) or getWeaponIDFromName(weapon) 
        if not weapon then 
            return 
        end 
        amount = amount and tonumber(amount) or 500 
        server.giveMeWeapon(math.floor(weapon), amount) 
    else 
        -- outputChatBox("You need to be at right dimension to get weapons!") 
    end 
end 
addCommandHandler('give', giveWeaponCommand) 
addCommandHandler('wp', giveWeaponCommand) 

Link to comment
--------------------------- 
-- Weapon window 
--------------------------- 
  
function addWeapon(leaf, amount) 
    if type(leaf) ~= 'table' then 
        leaf = getSelectedGridListLeaf(wndWeapon, 'weaplist') 
        amount = getControlNumber(wndWeapon, 'amount') 
        if not amount or not leaf then 
            return 
        end 
    end 
    server.giveMeWeapon(leaf.id, amount) 
end 
  
wndWeapon = { 
    'wnd', 
    text = 'Give weapon', 
    width = 250, 
    controls = { 
        { 
            'lst', 
            id='weaplist', 
            width=230, 
            height=280, 
            columns={ 
                {text='Weapon', attr='name'} 
            }, 
            rows={xml='weapons.xml', attrs={'id', 'name'}}, 
            onitemdoubleclick=function(leaf) addWeapon(leaf, 500) end 
        }, 
        {'br'}, 
        {'txt', id='amount', text='500', width=60}, 
        {'btn', id='add', onclick=addWeapon}, 
        {'btn', id='close', closeswindow=true} 
    } 
} 
  
local dimension = 1 
local thePlayer = getLocalPlayer() 
  
function giveWeaponCommand(cmd, weapon, amount) 
    if (getElementDimension(thePlayer) == dimension) then 
        weapon = tonumber(weapon) or getWeaponIDFromName(weapon) 
        if not weapon then 
            return 
        end 
        amount = amount and tonumber(amount) or 500 
        server.giveMeWeapon(math.floor(weapon), amount) 
    else 
        outputChatBox("You cannot take a weapon as you are not in the right dimension!", 255, 0, 0) 
    end 
end 
addCommandHandler('give', giveWeaponCommand) 
addCommandHandler('wp', giveWeaponCommand) 

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...