Jump to content

What i must do???


Lord_of_VW

Recommended Posts

Hi, i have a problem, how i can use gridlists.

i have create one (name:choose a team) and a button (name: OK)

how i can do it, when i click the team in the gridlist and then i click the button, that i will spawn...? please help me if you know what i mean

listls = guiCreateGridList(0.01,0.02,0.4,0.96,true,ls) 
teamsls = guiGridListAddColumn(listls,"Choose A Team",0.9) 
  
                        local row1 = guiGridListAddRow ( listls ) 
                        local row2 = guiGridListAddRow ( listls ) 
                        local row3 = guiGridListAddRow ( listls ) 
                        local row4 = guiGridListAddRow ( listls ) 
                        local row5 = guiGridListAddRow ( listls ) 
                        local row6 = guiGridListAddRow ( listls ) 
  
       lspdt = guiGridListSetItemText ( listls, row1, teamsls, "LSPD", false, false ) 
       lbt = guiGridListSetItemText ( listls, row2, teamsls, "Los Banditos", false, false ) 
       grvt = guiGridListSetItemText ( listls, row3, teamsls, "Grove", false, false ) 
       lcnt = guiGridListSetItemText ( listls, row4, teamsls, "La Costa Nostra", false, false ) 
       ballt = guiGridListSetItemText ( listls, row5, teamsls, "Ballas", false, false ) 
       medlst = guiGridListSetItemText ( listls, row6, teamsls, "Medic", false, false ) 
    lsok = guiCreateButton(0.79,0.83,0.2,0.15,"OK",true,ls) 
    guiSetProperty( lsok, "HoverTextColour", "FF0064FF" ) 

Link to comment

You want to attach an onClientGUIClick event handler to the button, and in that handler use guiGridListGetSelectedItem to find out what team was selected. From there you can use triggerServerEvent to send the choice to the server, so that the server can spawn you. An important note here is to set the getPropagated parameter of the guiclick addEventHandler to false, otherwise the button will also get triggered when the user clicks in an empty area of the window (because the button is a child of the window and thus receives its events)

Also as a side suggestion, it would be more user friendly to have a button per team instead of a list. That way, players can directly click a team button and immediately spawn, instead of having to make a list selection and clicking "OK". You could even put little pictures representing the team skin in or next to such buttons.

Link to comment

Sorry, I have neither. And even if I did, I wouldn't just write your gamemode for you :P. The information I gave you should be enough for you to do what you want.

Well, maybe some addEventHandler example code is in order:

function okButtonClicked() 
    -- find out what item is selected and send it to the server 
end 
addEventHandler("onClientGUIClick", lsok, okButtonClicked, false) 

Edited by Guest
Link to comment

like this?

p = getLocalPlayer(p) 
function gamembox () 
    if guiGetVisible(gamemm) then 
        guiSetVisible(gamemm,false) 
        showCursor(false) 
    else 
gamemm = guiCreateWindow(0.325,0.350,0.350,0.350,"Rio Grande Gamemode v0.5",true) 
    guiWindowSetSizable(gamemm,false) 
    guiWindowSetMovable(gamemm,false) 
tabPanel = guiCreateTabPanel ( 0, 0.1, 1, 1, true, gamemm ) 
ls = guiCreateTab( "Los Santos", tabPanel )   
sf = guiCreateTab( "San Fierro", tabPanel )   
lv = guiCreateTab( "Las Vanturas", tabPanel ) 
  
  
listls = guiCreateGridList(0.01,0.02,0.4,0.96,true,ls) 
teamsls = guiGridListAddColumn(listls,"Choose A Team",0.9) 
  
                        local row1 = guiGridListAddRow ( listls ) 
                        local row2 = guiGridListAddRow ( listls ) 
                        local row3 = guiGridListAddRow ( listls ) 
                        local row4 = guiGridListAddRow ( listls ) 
                        local row5 = guiGridListAddRow ( listls ) 
                        local row6 = guiGridListAddRow ( listls ) 
  
       lspdt = guiGridListSetItemText ( listls, row1, teamsls, "LSPD", false, false ) 
       lbt = guiGridListSetItemText ( listls, row2, teamsls, "Los Banditos", false, false ) 
       grvt = guiGridListSetItemText ( listls, row3, teamsls, "Grove", false, false ) 
       lcnt = guiGridListSetItemText ( listls, row4, teamsls, "La Costa Nostra", false, false ) 
       ballt = guiGridListSetItemText ( listls, row5, teamsls, "Ballas", false, false ) 
       medlst = guiGridListSetItemText ( listls, row6, teamsls, "Medic", false, false ) 
  
    lsok = guiCreateButton(0.79,0.83,0.2,0.15,"OK",true,ls) 
    guiSetProperty( lsok, "HoverTextColour", "FF0064FF" ) 
  
  
  
  
  
  
addEventHandler ( "onClientGUIClick", lsok, team , false )   
end 
end 
function team() 
guiGridListGetItemText ( listls, guiGridListGetSelectedItem ( listls ) ) 
end 
function teamgrov () 
        guiSetVisible(gamemm,false) 
        showCursor(false) 
        triggerServerEvent("onTeamGrov", getRootElement(), p) 
end 
function teamLSPD () 
        guiSetVisible(gamemm,false) 
        showCursor(false) 
        triggerServerEvent("onTeamLSPD", getRootElement(), p) 
end 
function teamlcn () 
        guiSetVisible(gamemm,false) 
        showCursor(false) 
        triggerServerEvent("onTeamlcn", getRootElement(), p) 
end 
function teamlb () 
        guiSetVisible(gamemm,false) 
        showCursor(false) 
        triggerServerEvent("onTeamLB", getRootElement(), p) 
end 
function teambal () 
        guiSetVisible(gamemm,false) 
        showCursor(false) 
        triggerServerEvent("onTeamBal", getRootElement(), p) 
end 
  
addEventHandler( "onClientResourceStart", getResourceRootElement( getThisResource( ) ), gamembox ) 
addEventHandler ( "onClientPlayerWasted", getLocalPlayer(), gamembox ) 

sry but i dont understand it xD what i have to do now?

server side :

  function createTeamsOnStart () 
        teamMedic = createTeam ( "Medic", 255, 0, 0 )
        teamLSPD = createTeam ( "LSPD", 0, 0, 255  )
        teamSFPD = createTeam ( "SFPD", 0, 0, 255 )
        teamLVPD = createTeam ( "LVPD", 0, 0, 255 )
        teamArmy = createTeam ( "Army", 34,139,34 )
 
--gangs
        teamTune = createTeam ( "Tunestars", 34,139,34 )
        teamCivi = createTeam ( "Civilan", 255,222,173 )
 
 
        teamLCN = createTeam ( "LCN", 65,105,225 )
        teamLB = createTeam ( "LB", 32,178,170 )
        teamYak = createTeam ( "Yakuzza", 105,105,105 )
        teamCob = createTeam ( "The Cobras", 97,97,97 )
        teamBal = createTeam ( "Ballas", 139,0,0 )
        teamWA = createTeam ( "The Warriors", 250,235,215 )
        teamGrov = createTeam ( "Groves", 0,255,0 )
end
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), createTeamsOnStart  )
function civi ( source, weapon, ammo)
  setPlayerTeam ( source, teamCivi )
          spawnPlayer ( source, 414, 2536, 19  )
 takeAllWeapons ( source )
 setElementHealth ( source, 100 )
  setPlayerNametagColor ( source, 255,222,173 )
          setPlayerSkin ( source, randInt(18, 26) )
      setPlayerArmor ( source, 0 )
end
addEvent("onTeamCivi", true)
addEventHandler("onTeamCivi", getRootElement(), civi)
function tune ( source, weapon, ammo)
  setPlayerTeam ( source, teamTune )
          spawnPlayer ( source, -1952, 280, 35  )
 takeAllWeapons ( source )
  giveWeapon ( source, 1, 1 )
  giveWeapon ( source, 4, 1 )
  giveWeapon ( source, 24, 500 )
  giveWeapon ( source, 28, 500 )
  giveWeapon ( source, 31, 500 )
  giveWeapon ( source, 41, 1000 )
  giveWeapon ( source, 39, 50 )
 setElementHealth ( source, 100 )
  setPlayerNametagColor ( source, 0,100,255 )
          setPlayerSkin ( source, randInt(46,48) )
      setPlayerArmor ( source, 100 )
end
addEvent("onTeamTune", true)
addEventHandler("onTeamTune", getRootElement(), tune)
--Staatsdiener
   function Medic ( source, weapon, ammo)
  setPlayerTeam ( source, teamMedic )
          spawnPlayer ( source, 1172.7, -1320.04, 15.4  )
 takeAllWeapons ( source )
  giveWeapon ( source, 3, 1 )
  giveWeapon ( source, 24, 300 )
  giveWeapon ( source, 29, 300 )
  giveWeapon ( source, 41, 100 )
 setElementHealth ( source, 100 )
  setPlayerNametagColor ( source, 255, 0, 0 )
          setPlayerSkin ( source, randInt (274, 276) )
      setPlayerArmor ( source, 0 )
end
addEvent("onTeamMed", true)
addEventHandler("onTeamMed", getRootElement(), Medic)
function LSPD ( source, commandName )
  setPlayerTeam ( source, teamLSPD )
             spawnPlayer ( source, 1580,-1635,13  )  
 takeAllWeapons ( source )
  giveWeapon ( source, 3, 1 )
  giveWeapon ( source, 24, 500 )
  giveWeapon ( source, 29, 500 )
  giveWeapon ( source, 31, 500 )
  giveWeapon ( source, 17, 500 )
  giveWeapon ( source, 41, 1000 )
  setPlayerArmor ( source, 0 )
  setPlayerSkin ( source, 280 )
 setElementHealth ( source, 100 )
  setPlayerNametagColor ( source, 0, 0, 255 )
end
addEvent("onTeamLSPD", true)
addEventHandler("onTeamLSPD", getRootElement(), LSPD)
function SFPD ( source, commandName )
  setPlayerTeam ( source, teamSFPD )
          spawnPlayer ( source, -1614.8, 687, 7  )
 takeAllWeapons ( source )
  giveWeapon ( source, 3, 1 )
  giveWeapon ( source, 24, 500 )
  giveWeapon ( source, 29, 500 )
  giveWeapon ( source, 31, 500 )
  giveWeapon ( source, 17, 500 )
  giveWeapon ( source, 41, 1000 )
  setPlayerArmor (source, 0 )
  setPlayerSkin ( source, 283 )
 setElementHealth ( source, 100 )
  setPlayerNametagColor ( source, 0, 0, 255 )
end
addEvent("onTeamSFPD", true)
addEventHandler("onTeamSFPD", getRootElement(), SFPD)
function LVPD ( source, commandName )
  setPlayerTeam (source, teamLVPD )
          spawnPlayer ( source, 2293, 2451.8, 11  )
 takeAllWeapons ( source )
  giveWeapon ( source, 3, 1 )
  giveWeapon ( source, 24, 500 )
  giveWeapon ( source, 29, 500 )
  giveWeapon ( source, 31, 500 )
  giveWeapon ( source, 17, 500 )
  giveWeapon ( source, 41, 1000 )
  setPlayerArmor ( source, 0 )
  setPlayerSkin ( source, 282 )
 setElementHealth ( source, 100 )
  setPlayerNametagColor ( source, 00, 0, 255 )
end
addEvent("onTeamLVPD", true)
addEventHandler("onTeamLVPD", getRootElement(), LVPD)
function Army ( source, commandName )
  setPlayerTeam ( source, teamArmy )
          spawnPlayer ( source, -1342, 491.8, 11.2  )
  takeAllWeapons ( source )
  giveWeapon ( source, 30, 500 )
  giveWeapon ( source, 22, 500 )
  giveWeapon ( source, 27, 500 )
  giveWeapon ( source, 32, 500 )
  giveWeapon ( source, 16, 500 )
  giveWeapon ( source, 44, 500 )
  setPlayerArmor ( source, 100 )
  setPlayerSkin ( source, 287 )
 setElementHealth ( source, 100 )
  setPlayerNametagColor ( source, 34,139,34 )
end
 
addEvent("onTeamArm", true)
addEventHandler("onTeamArm", getRootElement(), Army)
 
 
 
--Gangs
function warri ( source, commandName )
  setPlayerTeam ( source, teamWA )
          spawnPlayer ( source, 1956, 742, 14  )
  takeAllWeapons ( source )
  giveWeapon ( source, 1, 1 )
  giveWeapon ( source, 4, 1 )
  giveWeapon ( source, 24, 500 )
  giveWeapon ( source, 28, 500 )
  giveWeapon ( source, 30, 500 )
  giveWeapon ( source, 18, 100 )
  giveWeapon ( source, 41, 500 )
 setElementHealth ( source, 100 )
  setPlayerSkin ( source,  randInt (227, 228) )
  setPlayerNametagColor ( source, 250,235,215 )
end
addEvent("onTeamWarri", true)
addEventHandler("onTeamWarri", getRootElement(), warri)
function bike ( source, commandName )
  setPlayerTeam ( source, teamCob )
          spawnPlayer ( source, 2578, 2346, 18  )
  takeAllWeapons ( source )
  giveWeapon ( source, 1, 1 )
  giveWeapon ( source, 4, 1 )
  giveWeapon ( source, 24, 500 )
  giveWeapon ( source, 28, 500 )
  giveWeapon ( source, 30, 500 )
  giveWeapon ( source, 18, 100 )
  giveWeapon ( source, 41, 500 )
 setElementHealth ( source, 100 )
  setPlayerSkin ( source,  randInt (247,248) )
  setPlayerNametagColor ( source, 97,97,97 )
end
addEvent("onTeamBike", true)
addEventHandler("onTeamBike", getRootElement(), bike)
function yak ( source, commandName )
  setPlayerTeam ( source, teamYak )
          spawnPlayer ( source, 2633, 1824, 11  )
  takeAllWeapons ( source )
  giveWeapon ( source, 1, 1 )
  giveWeapon ( source, 4, 1 )
  giveWeapon ( source, 24, 500 )
  giveWeapon ( source, 28, 500 )
  giveWeapon ( source, 30, 500 )
  giveWeapon ( source, 18, 100 )
  giveWeapon ( source, 41, 500 )
 setElementHealth ( source, 100 )
  setPlayerSkin ( source,  randInt (117, 120) )
  setPlayerNametagColor ( source, 105,105,105 )
end
addEvent("onTeamYAK", true)
addEventHandler("onTeamYAK", getRootElement(), yak)
function lcn ( source, commandName )
          spawnPlayer ( source, 1123, -2044, 74  )
  setPlayerTeam ( source, teamLCN )
  takeAllWeapons ( source )
  giveWeapon ( source, 1, 1 )
  giveWeapon ( source, 4, 1 )
  giveWeapon ( source, 24, 500 )
  giveWeapon ( source, 28, 500 )
  giveWeapon ( source, 30, 500 )
  giveWeapon ( source, 18, 100 )
  giveWeapon ( source, 41, 500 )
 setElementHealth ( source, 100 )
  setPlayerSkin ( source,  randInt (111, 113) )
  setPlayerNametagColor ( source, 65,105,225 )
end
addEvent("onTeamlcn", true)
addEventHandler("onTeamlcn", getRootElement(), lcn)
function lb ( source, commandName )
  setPlayerTeam ( source, teamLB )
spawnPlayer ( source, 2789, -1628, 10.9  )
  takeAllWeapons ( source )
  giveWeapon ( source, 1, 1 )
  giveWeapon ( source, 4, 1 )
  giveWeapon ( source, 24, 500 )
  giveWeapon ( source, 28, 500 )
  giveWeapon ( source, 30, 500 )
  giveWeapon ( source, 18, 100 )
  giveWeapon ( source, 41, 500 )
 setElementHealth ( source, 100 )
  setPlayerSkin ( source,  randInt (173, 175) )
  setPlayerNametagColor ( source, 32,178,170 )
end
addEvent("onTeamLB", true)
addEventHandler("onTeamLB", getRootElement(), lb)
function Grov ( source, commandName )
  setPlayerTeam ( source, teamGrov )
  spawnPlayer ( source, 2492.394, -1692.6, 15  )
  takeAllWeapons ( source )
  giveWeapon ( source, 1, 1 )
  giveWeapon ( source, 4, 1 )
  giveWeapon ( source, 24, 500 )
  giveWeapon ( source, 28, 500 )
  giveWeapon ( source, 30, 500 )
  giveWeapon ( source, 18, 100 )
  giveWeapon ( source, 41, 500 )
 setElementHealth ( source, 100 )
  setPlayerSkin ( source,  randInt (105, 107) )
  setPlayerNametagColor ( source, 0, 255,0 )
end
addEvent("onTeamGrov", true)
addEventHandler("onTeamGrov", getRootElement(), Grov)
function Ballas ( source, commandName )
  setPlayerTeam ( source, teamBal )
          spawnPlayer ( source, 1803.66, -2140.165, 13.54  )
  takeAllWeapons ( source )
  giveWeapon ( source, 1, 1 )
  giveWeapon ( source, 4, 1 )
  giveWeapon ( source, 24, 500 )
  giveWeapon ( source, 28, 500 )
  giveWeapon ( source, 30, 500 )
  giveWeapon ( source, 18, 100 )
  giveWeapon ( source, 41, 500 )
Link to comment

Please try this: https://forum.multitheftauto.com/viewtop ... 91&t=24122

It's much easier to make gridlist and click handlers with my classes. Here's how your gridlist would be created:

ls = Window:CreateWindow( .... ); -- pass your parameters in place of '....' 
gridlist = ls:AddGridList( .01, .02, .4, .96, true ); 
gridlist:AddColumn( "Choose a team:" ); 
  
gridlist:AddRow( "LSPD" ); 
gridlist:AddRow( "Los Banditos" ); 
gridlist:AddRow( "Grove" ); 
gridlist:AddRow( "La Costa Nostra" ); 
gridlist:AddRow( "Ballas" ); 
gridlist:AddRow( "Medic" ); 
  
button = ls:AddButton( .79, .83, .2, .15, "OK", true ); 
button:ColorOnHover( "0064FFFF" ); -- RRGGBBAA 
button:AddOnClick( 
    function( ) 
        triggerServerEvent( .... ); -- your params here... 
    end 
) 

Also, check my post here: https://forum.multitheftauto.com/viewtop ... 48#p288402

it shows you how to get text of the selected item in the gridlist.

Peace and Love!

Link to comment
... Sry but i dont understand that :oo.O

It's so simple and you still don't understand? Check the topics I gave you the links to in my previous post because I'm 99% sure you didn't even read them. All you need is there and here already -_-

Try to read and understand. Also practice by writing scripts. When you don't try writing yourself you will never learn. If you have errors in your scripts, just post here and people will be glad help.

When I say it's easiest way of scripting GUI so far then it must be true because if you don't script OOP way then your code can be messy sometimes, especially scripting more complex GUI. I gave you an example, why don't you try it. Download my GUI Classes and give it a go. I also made a few examples in "test.lua" file so you can learn from it too.

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