Jump to content

[help] give weapon command on dayzepoch


sirrjohn

Recommended Posts

	function give()
		if (guiGridListGetSelectedItem(giveWindowGridlist) ~= -1) then
			local item = guiGridListGetItemText(giveWindowGridlist,guiGridListGetSelectedItem(giveWindowGridlist))
			local quantity = guiGetText(giveWindowEditboxQuant)
			local selectedPlayer = getPlayerFromName(guiGridListGetItemText(gridlistPlayers1,item,1))
			if selectedPlayer then
				triggerServerEvent("giveEvent",localPlayer,selectedPlayer,item,quantity)
			end
		end
	end

	function giveAll()
		if (guiGridListGetSelectedItem(giveWindowGridlist) ~= -1) then
			local item = guiGridListGetItemText(giveWindowGridlist,guiGridListGetSelectedItem(giveWindowGridlist))
			local quantity = guiGetText(giveWindowEditboxQuant)
			triggerServerEvent("giveAllEvent",localPlayer,item,quantity)
		end
	end

 

client

 

function giveEvent(selectedPlayer,item,quantity)
	setElementData(selectedPlayer,item,getElementData(selectedPlayer,item)+quantity)
	outputChatBox(prefix.." Admin "..string.gsub(getPlayerName(source), "#%x%x%x%x%x%x", "").." gave you "..quantity.." "..item,selectedPlayer,0,0,0,true)
	outputChatBox(prefix.." You gave "..quantity.." "..item.." to "..string.gsub(getPlayerName(selectedPlayer), "#%x%x%x%x%x%x", ""),source,0,0,0,true)
end
addEvent("giveEvent",true)
addEventHandler("giveEvent",root,giveEvent)

function giveAllEvent(item,quantity)
	for i,p in ipairs(getElementsByType("player")) do
		setElementData(p,item,getElementData(p,item)+quantity)
	end
	outputChatBox(prefix.." Admin "..string.gsub(getPlayerName(source), "#%x%x%x%x%x%x", "").." gave "..quantity.." "..item.." to everyone",root,0,0,0,true)
end
addEvent("giveAllEvent",true)
addEventHandler("giveAllEvent",root,giveAllEvent)

server

Error spacer.pnghttps://imgur.com/a/fRu07Ni

Link to comment
  • 2 weeks later...

You're getting the text of the selected item of giveWindowGridlist and using that text as row index of gridlistPlayers1 to get the text from. Which won't work unless the grid list actually contains values like 0, 1, 2, ...

I think you meant to get the player name the same way you get item? Like using guiGridListGetSelectedItem on gridlistPlayers1 and then passing the result to guiGridListGetItemText?

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