Zaloguj się by uzyskać pełen dostęp. Nie masz jeszcze konta? Założ je już teraz w kilka sekund.

Wysłany: 2016-03-06, 10:51


P.Wiśnia

Programista LUA






Wiek: 24
Na forum: 4044 dni
Posty: 568
Nick w MP: P.Wiśnia

Piwa: 376

Respekt: 100
Respekt: 100

Witam ma problem poniewa? niewiem jak przerobi? t? skrypt aby dzia?a? z systemem aut pana prezes.
Skrypt ma polega? na tym ?e to czygan ?e je takie co?.
Aby kupi? pojazd wejdz i wpisz /kuppojazd
a i ?eby tak?e by? vopis np
Sadler
Przebieg 595656
Cena 2200


Kod
Client
Kod:

addEventHandler("onClientRender",getRootElement(),function ()
for key, value in ipairs(getElementsByType("vehicle")) do
if getElementData(value,"vehicle:owner")==0 then
if getElementData(value,"vehicle:travel") then
local x, y, z = getElementPosition(value)
local xs, ys, ds = getScreenFromWorldPosition(x,y,z)
if ds~= nil then
if ds<=15 then
if not getElementData(value,"vehicle:used") then
dxDrawText(" Pojazd \n Nazwa: "..getVehicleName(value).." \n Stan: Nowy \n Przebieg: "..math.floor(getElementData(value,"vehicle:travel")/1000).." Kilometr?w \n Cena: "..getElementData(value,"vehicle:cost").."$",xs,ys+4,xs,ys,tocolor(255,255,255),1.2,"default","center")
else
dxDrawText(" Pojazd \n Nazwa: "..getVehicleName(value).." \n Stan: U?ywany \n Przebieg: "..math.floor(getElementData(value,"vehicle:travel")/1000).." Kilometr?w \n Cena: "..getElementData(value,"vehicle:cost").."$",xs,ys+4,xs,ys,tocolor(255,255,255),1.2,"default","center")
end
end
end
end
end
end
end)



addEventHandler("onClientRender",getRootElement(),function ()
for key, value in ipairs(getElementsByType("blip")) do
if getElementData(value,"blip:vehicle") then
if getElementType(getElementData(value,"blip:vehicle"))=="vehicle" then
local x, y, z = getElementPosition(getElementData(value,"blip:vehicle"))
setElementPosition(value,x,y,z)
end
end
end
end)


Serwer
Kod:

function isPlayerInACL ( player, acl )
local account = getPlayerAccount ( player )
if ( isGuestAccount ( account ) ) then
return false
end
return isObjectInACLGroup ( "user."..getAccountName ( account ), aclGetGroup ( acl ) )
end


function give(playerSource,pcar,car,cost,km)
if isPlayerInACL(playerSource,"Admin") then
if ( car ) then
if not tonumber(car) then
car = string.lower(car)
car = getVehicleModelFromName(car)
end -- w innym przypadku zmienna car nadal b?dzie przechowywa?a ID pojazdu, wi?c nic nie robimy w przypadku gd y podano ID.
x, y, z = getElementPosition(playerSource)
local theCar = createVehicle(car,x,y,z+0.15)
setElementPosition(playerSource,x,y,z+1.5)
local xr,yr,zr = getElementRotation(playerSource)
setElementRotation(theCar,xr,yr,zr)
setElementData(theCar,"vehicle:cost",tonumber(cost))
setElementData(theCar,"vehicle:owner", false)
setElementFrozen(theCar,true)
o utputChatBox("#63DBFF*Stworzy?e? pojazd #B9F46C"..getVehicleNameFromModel(car).." #63DBFFkt?ry kosztuje #B9F46C"..cost.."$#63DBFF.",playerSource,0,0,0,true)
if km then
setElementData(theCar,"vehicle:travel",tonumber(km))
end
else
outputChatBox("#63DBFF*Wpisa?e? z?? nazw? auta.",playerSource,0,0,0,true)
end
end
end

addCommandHandler("pcar",give)

function onBuyCar(sPlayer)
if not isGuestAccount(getPlayerAccount(sPlayer)) then
if isPedInVehicle(sPlayer) then
if getElementData(getPedOccupiedVehicle(sPlayer),"vehicle:owner") == false then
if getPlayerMoney(sPlayer)>=tonumber(getElementData(getPedOccupiedVehicle(sPlayer),"vehicle:cost")) then
setElementData(getPedOccupiedVehicle(sPlayer),"vehicle:owner",getPlayerAccount(sPlayer))
setElementData(getPedOccupiedVehicle(sPlayer),"ownername",getPlayerName(sPlayer))
takePlayerMoney(sPlayer,getElementData(getPedOccupiedVehicle(sPlayer),"vehicle:cost"))
setVehicleEngineState(getPedOccupiedVehicle(sPlayer),true)
setElementFrozen(getPedOccupiedVehicle(sPlayer),false)
setElementData(getPedOccupiedVehicle(sPlayer),"ownername",getPlayerName(sPlayer))
outputChatBox("#63DBFF*Kupi?e?/a? pojazd #B9F46C"..getVehicleName(getPedOccupiedVehicle(sPlayer)).."#63DBFF za #B9F46C"..getElementData(getPedOccupiedVehicle(sPlayer),"vehicle:cost").."$#63DBFF.",sPlayer,0,0,0,true)
local x, y, z = getElementPosition(getPedOccupiedVehicle(sPlayer))
local blip = createBlip(x,y,z,0,1,0,0,255,255,0,65535,sPlayer) setElementData(blip,"blip:vehicle",getPedOccupiedVehicle(sPlayer))
else
outputChatBox("#63DBFF*Nie masz wystarczaj?co du?o pieni?dzy ?eby kupi? ten pojazd.",sPlayer,0,0,0,true)
end
end
else
outputChatBox("#63DBFF*Musisz by? zalogowany.",sPlayer,0,0,0,true)
end
end
end

addCommandHandler("kuppojazd",onBuyCar)


function onEnterCar(thePlayer,seat,jacked)
if seat == 0 then
if getElementData(source,"vehicle:owner") == false then
setVehicleEngineState(source,false)
outputChatBox("#63DBFF*Ten pojazd #B9F46C("..getVehicleName(source)..") #63DBFFkosztuje#B9F46C "..getElementData(source,"vehicle:cost").."$#63DBFF.",thePlayer,0,0,0,true)
outputChatBox("#63DBFF*Je?eli chcesz kupi? ten pojazd wpisz#B9F46C /kuppojazd".."#63DBFF.",thePlayer,0,0,0,true)
elseif seat == 0 then
if getElementData(source,"vehicle:owner") then
if getElementData(source,"vehicle:owner") ~= getPlayerAccount(thePlayer)then
removePedFromVehicle(thePlayer)
outputChatBox("#63DBFF*Ten pojazd #B9F46C("..getVehicleName(source)..") #63DBFFnie nale?y do ciebie.",thePlayer,0,0,0,true)
end
end
end
end
end


addEventHandler("onVehicleStartEnter",getRootElement(),
function (thePlayer,seat,jacked)
if seat == 0 then
if getElementData(source,"vehicle:owner") =~ getPlayerAccount(source) or getElementData(source, "vehicle:owner") == false then
outputChatBox("#63DBFF*Ten pojazd #B9F46C("..getVehicleName(source)..") #63DBFFnie nale?y do ciebie.",thePlayer,0,0,0,true)
end
end
end
)

addEventHandler("onVehicleEnter",getRootElement(),onEnterCar)



-- Tutaj bylo odswiezanie blipow ale wywalilem to i same blipy bo bylo to nieoptymalne


function sellCar(pps,command,koszt)
if isPedInVehicle(pps) then
if getElementData(getPedOccupiedVehicle(pps),"vehicle:owner") == getPlayerAccount(pps) then
if koszt then
if getElementData(getPedOccupiedVehicle(pps),"vehicle:cost")>=tonumber(koszt) then
setElementData(getPedOccupiedVehicle(pps),"vehicle:cost",tonumber(koszt))
carx = getPedOccupiedVehicle(pps)
setElementFrozen(carx,true)
setVehicleEngineState(carx,false)
setVehicleDamageProof(carx,true)
setElementData(carx,"vehicle:owner", false)
setElementData(carx,"vehicle:used",true)
setElementData(carx,"vehicle:cost",tonumber(koszt))
givePlayerMoney(pps,tonumber(koszt))
outputChatBox("#63DBFF*Wystawi?e?/a? pojazd #B9F46C"..getVehicleName(carx).." #63DBFFza #B9F46C"..tostring(koszt).."$#63DBFF.",pps,0,0,0,true)
removePedFromVehicle(pps)
else
carx = getPedOccupiedVehicle(pps)
outputChatBox("#63DBFF*Nie mo?esz wystawi? tego pojazdu za #B9F46C"..tostring(koszt).."$ #63DBFFponiewa? jest to wi?cej ni? jego poprzednia cena #B9F46C("..tostring(getElementData(carx,"vehicle:cost")).."$)#63DBFF.",pps,0,0,0,true)
end
else
outputChatBox("#63DBFF*?le wpisana komenda powinno by? #B9F46C/sprzedajpojazd <cena>#63DBFF.",pps,0,0,0,true)
end
else
outputChatBox("#63DBFF*Ten pojazd nie nale?y do ciebie.",pps,0,0,0,true)
end
end
end

addCommandHandler("sprzedajpojazd",sellCar)

addEventHandler("onElementDestroy",getRootElement(),function ()
if getElementType(source) = ="vehicle" then
setElementData(source,"vehicle:owner",nil)
setElementData(source,"vehicle:cost",nil)
setElementData(source,"vehicle:used",nil)
setElementData(source,"vehicle:travel",nil)
if getElementData(source,"vehicle:blip") ~= nil or getElementData(source,"vehicle:blip") =~ false then
destroyElement(getElementData(source,"vehicle:blip"))
end
end
end)



setTimer(function ()
for k, v in ipairs(getElementsByType("player")) do
for key, value in ipairs(getElementsByType("blip")) do
if getElementData(value,"blip:vehicle") then
if isElement(getElementData(value,"blip:vehicle")) then
if getElementType(getElementData(value,"blip:vehicle"))=="vehicle" then
local vehicle = getElementData(value,"blip:vehicle")
if getElementData(vehicle,"vehicle:owner")~=0 then
if getElementData(vehicle,"vehicle:owner") == getPlayerAccount(v) then
setElementVisibleTo(value,v,true)
else
setElementVisibleTo(value,v,false)
end
end
end
end
end
end
end
end,1000,0)


Postaw piwo autorowi tego posta
 

 
Wysłany: 2016-03-06, 19:10


mati2409

Uczę się LUA!






Wiek: 33
Na forum: 3800 dni
Posty: 97
Nick w MP: mati2409

Piwa: 73

Respekt: 50

Aidis, 1-wszym krokiem musisz doda? elementdate systemu pojazd?w prezesa czyli
 veh 
,a vopis kod nie m?j jest tutaj na forum

 addCommandHandler("vopis", function(plrcmd, ...)
        local opis table.concat(arg" ")
        if (string.len(opis)<3then
            outputChatBox("U?yj: /vopis <opis>, lub /vopis usun"plr)
            return
        end
    
        local auto1 getPedOccupiedVehicle(plr)
    
        if (not auto1then
            outputChatBox("Musisz by? w poje?dzie w kt?rym chcesz zmieni? opis."plr25500)
            return
        end
    
        if (opis=="usun" or opis=="USUN"then
            removeElementData(auto1"pojazd_opis")
        else
            setElementData(auto1"pojazd_opis"opis)
        end
end
to by?a strona serwera

strona clienta
local sw,sh guiGetScreenSize()

addEventHandler("onClientRender"root, function()
    local rx,ry,rz getCameraMatrix()

    for i,v in ipairs(getElementsByType("vehicle"root)) do
        local opis getElementData(v"pojazd_opis")
        if opis then
            local x,y,getElementPosition(v)
            local distance getDistanceBetweenPoints3D(rx,ry,rz,x,y,z)
            if distance <= 25 then
                local sx,sy getScreenFromWorldPosition(x,y,z200)
                if sx and sy then
                dxDrawText(opissx-(sw/5),sy,sx+(sw/5),sytocolor(255255255155), 1.2"default-small""center""center"falsetrue)
                end
            end
        end
    end
end)


 
oraz meta.xml

 <meta>
<script src="vopis_c.lua" type="client" />
<script src="vopis_s.lua" type="server" />
</meta


Podpis
Mapping <3
Postaw piwo autorowi tego posta
 

 
Tagi: cygan :: systemem :: pana :: prezesa
Anonymous





Na forum: 245 dni
Posty: 1



Anonymous Koniecznie zajrzyj na:






Skocz do:  
Wyświetl posty z ostatnich:   
GTAONLINE.PL » JĘZYKI PROGRAMOWANIA » LUA Ten temat jest zablokowany bez możliwości zmiany postów lub pisania odpowiedzi

Nie możesz pisać nowych tematów
Nie możesz odpowiadać w tematach
Nie możesz zmieniać swoich postów
Nie możesz usuwać swoich postów
Nie możesz głosować w ankietach
Dodaj temat do Ulubionych
Wersja do druku