local x,y = guiGetScreenSize()
koszt = 7
taxiWindow = { }
taxiButton = { }
taxiGrid = { }
taxirow = {}
taxiEdit = { }
taxilabel = { }
taxiTable = { }
wyplatytable = { }
taxiWindow[1] = guiCreateWindow((x/2 - 400/2), (y/2 - 415/2), 400, 415, "Taxi panel" false)
taxiButton[1] = guiCreateButton(170, 40, 230, 50, "Start rachunek", false, taxiWindow[1])
taxiButton[2] = guiCreateButton(170, 100, 230, 50, "Stop rachunek", false, taxiWindow[1])
taxiButton[3] = guiCreateButton(330, 375, 60, 50, "Wyjdz", false, taxiWindow[1])
taxiButton[4] = guiCreateButton(170, 250, 230, 50, "Odbierz pieni?dze za przew?z", false, taxiWindow[1])
taxiButton[5] = guiCreateButton(170, 160, 230, 50, "Anuluj wezwanie", false, taxiWindow[1])
taxiButton[6] = guiCreateButton(170, 310, 230, 50, "Wyrzu? wszystkich graczy z tax?wki", false, taxiWindow[1])
taxiGrid[1] = guiCreateGridList(10, 20, 150, 220, false, taxiWindow[1])
taxiGrid[2] = guiCreateGridList(10, 250, 150, 140, false, taxiWindow[1])
taxirow[1] = guiGridListAddColumn(taxiGrid[1], "Gracze", .9)
taxirow[2] = guiGridListAddColumn(taxiGrid[2], "Gracz", .4)
taxirow[3] = guiGridListAddColumn(taxiGrid[2], "Koszt", .4)
taxilabel[1] = guiCreateLabel(170,210,160,15,"Stawka za 100 yard?w: "..koszt.."$",false,taxiWindow[1])
taxilabel[2] = guiCreateLabel(170,230,230,15, "Gracz:", false,taxiWindow[1])
guiWindowSetSizable(taxiWindow[1], false)
guiSetVisible(taxiWindow[1], false)
function openTaxiPanel()
showCursor(true)
guiSetVisible(taxiWindow[1], true)
for k,v in ipairs(getElementsByType("player")) do
guiGridListSetItemPlayerName (taxiGrid[1], guiGridListAddRow (taxiGrid[1]), 1, getPlayerName (v), false, false )
end
end
function onClick()
if source == taxiButton[1] then
local veh = getPedOccupiedVehicle(getLocalPlayer())
if veh then
local model = getElementModel(veh)
if model == 420 or model == 438 then
local pl = guiGridListGetItemText (taxiGrid[1], guiGridListGetSelectedItem (taxiGrid[1]), taxirow[1])
if pl ~= "" then
local player = getPlayerFromName(pl)
if player then
if getElementData(player,"login") == true then
if isPlayerVehiclePassager(veh,player) then
local acc = getElementData(player,"account_rpg")
if acc then
local x,y,z = getElementPosition(player)
table.insert(taxiTable,{player,acc,x,y,z})
outputChatBox("Rozpocz?to nalicznie",255,255,0)
else
outputChatBox("B??d gamemoda. Popro? gracza o reconnect, je?li nie pomo?e zg?o? do administratora!",255,0,0)
end
else
outputChatBox("Gracz nie jest twoim pasa?em!",255,0,0)
end
else
outputChatBox("Gracz nie jest zalogowany!",255,0,0)
end
else
outputChatBox("Nie znaleziono gracza!",255,0,0)
end
else
outputChatBox("Nie zaznaczy?e? gracza!",255,0,0)
end
else
outputChatBox("Twoje auto to nie tax?wka!",255,0,0)
end
else
outputChatBox("Nie jeste? w aucie!",255,0,0)
end
elseif source == taxiButton[2] then
local pl = guiGridListGetItemText (taxiGrid[1], guiGridListGetSelectedItem (taxiGrid[1]), taxirow[1])
if pl ~= "" then
local gracz = getPlayerFromName(pl)
if isElement(gracz) then
local veh = getPedOccupiedVehicle(getLocalPlayer())
if isPlayerVehiclePassager(veh,gracz) then
for k,v in ipairs(taxiTable) do
if v[1] == gracz then
local x,y,z = getElementPosition(gracz)
local dystans = getDistanceBetweenPoints3D (x,y,z,v[3],v[4],v[5])
local cash = math.floor((dystans/100)*koszt)
table.remove(taxiTable,k)
table.insert(wyplatytable,{v[2],tostring(cash)})
outputChatBox("Naliczanie zako?czono",255,255,0)
refresh_wyplaty()
end
end
else
outputChatBox("Gracz nie jest twoim pasa?em!",255,0,0)
end
else
outputChatBox("Nie znaleziono gracza!",255,0,0)
end
else
outputChatBox("Nie zaznaczy?e? gracza!",255,0,0)
end
elseif source == taxiButton[3] then
guiSetVisible(taxiWindow[1], false)
showCursor(false)
guiGridListClear (taxiGrid[1])
guiSetText(taxilabel[2],"")
elseif source == taxiButton[4] then
local row = guiGridListGetSelectedItem (taxiGrid[2])
if row then
local name = guiGridListGetItemText (taxiGrid[2], row, taxirow[2])
local cash = guiGridListGetItemText (taxiGrid[2], row, taxirow[3])
if name ~= "" and cash ~= "" then
guiGridListRemoveRow(taxiGrid[2], row)
triggerServerEvent("taxi:giveWyplata",getLocalPlayer(),name,cash)
for k,v in ipairs(wyplatytable) do
if v[1] == tostring(name) and v[2] == tostring(cash) then
table.remove(wyplatytable,k)
refresh_wyplaty()
return
end
end
end
end
elseif source == taxiButton[5] then
triggerServerEvent("taxi:anulujWezwanie",getLocalPlayer(),guiGridListGetItemText (taxiGrid[1], guiGridListGetSelectedItem (taxiGrid[1]), taxirow[1]))
elseif source == taxiGrid[1] then
local pl = guiGridListGetItemText (taxiGrid[1], guiGridListGetSelectedItem (taxiGrid[1]), taxirow[1])
guiSetText(taxilabel[2],"Gracz: "..pl)
elseif source == taxiButton[6] then
triggerServerEvent("taxi:removePlayerFromCar",getLocalPlayer())
end
end
function refresh_wyplaty()
guiGridListClear (taxiGrid[2])
for k,v in ipairs(wyplatytable) do
local row = guiGridListAddRow (taxiGrid[2])
guiGridListSetItemPlayerName(taxiGrid[2], row, taxirow[2], v[1], false, false )
guiGridListSetItemPlayerName(taxiGrid[2], row, taxirow[3], v[2], false, false )
end
end
function isPlayerVehiclePassager(vehicle,player)
if getElementType(vehicle) == "vehicle" then
local pass = getVehiclePassagers (vehicle)
if pass then
for k,v in ipairs(pass) do
if v == player then
return true
end
end
end
end
return false
end
function getVehiclePassagers (theVehicle)
local ret_table = { }
local numseats = getVehicleMaxPassengers ( theVehicle )
if tonumber(numseats) then
for s = 0, numseats do
local targetPlayer = getVehicleOccupant ( theVehicle, s )
if targetPlayer and isElement(targetPlayer) and isPedInVehicle(targetPlayer) then
table.insert(ret_table,targetPlayer)
end
end
end
return ret_table
end
function onChangeNick(oldNick, newNick)
if guiGetVisible(taxiWindow[1]) then
local id = 0
while ( id <= guiGridListGetRowCount(taxiGrid[1]) ) do
if ( guiGridListGetItemPlayerName(taxiGrid[1], id, 1 ) == oldNick ) then
guiGridListRemoveRow(taxiGrid[1], id )
guiGridListSetItemText (taxiGrid[1], guiGridListAddRow (taxiGrid[1]), taxirow[1], newNick, false, false )
end
id = id + 1
end
end
end
function guiGridListGetItemPlayerName( gridlist, row, col )
return guiGridListGetItemData( gridlist, row, col ) or guiGridListGetItemText( gridlist, row, col )
end
function onJoin()
if guiGetVisible(taxiWindow[1]) then
guiGridListSetItemPlayerName (taxiGrid[1], guiGridListAddRow (taxiGrid[1]), 1, getPlayerName ( source ), false, false )
end
end
function guiGridListSetItemPlayerName( gridlist, row, col, name )
guiGridListSetItemText( gridlist, row, col, name, false, false )
guiGridListSetItemData( gridlist, row, col, name )
end
function onQuit()
if guiGetVisible(taxiWindow[1]) then
local id = 0
while ( id <= guiGridListGetRowCount(taxiGrid[1]) ) do
if ( guiGridListGetItemPlayerName(taxiGrid[1], id, 1 ) == getPlayerName ( source ) ) then
guiGridListRemoveRow(taxiGrid[1], id )
end
id = id + 1
end
end
for k,v in ipairs(taxiTable) do
if isPlayerVehiclePassager(getPedOccupiedVehicle(getLocalPlayer()),source) then
if v[1] == source then
local x,y,z = getElementPosition(source)
local dystans = getDistanceBetweenPoints3D (x,y,z,v[3],v[4],v[5])
local cash = math.floor((dystans/100)*koszt)
table.remove(taxiTable,k)
table.insert(wyplatytable,{v[2],tostring(cash)})
outputChatBox("Automatycznie zako?czono naliczanie",255,255,0)
refresh_wyplaty()
end
end
end
end
function onExit(pl,seat)
local pveh = getPedOccupiedVehicle(getLocalPlayer())
if isElement(pveh) then
if isPlayerVehiclePassager(pveh,pl) then
for k,v in ipairs(taxiTable) do
if v[1] == pl then
local x,y,z = getElementPosition(pl)
local dystans = getDistanceBetweenPoints3D (x,y,z,v[3],v[4],v[5])
local cash = math.floor((dystans/100)*koszt)
table.remove(taxiTable,k)
table.insert(wyplatytable,{v[2],tostring(cash)})
outputChatBox("Automatycznie zako?czono naliczanie",255,255,0)
refresh_wyplaty()
end
end
end
end
end
--
addEvent("taxi:openPanel", true)
addEventHandler("taxi:openPanel", getRootElement(), openTaxiPanel)
addEventHandler ( "onClientPlayerChangeNick", getRootElement(),onChangeNick)
addEventHandler ( "onClientPlayerJoin", getRootElement(), onJoin)
addEventHandler ( "onClientPlayerQuit", getRootElement(), onQuit)
addEventHandler ( "onClientVehicleStartExit",getRootElement(),onExit)
addEventHandler ( "onClientGUIClick", getResourceRootElement(getThisResource()), onClick)