Jump to content

Attempt to call Clist.!


ramzi

Recommended Posts

Posted

Guys i have got scripts of Nurd Gaming,but i had this problems with 2 scripts:

NGPhone:

screenshot_1.png

Lua Code:Vehicles client side

function appFunctions.vehicles:onPanelLoad ( ) 
    guiGridListClear ( pages['vehicles'].grid ) 
    givingVehicle = nil 
    appFunctions.vehicles:ReloadList ( ) 
     
    guiSetEnabled ( pages['vehicles'].show, false ) 
    guiSetEnabled ( pages['vehicles'].recover, false ) 
    guiSetEnabled ( pages['vehicles'].sell, false ) 
    guiSetEnabled ( pages['vehicles'].warptome, false ) 
end 
  
addEvent ( "NGPhone:App->Vehicles:onClientGetVehicles", true ) 
addEventHandler ( "NGPhone:App->Vehicles:onClientGetVehicles", root, function  ( cList )  
    vehicleData = { } 
    guiGridListClear ( pages['vehicles'].grid ) 
    if ( #cList == 0 ) then 
        guiGridListSetItemText ( pages['vehicles'].grid, guiGridListAddRow ( pages['vehicles'].grid ), 2, "You have no vehicles.", true, true ) 
    else 
        local impoundedVehicles = 0 
        for i, v in ipairs ( cList ) do 
            if ( v[11] == 0 ) then 
                local row = guiGridListAddRow ( pages['vehicles'].grid ) 
                guiGridListSetItemText ( pages['vehicles'].grid, row, 1, tostring ( getVehicleNameFromModel ( v[3] ) ), false, false ) 
                guiGridListSetItemData ( pages['vehicles'].grid, row, 1, v[2] ) 
                table.insert ( vehicleData, v[2], v ) 
            else 
                impoundedVehicles = impoundedVehicles + 1 
            end 
        end 
        if ( impoundedVehicles ~= 0 ) then 
            exports['NGMessages']:sendClientMessage ( "You have "..impoundedVehicles.." vehicles impounded.", 255, 255, 0 ) 
        end 
    end 
end ) 
  
function appFunctions.vehicles:CloseMenu ( ) 
    guiSetText ( pages['vehicles'].show, "Show" ) 
    guiGridListClear ( pages['vehicles'].grid ) 
    showCursor ( false ) 
    vehicleData = nil 
end 
  
function appFunctions.vehicles:ReloadList ( ) 
    guiGridListClear ( pages['vehicles'].grid ) 
    guiGridListSetItemText ( pages['vehicles'].grid, guiGridListAddRow ( pages['vehicles'].grid ), 2, "Loading...", true, true ) 
    triggerServerEvent ( "NGPhone:App->Vehicles:onPanelOpened", localPlayer ) 
end 
  
function appFunctions.vehicles:GetVehicleVisible ( id ) 
    local i = vehicleData[id][9] 
    if ( i == 1 ) then 
        return true 
    else 
        return false 
    end 
end 

and:Vehicles server side:

addEvent ( "NGPhone:App->Vehicles:onPanelOpened", true ) 
addEventHandler ( "NGPhone:App->Vehicles:onPanelOpened", root, function ( )  
    local cars = exports.NGVehicles:getAccountVehicles ( getAccountName ( getPlayerAccount ( source ) ) ) 
    triggerClientEvent ( source, "NGPhone:App->Vehicles:onClientGetVehicles", source, cars ) 
end ) 
  
addEvent ( "NGPhone:Apps->Vehicles:SetVehicleVisible", true ) 
addEventHandler ( "NGPhone:Apps->Vehicles:SetVehicleVisible", root, function ( id, stat )  
    local v = exports.NGVehicles:SetVehicleVisible ( id, stat, source ) 
end ) 
  
addEvent ( "NGPhone:Apps->Vehicles:AttemptRecoveryOnID", true ) 
addEventHandler ( "NGPhone:Apps->Vehicles:AttemptRecoveryOnID", root, function ( id ) 
    exports.NGVehicles:recoverVehicle ( source, id ) 
end )  
  
addEvent ( "NGPhone:App->Vehicles:sellPlayerVehicle", true ) 
addEventHandler ( "NGPhone:App->Vehicles:sellPlayerVehicle", root, function ( plr, data ) 
    exports.NGVehicles:sellVehicle ( plr, data ) 
end ) 
  
addEvent ( "NGPhone:Apps->Vehicles:WarpThisVehicleToMe", true ) 
addEventHandler ( "NGPhone:Apps->Vehicles:WarpThisVehicleToMe", root, function ( id ) 
    if ( not exports.NGVehicles:warpVehicleToPlayer ( id, source ) ) then 
        exports.NGMessages:sendClientMessage ( "Error: Unable to warp vehicle", source, 255, 0, 0 ) 
    end 
end ) 

and NGVehicles_s Lua:

addEventHandler ( "onResourceStart", resourceRoot, function ( ) 
    exports['NGSQL']:db_exec ( "CREATE TABLE IF NOT EXISTS vehicles ( Owner TEXT, VehicleID INT, ID INT, Color TEXT, Upgrades TEXT, Position TEXT, Rotation TEXT, Health TEXT, Visible INT, Fuel INT, Impounded INT, Handling TEXT )" )
end )
 
vehicles = { }
local blip = { }
local texts = { }
function getAllAccountVehicles ( account )
    local cars = { }
    local q = exports['NGSQL']:db_query ( "SELECT * FROM vehicles WHERE Owner=? ", tostring(account) )
    for i, v in pairs ( q ) do
        table.insert ( cars, v )
    end
    return cars
end
 
function showVehicle ( id, stat, player, msg )
    if stat then
        if ( not isElement ( vehicles[id] ) ) then
            local q = exports['NGSQL']:db_query ( "SELECT * FROM vehicles WHERE VehicleID=? LIMIT 1", tostring(id) )
            if ( q and type ( q ) == 'table' and #q > 0 ) then
                local d = q[1]
                local health = tonumber ( d['Health'] )
               
                local owner, vehID = tostring ( d['Owner'] ), tonumber ( d['ID'] )
                local color, upgrades = d['Color'], d['Upgrades']
                local pos, rot = d['Position'], d['Rotation']
               
                local pos = fromJSON ( pos )
                local pos = split ( pos, ', ' )
                local x, y, z = tonumber ( pos[1] ), tonumber ( pos[2] ), tonumber ( pos[3] )
 
                local rot = fromJSON ( rot )
                local rot = split ( rot, ', ' )
                local rx, ry, rz = tonumber ( rot[1] ), tonumber ( rot[2] ), tonumber ( rot[3] )
               
                local color = fromJSON ( color )
                local color = split ( color, ', ' )
                local r, g, b = tonumber ( color[1] ), tonumber ( color[2] ), tonumber ( color[3] )
                local upgrades = fromJSON ( upgrades )
                local hndl = fromJSON ( d['Handling'] )
               
                vehicles[id] = createVehicle ( vehID, x, y, z, rx, ry, rz )
                setElementData ( vehicles[id], "fuel", tonumber ( d['Fuel'] ) )
                setVehicleColor ( vehicles[id], r, g, b )
                setElementData ( vehicles[id], "NGVehicles:VehicleAccountOwner", tostring ( owner ) )
                setElementData ( vehicles[id], "NGVehicles:VehicleID", id )
                setElementHealth ( vehicles[id], tonumber ( health ) )
               
                if ( hndl and type ( hndl ) == "table" ) then
                    for i, v in pairs ( hndl ) do
                        setVehicleHandling ( vehicles [ id ], tostring ( i ), v )
                    end
                end
               
                for i, v in ipairs ( upgrades ) do
                    addVehicleUpgrade ( vehicles[id], tonumber ( v ) )
                end
                exports['NGSQL']:db_exec ( "UPDATE vehicles SET Visible=? WHERE VehicleID=?", '1', id )
               
                if ( isElement ( blip[id] ) ) then
                    destroyElement ( blip[id] )
                end if ( isElement ( texts[id] ) ) then
                    destroyElement ( texts[id] )
                end
                texts[id] = exports['NGJobs']:create3DText ( owner.."'s vehicle", { 0, 0, 0.5 }, { 255, 255, 255 }, vehicles[id], { 5, true }  )
                if ( isElement ( player ) ) then
                    blip[id] = createBlipAttachedTo ( vehicles[id], 51, 2, 255, 255, 255, 255, 0, 1500, player )
                    setElementData ( vehicles[id], "NGVehicles:VehiclePlayerOwner", player )
                end
           
               
                addEventHandler ( "onVehicleDamage", vehicles[id], function ( )
                    local health = math.floor ( getElementHealth ( source ) )
                    if ( health <= 300 ) then
                        local id = getElementData ( source, "NGVehicles:VehicleID" )
                        local driver = getVehicleOccupant ( source )
                        if ( driver ) then
                            exports['NGMessages']:sendClientMessage ( "This vehicle is broken and requires a mechanic to fix it.", driver, 255, 0, 0 )
                        end
 
                        showVehicle ( id, false )
                    end
                end )
               
                addEventHandler ( "onVehicleStartEnter", vehicles[id], function ( p, s )
                    if ( getVehicleOccupant ( source ) )then
                        local t = getPlayerTeam ( p )
                        if ( t ) then
                            if ( exports['NGPlayerFunctions']:isTeamLaw ( getTeamName ( t ) ) and getPlayerWantedLevel ( getVehicleOccupant ( source ) ) > 0 and s == 0 ) then
                                setVehicleLocked ( source, false )
                                return
                            end
                        end
                    end
                   
                    if ( isVehicleLocked ( source ) ) then
                        exports['NGMessages']:sendClientMessage ( "This vehicle is locked.", p, 255, 255, 0 )
                        cancelEvent ( )
                    end
                end )
               
                addEventHandler ( "onVehicleEnter", vehicles[id], function ( p, seat )
                    local health = getElementHealth ( source )
                    local id = getElementData ( source, "NGVehicles:VehicleID" )
                    if ( health <= 300 ) then
                        showVehicle ( id, false )
                        exports.ngmessages:sendClientMessage ( "This vehicle was hidden due to low health", p, 255, 0, 0 )
                        return
                    end
               
                    local acc = getPlayerAccount ( p )
                    if ( isGuestAccount ( acc ) ) then return end
                    local acc = getAccountName ( acc )
                    local name = getVehicleNameFromModel ( getElementModel ( source ) )
                    local owner = getElementData ( source, 'NGVehicles:VehicleAccountOwner' )
                    if ( acc == owner ) then
                        exports['NGMessages']:sendClientMessage ( "This is your "..name.."!", p, 0, 255, 0 )
                    else
                        exports['NGMessages']:sendClientMessage ( "This "..name.." belongs to "..owner..".", p, 255, 255, 0 )
                    end
                end )
               
                if ( msg ) then
                    exports['NGMessages']:sendClientMessage ( "Your "..getVehicleNameFromModel(vehID).." is located in "..getZoneName(x,y,z)..", "..getZoneName(x,y,z,true).."!",player,0,255,0)
                end
                if ( isElement ( player ) and vehID ) then exports['NGLogs']:outputActionLog ( getPlayerName ( player ).." spawned their "..getVehicleNameFromModel ( vehID ) ) end
                return vehicles[id]
            end
        end
        return vehicles[id]
    else
        if ( isElement ( vehicles[id] ) ) then
            local pos = toJSON ( createToString ( getElementPosition ( vehicles[id] ) ) )
            local rot = toJSON ( createToString ( getElementRotation ( vehicles[id] ) ) )
            local color = toJSON ( createToString ( getVehicleColor ( vehicles[id], true ) ) )
            local upgrades = toJSON ( getVehicleUpgrades ( vehicles[id] ) )
            local health, fuel = tostring ( getElementHealth ( vehicles[id] ) ), tonumber ( getElementData ( vehicles[id], "fuel" ) )
            local model = getElementModel ( vehicles[id] )
            local hdnl = toJSON ( getVehicleHandling ( vehicles [ id ] ) )
            exports['NGSQL']:db_exec ( "UPDATE vehicles SET Color=?, Upgrades=?, Position=?, Rotation=?, Health=?, Fuel=?, Handling=? WHERE VehicleID=?", color, upgrades, pos, rot, health, fuel, hdnl, id )
            destroyElement ( vehicles[id] )
            vehicles[id] = nil
            exports['NGSQL']:db_exec ( "UPDATE vehicles SET Visible=? WHERE VehicleID=?", '0', id )
            if ( isElement ( blip[id] ) ) then
                destroyElement ( blip[id] )
            end if ( isElement ( texts[id] ) ) then
                destroyElement ( texts[id] )
            end
           
            if ( isElement ( player ) ) then
                exports['NGLogs']:outputActionLog ( getPlayerName ( player ).." hid their "..getVehicleNameFromModel ( model ) )
            end
        end
    end
    return false
end
 
function warpVehicleToPlayer ( id, player )
    if ( not isElement ( vehicles [ id ] ) )  then return false end
    if ( getElementInterior ( player ) ~= 0 or getElementDimension ( player ) ~= 0 ) then return false end
    if ( getVehicleController ( vehicles [ id ] ) ) then return false end
    local x, y, z = getElementPosition ( player )
    local rot = getPedRotation ( player )
    local rx, ry, rz = getElementRotation ( vehicles [ id ] )
    setElementPosition ( vehicles [ id ], x, y, z + 1 )
    setElementRotation ( vehicles [ id ], rx, ry, rot )
    warpPedIntoVehicle ( player, vehicles [ id ] )
    return true
end
 
function givePlayerVehicle ( player, vehID, r, g, b )
    if ( isGuestAccount ( getPlayerAccount ( player ) ) ) then return false end
    local r, g, b = r or 0, g or 0, b or 0
    local ids = exports['NGSQL']:db_query ( "SELECT VehicleID FROM vehicles" )
    local id = 1
    local idS = { }
    for i, v in ipairs ( ids ) do idS[tonumber(v['VehicleID'])] = true end
    while ( idS[id] ) do id = id + 1 end
    local pos = toJSON ( createToString ( getElementPosition ( player ) ) )
    local rot = toJSON ( createToString ( 0, 0, getPedRotation ( player ) ) )
    local color = toJSON ( createToString ( r, g, b ) )
    local upgrades = toJSON ( { } )
    local health = 1000
    exports['NGLogs']:outputActionLog ( getPlayerName ( player ).." bought a "..getVehicleNameFromModel ( vehID ) )
    exports['NGSQL']:db_exec ( "INSERT INTO `vehicles` (`Owner`, `VehicleID`, `ID`, `Color`, `Upgrades`, `Position`, `Rotation`, `Health`, `Visible`, `Fuel`, `Impounded`, `Handling`) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", getAccountName(getPlayerAccount(player)), tostring(id), tostring(vehID), color, upgrades, pos, rot, health, '100', '0', '0', toJSON ( getModelHandling ( vehID ) ) )
    return id
end
 
function getAccountVehicles ( account )
    local query = getAllAccountVehicles ( account )
    if ( type ( query ) == 'table' and #query >= 1 ) then
        local rV = { }
        for i, v in pairs ( query ) do
            table.insert ( rV, { v['Owner'], v['VehicleID'], v['ID'], v['Color'], v['Upgrades'], v['Position'], v['Rotation'], v['Health'], v['Visible'], v['Fuel'], v['Impounded'], v['Handling'] } )
        end
        return rV
    else
        return { }
    end
end
 
function sellVehicle ( player, id )
    --showVehicle ( id, false )
    local data = exports['NGSQL']:db_query ( "SELECT * FROM vehicles WHERE VehicleID=?", tostring(id) )
    local model = tonumber ( data[1]['ID'] )
    local price = nil
    for i, v in pairs ( vehicleList ) do
        for k, x in ipairs ( v ) do
            if ( x[1] == model ) then
                price = math.floor ( x[2] / 1.4 ) + math.random ( 500, 2200 )
                if price > x[2] then
                    while ( price >= x[2] ) do
                        price = math.floor ( x[2] / 1.4 ) + math.random ( 100, 1000 )
                    end
                end
                break
            end
        end
    end
    exports['NGMessages']:sendClientMessage ( "You've sold your "..getVehicleNameFromModel ( model ).." for $"..convertNumber ( price ).."!", player, 0, 255, 0 )
    givePlayerMoney ( player, price )
    exports['NGSQL']:db_exec ( "DELETE FROM vehicles WHERE VehicleID=?", tostring(id) )
    exports['NGLogs']:outputActionLog ( getPlayerName ( player ).." sold their "..getVehicleNameFromModel ( model ).." (ID: "..tostring ( id )..")" )
   
end
addEvent ( "NGVehicles:sellPlayerVehicle", true )
addEventHandler ( "NGVehicles:sellPlayerVehicle", root, sellVehicle )
 
addCommandHandler ( "hideall", function ( p )
    local acc = getPlayerAccount ( p )
    if ( isGuestAccount ( acc ) ) then return end
    local name = getAccountName ( acc )
    exports['NGMessages']:sendClientMessage ( "All of your vehicles have been hidden.", p, 0, 255, 0 )
    for i, v in pairs ( vehicles ) do
        if ( getElementData ( v, "NGVehicles:VehicleAccountOwner" ) == name ) then
            showVehicle ( i, false )
        end
    end
end )
 
function createToString ( x, y, z )
    return table.concat ( { x, y, z }, ", " )
end
 
addEventHandler ( "onResourceStop", resourceRoot, function ( )
    for i, v in pairs ( vehicles ) do
        showVehicle ( i, false )
    end
end )
 
 
  • MTA Team
Posted

Did you just copy some resources and want us to make it compatible with your server?

Anyway, that script has no problems. It's the data input it gets from a resource, which you didn't copy and doesn't exist.

Posted

Dude, the server owner gave his server script for Public,i didnt steal,i have all the server but only this 2 scripts dont work for me,and here is the link:https://forum.multitheftauto.com/viewtopic.php?f=108&p=754846

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...