DORIAN112
Wiek: 42 Na forum: 6183 dni Posty: 76
Piwa : 1
Cytat: Chce zrobic panel salonu i mam gotowca kolega mi pomogl z nim i nie umimem do niego dodac aut zeby sie dalo sprzedawac
GUIEditor_Window = {}
Button = {}
GUIEditor_Grid = {}
kolumn = { }
label = { }
edit = { }
cars = { }
local x,y = guiGetScreenSize()
local v = "v1.1"
GUIEditor_Window[1] = guiCreateWindow((x/2)-(557/2),(y/2)-(412/2),657,412,"Salon Panel - "..v,false)
GUIEditor_Grid[1] = guiCreateGridList(21,43,153,320,false,GUIEditor_Window[1])
GUIEditor_Grid[2] = guiCreateGridList(389,43,153,320,false,GUIEditor_Window[1])
kolumn[1] = guiGridListAddColumn(GUIEditor_Grid[1],"Gracz",0.8)
kolumn[2] = guiGridListAddColumn(GUIEditor_Grid[2],"Auto",0.8)
Button[1] = guiCreateButton(192,227,175,44,"Sprzedaj",false,GUIEditor_Window[1])
Button[2] = guiCreateButton(192,281,175,44,"Anuluj Zamowienia",false,GUIEditor_Window[1])
Button[3] = guiCreateButton(192,334,175,44,"Wyjdz",false,GUIEditor_Window[1])
Button[4] = guiCreateButton(553,43,80,40,"Otworz",false,GUIEditor_Window[1])
Button[5] = guiCreateButton(553,103,80,40,"Zamknij",false,GUIEditor_Window[1])
Button[6] = guiCreateButton(553,163,80,40,"Garaz Otworz",false,GUIEditor_Window[1])
Button[7] = guiCreateButton(553,223,80,40,"Garaz Zamknij",false,GUIEditor_Window[1])
edit[1] = guiCreateEdit(389,367,153,20,"",false,GUIEditor_Window[1])
edit[2] = guiCreateEdit(21,367,153,20,"",false,GUIEditor_Window[1])
label[1] = guiCreateLabel(180,43,200,15, "Informacje:", false,GUIEditor_Window[1])
label[2] = guiCreateLabel(180,63,200,15, "Gracz:", false,GUIEditor_Window[1])
label[3] = guiCreateLabel(180,83,200,15, "Auto:", false,GUIEditor_Window[1])
label[4] = guiCreateLabel(180,103,200,15, "Koszt:", false,GUIEditor_Window[1])
label[5] = guiCreateLabel(180,123,200,15, "Tunigng:", false,GUIEditor_Window[1])
guiSetSize (GUIEditor_Window[1], 557,412, false)
guiWindowSetMovable(GUIEditor_Window[1],false)
guiWindowSetSizable(GUIEditor_Window[1],false)
guiSetVisible(GUIEditor_Window[1], false)
function onStart()
for id, player in ipairs(getElementsByType("player")) do
guiGridListSetItemText (GUIEditor_Grid[1], guiGridListAddRow (GUIEditor_Grid[1]), kolumn[1], getPlayerName ( player ), false, false )
end
local xml = xmlLoadFile("auta.xml")
if xml then
local id = 0
while ( xmlFindChild ( xml, "auto", id ) ~= false ) do
local sub = xmlFindChild ( xml, "auto", id )
local row = guiGridListAddRow (GUIEditor_Grid[2])
guiGridListSetItemPlayerName (GUIEditor_Grid[2], row, kolumn[2],getVehicleNameFromModel (xmlNodeGetValue(sub)), false, false )
table.insert(cars,getVehicleNameFromModel (xmlNodeGetValue(sub)))
id = id + 1
end
xmlUnloadFile(xml)
end
end
function onJoin()
local text = guiGetText(edit[2])
local name = getPlayerName ( source )
if text == "" then
local row = guiGridListAddRow (GUIEditor_Grid[1])
guiGridListSetItemPlayerName (GUIEditor_Grid[1], row, kolumn[1], name, false, false )
else
if string.find(string.upper(text), string.upper(name)) then
local row = guiGridListAddRow (GUIEditor_Grid[1])
guiGridListSetItemPlayerName (GUIEditor_Grid[1], row, kolumn[1], name, false, false )
end
end
end
function guiGridListSetItemPlayerName( gridlist, row, col, name )
guiGridListSetItemText( gridlist, row, col, name, false, false )
guiGridListSetItemData( gridlist, row, col, name )
end
function onQuit()
local id = 0
while ( id <= guiGridListGetRowCount(GUIEditor_Grid[1]) ) do
if ( guiGridListGetItemPlayerName(GUIEditor_Grid[1], id, 1 ) == getPlayerName ( source ) ) then
guiGridListRemoveRow(GUIEditor_Grid[1], id )
end
id = id + 1
end
end
function onChangeNick(oldNick, newNick)
local id = 0
while ( id <= guiGridListGetRowCount(GUIEditor_Grid[1]) ) do
if ( guiGridListGetItemPlayerName(GUIEditor_Grid[1], id, 1 ) == oldNick ) then
guiGridListRemoveRow(GUIEditor_Grid[1], id )
guiGridListSetItemText (GUIEditor_Grid[1], guiGridListAddRow (GUIEditor_Grid[1]), kolumn[1], newNick, false, false )
end
id = id + 1
end
end
function onChangeNick(oldNick, newNick)
local id = 0
while ( id <= guiGridListGetRowCount(GUIEditor_Grid[1]) ) do
if ( guiGridListGetItemPlayerName(GUIEditor_Grid[1], id, 1 ) == oldNick ) then
guiGridListRemoveRow(GUIEditor_Grid[1], id )
guiGridListSetItemText (GUIEditor_Grid[1], guiGridListAddRow (GUIEditor_Grid[1]), kolumn[1], newNick, false, false )
end
id = id + 1
end
end
function guiGridListGetItemPlayerName( gridlist, row, col )
return guiGridListGetItemData( gridlist, row, col ) or guiGridListGetItemText( gridlist, row, col )
end
function getCarKoszt(a)
local xml = xmlLoadFile("auta.xml")
if xml then
local id = 0
while ( xmlFindChild ( xml, "auto", id ) ~= false ) do
local sub = xmlFindChild ( xml, "auto", id )
if tonumber(xmlNodeGetValue(sub)) == tonumber(a) then
local kasa = xmlNodeGetAttribute(sub,"koszt")
xmlUnloadFile(xml)
return kasa
end
id = id + 1
end
end
end
function getMinScore(a)
local xml = xmlLoadFile("auta.xml")
if xml then
local id = 0
while ( xmlFindChild ( xml, "auto", id ) ~= false ) do
local sub = xmlFindChild ( xml, "auto", id )
if tonumber(xmlNodeGetValue(sub)) == tonumber(a) then
local kasa = xmlNodeGetAttribute(sub,"minscore")
xmlUnloadFile(xml)
return kasa
end
id = id + 1
end
end
end
function onRender()
if guiGetVisible(GUIEditor_Window[1]) then
local player = guiGridListGetItemText (GUIEditor_Grid[1], guiGridListGetSelectedItem (GUIEditor_Grid[1]), 1 )
local car = guiGridListGetItemText (GUIEditor_Grid[2], guiGridListGetSelectedItem (GUIEditor_Grid[2]), 1 )
if car ~= "" then
id1 = car
else
id1 = "zaznacz auto"
end
if car ~= "" then
koszt1 = getCarKoszt(getVehicleModelFromName(car))
minimalscore = getMinScore(getVehicleModelFromName(car))
else
koszt1 = tonumber(0)
minimalscore = tonumber(0)
end
guiSetText(label[4],"Koszt: "..koszt1.."$")
guiSetText(label[2],"Gracz: "..player)
guiSetText(label[3],"Auto: "..id1)
if guiCheckBoxGetSelected(checkbox) then
guiSetSize (GUIEditor_Window[1], 657,412, false)
guiSetPosition (GUIEditor_Window[1],(x/2)-(657/2),(y/2)-(412/2),false)
else
guiSetSize (GUIEditor_Window[1], 557,412, false)
guiSetPosition (GUIEditor_Window[1],(x/2)-(557/2),(y/2)-(412/2),false)
end
--triggerServerEvent("salon:getStatus", getLocalPlayer())
end
end
function sprzedaj()
local player = guiGridListGetItemText (GUIEditor_Grid[1], guiGridListGetSelectedItem (GUIEditor_Grid[1]), 1 )
local car = guiGridListGetItemText (GUIEditor_Grid[2], guiGridListGetSelectedItem (GUIEditor_Grid[2]), 1 )
if player ~= "" then
if car ~= "" then
local id = getVehicleModelFromName(car)
local kasa = getCarKoszt(id)
local score = getMinScore(id)
if id and kasa and score then
dajCar(player,id,kasa,score)
else
outputChatBox("Wyst?pi? b??d w skrypcie",255,0,0)
end
else
outputChatBox("Zaznacz Auto!",255,0,0)
end
else
outputChatBox("Zaznacz Gracza!",255,0,0)
end
end
function dajCar(player,id,kasa,score)
triggerServerEvent("salon:dajAuto", getLocalPlayer(),player,id,kasa,score)
end
function buttonFunction ()
if source == Button[1] then
sprzedaj()
elseif source == Button[2] then
local player = guiGridListGetItemText (GUIEditor_Grid[1], guiGridListGetSelectedItem (GUIEditor_Grid[1]), 1 )
if player ~= "" then
triggerServerEvent("salon:anuluj", getLocalPlayer(),player)
else
outputChatBox("Zaznacz Gracza!",255,0,0)
end
elseif source == Button[3] then
showCursor(false)
guiSetVisible(GUIEditor_Window[1], false)
triggerServerEvent("salon:onClose", getLocalPlayer())
else
for k,v in ipairs(Button) do
if v == source then
triggerServerEvent("salon:ruchomoscWind", getLocalPlayer(),tostring(tonumber(k)-tonumber(3)))
end
end
end
end
function onChanged(el)
if el == edit[1] then
guiGridListClear (GUIEditor_Grid[2])
local text = guiGetText(edit[1])
if text == "" then
for k,v in ipairs(cars) do
local row = guiGridListAddRow (GUIEditor_Grid[2])
guiGridListSetItemPlayerName (GUIEditor_Grid[2], row, kolumn[2],v, false, false )
end
else
for k,v in ipairs(cars) do
if string.find(string.upper(v), string.upper(text)) then
local row = guiGridListAddRow (GUIEditor_Grid[2])
guiGridListSetItemPlayerName (GUIEditor_Grid[2], row, kolumn[2],v, false, false )
end
end
end
elseif el == edit[2] then
guiGridListClear (GUIEditor_Grid[1])
local text = guiGetText(edit[2])
if text == "" then
for k,v in ipairs(getElementsByType("player")) do
local row = guiGridListAddRow (GUIEditor_Grid[1])
guiGridListSetItemPlayerName (GUIEditor_Grid[1], row, kolumn[1],getPlayerName(v), false, false )
end
else
for k,v in ipairs(getElementsByType("player")) do
if string.find(string.upper(getPlayerName(v)), string.upper(text)) then
local row = guiGridListAddRow (GUIEditor_Grid[1])
guiGridListSetItemPlayerName (GUIEditor_Grid[1], row, kolumn[1],getPlayerName(v), false, false )
end
end
end
end
end
function getStatusClient(table)
if guiGetVisible(GUIEditor_Window[1]) then
guiSetText(label[5],"Status bramy: "..table[1])
guiSetText(label[6],"Status garazu: "..table[2])
end
end
function SalonPanel ()
showCursor(true)
guiSetVisible(GUIEditor_Window[1], true)
end
addEvent("salon:SalonPanelOpen",true)
addEvent("salon:getStatusClient",true)
addEventHandler ( "onClientRender", getRootElement(), onRender)
addEventHandler ("onClientPlayerJoin", getRootElement(), onJoin)
addEventHandler ( "onClientPlayerQuit", getRootElement(), onQuit)
addEventHandler ( "onClientGUIClick", getRootElement(), buttonFunction)
addEventHandler ("onClientGUIChanged", getRootElement(), onChanged)
addEventHandler ( "salon:SalonPanelOpen", getRootElement(), SalonPanel)
addEventHandler ("onClientPlayerChangeNick", getRootElement(),onChangeNick)
addEventHandler ( "salon:getStatusClient", getRootElement(), getStatusClient)
--addEventHandler ("onClientResourceStop", getResourceRootElement(getThisResource()), onStop)
addEventHandler ("onClientResourceStart", getResourceRootElement(getThisResource()), onStart)
Ostatnio zmieniony przez DORIAN112 2011-08-29, 18:43, w całości zmieniany 1 raz