Wysłany: 2020-03-15, 16:16
NZF
Wiek: 26 Na forum: 2272 dni Posty: 6
Nick w MP: NZF
Hej, ostatnimi czasami zacz??em si? uczy? lua
Stworzy?em prosty kod salon?w
Problem jest taki ?e gdy podejde do 1 konkretnego pojazdu ( elegy ) to kod dalej sie moze wykonac
Gdy juz go chce kupic to kupuje kazdy pojazd z asortymentu
function getVehicleHandlingProperty ( element , property )
if isElement ( element ) and getElementType ( element ) == "vehicle" and type ( property ) == "string" then -- Make sure there 's a valid vehicle and a property string
local handlingTable = getVehicleHandling ( element ) -- Get the handling as table and save as handlingTable
local value = handlingTable[property] -- Get the value from the table
if value then -- If there' s a value ( valid property )
return value -- Return it
end
end
return false -- Not an element , not a vehicle or no valid property string . Return failure
end
db = exports [ 'sy_db' ]
local vehicles = {
-- id , x , y , z , rx , ry , rz , cena , silnik , paliwo , naped
{ 451 , 1394.2 , - 1682.0 , 13.6 , 0 , 0 , 180 , 1200000 , 1.4 , 'PB-95' , 'AWD' }, -- turismo
{ 541 , 1411.7 , - 1670.8 , 13.5 , 0 , 0 , 217 , 730000 , 1.6 , 'PB-95' , 'RWD' }, -- bullet
{ 411 , 1406.3 , - 1681.2 , 13.6 , 0 , 0 , 180 , 1200000 , 1.6 , 'PB-95' , 'RWD' }, -- infernus
{ 560 , 1401.2 , - 1701.0 , 13.6 , 0 , 0 , 0 , 450000 , 1.6 , 'PG-95' , 'AWD' }, -- sultan
{ 477 , 1412.7 , - 1691.7 , 13.6 , 0 , 0 , 166 , 450000 , 1.6 , 'PB-95' , 'RWD' }, -- zr - 350
{ 562 , 1397.8 , - 1672.0 , 13.6 , 0 , 0 , 135 , 450000 , 1.6 , 'PB-95' , 'RWD' }, -- elegy
}
functions = {}
functions . spawnAllVehicles = function()
for k , v in pairs ( vehicles ) do
local veh = createVehicle ( v [ 1 ], v [ 2 ], v [ 3 ], v [ 4 ], v [ 5 ], v [ 6 ], v [ 7 ], 'SALON' )
sphere = createColSphere ( v [ 2 ], v [ 3 ], v [ 4 ], 4 )
setElementFrozen ( veh , true )
setElementData ( veh , 'vehicle:salon' , true )
setElementData ( veh , 'vehicle:sell:info' ,{
[ 'model' ] = v [ 1 ],
[ 'cost' ] = v [ 8 ],
[ 'engine' ] = v [ 9 ],
[ 'fueltype' ] = v [ 10 ],
[ 'naped' ] = v [ 11 ],
},
true )
end
end
addEventHandler ( 'onResourceStart' , resourceRoot , functions . spawnAllVehicles )
addEventHandler ( 'onVehicleStartEnter' , resourceRoot ,function()
for i , v in ipairs ( getElementsByType ( 'vehicle' )) do
if getElementData ( v , 'vehicle:salon' ) then
cancelEvent ()
end
end
end )
functions . checkBindShape = function( player , dim )
if source == sphere then
if isElementWithinColShape ( player , sphere ) then
exports [ 'sy_noti' ]: showPlayerNotification ( player , "Kliknij K aby kupi? ten pojazd." , "info" , 3000 )
bindKey ( player , 'K' , 'down' , functions . buyVehicle )
else
functions . removeAllBinds ( player )
end
end
end
addEventHandler ( 'onColShapeHit' , resourceRoot , functions . checkBindShape )
functions . buyVehicle = function( player )
for i , v in ipairs ( getElementsByType ( 'vehicle' )) do
if getElementData ( v , 'vehicle:salon' ) == true then
local data = getElementData ( v , 'vehicle:sell:info' )
local money = getPlayerMoney ( player )
local cost = data . cost
local model = data . model
if cost > money then
exports [ 'sy_noti' ]: showPlayerNotification ( player , "Nie sta? Ci? na ten pojazd." , "error" , 3000 )
return end
takePlayerMoney ( player , cost )
db : setDB ( "INSERT INTO `pystories_vehicles` (`model`,`ownedPlayer`,`mileage`,`registered`,`parking`,`engine`,`color`,`fuel`) VALUES (?,?,?,?,1,?,?,?)" , model , getElementData ( player , "player:sid" ), 0 , "true" , data [ 'engine' ], "255,255,255,255,255,255,255,255,255,255,255,255" , '15' )
exports [ 'sy_noti' ]: showPlayerNotification ( player , "Pomy?lnie zakupi?e? pojazd " .. getVehicleNameFromModel ( model ).. '. Znajdziesz go w przechowalni pojazd?w!' , "success" , 3000 )
end
end
end
functions . removeAllBinds = function( player )
if not isElementWithinColShape ( player , sphere ) then
unbindKey ( player , 'K' , 'down' )
end
end
addEventHandler ( 'onColShapeLeave' , resourceRoot , functions . removeAllBinds )
addEventHandler ( 'onVehicleDamage' , resourceRoot ,function()
for i , v in ipairs ( getElementsByType ( 'vehicle' )) do
if getElementData ( v , 'vehicle:salon' ) then
cancelEvent ()
setElementHealth ( v , 1000 )
end
end
end )
Jesli ktos zna prostrze rozwiazania to polecam napisac
Wysłany: 2020-03-15, 16:23
nanKy
Wiek: 22 Na forum: 3865 dni Posty: 498
Nick w MP: nanky
Piwa : 1773
Jak ma si? wykonywa? na jeden pojazd z salonu skoro zrobi?e? p?tl? na ka?dy dost?pny w nim?
Więcej szczegółów
Wystawiono 1 piw(a):NZF
Wysłany: 2020-03-15, 16:25
NZF
Wiek: 26 Na forum: 2272 dni Posty: 6
Nick w MP: NZF
Dlatego prosz? o pomoc ;d
Wysłany: 2020-03-15, 16:28
nanKy
Wiek: 22 Na forum: 3865 dni Posty: 498
Nick w MP: nanky
Piwa : 1773
Jedn? z opcji jest nadanie dla colshape warto?ci do jakiego pojazdu on nale?y i przy wchodzeniu w niego zrzucanie danych na gracza, i przy wychodzeniu usuwanie rzecz jasna danych z gracza. I za pomoc? wy?ej wymienionego sposobu wyszuka? z p?tli dany pojazd.
Więcej szczegółów
Wystawiono 1 piw(a):NZF
Wysłany: 2020-03-15, 16:28
NZF
Wiek: 26 Na forum: 2272 dni Posty: 6
Nick w MP: NZF
Wysłany: 2020-03-15, 16:32
nanKy
Wiek: 22 Na forum: 3865 dni Posty: 498
Nick w MP: nanky
Piwa : 1773
Nadajesz elementdat? dla colshape, z danymi pojazdu potem przy wej?ciu w niego zapisujesz j? na gracza i po tym sprawdzasz czy dany pojazd si? pokrywa.
Wysłany: 2020-03-15, 16:36
NZF
Wiek: 26 Na forum: 2272 dni Posty: 6
Nick w MP: NZF
functions . onShapeHit = function()
if source == shape then
local data_x = getElementData ( sphere , 'vehicle:sell:info' )
if data_x then
setElementData ( source , 'vehicle:sell:info' , data_x )
bindKey ( source , 'K' , 'down' , functions . buyVehicle )
end
end
end
end
?
Wysłany: 2020-03-15, 16:39
nanKy
Wiek: 22 Na forum: 3865 dni Posty: 498
Nick w MP: nanky
Piwa : 1773
"NZF" napisał/a :
functions . onShapeHit = function()
if source == shape then
local data_x = getElementData ( sphere , 'vehicle:sell:info' )
if data_x then
setElementData ( source , 'vehicle:sell:info' , data_x )
bindKey ( source , 'K' , 'down' , functions . buyVehicle )
end
end
end
end
?
Tutaj widz? b??d pocz?tkuj?cego, z angielskiego source to ?r?d?o . Gdy robisz event opieraj?cy si? na Shape source b?dzie oznacza?o dany Shape kt?ry sam okre?li?e? w linijce to w przypadku ni?ej jakim cudem gracz mo?e by? source skoro jest nim shape?
Wysłany: 2020-03-15, 16:42
NZF
Wiek: 26 Na forum: 2272 dni Posty: 6
Nick w MP: NZF
Wysłany: 2020-03-15, 16:44
nanKy
Wiek: 22 Na forum: 3865 dni Posty: 498
Nick w MP: nanky
Piwa : 1773
"NZF" napisał/a :
zacznij od studiowania mta wiki.
w pierwszym argumencie eventu masz hitElement (czyli element kt?ry wchodzi do colshape), na samym pocz?tku zdarzenia musisz sprawdzi? czy dany element jest graczem za pomoc? warunku
if getElementType ( hitElement ) == 'player' then
-- xx
end
i wtedy graczem nie jest source a hitElement
Wysłany: 2020-03-15, 16:53
NZF
Wiek: 26 Na forum: 2272 dni Posty: 6
Nick w MP: NZF
Kazdy hit w inny colshape zwraca ten sam iprint
Tagi: salon :: pojazdów
Anonymous
Na forum: 245 dni
Posty: 1
Anonymous Koniecznie zajrzyj na: