Dany Alex Posted April 26, 2016 Share Posted April 26, 2016 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
Miika Posted April 27, 2016 Share Posted April 27, 2016 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
Dany Alex Posted April 28, 2016 Author Share Posted April 28, 2016 not working in any dimension and not working button from f1 weapon Link to comment
..:D&G:.. Posted April 28, 2016 Share Posted April 28, 2016 --------------------------- -- 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now