Jump to content

Why not working giveweapon function in freeroam?


Turbe$Z

Recommended Posts

11 hours ago, Mr.Loki said:

No code no help...

---------------------------
-- Weapon window
---------------------------

function addWeapon(leaf, amount)
	if isCommandOnCD("giveweapon", true) then return end
	if type(leaf) ~= 'table' then
		leaf = getSelectedGridListLeaf(wndWeapon, 'weaplist')
		amount = getControlNumber(wndWeapon, 'amount')
		if not amount or not leaf or not leaf.id then
			return
		end
	end
	server.giveMeWeapon(leaf.id, amount)
end

wndWeapon = {
	'wnd',
	text = 'fegyverek',
	width = 250,
	controls = {
		{
			'lst',
			id='weaplist',
			width=230,
			height=280,
			columns={
				{text='Fegyver', attr='name'}
			},
			rows={xml='weapons.xml', attrs={'id', 'name'}},
			onitemdoubleclick=function(leaf) addWeapon(leaf, 500) end
		},
		{'br'},
		{'txt', id='töltény', text='500', width=60},
		{'btn', id='ok', onclick=addWeapon},
		{'btn', id='bezár', closeswindow=true}
	}
}

function giveWeaponCommand(cmd, weapon, amount)
	if isCommandOnCD(cmd) then return end
	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)

---------------------------
-- Main window
---------------------------

function updateGUI(updateVehicle)
	-- update position
	local x, y, z = getElementPosition(g_Me)
	setControlNumbers(wndMain, {xpos=math.ceil(x), ypos=math.ceil(y), zpos=math.ceil(z)})
	
	-- update jetpack toggle
	guiCheckBoxSetSelected( getControl(wndMain, 'jetpack'), doesPedHaveJetPack(g_Me) )
	
	if updateVehicle then
		-- update current vehicle
		local vehicle = getPedOccupiedVehicle(g_Me)
		if vehicle and isElement(vehicle) then
			setControlText(wndMain, 'curvehicle', getVehicleName(vehicle))
		else
			setControlText(wndMain, 'curvehicle', 'On foot')
		end
	end
end

function mainWndShow()
	if not getPedOccupiedVehicle(g_Me) then
		hideControls(wndMain, 'repair', 'flip', 'upgrades', 'color', 'paintjob', 'lightson', 'lightsoff')
	end
	updateTimer = updateTimer or setTimer(updateGUI, 2000, 0)
	updateGUI(true)
end

function mainWndClose()
	killTimer(updateTimer)
	updateTimer = nil
	colorPicker.closeSelect()
end

function onEnterVehicle(vehicle)
	setControlText(wndMain, 'curvehicle', getVehicleName(vehicle))
	showControls(wndMain, 'repair', 'flip', 'upgrades', 'color', 'paintjob', 'lightson', 'lightsoff')
	guiCheckBoxSetSelected(getControl(wndMain, 'lightson'), getVehicleOverrideLights(vehicle) == 2)
	guiCheckBoxSetSelected(getControl(wndMain, 'lightsoff'), getVehicleOverrideLights(vehicle) == 1)
end

function onExitVehicle(vehicle)
	setControlText(wndMain, 'curvehicle', 'On foot')
	hideControls(wndMain, 'repair', 'flip', 'upgrades', 'color', 'paintjob', 'lightson', 'lightsoff')
	closeWindow(wndUpgrades)
	closeWindow(wndColor)
end

function killLocalPlayer()
	server.killPed(g_Me)
end

function alphaCommand(command, alpha)
	alpha = alpha and tonumber(alpha)
	if alpha then
		server.setElementAlpha(g_Me, alpha)
	end
end
addCommandHandler('alpha', alphaCommand)
addCommandHandler('ap', alphaCommand)

addCommandHandler('kill', killLocalPlayer)

addEventHandler( 'onClientPlayerChangeNick', g_Me,
function( old, new )
	guiSetText ( getControl ( wndMain, 'plrname' ), new )
end )

function togglewarptome()
	if ( guiCheckBoxGetSelected( getControl ( wndMain, 'togglewarptme' ) ) == true ) then
		setElementData( g_Me, 'isWarpEnabled', 'false' )
	else
		setElementData( g_Me, 'isWarpEnabled', nil )
	end
end 

wndMain = {
	'wnd',
	text = 'FR GUI',
	x = 10,
	y = 150,
	width = 280,
	alpha = 1.0,
	controls = {
		{'lbl', id='myPos', text='Pozíciód:', width=80, height = 20},
		{'lbl', id='xpos', text='x', width=45},
		{'lbl', id='ypos', text='y', width=45},
		{'lbl', id='zpos', text='z', width=45},
		{'br'},
		{'lbl', id='linelbl1', text='====================================================', width=250, height = 20},
		{'br'},
		{'btn', id='Öngyilkosság', onclick=killLocalPlayer, width=80, height = 20},
		{'btn', id='Kinézet', window=wndSkin, width=80, height = 20},
		{'btn', id='Animáció', window=wndAnim, width=80, height = 20},
		{'btn', id='Ruhák(CJ)', window=wndClothes, width=80, height = 20},
		{'btn', id='playergrav', text='Gravitáció', window=wndGravity, width=80, height = 20},
		{'btn', id='Teleport', window=wndWarp, width=80, height = 20},
		{'btn', id='Statisztika', window=wndStats, width=80, height = 20},
		{'btn', id='Helyeid', window=wndBookmarks, width=80, height = 20},
		{'btn', id='Fegyverek', window=wndWeapon, width=80, height = 20},
		{'br'},
		{'chk', id='jetpack', onclick=toggleJetPack, width=80, height = 20},
		{'chk', id='falloff', text='Motoresés', onclick=toggleFallOffBike, width=150, height = 20},
		{'chk', id='togglewarptme', text='Teleportálás tiltása', onclick=togglewarptome, width=1000, height = 20},
		{'br'},
		{'lbl', id='linelbl2', text='====================================================', width=250, height = 20},
		{'br'},
		{'btn', id='setpos', text='Térkép', window=wndSetPos, width=80, height = 20},
		{'btn', id='setinterior', text='Ház belsők', window=wndSetInterior, width=80, height = 20},
		{'br'},
		{'lbl', id='linelbl3', text='====================================================', width=250, height = 20},
		{'br'},
		{'lbl', id='vehlbl', text='Jármű:', width=80, height = 20},
		{'br'},
		{'lbl', id='curlbl', text='Jelenlegi:', width=80, height = 20},
		{'lbl', id='curvehicle', width=80, height = 20},
		{'br'},
		{'btn', id='createvehicle', window=wndCreateVehicle, text='Létrehozás', width=80, height = 20},
		{'btn', id='Javítás', onclick=repairVehicle, width=80, height = 20},
		{'btn', id='Forgatás', onclick=flipVehicle, width=80, height = 20},
		{'btn', id='Tuning', window=wndUpgrades, width=80, height = 20},
		{'btn', id='Szín', onclick=openColorPicker, width=80, height = 20},
		{'btn', id='Matrica', window=wndPaintjob, width=80, height = 20},
		{'br'},
		{'chk', id='lightson', text='Lámpák be', onclick=forceLightsOn, width=87, height = 20},
		{'chk', id='lightsoff', text='Lámpák ki', onclick=forceLightsOff, width=87, height = 20},
	},
	oncreate = mainWndShow,
	onclose = mainWndClose
}

this is the fr_client.lua

Link to comment
7 minutes ago, Turbo777 said:

---------------------------
-- Weapon window
---------------------------

function addWeapon(leaf, amount)
	if isCommandOnCD("giveweapon", true) then return end
	if type(leaf) ~= 'table' then
		leaf = getSelectedGridListLeaf(wndWeapon, 'weaplist')
		amount = getControlNumber(wndWeapon, 'amount')
		if not amount or not leaf or not leaf.id then
			return
		end
	end
	server.giveMeWeapon(leaf.id, amount)
end

wndWeapon = {
	'wnd',
	text = 'fegyverek',
	width = 250,
	controls = {
		{
			'lst',
			id='weaplist',
			width=230,
			height=280,
			columns={
				{text='Fegyver', attr='name'}
			},
			rows={xml='weapons.xml', attrs={'id', 'name'}},
			onitemdoubleclick=function(leaf) addWeapon(leaf, 500) end
		},
		{'br'},
		{'txt', id='töltény', text='500', width=60},
		{'btn', id='ok', onclick=addWeapon},
		{'btn', id='bezár', closeswindow=true}
	}
}

function giveWeaponCommand(cmd, weapon, amount)
	if isCommandOnCD(cmd) then return end
	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)

---------------------------
-- Main window
---------------------------

function updateGUI(updateVehicle)
	-- update position
	local x, y, z = getElementPosition(g_Me)
	setControlNumbers(wndMain, {xpos=math.ceil(x), ypos=math.ceil(y), zpos=math.ceil(z)})
	
	-- update jetpack toggle
	guiCheckBoxSetSelected( getControl(wndMain, 'jetpack'), doesPedHaveJetPack(g_Me) )
	
	if updateVehicle then
		-- update current vehicle
		local vehicle = getPedOccupiedVehicle(g_Me)
		if vehicle and isElement(vehicle) then
			setControlText(wndMain, 'curvehicle', getVehicleName(vehicle))
		else
			setControlText(wndMain, 'curvehicle', 'On foot')
		end
	end
end

function mainWndShow()
	if not getPedOccupiedVehicle(g_Me) then
		hideControls(wndMain, 'repair', 'flip', 'upgrades', 'color', 'paintjob', 'lightson', 'lightsoff')
	end
	updateTimer = updateTimer or setTimer(updateGUI, 2000, 0)
	updateGUI(true)
end

function mainWndClose()
	killTimer(updateTimer)
	updateTimer = nil
	colorPicker.closeSelect()
end

function onEnterVehicle(vehicle)
	setControlText(wndMain, 'curvehicle', getVehicleName(vehicle))
	showControls(wndMain, 'repair', 'flip', 'upgrades', 'color', 'paintjob', 'lightson', 'lightsoff')
	guiCheckBoxSetSelected(getControl(wndMain, 'lightson'), getVehicleOverrideLights(vehicle) == 2)
	guiCheckBoxSetSelected(getControl(wndMain, 'lightsoff'), getVehicleOverrideLights(vehicle) == 1)
end

function onExitVehicle(vehicle)
	setControlText(wndMain, 'curvehicle', 'On foot')
	hideControls(wndMain, 'repair', 'flip', 'upgrades', 'color', 'paintjob', 'lightson', 'lightsoff')
	closeWindow(wndUpgrades)
	closeWindow(wndColor)
end

function killLocalPlayer()
	server.killPed(g_Me)
end

function alphaCommand(command, alpha)
	alpha = alpha and tonumber(alpha)
	if alpha then
		server.setElementAlpha(g_Me, alpha)
	end
end
addCommandHandler('alpha', alphaCommand)
addCommandHandler('ap', alphaCommand)

addCommandHandler('kill', killLocalPlayer)

addEventHandler( 'onClientPlayerChangeNick', g_Me,
function( old, new )
	guiSetText ( getControl ( wndMain, 'plrname' ), new )
end )

function togglewarptome()
	if ( guiCheckBoxGetSelected( getControl ( wndMain, 'togglewarptme' ) ) == true ) then
		setElementData( g_Me, 'isWarpEnabled', 'false' )
	else
		setElementData( g_Me, 'isWarpEnabled', nil )
	end
end 

wndMain = {
	'wnd',
	text = 'FR GUI',
	x = 10,
	y = 150,
	width = 280,
	alpha = 1.0,
	controls = {
		{'lbl', id='myPos', text='Pozíciód:', width=80, height = 20},
		{'lbl', id='xpos', text='x', width=45},
		{'lbl', id='ypos', text='y', width=45},
		{'lbl', id='zpos', text='z', width=45},
		{'br'},
		{'lbl', id='linelbl1', text='====================================================', width=250, height = 20},
		{'br'},
		{'btn', id='Öngyilkosság', onclick=killLocalPlayer, width=80, height = 20},
		{'btn', id='Kinézet', window=wndSkin, width=80, height = 20},
		{'btn', id='Animáció', window=wndAnim, width=80, height = 20},
		{'btn', id='Ruhák(CJ)', window=wndClothes, width=80, height = 20},
		{'btn', id='playergrav', text='Gravitáció', window=wndGravity, width=80, height = 20},
		{'btn', id='Teleport', window=wndWarp, width=80, height = 20},
		{'btn', id='Statisztika', window=wndStats, width=80, height = 20},
		{'btn', id='Helyeid', window=wndBookmarks, width=80, height = 20},
		{'btn', id='Fegyverek', window=wndWeapon, width=80, height = 20},
		{'br'},
		{'chk', id='jetpack', onclick=toggleJetPack, width=80, height = 20},
		{'chk', id='falloff', text='Motoresés', onclick=toggleFallOffBike, width=150, height = 20},
		{'chk', id='togglewarptme', text='Teleportálás tiltása', onclick=togglewarptome, width=1000, height = 20},
		{'br'},
		{'lbl', id='linelbl2', text='====================================================', width=250, height = 20},
		{'br'},
		{'btn', id='setpos', text='Térkép', window=wndSetPos, width=80, height = 20},
		{'btn', id='setinterior', text='Ház belsők', window=wndSetInterior, width=80, height = 20},
		{'br'},
		{'lbl', id='linelbl3', text='====================================================', width=250, height = 20},
		{'br'},
		{'lbl', id='vehlbl', text='Jármű:', width=80, height = 20},
		{'br'},
		{'lbl', id='curlbl', text='Jelenlegi:', width=80, height = 20},
		{'lbl', id='curvehicle', width=80, height = 20},
		{'br'},
		{'btn', id='createvehicle', window=wndCreateVehicle, text='Létrehozás', width=80, height = 20},
		{'btn', id='Javítás', onclick=repairVehicle, width=80, height = 20},
		{'btn', id='Forgatás', onclick=flipVehicle, width=80, height = 20},
		{'btn', id='Tuning', window=wndUpgrades, width=80, height = 20},
		{'btn', id='Szín', onclick=openColorPicker, width=80, height = 20},
		{'btn', id='Matrica', window=wndPaintjob, width=80, height = 20},
		{'br'},
		{'chk', id='lightson', text='Lámpák be', onclick=forceLightsOn, width=87, height = 20},
		{'chk', id='lightsoff', text='Lámpák ki', onclick=forceLightsOff, width=87, height = 20},
	},
	oncreate = mainWndShow,
	onclose = mainWndClose
}

this is the fr_client.lua

you should use the default mta freeroam resource for your server as it would be bug free

  • Like 1
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...