Price. Posted October 24, 2014 Share Posted October 24, 2014 well I had this script and I'am not that good with gui's so basically I want to attach a police chief script to a GUI instead of some commands, for example i want to "sack some officer" like to get him off duty with time so he cant join the police force until this period of time is passed function giveHeadOfficerRights(admin, commandName, accountName) local accName = getAccountName( getPlayerAccount( admin )) if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" )) then if accountName then local account = getAccount( accountName ) local policeChief = getAccountPlayer( account ) if account and policeChief then if not getAccountData( account, "isPoliceChief" ) then setElementData( policeChief, "isPoliceChief", true ) setAccountData( account, "isPoliceChief", true ) outputChatBox( "Player: "..getPlayerName(policeChief).." was successfully added as police chief", admin, 0, 200, 0 ) else setElementData( policeChief, "isPoliceChief", false ) setAccountData( account, "isPoliceChief", false ) outputChatBox( "Player: "..getPlayerName(policeChief).." was removed from police chief", admin, 255, 200, 0 ) end end else outputChatBox ("Correct syntax: /addpc ", playerSource) end end end addCommandHandler( "addpc", giveHeadOfficerRights) addCommandHandler( "removepc", giveHeadOfficerRights) function kickBadPolice(policeChief, commandName, badOfficer) if getElementData( policeChief, "isPoliceChief" ) then local cop = getPlayerFromName( badOfficer ) if cop then setElementData( cop, "bannedFromLaw", true ) outputChatBox( "You have been kicked from the force by: "..getPlayerName(policeChief), cop, 255, 0, 0) outputChatBox( "Police: "..badOfficer.." was kicked from the police job", policeChief, 0, 200, 0 ) -- Reset job and team local unemployed = getTeamFromName( "Unemployed" ) setPlayerTeam( cop, unemployed ) setPlayerNametagColor( cop, 255, 255, 0 ) setElementData( cop, "admin",false) local skinID = exports["clothes"]:getBoughtSkin ( cop ) setElementModel( cop, skinID ) setElementData( cop, "Occupation", "" ) else outputChatBox( "Correct syntax: /rj ", policeChief, 255, 200, 0 ) end end end addCommandHandler( "rj", kickBadPolice ) function allowPoliceJob(policeChief, commandName, badOfficer) if getElementData( policeChief, "isPoliceChief" ) then local cop = getPlayerFromName( badOfficer ) if cop then setElementData( cop, "bannedFromLaw", false ) outputChatBox( "You have been unblocked from law jobs by: "..getPlayerName(policeChief), cop, 0, 255, 0) outputChatBox( "Police: "..badOfficer.." was unbanned from the police job", policeChief, 0, 200, 0 ) else outputChatBox( "Correct syntax: /cj ", policeChief, 255, 200, 0 ) end end end addCommandHandler( "cj", allowPoliceJob ) there is a GUI here but its from community script so has different functions function centerWindow(center_window) local screenW,screenH=guiGetScreenSize() local windowW,windowH=guiGetSize(center_window,false) local x,y = (screenW-windowW)/2,(screenH-windowH)/2 guiSetPosition(center_window,x,y,false) end GUIEditor_Button = {} GUIEditor_Label = {} wnd = guiCreateWindow(0.32,0.175,0.5138,0.7583,"Police Chief Panel",true) guiWindowSetMovable(wnd,false) guiWindowSetSizable(wnd,false) centerWindow(wnd) grid = guiCreateGridList(9,25,183,375,false,wnd) guiGridListSetSelectionMode(grid,1) guiGridListAddColumn(grid,"Players",0.-- s8) --> edit = guiCreateEdit(9,406,182,40,"",false,wnd) GUIEditor_Button[1] = guiCreateButton(196,33,205,34,"Sack Selected",false,wnd) GUIEditor_Button[2] = guiCreateButton(196,79,205,34,"Unsack Selected",false,wnd) GUIEditor_Button[3] = guiCreateButton(196,125,205,34,"Place APB",false,wnd) GUIEditor_Button[4] = guiCreateButton(196,174,205,34,"/gochief",false,wnd) GUIEditor_Button[5] = guiCreateButton(315,397,87,49,"Close window",false,wnd) guiSetFont(GUIEditor_Button[5],"default-bold-small") guiSetProperty(GUIEditor_Button[5],"NormalTextColour","ffff0000") GUIEditor_Label[6] = guiCreateLabel(199,333,201,27,"Skin:",false,wnd) guiSetVisible(wnd,false) for i,btn in ipairs(GUIEditor_Button) do guiSetFont(btn,"default-bold-small") guiSetProperty(btn,"NormalTextColour","ffff0000") end for i,lal in ipairs(GUIEditor_Label) do guiSetFont(lal,"default-bold-small") guiLabelSetColor(lal,255,255,0) end function open() triggerServerEvent("isPolice",localPlayer) end bindKey(key,"down",open) addEvent("Yes",true) addEventHandler("Yes",root, function () if guiGetVisible(wnd) then guiSetVisible(wnd,false) showCursor(false) guiSetInputEnabled(false) else guiSetVisible(wnd,true) showCursor(true) guiSetInputEnabled(true) putAllPlayersInList() end end ) function putAllPlayersInList() guiGridListClear(grid) for i,v in ipairs(getElementsByType("player")) do local row = guiGridListAddRow(grid) guiGridListSetItemText(grid,row,1,getPlayerName(v),false,false) guiGridListSetItemColor(grid,row,1,0,255,0) end end addEventHandler("onClientGUIClick",root, function () if ( source == GUIEditor_Button[5] ) then guiSetVisible(wnd,false) showCursor(false) guiSetInputEnabled(false) end end ) function setPlayerSep(player) setCameraTarget(player) x,y = guiGetScreenSize() endkey = guiCreateButton(0.1,0.4,0.1,0.15,"End",true) addEventHandler("onClientGUIClick",endkey,onEndSep,false) end function onEndSep() destroyElement(endkey) setCameraTarget(localPlayer) end addEventHandler("onClientGUIClick",root, function () local sel = guiGridListGetSelectedItem(grid) local text = guiGridListGetItemText(grid,sel,1) if ( source == GUIEditor_Button[2] ) then if ( sel ~= -1 ) then setPlayerSep(getPlayerFromName(text)) else show("Please Choose Player To Spectator it") end elseif ( source == GUIEditor_Button[1] ) then if ( sel ~= -1 ) then triggerServerEvent("killPlayer",localPlayer,text) else show("Please Choose Player To Kill it") end elseif ( source == GUIEditor_Button[3] ) then if ( sel ~= -1 ) then local player = getPlayerFromName(text) if isPedInVehicle(player) then triggerServerEvent("onDes",localPlayer,text) else show("This Player Don't Have Vehicle") end else show("Please Choose Player To Destroy His Vehicle") end elseif ( source == GUIEditor_Button[4] ) then if ( sel ~= -1 ) then local player = getPlayerFromName(text) if isPedInVehicle(player) then triggerServerEvent("onBlow",localPlayer,text) else show("This Player Don't Have Vehicle") end else show("Please Choose Player To Blow His Vehicle") end end end ) addEventHandler("onClientGUIClick",root, function () if ( source == grid ) then local sel = guiGridListGetSelectedItem(grid) local text = guiGridListGetItemText(grid,sel,1) local player = getPlayerFromName(text) if ( player ) then guiSetText(GUIEditor_Label[1],"Name: " .. getPlayerName(player)) guiSetText(GUIEditor_Label[2],"Money: " .. getPlayerMoney(player) .. "$") guiSetText(GUIEditor_Label[3],"Ping: " .. getPlayerPing(player)) guiSetText(GUIEditor_Label[4],"Health: " .. math.ceil(getElementHealth(player)) .. "%") guiSetText(GUIEditor_Label[5],"Armor: " .. math.ceil(getPedArmor(player)) .. "%") guiSetText(GUIEditor_Label[6],"Skin: " .. getElementModel(player)) else guiSetText(GUIEditor_Label[1],"Name: N/A") guiSetText(GUIEditor_Label[2],"Money: N/A") guiSetText(GUIEditor_Label[3],"Ping: N/A") guiSetText(GUIEditor_Label[4],"Health: N/A") guiSetText(GUIEditor_Label[5],"Armor: N/A") guiSetText(GUIEditor_Label[6],"Skin: N/A") end end end ) addEventHandler("onClientGUIChanged",root, function () if ( source == edit ) then local text = guiGetText(edit) if ( text == "" ) then putAllPlayersInList() else guiGridListClear(grid) for i,v in ipairs(getElementsByType("player")) do local name = getPlayerName(v) if string.find(name,text) then local row = guiGridListAddRow(grid) guiGridListSetItemText(grid,row,1,name,false,false) guiGridListSetItemColor(grid,row,1,255,255,0) end end end end end ) Again i just want instead of commands to be attached to gui like this sack button, I want when I press sack another gui opens and tell me for how long and reason then he gets to "Civilian" team and cannot join the force till the period of time is finished, and /gochief I want it to be attached to /gochief button Link to comment
Price. Posted October 24, 2014 Author Share Posted October 24, 2014 would anyone help??? Link to comment
.:HyPeX:. Posted October 24, 2014 Share Posted October 24, 2014 You should always write your own code, no one will help you to adapt someone's elses script to work with yours. Link to comment
Price. Posted October 24, 2014 Author Share Posted October 24, 2014 the GUI is the only thing iam missing but...... iam not good with GUI's Link to comment
crismar Posted October 25, 2014 Share Posted October 25, 2014 Adapting resources is harder then making them yourself. Give it a try, make the GUI wth Gui Editor, make sure you rename each GUI element (i personally dont like their name format 'GUIEditorButton[1]' etc). If you ahve troubles after you tried, you can come here and we'll be more then glad to help you. Link to comment
Mr_Moose Posted October 26, 2014 Share Posted October 26, 2014 All you need to do is to use triggerServerEvent, once the right button is clicked in the GUI, then you need an event handler in the server side part. In fact, there is already a GUI included in the source which shows exactly how you can do this, http://code.albonius.com/?action=download&id=8523e282173778cc46739ae4405d3784 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now