-- Client side
addEventHandler("onClientResourceStart", resourceRoot,
function()
window1 = guiCreateWindow(509, 175, 311, 452, "Revive Panel", false)
guiWindowSetSizable(window1, false)
guiSetVisible( window1 ,false)
gridlist = guiCreateGridList(13, 26, 288, 341, false, window1)
guiGridListAddColumn(gridlist, "Players", 0.9)
Button1 = guiCreateButton(17, 379, 139, 63, "Revive Player", false, window1)
Button2 = guiCreateButton(166, 379, 135, 63, "Close", false, window1)
guiGridListClear(gridlist)
end
)
addCommandHandler('rp',
function ()
guiSetVisible(window1,not guiGetVisible(window1))
showCursor(guiGetVisible(window1))
changeGridListToPlayers ( gridlist, 1 )
end
)
-- Close button
addEventHandler ( "onClientGUIClick",root,
function ()
if (source == Button2) then
guiSetVisible( window1 ,false)
showCursor(false)
end
end
)
-- Health button
addEventHandler ( "onClientGUIClick", resourceRoot,
function ()
if (source == Button1) then
local gRow, gColumn = guiGridListGetSelectedItem ( gridlist )
if gRow >= 0 then
local PlayerName = guiGridListGetSelectedItemText ( gridlist )
local target = getPlayerFromName(PlayerName)
triggerServerEvent("onPlayerHealed", resourceRoot, target)
guiSetVisible( window1 ,false)
showCursor(false)
else
outputChatBox("Select a player to heal!", 0, 255, 0)
end
end
end)
-- [[ Useful functions ]] --
function guiGridListGetSelectedItemText ( gridList, column )
local item = guiGridListGetSelectedItem ( gridList )
if item then
return guiGridListGetItemText ( gridList, item, column or 1 )
end
return false
end
function changeGridListToPlayers ( gridlist, column )
if type ( column ) == 'number' and type ( range ) == 'number' and getElementType ( gridlist ) == 'gui-gridlist' then
guiGridListClear ( gridlist )
for i,v in ipairs ( getElementsByType ( 'player' ) ) do
if ( v ~= localPlayer ) then
local row = guiGridListAddRow ( gridlist )
return guiGridListSetItemText ( gridlist, row, column, getPlayerName ( v ), false, false )
end
end
else
return false
end
end
-- Server side.
addEvent("onPlayerHealed", true)
addEventHandler("onPlayerHealed", resourceRoot,
function (target)
if isElement (target) then
outputChatBox( getPlayerName(target) .. " has been healed.", client, 0, 255, 0)
setElementHealth( target, 100 )
end
end)