Jump to content

Panel Problem


GerardWay

Recommended Posts

Client side:

local GUI_Buttons = {} 
local GOD_STR = "" 
local elementID = 
{ 
    [TURISMO_ID]    = { type = "vehicle", name = "Turismo", positions = { 17, 80, 130, 59 } }, 
    [HYDRA_ID]      = { type = "vehicle", name = "Hydra", positions = { 173, 80, 132, 57 } }, 
    [CHAINSAW_ID]   = { type = "vehicle", name = "Chainsaw", positions = { 17, 176, 127, 58 } }, 
    [RPG_ID]        = { type = "weapon", name = "RPG", positions = { 163, 176, 138, 53 } }, 
    [NRG500_ID]     = { type = "weapon", name = "NRG-500", positions = { 12, 348, 124, 53 } } 
}; 
  
addEventHandler ( "onClientResourceStart", resourceRoot, 
    function() 
        --create window and other GUI elements 
        p_Window = guiCreateWindow ( 0, 274, 331, 493, "V.I.P. Panel", false ); 
        if ( p_Window ) then 
            guiWindowSetSizable ( p_Window, false ); 
            guiSetAlpha ( p_Window, 1 ); 
            guiSetVisible ( p_Window, false ); 
            showCursor ( false ); 
         
            for index, value in pairs( vehicleID ) do 
                local px, py, width, height = unpack ( value.positions ); 
                GUI_Buttons[index] = guiCreateButton ( px, py, width, height, "Give " .. value.name, false, p_Window ); 
            end 
             
            --CHECK HERE WHETHER LOCAL PLAYERS GOD MODE IS ENABLED OR NOT AND SET GOD_STR TO "Enable GodMode" or "Disable GodMode" 
             
            p_Godmode = guiCreateButton ( 10, 268, 129, 54, GOD_STR, false, p_Window ); 
             
            p_Close = guiCreateButton ( 162, 352, 121, 49, "Close panel", false, p_Window ); 
             
            --event/command handlers 
            addEventHandler ( "onClientGUIClick", root, GUI_Click, false ); 
            addCommandHandler ( "ovp", GUI_Visible ); 
        end 
    end 
) 
  
function GUI_Click() 
    for index, value in pairs( GUI_Buttons ) do 
        if ( source == value ) then 
            triggerServerEvent( "panel:createElement", localPlayer, value.type, index ); 
        end 
    end 
     
    if ( source == p_Godmode ) then 
        --check if god mode is enabled or not and do your things 
    end 
     
    if ( source == p_Close ) then 
        guiSetVisible( p_Window, false ); 
        showCursor ( false ); 
    end 
end 
  
function GUI_Visible() 
    guiSetVisible ( p_Window, not guiGetVisible( p_Window ) ); 
    showCursor( guiGetVisible( p_Window ) ); 
end 

Server side:

addEvent ( "panel:createElement", true ); 
addEventHandler ( "panel:createElement", root, 
    function ( type, id ) 
        if ( type == "vehicle" ) then 
            local px, py, pz = getElementPosition ( source ); 
            if ( px and py and pz ) then 
                warpPedIntoVehicle ( source, createVehicle ( tonumber ( id ), px, py, pz + 2 ) ); 
            end 
        elseif ( type == "weapon" ) then 
            giveWeapon ( source, id, 1, true ); 
        end 
    end 
) 

Didn't test it, just wanted to show you an easier way to do what you want.

To add a vehicle/weapon you simply need to do this:

1. Find out "elementID" array ( it's on top of the file ).

2. Between the { } add this:

[ MODEL_ID ] = { type = "vehicle/weapon", name = "Name that will appear in the button", positions = { WRITE_HERE_POSX_POSY_WIDTH_HEIGHT_DIVIDED_BY_COMMAS_OF_THE_BUTTONS }, 

Example:

--for vehicle: 
[411] = { type = "vehicle", name = "Infernus", positions = { 0, 0, 0, 0 } }, 
  
--for weapon: 
[38] = { type = "weapon", name = "Minigun", positions = { 0, 0, 0, 0 } }, 

P.S. You should look at comments in the code and edit it, otherwise code won't work properly.

Link to comment

forumc.lua:

addEventHandler("onClientResourceStart", resourceRoot, 
  
  
GUIEditor.window[1] =  guiCreateWindow(0, 274, 331, 493, "V.I.P Panel", false )  
guiWindowSetSizable(GUIEditor.window[1], false) 
guiSetAlpha(GUIEditor.window[1], 1.00) 
guiSetVisible( GUIEditor.window[1], false ) 
        
  
Turismo = guiCreateButton(17, 80, 130, 59, "Give Turismo", false, GUIEditor.window[1]) 
  
        
  
Hydra = guiCreateButton(173, 80, 132, 57, "Give Hydra", false, GUIEditor.window[1]) 
  
        
  
Chainsaw = guiCreateButton(17, 176, 127, 58, "Give Chainsaw", false, GUIEditor.window[1]) 
  
        
  
RPG = guiCreateButton(163, 176, 138, 53, "Give RPG x20", false, GUIEditor.window[1]) 
  
        
  
EnableGodmode = guiCreateButton(10, 268, 129, 54, "Enable Godmode", false, GUIEditor.window[1]) 
  
        
  
DisableGodmode = guiCreateButton(162, 268, 126, 49, "Disable Godmode", false, GUIEditor.window[1]) 
  
        
  
NRG500 = guiCreateButton(12, 348, 124, 53, "Give NRG-500", false, GUIEditor.window[1]) 
  
  
Close = guiCreateButton(162, 352, 121, 49, "Close Panel", false, GUIEditor.window[1])     
  
showCursor( false ) 
  
  
GUIEditor = { 
  
button = {}, 
  
window = {}, 
  
} 
  
addEventHandler("onClientResourceStart", resourceRoot, 
function() 
GUIEditor.window[1] = guiCreateWindow(0, 274, 331, 493, "V.I.P Panel", false) 
guiWindowSetSizable(GUIEditor.window[1], false) 
guiSetAlpha(GUIEditor.window[1], 1.00) 
guiSetVisible( GUIEditor.window[1], false ) 
        
  
Turismo = guiCreateButton(17, 80, 130, 59, "Give Turismo", false, GUIEditor.window[1]) 
  
        
  
Hydra = guiCreateButton(173, 80, 132, 57, "Give Hydra", false, GUIEditor.window[1]) 
  
        
  
Chainsaw = guiCreateButton(17, 176, 127, 58, "Give Chainsaw", false, GUIEditor.window[1]) 
  
        
  
RPG = guiCreateButton(163, 176, 138, 53, "Give RPG x20", false, GUIEditor.window[1]) 
  
        
  
EnableGodmode = guiCreateButton(10, 268, 129, 54, "Enable Godmode", false, GUIEditor.window[1]) 
  
        
  
DisableGodmode = guiCreateButton(162, 268, 126, 49, "Disable Godmode", false, GUIEditor.window[1]) 
  
        
  
NRG500 = guiCreateButton(12, 348, 124, 53, "Give NRG-500", false, GUIEditor.window[1]) 
  
  
Close = guiCreateButton(162, 352, 121, 49, "Close Panel", false, GUIEditor.window[1])     
  
showCursor( false ) 
  
function buyCar(thePlayer) 
triggerServerEvent ( "buyVeh", getLocalPlayer(), "greetingHandler" ) 
end 
) 
  
  
  
addEventHandler("onClientGUIClick", root, 
function() 
if source == Turismo then 
triggerServerEvent("Turismo", localPlayer) 
  elseif source == Hydra then 
    triggerServerEvent("Hydra", localPlayer) 
 elseif source == Chainsaw then 
    triggerServerEvent("Chainsaw", localPlayer) 
 elseif source == RPG then 
    triggerServerEvent("RPG", localPlayer) 
  elseif source == NRG500 then 
    triggerServerEvent("NRG500", localPlayer) 
  elseif source == Close then 
    guiSetVisible(GUIEditor.window[1], false) 
    showCursor(false) 
    end 
  end 
) 
  
function showit ( ) 
guiSetVisible( GUIEditor.window[1], true ) 
showCursor( true ) 
end 
addCommandHandler( "ovp", showit ) 
  

forums.lua:

  
addEvent( "Turismo", true) 
addEventHandler( "Turismo", root, 
function()                       
x, y, z = getElementPosition ( source ) 
Vehicle = createVehicle ( 451, x, y, z + 2) 
warpPedIntoVehicle ( source, Vehicle ) 
end 
) 
  
  
  
addEvent( "Hydra", true) 
addEventHandler( "Hydra", root, 
function()                       
x, y, z = getElementPosition ( source ) 
Vehicle = createVehicle ( 520, x, y, z + 2) 
warpPedIntoVehicle ( source, Vehicle ) 
end 
) 
  
  
  
addEvent( "NRG500", true) 
addEventHandler( "NRG500", root, 
function()                       
x, y, z = getElementPosition ( source ) 
Vehicle = createVehicle ( 522, x, y, z + 2) 
warpPedIntoVehicle ( source, Vehicle ) 
end 
) 
  
addEvent( "RPG", true) 
addEventHandler( "RPG", root, 
function()                       
giveWeapon( root, 35, 1, true ) 
end 
) 
  
  
  
addEvent( "Chainsaw", true) 
addEventHandler( "Chainsaw", root, 
function()                       
giveWeapon( root, 9, 1, true ) 
end 
) 
  

Edited by Guest
Link to comment

copy this

forumc.lua

  
GUIEditor = { 
  
    button = {}, 
  
    window = {}, 
  
} 
  
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        GUIEditor.window[1] = guiCreateWindow(0, 274, 331, 493, "V.I.P Panel", false) 
        guiWindowSetSizable(GUIEditor.window[1], false) 
        guiSetAlpha(GUIEditor.window[1], 1.00) 
        guiSetVisible( GUIEditor.window[1], false ) 
         
  
Turismo = guiCreateButton(17, 80, 130, 59, "Give Turismo", false, GUIEditor.window[1]) 
  
         
  
Hydra = guiCreateButton(173, 80, 132, 57, "Give Hydra", false, GUIEditor.window[1]) 
  
         
  
Chainsaw = guiCreateButton(17, 176, 127, 58, "Give Chainsaw", false, GUIEditor.window[1]) 
  
         
  
RPG = guiCreateButton(163, 176, 138, 53, "Give RPG x20", false, GUIEditor.window[1]) 
  
         
  
EnableGodmode = guiCreateButton(10, 268, 129, 54, "Enable Godmode", false, GUIEditor.window[1]) 
  
         
  
DisableGodmode = guiCreateButton(162, 268, 126, 49, "Disable Godmode", false, GUIEditor.window[1]) 
  
         
  
NRG500 = guiCreateButton(12, 348, 124, 53, "Give NRG-500", false, GUIEditor.window[1]) 
  
  
Close = guiCreateButton(162, 352, 121, 49, "Close Panel", false, GUIEditor.window[1])     
  
showCursor( false ) 
  
function buyCar(thePlayer) 
    triggerServerEvent ( "buyVeh", getLocalPlayer(), "greetingHandler" ) 
      end 
end 
) 
  
  
  
addEventHandler("onClientGUIClick", root, 
 function() 
  if source == Turismo then 
    triggerServerEvent("Turismo", localPlayer) 
  elseif source == Hydra then 
    triggerServerEvent("Hydra", localPlayer) 
 elseif source == Chainsaw then 
    triggerServerEvent("Chainsaw", localPlayer) 
 elseif source == RPG then 
    triggerServerEvent("RPG", localPlayer) 
  elseif source == NRG500 then 
    triggerServerEvent("NRG500", localPlayer) 
  elseif source == Close then 
    guiSetVisible(GUIEditor.window[1], false) 
    showCursor(false) 
    end 
  end 
) 
  
function showit ( ) 
guiSetVisible( GUIEditor.window[1], true ) 
showCursor( true ) 
end 
addCommandHandler( "ovp", showit ) 
  

Link to comment
Client side:
local GUI_Buttons = {} 
local GOD_STR = "" 
local elementID = 
{ 
    [TURISMO_ID]    = { type = "vehicle", name = "Turismo", positions = { 17, 80, 130, 59 } }, 
    [HYDRA_ID]      = { type = "vehicle", name = "Hydra", positions = { 173, 80, 132, 57 } }, 
    [CHAINSAW_ID]   = { type = "vehicle", name = "Chainsaw", positions = { 17, 176, 127, 58 } }, 
    [RPG_ID]        = { type = "weapon", name = "RPG", positions = { 163, 176, 138, 53 } }, 
    [NRG500_ID]     = { type = "weapon", name = "NRG-500", positions = { 12, 348, 124, 53 } } 
}; 
  
addEventHandler ( "onClientResourceStart", resourceRoot, 
    function() 
        --create window and other GUI elements 
        p_Window = guiCreateWindow ( 0, 274, 331, 493, "V.I.P. Panel", false ); 
        if ( p_Window ) then 
            guiWindowSetSizable ( p_Window, false ); 
            guiSetAlpha ( p_Window, 1 ); 
            guiSetVisible ( p_Window, false ); 
            showCursor ( false ); 
         
            for index, value in pairs( vehicleID ) do 
                local px, py, width, height = unpack ( value.positions ); 
                GUI_Buttons[index] = guiCreateButton ( px, py, width, height, "Give " .. value.name, false, p_Window ); 
            end 
             
            --CHECK HERE WHETHER LOCAL PLAYERS GOD MODE IS ENABLED OR NOT AND SET GOD_STR TO "Enable GodMode" or "Disable GodMode" 
             
            p_Godmode = guiCreateButton ( 10, 268, 129, 54, GOD_STR, false, p_Window ); 
             
            p_Close = guiCreateButton ( 162, 352, 121, 49, "Close panel", false, p_Window ); 
             
            --event/command handlers 
            addEventHandler ( "onClientGUIClick", root, GUI_Click, false ); 
            addCommandHandler ( "ovp", GUI_Visible ); 
        end 
    end 
) 
  
function GUI_Click() 
    for index, value in pairs( GUI_Buttons ) do 
        if ( source == value ) then 
            triggerServerEvent( "panel:createElement", localPlayer, value.type, index ); 
        end 
    end 
     
    if ( source == p_Godmode ) then 
        --check if god mode is enabled or not and do your things 
    end 
     
    if ( source == p_Close ) then 
        guiSetVisible( p_Window, false ); 
        showCursor ( false ); 
    end 
end 
  
function GUI_Visible() 
    guiSetVisible ( p_Window, not guiGetVisible( p_Window ) ); 
    showCursor( guiGetVisible( p_Window ) ); 
end 

Server side:

addEvent ( "panel:createElement", true ); 
addEventHandler ( "panel:createElement", root, 
    function ( type, id ) 
        if ( type == "vehicle" ) then 
            local px, py, pz = getElementPosition ( source ); 
            if ( px and py and pz ) then 
                warpPedIntoVehicle ( source, createVehicle ( tonumber ( id ), px, py, pz + 2 ) ); 
            end 
        elseif ( type == "weapon" ) then 
            giveWeapon ( source, id, 1, true ); 
        end 
    end 
) 

Didn't test it, just wanted to show you an easier way to do what you want.

To add a vehicle/weapon you simply need to do this:

1. Find out "elementID" array ( it's on top of the file ).

2. Between the { } add this:

[ MODEL_ID ] = { type = "vehicle/weapon", name = "Name that will appear in the button", positions = { WRITE_HERE_POSX_POSY_WIDTH_HEIGHT_DIVIDED_BY_COMMAS_OF_THE_BUTTONS }, 

Example:

--for vehicle: 
[411] = { type = "vehicle", name = "Infernus", positions = { 0, 0, 0, 0 } }, 
  
--for weapon: 
[38] = { type = "weapon", name = "Minigun", positions = { 0, 0, 0, 0 } }, 

P.S. You should look at comments in the code and edit it, otherwise code won't work properly.

Awesome!And easy!^ ^

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