Jump to content

[HELP] vehicle script


Agon

Recommended Posts

Posted
vehicleIDS = { 602, 545, 496, 517, 401, 410, 518, 600, 527, 436, 589, 580, 419, 439, 533, 549, 526, 491, 474, 445, 467, 604, 426, 507, 547, 585, 
405, 587, 409, 466, 550, 492, 566, 546, 540, 551, 421, 516, 529, 592, 553, 577, 488, 511, 497, 548, 563, 512, 476, 593, 447, 425, 519, 520, 460, 
417, 469, 487, 513, 581, 510, 509, 522, 481, 461, 462, 448, 521, 468, 463, 586, 472, 473, 493, 595, 484, 430, 453, 452, 446, 454, 485, 552, 431,  
438, 437, 574, 420, 525, 408, 416, 596, 433, 597, 427, 599, 490, 432, 528, 601, 407, 428, 544, 523, 470, 598, 499, 588, 609, 403, 498, 514, 524,  
423, 532, 414, 578, 443, 486, 515, 406, 531, 573, 456, 455, 459, 543, 422, 583, 482, 478, 605, 554, 530, 418, 572, 582, 413, 440, 536, 575, 534,  
567, 535, 576, 412, 402, 542, 603, 475, 449, 537, 538, 441, 464, 501, 465, 564, 568, 557, 424, 471, 504, 495, 457, 539, 483, 508, 571, 500, 444, 
556, 429, 411, 541, 559, 415, 561, 480, 560, 562, 506, 565, 451, 434, 558, 494, 555, 502, 477, 503, 579, 400, 404, 489, 505, 479, 442, 458, 606, 
607, 610, 590, 569, 611, 584, 608, 435, 450, 591, 594 } 
  
  
function fGiveVehicle(player, command, id) 
    if id == vehicleIDS then 
        if not isPedInVehicle(player) then 
            local x, y, z = getElementPosition(player) 
                local xr, yr, zr = getElementRotation(player) 
                    local veh = createVehicle(id, x, y, z, xr, yr, zr) 
                        warpPedIntoVehicle(player, veh) 
        else local ocVeh = getPedOccupiedVehicle(player) 
            setElementModel(ocVeh, id) 
    else outputChatBox("Invalid vehicle id", 255, 0, 0) 
end 
end 
end 
addCommandHandler("vehicle", fGiveVehicle) 
  

i did this script but i think i screwed up because it doesn't work.

This is meta.xml

<meta> <script src="vehicle.lua" type="client" /> </meta> 

I also want to use both vehicle ids and names. i thought of using getVehicleIDFromName and getVehicleNameFromID but couldn't make :P waiting for your helps :)

Guest Guest4401
Posted
but i used clientside codes i think

No

+ Commands don't have player parameter if it is clientside

+ warpPedIntoVehicle is server-only-function.

edit: tried serverside but didn't work
if id == vehicleIDS then 

You expect a string to be a table?

Posted
You expect a string to be a table?

I want to check if the written id is in vehicleIDS table.

By the way how can i fix the script? It doesn't work...

Posted
function isModelInTable ( theModel ) 
    local found = false 
    for _, model in ipairs ( vehicleIDS ) do 
        if ( model == theModel ) then 
            found = true 
            break 
        end 
    end 
  
    return found 
end 

Posted

uhm.. :| like this?

vehicleIDS = { 602, 545, 496, 517, 401, 410, 518, 600, 527, 436, 589, 580, 419, 439, 533, 549, 526, 491, 474, 445, 467, 604, 426, 507, 547, 585, 
405, 587, 409, 466, 550, 492, 566, 546, 540, 551, 421, 516, 529, 592, 553, 577, 488, 511, 497, 548, 563, 512, 476, 593, 447, 425, 519, 520, 460, 
417, 469, 487, 513, 581, 510, 509, 522, 481, 461, 462, 448, 521, 468, 463, 586, 472, 473, 493, 595, 484, 430, 453, 452, 446, 454, 485, 552, 431,  
438, 437, 574, 420, 525, 408, 416, 596, 433, 597, 427, 599, 490, 432, 528, 601, 407, 428, 544, 523, 470, 598, 499, 588, 609, 403, 498, 514, 524,  
423, 532, 414, 578, 443, 486, 515, 406, 531, 573, 456, 455, 459, 543, 422, 583, 482, 478, 605, 554, 530, 418, 572, 582, 413, 440, 536, 575, 534,  
567, 535, 576, 412, 402, 542, 603, 475, 449, 537, 538, 441, 464, 501, 465, 564, 568, 557, 424, 471, 504, 495, 457, 539, 483, 508, 571, 500, 444, 
556, 429, 411, 541, 559, 415, 561, 480, 560, 562, 506, 565, 451, 434, 558, 494, 555, 502, 477, 503, 579, 400, 404, 489, 505, 479, 442, 458, 606, 
607, 610, 590, 569, 611, 584, 608, 435, 450, 591, 594 } 
  
function isModelInTable ( theModel ) 
    local found = false 
    for _, model in ipairs ( vehicleIDS ) do 
        if ( model == theModel ) then 
            found = true 
            break 
        end 
    end 
    return found 
end 
  
  
function fGiveVehicle(source, command, id) 
    if isModelInTable(id) then 
        if not isPedInVehicle(source) then 
            x, y, z = getElementPosition(source) 
                xr, yr, zr = getElementRotation(source) 
                    veh = createVehicle(id, x, y, z, xr, yr, zr) 
                        warpPedIntoVehicle(source, veh) 
        else ocVeh = getPedOccupiedVehicle(source) 
            setElementModel(ocVeh, id) 
    else outputChatBox("Invalid vehicle id", 255, 0, 0) 
end 
end 
end 
addCommandHandler("vehicle", fGiveVehicle) 

it says

loading script failed: veh\vehicle.lua:32: 'end' expected (to close 'if' at line 25) near 'else' 

Guest Guest4401
Posted
vehicleIDS = { 602, 545, 496, 517, 401, 410, 518, 600, 527, 436, 589, 580, 419, 439, 533, 549, 526, 491, 474, 445, 467, 604, 426, 507, 547, 585, 
405, 587, 409, 466, 550, 492, 566, 546, 540, 551, 421, 516, 529, 592, 553, 577, 488, 511, 497, 548, 563, 512, 476, 593, 447, 425, 519, 520, 460, 
417, 469, 487, 513, 581, 510, 509, 522, 481, 461, 462, 448, 521, 468, 463, 586, 472, 473, 493, 595, 484, 430, 453, 452, 446, 454, 485, 552, 431, 
438, 437, 574, 420, 525, 408, 416, 596, 433, 597, 427, 599, 490, 432, 528, 601, 407, 428, 544, 523, 470, 598, 499, 588, 609, 403, 498, 514, 524, 
423, 532, 414, 578, 443, 486, 515, 406, 531, 573, 456, 455, 459, 543, 422, 583, 482, 478, 605, 554, 530, 418, 572, 582, 413, 440, 536, 575, 534, 
567, 535, 576, 412, 402, 542, 603, 475, 449, 537, 538, 441, 464, 501, 465, 564, 568, 557, 424, 471, 504, 495, 457, 539, 483, 508, 571, 500, 444, 
556, 429, 411, 541, 559, 415, 561, 480, 560, 562, 506, 565, 451, 434, 558, 494, 555, 502, 477, 503, 579, 400, 404, 489, 505, 479, 442, 458, 606, 
607, 610, 590, 569, 611, 584, 608, 435, 450, 591, 594 } 
  
function isModelInTable ( theModel ) 
    local found = false 
    for _, model in ipairs ( vehicleIDS ) do 
        if ( model == theModel ) then 
            found = true 
            break 
        end 
    end 
    return found 
end 
  
  
function fGiveVehicle(source, command, id) 
    if isModelInTable(id) then 
        if not isPedInVehicle(source) then 
            x, y, z = getElementPosition(source) 
            xr, yr, zr = getElementRotation(source) 
            veh = createVehicle(id, x, y, z, xr, yr, zr) 
            warpPedIntoVehicle(source, veh) 
        else 
            ocVeh = getPedOccupiedVehicle(source) 
            setElementModel(ocVeh, id) 
        end 
    else 
        outputChatBox("Invalid vehicle id",source,255, 0, 0) 
    end 
end 
addCommandHandler("vehicle", fGiveVehicle) 

Posted

Because the 'id' argument will return a string, you must convert it to a number with: tonumber ( ).

if isModelInTable ( tonumber ( id ) ) then 

Posted

i know getVehicleNameFromModel but don't know how to place it in the script

made the vehicle table now what? btw can i make something that when i type either car name or id and it will see it as the vehicle's id and spawn the vehicle? i'm not good at tables but i think it was something like that:

vehicleTable = { [429] = "Banshee", [500] = "Mesa"} 

. when i type mesa, it will find the id in the table and spawn the vehicle by it's id not name. that can be very easy if you tell me how can i make this.

vehicleIDS = { 602, 545, 496, 517, 401, 410, 518, 600, 527, 436, 589, 580, 419, 439, 533, 549, 526, 491, 474, 445, 467, 604, 426, 507, 547, 585, 
405, 587, 409, 466, 550, 492, 566, 546, 540, 551, 421, 516, 529, 592, 553, 577, 488, 511, 497, 548, 563, 512, 476, 593, 447, 425, 519, 520, 460, 
417, 469, 487, 513, 581, 510, 509, 522, 481, 461, 462, 448, 521, 468, 463, 586, 472, 473, 493, 595, 484, 430, 453, 452, 446, 454, 485, 552, 431, 
438, 437, 574, 420, 525, 408, 416, 596, 433, 597, 427, 599, 490, 432, 528, 601, 407, 428, 544, 523, 470, 598, 499, 588, 609, 403, 498, 514, 524, 
423, 532, 414, 578, 443, 486, 515, 406, 531, 573, 456, 455, 459, 543, 422, 583, 482, 478, 605, 554, 530, 418, 572, 582, 413, 440, 536, 575, 534, 
567, 535, 576, 412, 402, 542, 603, 475, 449, 537, 538, 441, 464, 501, 465, 564, 568, 557, 424, 471, 504, 495, 457, 539, 483, 508, 571, 500, 444, 
556, 429, 411, 541, 559, 415, 561, 480, 560, 562, 506, 565, 451, 434, 558, 494, 555, 502, 477, 503, 579, 400, 404, 489, 505, 479, 442, 458, 606, 
607, 610, 590, 569, 611, 584, 608, 435, 450, 591, 594 } 
  
vehicleNames = { alpha, blista compact, bravura, buccaneer, cadrona, club, esperanto, feltzer, fortune, hermes, hustler, majestic, manana, picador, 
previon, stafford, stallion, tampa, virgo, admiral, damaged glendale, elegant, emperor, euros, glendale, greenwood, intruder, merit, nebula, oceanic, 
premier, primo, sentinel, stretch, sunrise, tahoma, vincent, washington, willard, andromada, at-400, beagle, cargobob, cropduster, dodo, hunter, hydra, 
leviathan, maverick, nevada, news chopper, police maverick, raindance, rustler, seasparrow, shamal, skimmer, sparrow, stuntplane, bf-400, bike, bmx, faggio, 
fcr-900, freeway, mountain bike, nrg-500, pcj-600, pizza boy, sanchez, wayfarer, coastguard, dinghy, jetmax, launch, marquis, predator, reefer, speeder, squalo, 
tropic, baggage, utility van, bus, cabbie, coach, sweeper, taxi, towtruck, trashmaster, ambulance, barracks, enforcer, fbi rancher, fbi truck, fire truck, hpv1000,  
patriot, police car, police ranger, S.W.A.T., securicar, benson, black boxville, boxville, cement truck, combine harvester, dft-30, dozer, dumper, dune, flatbed, hotdog, 
linerunner, mr. whoopee, mule, packer, roadtrain, tractor, yankee, berkley's rc van, bobcat, burrito, damaged sadler, forklift, moonbeam, mower, news van, pony, rumpo, sadler, 
tug, walton, yosemite, blade, broadway, remington, savanna, slamvan, tornado, voodoo, buffalo, clover, phoenix, sabre, tram, freight, brown streak, flat freight, box freight, rc bandit, 
rc baron, rc goblin, rc raider, rc tiger, bandito, bf injection, bloodring banger, caddy, camper, journey, kart, mesa, monster, monster 2, monster 3, quadbike, sandking, vortex, 
banshee, bullet, cheetah, comet, elegy, flash, hotknife, hotring racer, hotring racer 2 ,hotring racer 3, infernus, jester, stratum, sultan, super gt, turismo, uranus, windsor, 
zr-350, huntley, landstalker, perennial, rancher, regina, romero, solair, baggaga trailer, farm trailer, street clean trailer, stairs, trailer 1, trailer 2, trailer 3, rc cam} 
  
function isModelInTable ( theModel ) 
    local found = false 
    for _, model in ipairs ( vehicleIDS ) do 
        if ( model == theModel ) then 
            found = true 
            break 
        end 
    end 
    return found 
end 
  
function fGiveVehicle(source, command, id) 
    if isModelInTable ( tonumber ( id ) ) then 
        if not isPedInVehicle(source) then 
            x, y, z = getElementPosition(source) 
            xr, yr, zr = getElementRotation(source) 
            veh = createVehicle(id, x, y, z, xr, yr, zr) 
            warpPedIntoVehicle(source, veh) 
        else 
            ocVeh = getPedOccupiedVehicle(source) 
            setElementModel(ocVeh, id) 
        end 
    else 
        outputChatBox("Invalid vehicle id",source,255, 0, 0) 
    end 
end 
addCommandHandler("vehicle", fGiveVehicle) 
  
 

Guest Guest4401
Posted
vehicleIDS = { 602, 545, 496, 517, 401, 410, 518, 600, 527, 436, 589, 580, 419, 439, 533, 549, 526, 491, 474, 445, 467, 604, 426, 507, 547, 585, 
405, 587, 409, 466, 550, 492, 566, 546, 540, 551, 421, 516, 529, 592, 553, 577, 488, 511, 497, 548, 563, 512, 476, 593, 447, 425, 519, 520, 460, 
417, 469, 487, 513, 581, 510, 509, 522, 481, 461, 462, 448, 521, 468, 463, 586, 472, 473, 493, 595, 484, 430, 453, 452, 446, 454, 485, 552, 431, 
438, 437, 574, 420, 525, 408, 416, 596, 433, 597, 427, 599, 490, 432, 528, 601, 407, 428, 544, 523, 470, 598, 499, 588, 609, 403, 498, 514, 524, 
423, 532, 414, 578, 443, 486, 515, 406, 531, 573, 456, 455, 459, 543, 422, 583, 482, 478, 605, 554, 530, 418, 572, 582, 413, 440, 536, 575, 534, 
567, 535, 576, 412, 402, 542, 603, 475, 449, 537, 538, 441, 464, 501, 465, 564, 568, 557, 424, 471, 504, 495, 457, 539, 483, 508, 571, 500, 444, 
556, 429, 411, 541, 559, 415, 561, 480, 560, 562, 506, 565, 451, 434, 558, 494, 555, 502, 477, 503, 579, 400, 404, 489, 505, 479, 442, 458, 606, 
607, 610, 590, 569, 611, 584, 608, 435, 450, 591, 594 } 
  
function isModelInTable ( theModel ) 
    local found = false 
    for _, model in ipairs ( vehicleIDS ) do 
        if ( model == theModel ) then 
            found = true 
            break 
        end 
    end 
    return found 
end 
  
  
function fGiveVehicle(source, command, id) 
    if id then 
        local id = tonumber(id) or getVehicleModelFromName(id) 
        if isModelInTable(id) then 
            if not isPedInVehicle(source) then 
                x, y, z = getElementPosition(source) 
                xr, yr, zr = getElementRotation(source) 
                veh = createVehicle(id, x, y, z, xr, yr, zr) 
                warpPedIntoVehicle(source, veh) 
                outputChatBox("You spawned a "..getVehicleNameFromModel(id),source,0,255,255) 
            else 
                ocVeh = getPedOccupiedVehicle(source) 
                setElementModel(ocVeh, id) 
            end 
        else 
            outputChatBox("Invalid vehicle name/id",source,255, 0, 0) 
        end 
    else 
        outputChatBox("Please use: /vehicle [id or name]",source,0,255,255) 
    end 
end 
addCommandHandler("vehicle", fGiveVehicle) 

Posted

Thank you it works :D but i have a problem. when i type /vehicle blista compact, it sees the command as /vehicle blista. so i found this

id:gsub(' ', ' ') 

but it doesn't work (on the 5th line)

function fGiveVehicle(source, command, id) 
    if id then 
        local id = tonumber(id) or getVehicleModelFromName(id) 
        if isModelInTable(id) then 
        id:gsub(' ', ' ') 
            if not isPedInVehicle(source) then 
                x, y, z = getElementPosition(source) 
                xr, yr, zr = getElementRotation(source) 
                veh = createVehicle(id, x, y, z, xr, yr, zr) 
                warpPedIntoVehicle(source, veh) 
                outputChatBox("You spawned a "..getVehicleNameFromModel(id),source,0,255,255) 
            else 
                ocVeh = getPedOccupiedVehicle(source) 
                setElementModel(ocVeh, id) 
            end 
        else 
            outputChatBox("Invalid vehicle name/id",source,255, 0, 0) 
        end 
    else 
        outputChatBox("Please use: /vehicle [id or name]",source,0,255,255) 
    end 
end 
addCommandHandler("vehicle", fGiveVehicle) 

Guest Guest4401
Posted
function fGiveVehicle(source, command, ...) 
    local id = table.concat(arg," ") 
    if id then 
        local id = tonumber(id) or getVehicleModelFromName(id) 
        if isModelInTable(id) then 
            if not isPedInVehicle(source) then 
                x, y, z = getElementPosition(source) 
                xr, yr, zr = getElementRotation(source) 
                veh = createVehicle(id, x, y, z, xr, yr, zr) 
                warpPedIntoVehicle(source, veh) 
                outputChatBox("You spawned a "..getVehicleNameFromModel(id),source,0,255,255) 
            else 
                ocVeh = getPedOccupiedVehicle(source) 
                setElementModel(ocVeh, id) 
            end 
        else 
            outputChatBox("Invalid vehicle name/id",source,255, 0, 0) 
        end 
    else 
        outputChatBox("Please use: /vehicle [id or name]",source,0,255,255) 
    end 
end 
addCommandHandler("vehicle", fGiveVehicle) 

Posted

thank you guys it works :D

edit: btw why this?

function fGiveVehicle(source, command, ...) 
    local id = table.concat(arg," ") 

I mean what do table.concat(arg, " ") and ... do?

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...