Pyrek24
Wiek: 25 Na forum: 3438 dni Posty: 546
Nick w MP: Pyrek
Piwa : 10
Witam ot?? mam kod na elektryki i chcia?ym o pomoc jak to przerobi? na powi?kszane baki pr?bowa?em, doda? sam, stworzy? zapisy w sql "bak" oraz element daty, lecz nie ogarniam, wi?c prosi? bym o pomoc w przerobieniu elektryk?w !
kod
c_paliwo
--[[
Resource : OURGame
Developers : Split < split . programista @ gmail . com >
Copyright < split . programista @ gmail . com > 2015 - 2016
You have no right to use this code without my permission .
]]
-- Kod odpowiadaj ? cy za odejmowanie paliwa oraz dodawanie paliwa
-- Wszelkie inne rzeczy s ? w systemie pojazd ? w // Split
local time = getTickCount ()
local isBike ={[ 509 ]= true ,[ 481 ]= true ,[ 510 ]= true }
elektrytki = {
[ 507 ] = true ,
[ 559 ] = true ,
}
function isEventHandlerAdded ( sEventName , pElementAttachedTo , func )
if
type ( sEventName ) == 'string' and
isElement ( pElementAttachedTo ) and
type ( func ) == 'function'
then
local aAttachedFunctions = getEventHandlers ( sEventName , pElementAttachedTo )
if type ( aAttachedFunctions ) == 'table' and #aAttachedFunctions > 0 then
for i , v in ipairs ( aAttachedFunctions ) do
if v == func then
return true
end
end
end
end
return false
end
local function naliczaj ( veh )
if getTickCount ()- time > 5000 then
time = getTickCount ()
local fuel = getElementData ( veh , "vehicle:fuel" ) or 0
local mileage = getElementData ( veh , "vehicle:mileage" ) or 0
local vx , vy , vz = getElementVelocity ( veh )
local spd =(( vx ^ 2 + vy ^ 2 + vz ^ 2 )^( 0.5 )/ 2 )
if spd > 0 then
if not elektrytki [ getElementModel ( veh )] then
fuel = fuel -(( spd * 1.75 )/ 3 )
elseif elektrytki [ getElementModel ( veh )] then
fuel = fuel -(( spd * 0.5 )/ 3 )
end
setElementData ( veh , "vehicle:fuel" , fuel )
mileage = mileage +( spd * 1.25 )
setElementData ( veh , "vehicle:mileage" , mileage )
end
end
end
function rendering ()
local vehicle = getPedOccupiedVehicle ( localPlayer )
if not vehicle then return end
if isBike [ getElementModel ( vehicle )] then return end
if not getVehicleEngineState ( vehicle ) then return end
if getElementData ( vehicle , "vehicle:fuel" ) and getElementData ( vehicle , "vehicle:fuel" ) or getElementData ( vehicle , "vehicle:mileage" ) and getElementData ( vehicle , "vehicle:mileage" ) then
naliczaj ( vehicle )
if getElementData ( vehicle , "vehicle:fuel" )< 1 then
setVehicleEngineState ( vehicle , false )
end
end
end
addEventHandler ( "onClientVehicleEnter" , root ,function( p )
if p ~= localPlayer then return end
if isTimer ( timer ) then killTimer ( timer ) end
time = getTickCount ()
timer = setTimer ( rendering , 5000 , 0 )
end )
addEventHandler ( "onClientVehicleExit" , root ,function( p )
if p ~= localPlayer then return end
if isTimer ( timer ) then killTimer ( timer ) end
end )
client
local cena = 250
barr = guiCreateStaticImage ( 0.27 , 0.63 , 0.53 , 0.32 , "logo.png" , true )
guiSetVisible ( barr , false )
bar = guiCreateProgressBar ( 0.31 , 0.83 , 0.45 , 0.07 , true )
guiSetVisible ( bar , false )
label = guiCreateLabel ( 0.36 , 0.85 , 0.39 , 0.03 , "Paliwo: 100 % | Przetrzymaj spacje aby zatankowa?" , true )
guiSetVisible ( label , false )
guiLabelSetColor ( label , 00 , 90 , 255 )
guiLabelSetHorizontalAlign ( label , "center" , false )
guiLabelSetVerticalAlign ( label , "center" )
local tekst = string . format ( "%s PLN" , cena )
label2 = guiCreateLabel ( 0.43 , 0.76 , 0.07 , 0.03 , tekst , true )
local font0_minus = guiCreateFont ( ":ogrpg-gui/minus.ttf" , 16 )
guiSetVisible ( label2 , false )
guiSetFont ( label2 , font0_minus )
guiLabelSetColor ( label2 , 32 , 232 , 22 )
guiLabelSetHorizontalAlign ( label2 , "center" , false )
guiLabelSetVerticalAlign ( label2 , "center" )
stacja_ladowania = {
}
addEventHandler ( "onClientResourceStart" , resourceRoot ,
function()
stacja_ladowania [ 1 ] = guiCreateButton ( 0.64 , 0.85 , 0.18 , 0.07 , "Na?aduj" , true )
local font0_def = guiCreateFont ( ":Radio-auta/files/def.ttf" , 24 )
guiSetFont ( stacja_ladowania [ 1 ], font0_def )
guiSetProperty ( stacja_ladowania [ 1 ], "NormalTextColour" , "FF443AC4" )
addEventHandler ( "onClientGUIClick" , stacja_ladowania [ 1 ], naladowanie , false )
stacja_ladowania [ 2 ] = guiCreateLabel ( 0.54 , 0.55 , 0.34 , 0.10 , "Do ilu % akumulatora chcesz naladowa?" , true )
local font1_def = guiCreateFont ( ":Radio-auta/files/def.ttf" , 21 )
guiSetFont ( stacja_ladowania [ 2 ], font1_def )
guiLabelSetHorizontalAlign ( stacja_ladowania [ 2 ], "center" , false )
guiLabelSetVerticalAlign ( stacja_ladowania [ 2 ], "center" )
stacja_ladowania [ 3 ] = guiCreateLabel ( 0.61 , 0.75 , 0.22 , 0.08 , "100%" , true )
local font2_def = guiCreateFont ( ":Radio-auta/files/def.ttf" , 36 )
guiSetFont ( stacja_ladowania [ 3 ], font2_def )
guiLabelSetHorizontalAlign ( stacja_ladowania [ 3 ], "center" , false )
guiLabelSetVerticalAlign ( stacja_ladowania [ 3 ], "center" )
stacja_ladowania [ 4 ] = guiCreateScrollBar ( 828 , 523 , 353 , 15 , true , false )
for i = 1 , 4 do
guiSetVisible ( stacja_ladowania [ i ], false )
end
end
)
elektrytki = {
[ 507 ] = true ,
[ 559 ] = true ,
}
function procenty ()
if math . floor ( guiScrollBarGetScrollPosition ( stacja_ladowania [ 4 ])) < math . floor ( getElementData ( getPedOccupiedVehicle ( localPlayer ), "vehicle:fuel" )) then
guiScrollBarSetScrollPosition ( stacja_ladowania [ 4 ], getElementData ( getPedOccupiedVehicle ( localPlayer ), "vehicle:fuel" ))
end
guiSetText ( stacja_ladowania [ 3 ], math . floor ( guiScrollBarGetScrollPosition ( stacja_ladowania [ 4 ])))
end
addEventHandler ( "onClientMarkerHit" , resourceRoot ,function( e )
if e == localPlayer then
if getElementType ( e )== "player" then
if getPedOccupiedVehicle ( e ) then
if getElementData ( getPedOccupiedVehicle ( e ), "vehicle:fuel" ) then
if getElementData ( source , "stacja" ) then
if elektrytki [ getElementModel ( getPedOccupiedVehicle ( e ))] then outputChatBox ( "** To jest auto elektryczne nie mozesz go zatankowac ." ) return end
guiSetVisible ( bar , true )
guiSetVisible ( barr , true )
guiSetVisible ( label , true )
guiSetVisible ( label2 , true )
guiSetText ( label , "Paliwo: " .. math . floor ( getElementData ( getPedOccupiedVehicle ( e ), "vehicle:fuel" )).. " L | Przetrzymaj spacje aby zatankowa?" )
cena = getElementData ( source , "cena" )
local tekst = string . format ( "%s PLN" , cena )
guiSetText ( label2 , tekst )
guiProgressBarSetProgress ( bar , getElementData ( getPedOccupiedVehicle ( e ), "vehicle:fuel" ))
elseif getElementData ( source , "stacja_elektryk" ) then
if getVehicleController ( getPedOccupiedVehicle ( e )) ~= localPlayer then return end
if not elektrytki [ getElementModel ( getPedOccupiedVehicle ( e ))] then outputChatBox ( "** Twoje auto nie jest elektryczne! " ) return end
guiScrollBarSetScrollPosition ( stacja_ladowania [ 4 ], getElementData ( getPedOccupiedVehicle ( e ), "vehicle:fuel" ))
timer = setTimer ( procenty , 100 , 0 )
for i = 1 , 4 do
guiSetVisible ( stacja_ladowania [ i ], true )
end
end
end
end
end
end
end )
function timertankuj ()
if getPedOccupiedVehicle ( localPlayer ) then
if getElementData ( getPedOccupiedVehicle ( localPlayer ), "vehicle:fuel" ) then
if getKeyState ( "space" ) == true then
tankuj ()
end
end
end
end
setTimer ( timertankuj , 115 , 0 )
addEventHandler ( "onClientMarkerLeave" , resourceRoot ,function( e )
if e == localPlayer then
if getElementData ( source , "stacja" ) then
guiSetVisible ( bar , false )
guiSetVisible ( barr , false )
guiSetVisible ( label , false )
guiSetVisible ( label2 , false )
elseif getElementData ( source , "stacja_elektryk" ) then
if isTimer ( timer ) then killTimer ( timer ) end
for i = 1 , 4 do
guiSetVisible ( stacja_ladowania [ i ], false )
end
end
end
end )
function tankuj ()
if getPedOccupiedVehicle ( localPlayer ) then
if getElementData ( getPedOccupiedVehicle ( localPlayer ), "vehicle:fuel" )>= 100 then return end
triggerServerEvent ( "TANKUJ" , localPlayer )
end
end
function naladowanie ( button )
if button == "left" then
if isTimer ( timer ) then killTimer ( timer ) end
triggerServerEvent ( "NALADOWANIE" , root , math . floor ( guiScrollBarGetScrollPosition ( stacja_ladowania [ 4 ])))
end
end
addEvent ( "TANKUJ" , true )
addEventHandler ( "TANKUJ" , root ,function()
if source == localPlayer then
local fuel = getElementData ( getPedOccupiedVehicle ( source ), "vehicle:fuel" )
setElementData ( getPedOccupiedVehicle ( source ), "vehicle:fuel" , fuel + 1 )
guiSetText ( label , "Paliwo: " .. math . floor ( getElementData ( getPedOccupiedVehicle ( source ), "vehicle:fuel" )).. " L | Przetrzymaj spacje aby zatankowa?" )
guiProgressBarSetProgress ( bar , getElementData ( getPedOccupiedVehicle ( source ), "vehicle:fuel" ))
end
end )
server
elektrytki = {
[ 507 ] = true ,
[ 559 ] = true ,
}
local aktualnie_laduje = {}
cena = math . random ( 100000 , 120000 )
function cenas ( x )
if not x then x = math . random ( 100000 , 120000 ) end
cena = x
for i , m in pairs ( getElementsByType ( "marker" , resourceRoot )) do
if getElementData ( m , "stacja" ) then
setElementData ( m , "cena" , cena )
local text = getElementData ( m , "text" )
setElementData ( text , "name" , "Cena za paliwo: " .. cena .. "$" )
end
end
-- outputChatBox ( "*[INFORMACJA] Nowa cena paliwa.." , root , 255 , 0 , 0 )
end
sync_czas = 1000 * 60 * 10 -- co 10 minut zmiana ceny
setTimer ( cenas , sync_czas , 0 )
local stacje ={
{- 2023.76 , 157.46 , 28.84 },
{- 1557.34 , 394.95 , 7.19 },
{- 1296.48 , - 472.61 , 14.15 },
}
for _ , v in ipairs ( stacje )do
local marker = createMarker ( v [ 1 ], v [ 2 ], v [ 3 ]- 0.9 , "cylinder" , 3 , 0 , 200 , 0 )
setElementData ( marker , "stacja" , true )
local blipStacji = createBlipAttachedTo ( marker , 56 )
setBlipVisibleDistance ( blipStacji , 400 )
local text = createElement ( 'text' )
setElementData ( text , "name" , "Cena za paliwo: " .. cena .. "$" )
setElementPosition ( text , v [ 1 ], v [ 2 ], v [ 3 ]+ 0.3 )
setElementData ( marker , "text" , text )
setElementData ( marker , "cena" , cena )
mkr = marker
end
addEvent ( "NALADOWANIE" , true )
addEventHandler ( "NALADOWANIE" , root ,function( procent )
local veh = getPedOccupiedVehicle ( client )
if not veh then return end
if not procent then return end
if not elektrytki [ getElementModel ( veh )] then outputChatBox ( "** Twoje auto nie jest elektryczne! " , client ) return end
local p = getElementData ( veh , "vehicle:fuel" )
if procent < p then outputChatBox ( "** Chcesz sie pozbyc bateri?! " , client ) return end
local procent2 = ( procent - getElementData ( veh , "vehicle:fuel" ))
local czas = procent2 * 60000 / 10
if czas < 50 then outputChatBox ( "* Masz naladowane w pelni auto!" , client ) return end
setElementData ( veh , "ladowany" , true )
local opis = getElementData ( veh , "vehicle:desc" ) or ""
setElementFrozen ( veh , true )
setVehicleLocked ( veh , true )
setElementData ( veh , "vehicle:desc" , "?aduje si?....." )
aktualnie_laduje [ veh ] = setTimer (function()
if isElement ( veh ) then
setElementData ( veh , "vehicle:fuel" , procent )
setVehicleLocked ( veh , false )
setElementData ( veh , "ladowany" , false )
setElementData ( veh , "vehicle:desc" , opis )
end
end , czas , 1 )
local czas = tonumber ( czas )/ 60000
removePedFromVehicle ( client )
local x , y , z = getElementPosition ( veh )
setElementPosition ( client , x , y - 1.25 , z )
czas = string . format ( "%0.2f" , czas )
outputChatBox ( "** Pozosta?y czas do naladowania to " .. czas .. " minut" , client , 0 , 255 , 0 )
end )
addEventHandler ( "onVehicleStartEnter" , root ,function( p )
if isTimer ( aktualnie_laduje [ source ]) then
local czas , _ , _ = getTimerDetails ( aktualnie_laduje [ source ])
czas = tonumber ( czas )/ 600000
czas = string . format ( "%0.2f" , czas )
outputChatBox ( "** Pozosta?y czas do naladowania to " .. czas .. " minut" , p , 0 , 255 , 0 )
end
end )
addEvent ( "TANKUJ" , true )
addEventHandler ( "TANKUJ" , root ,function()
if getPlayerMoney ( source )>= cena then
for i , m in pairs ( getElementsByType ( "marker" , resourceRoot )) do
if getElementData ( m , "stacja" ) then
if isElementWithinMarker ( source , m ) then
takePlayerMoney ( source , cena )
triggerClientEvent ( "TANKUJ" , source )
end
end
end
end
end )
function zgasSilnik ()
for i , v in ipairs ( getElementsByType ( "vehicle" )) do
local data = getElementData ( v , "vehicle:fuel" )
if data then
if tonumber ( data ) < 0 then
setVehicleEngineState ( v , false )
end
end
end
end
setTimer ( zgasSilnik , 1000 , 0 )
local stacje_elektryk ={
{- 1557.87 , 389.98 , 7.19 },
}
for _ , v in ipairs ( stacje_elektryk )do
local marker = createMarker ( v [ 1 ], v [ 2 ], v [ 3 ]- 0.9 , "cylinder" , 3 , 0 , 200 , 0 )
setElementData ( marker , "stacja_elektryk" , true )
local t = createElement ( 'text' )
setElementData ( t , 'name' , "Stacja Szybkiego ?adowania" )
setElementPosition ( t , v [ 1 ], v [ 2 ], v [ 3 ])
attachElements ( t , marker )
local blipStacji = createBlipAttachedTo ( marker , 9 )
setBlipVisibleDistance ( blipStacji , 400 )
end
addEventHandler ( "ustawpaliwo" ,function( plr , cmd , cenar )
if not cenar then cenas () return end
local cenar = tonumber ( cenar )
local cenar = math . floor ( cenar )
--if cenar < 1 then cenas () return end
cenas ( cenar )
end )