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

Wysłany: 2016-04-16, 18:15


Kradus







Wiek: 28
Na forum: 4169 dni
Posty: 100
Nick w MP: Salldan

Piwa: 78

Respekt: 50

Witam. Posiadam skrypt na prywatne pojazdy kt?rego autorem jest Jacob. I mam zapytanie czy jest kto? kto by mi pom?g? to zautomatyzowa?? Chodzi o to aby tworzenie nie odbywa?o si? przy u?yciu admina tylko na zasadzie salonu lub fabryki. A opr?cz tego aby mo?na by?o no handlowa? nimi. O ile dobrze pami?tam ten skrypt jest w oop. Wklejam ca?o?? lecz je?li kto? chce z ?r?d?a to podaj? link: Klik!

config.lua
--[[
    PRIVATE CARS
    by WhoAmI (aka Jacob)
    You are able to modify the script, if you dont change author.
    --#config.lua
--]]--

--[[ change if you wish
    availible values:
        - MySQL
        SQL
--]]--
connectionType "MySQL";

-- ONLY if you chose MySQL
MySQLdbhost ""; -- host
MySQLdbname ""; -- database name
MySQLdbuser ""; -- database user
MySQLdbpassword ""; -- user's password
--end

-- ONLY if you chose SQL
--SQLfilename = "example.db"; -- choose name for databse file
--[[ WARNING! without ".db" at the and it won't work.
     --REMEMBERyou have to add following line to meta.xml:
          --<file src="YOUR_NAME.db" />
     --AND create this file!
     --otherwiseSQL won't work. REMEMBER!
--end ]]


--ACL groups allowed to create private car
aclGroups = {
    "Admin",
    "Moderator",
};
-- end

-- ACL groups allowed to see car info
aclGroupsInfo = {
    "Everyone",
};
-- end

-- command name for car's information
carInfoCommandName "carinfo";
-- end

-- time after the vehicle will be fixed after explosion IN SECONDS
respawnTime 10;
-- end


db.lua
--[[
    PRIVATE CARS
    by WhoAmI (aka Jacob)
    You are able to modify the script, if you don't change author.
    #db.lua
]]--

-- connection to database and creating tables if don't exist
addEventHandler "onResourceStart"resourceRoot,
    function ( )
        if ( connectionType ~= "MySQL" and connectionType ~= "SQL" then -- if connectionType is bad
            outputServerLog "[ERROR] PRIVATE CARS: Invalid connection type! [config.lua]" );
            return;
        end
        
        if ( connectionType == "MySQL" then
            connection Connection "mysql""dbname=" .. MySQLdbname .. ";host=" .. MySQLdbhostMySQLdbuserMySQLdbpassword ); -- making connection if MySQL
            tableFormula "CREATE TABLE IF NOT EXISTS `vehicles` (`id` int(11) NOT NULL  PRIMARY KEY AUTO_INCREMENT,`vehicle_model` int(11) NOT NULL,`x` float NOT NULL,`y` float NOT NULL,`z` float NOT NULL,`rotX` float NOT NULL,`rotY` float NOT NULL,`rotZ` float NOT NULL,`color` varchar(255) NOT NULL,`upgrades` varchar(255) NOT NULL,`acc_name` varchar(255) NOT NULL)"; -- define formula to create tables in MySQL
        elseif ( connectionType == "SQL" then
            connection Connection "sqlite"SQLfilename ); -- making connection if SQL
            tableFormula "CREATE  TABLE  IF NOT EXISTS `vehicles` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `vehicle_model` INTEGER, `x` INTEGER, `y` INTEGER, `z` INTEGER, `rotX` INTEGER, `rotY` INTEGER, `rotZ` INTEGER, `color` VARCHAR, `upgrades` VARCHAR, `acc_name` VARCHAR )"; -- define formula to create tables in SQL 
        end
        
        if ( connection then -- checking if connection exist
            outputServerLog "[INFO] PRIVATE CARS: Loaded connection! [" .. connectionType .. "]" );
            local creatingTable connection:exec tableFormula ); -- creating tables
            if ( not creatingTable then -- if something went wrong
                outputServerLog "[ERROR] PRIVATE CARS: Unable to create table! [" .. connectionType .. "]" );
            end
        else -- if connection doesn't exist
            outputServerLog ( "[ERROR] PRIVATE CARS: Unable to connect to database! [" .. connectionType .. "] [config.lua]" );
        end
    end
);


main_c.lua
gui = {
    tab = {},
    tabpanel = {},
    edit = {},
    button = {},
    label = {}
};
screenXscreenY guiGetScreenSize ( );

-- events
addEvent "car:showGUI"true );
addEvent "car:message"true );
-- events

addEventHandler("onClientResourceStart"resourceRoot,
    function()
        gui.tabpanel[1] = guiCreateTabPanel((screenX 332)/2, (screenY 238)/2332238false);
        guiSetVisible gui.tabpanel[1], false );

        gui.tab[1] = guiCreateTab("Private cars"gui.tabpanel[1]);

        gui.label[1] = guiCreateLabel(5131635"Hi, mate! Here you are able to create private car. Nice, huh? Alright, type values you have to, in edit boxes below."falsegui.tab[1]);
        guiSetFont(gui.label[1], "default-small");
        guiLabelSetHorizontalAlign(gui.label[1], "center"true);
        guiLabelSetVerticalAlign(gui.label[1], "center");
        gui.label[2] = guiCreateLabel(6362219"x:"falsegui.tab[1]);
        guiSetFont(gui.label[2], "default-bold-small");
        guiLabelSetHorizontalAlign(gui.label[2], "center"true);
        guiLabelSetVerticalAlign(gui.label[2], "center");
        gui.label[3] = guiCreateLabel(6602219"y:"falsegui.tab[1]);
        guiSetFont(gui.label[3], "default-bold-small");
        guiLabelSetHorizontalAlign(gui.label[3], "center"true);
        guiLabelSetVerticalAlign(gui.label[3], "center");
        gui.label[4] = guiCreateLabel(6842219"z:"falsegui.tab[1]);
        guiSetFont(gui.label[4], "default-bold-small");
        guiLabelSetHorizontalAlign(gui.label[4], "center"true);
        guiLabelSetVerticalAlign(gui.label[4], "center");
        gui.edit[1] = guiCreateEdit(283722318""falsegui.tab[1]);
        gui.edit[2] = guiCreateEdit(286122318""falsegui.tab[1]);
        gui.edit[3] = guiCreateEdit(288522318""falsegui.tab[1]);
        gui.label[5] = guiCreateLabel(61139921"Account name:"falsegui.tab[1]);
        guiSetFont(gui.label[5], "default-bold-small");
        guiLabelSetHorizontalAlign(gui.label[5], "center"true);
        guiLabelSetVerticalAlign(gui.label[5], "center");
        gui.edit[4] = guiCreateEdit(10711521519""falsegui.tab[1])
        gui.button[1] = guiCreateButton(255376866"Get\ncurrent\nposition"falsegui.tab[1]);
        gui.button[2] = guiCreateButton(2191467419"Color picker"falsegui.tab[1]);
        gui.button[3] = guiCreateButton(1301848019"Cancel"falsegui.tab[1]);
        gui.button[4] = guiCreateButton(2201848019"Create"falsegui.tab[1]);
        gui.label[6] = guiCreateLabel(61446921"Color:"falsegui.tab[1]);
        guiSetFont(gui.label[6], "default-bold-small");
        guiLabelSetHorizontalAlign(gui.label[6], "center"false);
        guiLabelSetVerticalAlign(gui.label[6], "center");
        gui.edit[5] = guiCreateEdit(6514614419""falsegui.tab[1]);
        guiEditSetMaxLength gui.edit[5], );
        gui.label[7] = guiCreateLabel(2991442421"C"falsegui.tab[1]);
        guiSetFont(gui.label[7], "sa-gothic");
        gui.edit[6] = guiCreateEdit(651845518""falsegui.tab[1]);
        guiEditSetMaxLength gui.edit[6], );
        gui.label[8] = guiCreateLabel(61826921"Model:"falsegui.tab[1]);
        guiSetFont(gui.label[8], "default-bold-small");
        guiLabelSetHorizontalAlign(gui.label[8], "center"false);
        guiLabelSetVerticalAlign(gui.label[8], "center");
        
        bindKey "F7""down",
            function ( )
                triggerServerEvent "car:afterBind"localPlayer );
            end
        );
        addCommandHandler "privatecars",
            function ( )
                triggerServerEvent "car:afterBind"localPlayer );
            end
        );
        
        addEventHandler "onClientGUIClick"gui.button[2],
            function ( )
                if ( type cp ) == "table" then return; end
                cp colorPicker.create 1"""" );
            end,
        false );
        
        addEventHandler "onClientGUIChanged"resourceRoot,
            function ( )
                if ( source:getType ( ) ~= "gui-edit" then return; end
                guiSetText sourceguiGetText source ):gsub " """ ) );
            
                if ( source == gui.edit[5] ) then
                    local text guiGetText source );
                    if ( text:find "#%x%x%x%x%x%x" ) ) then
                        local rghex2rgb text );
                        guiLabelSetColor gui.label[7], rg);
                    end
                end
                
                if ( source == gui.edit[1] or source == gui.edit[2] or source == gui.edit[3] or source == gui.edit[6] ) then
                    local text guiGetText source );
                    if ( not tonumber text ) ) then
                        guiSetText sourcetext:sub 1#text - 1 ) );
                    end
                end
            end
        );
        
        addEventHandler "onClientGUIClick"gui.button[1],
            function ( )
                local p localPlayer.position;
                guiSetText gui.edit[1], p.);
                guiSetText gui.edit[2], p.);
                guiSetText gui.edit[3], p.);
            end,
        false );
        
        addEventHandler "onClientGUIClick"gui.button[3],
            function ( )
                showGUI ( );
            end,
        false );
        
        addEventHandler "onClientGUIClick"gui.button[4],
            function ( )
                local xyzaccNamecolormodel guiGetText gui.edit[1] ), guiGetText gui.edit[2] ), guiGetText gui.edit[3] ), guiGetText gui.edit[4] ), guiGetText gui.edit[5] ), guiGetText gui.edit[6] );
                if ( ~= "" and ~= "" and ~= "" and accName ~= "" and color ~= "" and model ~= "" then
                    local xyzmodel tonumber ), tonumber ), tonumber ), tonumber model );
                    if ( and and and model then
                        if ( getVehicleNameFromModel model ) == "" then
                            message "Invalid model ID.""error" );
                            return;
                        end                    
                        if ( color:find "#%x%x%x%x%x%x" ) ) then
                            triggerServerEvent "car:createFromGUI"localPlayerxyzaccNamecolormodel );
                        else
                            message "Type correct HEX code or use color picker!""error" );
                        end
                    else
                        message "Position's xyz have to be numbers.""error" );
                    end
                else
                    message "None of the edit box can be left blank.""error" );
                end
            end,
        false );
    end
);

function message texttype )
    local rg"";
    if ( type == "info" then
        rg02550;
    elseif ( type == "error" then
        rg25500;
    else
        return false;
    end
    
    outputChatBox string.upper type ) .. ": #FFFFFF" .. textrgbtrue );
    return true;
end
addEventHandler "car:message"rootmessage );

function hex2rgb hex )
    hex hex:gsub "#""" );
    return tonumber(  "0x" .. hex:sub 1) ), tonumber "0x" .. hex:sub 3) ), tonumber "0x" .. hex:sub 5) );
end

function clearEdits ( )
    for _v in pairs gui.edit ) do
        guiSetText v"" );
    end
end

function renderIfVisible ( )
    local text guiGetText gui.edit[5] );
    if ( #text == 0 ) then
        guiSetText gui.edit[5], "#FF0000" );
    end
end

function showGUI ( )
    local bool gui.tabpanel[1]:getVisible ( );
    local render bool and removeEventHandler or addEventHandler
    gui.tabpanel[1]:setVisible not bool );
    showCursor not bool );
    render "onClientRender"rootrenderIfVisible )
    if ( bool ) then
        clearEdits ( );
        if ( type cp ) == "table" then
            cp.handlers.destroy ( );
            cp nil;
        end
    end
end
addEventHandler "car:showGUI"rootshowGUI );


main_s.lua
--[[
    PRIVATE CARS
    by WhoAmI (aka Jacob)
    You are able to modify the script, if you dont change author.
    #main_s.lua
--]]---

-- events
addEvent "car:afterBind"true )
addEvent "car:createFromGUI"true )
-- events

vehicles = { };

addEventHandler "onResourceStart"resourceRoot,
    function ( )
        if ( not connection then return; end
        connection:query spawnVehiclesFromDatabase, { }, "SELECT * FROM `vehicles`" );
    end
);

addEventHandler "onResourceStop"resourceRoot,
    function ( )
        if ( not connection then return; end
        for _v in pairs vehicles ) do
            local id v:getID ( );
            local p v.position;
            local rot v.rotation;
            local rgbr1g1b1r2g2b2r3g3b3r4g4b4 v:getColor true );
            local color = { rgbr1g1b1r2g2b2r3g3b3r4g4b4 };
            local upgrades v:getUpgrades ( );
                
            connection:exec "UPDATE `vehicles` SET x=?, y=?, z=?, rotX=?, rotY=?, rotZ=?, color=?, upgrades=? WHERE id=?"p.xp.yp.zrot.xrot.yrot.ztoJSON color ), toJSON upgrades ), id )
        end
    end
);

function hex2rgb hex )
    hex hex:gsub "#""" );
    return tonumber(  "0x" .. hex:sub 1) ), tonumber "0x" .. hex:sub 3) ), tonumber "0x" .. hex:sub 5) );
end

function afterBind ( )
    if ( not isPlayerInGroup sourceaclGroups ) ) then
        return;
    end
    triggerClientEvent source"car:showGUI"source );
end
addEventHandler "car:afterBind"rootafterBind )

function isPlayerInGroup thePlayergroups )
    local account getPlayerAccount thePlayer );
    
    local inGroup false;
    for _group in ipairs groups ) do  
        if isObjectInACLGroup "user.".. getAccountName account ), aclGetGroup group ) ) then
            inGroup true;
            break;
        end
    end
 
    return inGroup;
end

last_id 0
function spawnVehiclesFromDatabase )
    if ( then
        local p q:poll );
        if ( #p > 0 ) then
            for _d in pairs ) do
                last_id d["id"];
                createCar d["vehicle_model"], d["x"], d["y"], d["z"], d["rotX"], d["rotY"], d["rotZ"], d["color"], d["upgrades"], d["acc_name"], d["id"] );
            end
        end
    end
end

function createCar modelxyzrotXrotYrotZcolorupgradesacc_nameid )
    local c type color ) == "table" and color or ( fromJSON color ) or { 00000000000} );
    local upgrades type upgrades ) == "table" and upgrades or ( fromJSON upgrades ) or { } );
    local rotX type rotX ) == "number" and rotX or 0;
    local rotY type rotY ) == "number" and rotY or 0;
    local rotZ type rotZ ) == "number" and rotZ or 0;
    local id id or ( last_id );
    
    local vehicle Vehicle modelxyzrotXrotYrotZ );
    if ( isElement vehicle ) ) then
        vehicle:setColor c[1], c[2], c[3], c[4], c[5], c[6], c[7], c[8], c[9], c[10], c[11], c[12] );
        vehicle:setID id );
        vehicle:setPlateText"LS" ..id )
        vehicle:setData "car:owner"acc_name );
        if ( #upgrades > 0 ) then
            for _upgrade in pairs upgrades ) do
                vehicle:addUpgrade upgrade );
            end
        end
    else
        return false;
    end
    vehicles[#vehicles+1] = vehicle;
    
    return vehicle;
end

function createPrivateCar modelxyzrotXrotYrotZcolorupgradesacc_name )
    if ( not model or not x or not y or not z or not acc_name then
        outputServerLog "[ERROR] PRIVATE CARS: Woops! Something went wrong. [createPrivateCar]" );
        return false;
    end

    local q connection:exec "INSERT INTO `vehicles` (`vehicle_model`, `x`, `y`, `z`, `rotX`, `rotY`, `rotZ`, `color`, `upgrades`, `acc_name` ) VALUES (?,?,?,?,?,?,?,?,?,?)"modelxyzrotXrotYrotZtoJSON color ), toJSON upgrades ), acc_name )
    if ( not q then
        return false;
    end
    local vehicle createCar modelxyzrotXrotYrotZcolorupgradesacc_name )
    if ( isElement vehicle ) ) then
        return vehicle;
    else
        return false;
    end
end

function isCarPrivate )
    if ( v:getData "car:owner" ) ) then
        return true;
    else
        return false;
    end
end

function getPrivateCarOwner )
    if ( v:getData "car:owner" ) ) then
        return tostring v:getData "car:owner" ) );
    else
        return false;
    end
end

function message playertexttype )
    triggerClientEvent player"car:message"playertexttype )
end

addEventHandler "car:createFromGUI"root,
    function ( xyzaccNamecolormodel )
        local account getAccount accName );
        if ( not account then
            triggerClientEvent source"car:message"source"Unable to find an account with this name.""error" );
            return;
        end

        local rot source.rotation;
        local rghex2rgb color );
        source:setPosition xy);
        local veh createPrivateCar modelxyzrot.xrot.yrot.z, { rgb00000000}, { }, accName );
        if ( isElement veh ) ) then
            veh:setColor rg);
            message source"Created " .. veh:getName ( ) .. " for account " .. accName .. ".""info" );
        else
            message source"Unknown error while creating the vehicle.""error" );
        end
    end
);

addEventHandler "onVehicleStartEnter"root,
    function ( playerseat )
        if ( seat ~= then
            return;
        end
        local owner source:getData "car:owner" );
        if ( owner then 
            local account player:getAccount ( );
            if ( account then
                if ( owner ~= account:getName ( ) ) then
                    message player"Nie masz kluczy do tego pojazdu.""info" );
                    cancelEvent ( );
                end
            end
        end
    end
);

function fixVehicleFromTimer )
    v:fix ( );
end

addEventHandler "onVehicleExplode"root,
    function ( )
        if ( source:getData "car:owner" ) ) then
            setTimer fixVehicleFromTimerrespawnTime 10001source )
        end
    end
);

addCommandHandler carInfoCommandName,
    function ( player )
        local v player:getOccupiedVehicle ( );
        if ( isElement ) ) then
            local owner v:getData "car:owner" );
            if ( not owner then
                return;
            end
            
            if ( isPlayerInGroup playeraclGroupsInfo ) ) then
                message player"W?a?cicielem tego pojazdu jest #00FF00" .. owner .. "#FFFFFF (ID " .. v:getID ( ) .. ").""info" );
            end
        end
    end
);


Postaw piwo autorowi tego posta
 

 
Wysłany: 2016-04-17, 14:37


Kradus







Wiek: 28
Na forum: 4169 dni
Posty: 100
Nick w MP: Salldan

Piwa: 78

Respekt: 50

"Kradus" napisał/a:

I mam zapytanie czy jest kto? kto by mi pom?g? to zautomatyzowa??


Co jak co ale trzeba no po prostu przeczyta? o co prosz? a nie. Na gotowca nie licz?. Ja potrzebuj? pomocy przy zmianie trybu tworzenia pojazd?w a nie o "zr?bcie mi a ja skocz? na kebsa"....

Postaw piwo autorowi tego posta
 

 
Wysłany: 2016-04-17, 20:19


Retrok







Wiek: 27
Na forum: 3734 dni
Posty: 58
Nick w MP: Retrok

Piwa: 4

Respekt: 50

Obczaj sobie gamemoda "ourgame" tak jest kupywanie aut w salonie :) .

Podpis
Pomogłem?? daj browca bo suszy!
Postaw piwo autorowi tego posta
 

 
Wysłany: 2016-04-17, 22:06


Kradus







Wiek: 28
Na forum: 4169 dni
Posty: 100
Nick w MP: Salldan

Piwa: 78

Respekt: 50

Jak tak patrz? na tego gm'a to widz?, ?e jeden skrypt wo?a kilka ehh widocznie b?dzie bardzo du?o zabawy z tym.

Postaw piwo autorowi tego posta
 

 
Tagi: prywatne :: pojazdy
Anonymous





Na forum: 245 dni
Posty: 1



Anonymous Koniecznie zajrzyj na:






Skocz do:  
Wyświetl posty z ostatnich:   
GTAONLINE.PL » JĘZYKI PROGRAMOWANIA » LUA » Prywatne pojazdy 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