Jump to content

freeroam weapons dimension


Dany Alex

Recommended Posts

Posted

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) 

Looking for a nice server freeroam or do you have fun?

n-560x95_FFFFFF_FFFFFF_000000_000000.png

Posted

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) 

Real motorbike backflip / frontflip script: https://forum.mtasa.com/viewtopic.php?f=108&t=98191

Posted
--------------------------- 
-- 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) 

76561198066470453.png

SP37Ecj.jpg?2MTA:Rust Pre-Alpha Build v.0.3:SP37Ecj.jpg?2

https://forum.mtasa.com/viewtopic.php?f=114&t=97848

2Pac: ''Only God can judge me!''

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