Jump to content

get random car


Thivenin

Recommended Posts

Posted

hai all, today I have a problem here the script and I explain more

allowedVehicles = { [602] = true, [545] = true, [469] = true, [517] = true, [401] = true, [410] = true, [518] = true, [600] = true, [527] = true, [436] = true, [589] = true, [580] = true, [419] = true, [439] = true, [533] = true, [549] = true, [526] = true, [491] = true, [474] = true, [445] = true, [604] = true, [507] = true, [585] = true, [587] = true, [466] = true, [492] = true, [546] = true, [551] = true, [516] = true, [467] = true, [426] = true, [547] = true, [405] = true, [409] = true, [550] = true, [566] = true, [540] = true, [421] = true, [529] = true, [485] = true, [552] = true, [431] = true, [438] = true, [437] = true, [574] = true, [420] = true, [525] = true, [408] = true, [416] = true, [433] = true, [427] = true, [490] = true, [528] = true, [407] = true, [544] = true, [523] = true, [470] = true, [598] = true, [596] = true, [597] = true, [599] = true, [601] = true, [428] = true, [499] = true, [609] = true, [498] = true, [524] = true, [532] = true, [578] = true, [486] = true, [406] = true, [573] = true, [455] = true, [588] = true, [403] = true, [514] = true, [423] = true, [414] = true, [443] = true, [515] = true, [531] = true, [456] = true, [459] = true, [422] = true, [482] = true, [605] = true, [530] = true, [418] = true, [572] = true, [582] = true, [413] = true, [440] = true, [543] = true, [583] = true, [478] = true, [554] = true, [536] = true, [575] = true, [534] = true, [567] = true, [535] = true, [576] = true, [412] = true, [402] = true, [542] = true, [603] = true, [475] = true, [568] = true, [424] = true, [504] = true, [457] = true, [483] = true, [508] = true, [571] = true, [500] = true, [444] = true, [556] = true, [557] = true, [471] = true, [495] = true, [539] = true, [429] = true, [411] = true, [559] = true, [541] = true, [415] = true, [561] = true, [480] = true, [560] = true, [562] = true, [506] = true, [565] = true, [451] = true, [434] = true, [558] = true, [494] = true, [555] = true, [502] = true, [477] = true, [503] = true, [579] = true, [400] = true, [404] = true, [489] = true, [505] = true, [479] = true, [442] = true, [458] = true } 
DDthirdMarker = createMarker ( -1353, 915, 1038, "cylinder", 5, 250, 0, 250, 255 ) 
setElementInterior ( DDthirdMarker, 15 ) 
  
function DDthirdTP ( markerHit, matchingDimension ) 
    if ( markerHit == DDthirdMarker ) then 
        player = source 
        pick = math.random(#allowedVehicles) 
            setElementPosition ( player, -1944, 938, 1037 ) 
    end 
end 
addEventHandler ( "onPlayerMarkerHit", getRootElement(), DDthirdTP ) 

bad argument #1 to 'random'

at this line

pick = math.random(#allowedVehicles) 

that should : when I take the marker, I get a random car at the position "setElementPosition ( player, -1944, 938, 1037 )"

idk what to do :/ help me pls

Posted

That kind of table won't work with math.random.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Change your table to something like this:

allowedVehicles = { 602, 545, etc, etc... } 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Post your new code.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
allowedVehicles = { 602, 545, 469, .... } 
  
DDthirdMarker = createMarker ( -1353, 915, 1038, "cylinder", 5, 250, 0, 250, 255 ) 
setElementInterior ( DDthirdMarker, 15 ) 
  
function DDthirdTP ( markerHit, matchingDimension ) 
    if ( markerHit == DDthirdMarker ) then 
        pick = math.random(#allowedVehicles) 
        spawnveh = spawnVehicle ( -1359, 935, 1038 ) 
            setElementPosition ( source, -1359, 935, 1038 ) 
    end 
end 
addEventHandler ( "onPlayerMarkerHit", getRootElement(), DDthirdTP ) 

Posted
allowedVehicles = { 602, 545, 469, .... } 
  
DDthirdMarker = createMarker ( -1353, 915, 1038, "cylinder", 5, 250, 0, 250, 255 ) 
setElementInterior ( DDthirdMarker, 15 ) 
  
function DDthirdTP ( markerHit, matchingDimension ) 
    if ( markerHit == DDthirdMarker ) then 
        local pick = math.random ( #allowedVehicles ) 
        local spawnveh = createVehicle ( allowedVehicles [ pick ], -1359, 935, 1038 ) 
        warpPedIntoVehicle ( source, spawnveh ) 
    end 
end 
addEventHandler ( "onPlayerMarkerHit", getRootElement(), DDthirdTP ) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
allowedVehicles = { 602, 545, 469, .... } 
  
DDthirdMarker = createMarker ( -1353, 915, 1038, "cylinder", 5, 250, 0, 250, 255 ) 
setElementInterior ( DDthirdMarker, 15 ) 
  
function DDthirdTP ( markerHit, matchingDimension ) 
    if ( markerHit == DDthirdMarker ) then 
        local pick = math.random ( #allowedVehicles ) 
        local spawnveh = createVehicle ( allowedVehicles [ pick ], -1359, 935, 1038 ) 
        setElementInterior ( spawnveh, 15 ) 
        warpPedIntoVehicle ( source, spawnveh ) 
    end 
end 
addEventHandler ( "onPlayerMarkerHit", getRootElement(), DDthirdTP ) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Eh, didn't took me 10 min, already knew what was missing :P.

You're welcome.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
Can I know why we should use this # in this pick = math.random(#allowedVehicles)

# is used to get the length of the table.

math.random will give you a number between 1 and the length of the table or the number you specify.

Also math.random can be used in three ways.

You can find more info about it here: http://lua-users.org/wiki/MathLibraryTutorial

CiTLh.png
Posted

as it's on the same screen I post it here

I have a problem I explain after the pub, jk :

DDseventhMarker = createMarker ( -1410, 998, 1025, "corona", 2, 250, 0, 250, 255 ) 
setElementInterior ( DDseventhMarker, 15 ) 
  
function DDrepair ( markerHit, matchingDimension ) 
    if ( markerHit == DDseventhMarker ) then 
    setMarkerColor ( DDseventhMarker, 250, 0, 250, 0 ) 
    thePlayer = source 
        fixVehicle ( thePlayer ) 
    timer = setTimer ( DDrepair, 30000, 1 ) 
    end 
end 
killTimer ( timer ) 
addEventHandler ( "onPlayerMarkerHit", getRootElement(), DDrepair ) 

I want to make this marker as a repair and when we take it, it's taking 30 scd for get it back... but I have an error that I can't understand : Bad argument @ 'killTimer' [Expected lua-timer at argument 1, got nil]

Posted

If you mean you want to remove the timer just remove the line 9 and 12

Try this.

DDseventhMarker = createMarker ( -1410, 998, 1025, "corona", 2, 250, 0, 250, 255 ) 
setElementInterior ( DDseventhMarker, 15 )[/center] 
function DDrepair ( markerHit, matchingDimension ) 
    if ( markerHit == DDseventhMarker ) then 
    setMarkerColor ( DDseventhMarker, 250, 0, 250, 0 ) 
    thePlayer = source 
        fixVehicle ( thePlayer ) 
    end 
end 
addEventHandler ( "onPlayerMarkerHit", getRootElement(), DDrepair ) 

To Visit Us

Press Here: mtasa://5.9.206.180:22002

b648040241b8f01.png

0d0a7bb38ca13e5.png

Posted
DDseventhMarker = createMarker(-1410, 998, 1025, "corona", 2, 250, 0, 250, 255) 
setElementInterior(DDseventhMarker, 15) 
  
hitTimer = {} 
  
function DDrepair(markerHit) 
    if (markerHit == DDseventhMarker) then 
        local vehicle = getPedOccupiedVehicle(source) 
        if vehicle and not isTimer(hitTimer[source]) then 
            hitTimer[source] = setTimer(function() end, 30000, 1) 
            setMarkerColor(DDseventhMarker, 250, 0, 250, 0) 
            fixVehicle(vehicle) 
        end 
    end 
end 
addEventHandler("onPlayerMarkerHit", root, DDrepair) 

CiTLh.png
Posted (edited)
DDseventhMarker = createMarker ( -1410, 998, 1025, "corona", 2, 250, 0, 250, 255 ) 
setElementInterior ( DDseventhMarker, 15 ) 
  
function DDrepair ( hitElement ) 
    if ( hitElement == localPlayer ) and ( isPedInVehicle ( hitElement ) ) then 
        if ( timer ) then return end 
        local vehicle = getPedOccupiedVehicle ( hitElement ) 
        setMarkerColor ( DDseventhMarker, 250, 0, 250, 0 ) 
        fixVehicle ( vehicle ) 
        timer = setTimer ( function ( ) setMarkerColor ( DDseventhMarker, 250, 0, 250, 0 ) timer = nil  end, 30000, 1 ) 
    end 
end 
addEventHandler ( "onClientMarkerHit", DDseventhMarker, DDrepair, false ) 

I made it clientside so it won't affect on server side, which means the timer would be set to the localplayer, and the marker color will be changed after the timer execution, hope that helped.

edit:

Me and TAPL have posted at the same time, but you choose whatever you like :P

Edited by Guest

F4MZM4.gif

Posted
fixVehicle client side won't affect server side vehicle, if i'm not wrong.

I'm sure it works for both sides, haven't tried it, but Thivenin will try it anyways.

F4MZM4.gif

Posted
DDseventhMarker = createMarker ( -1410, 998, 1025, "corona", 2, 250, 0, 250, 255 ) 
setElementInterior ( DDseventhMarker, 15 ) 
  
function DDrepair ( markerHit ) 
    if ( markerHit == DDseventhMarker ) then 
        local vehicle = getPedOccupiedVehicle ( source ) 
        if ( vehicle and not isTimer ( hitTimer ) ) then 
            setMarkerColor ( DDseventhMarker, 250, 0, 250, 0 ) 
            fixVehicle ( vehicle ) 
            hitTimer = setTimer ( setMarkerColor, 30000, 1, DDseventhMarker, 250, 0, 250, 255 ) 
        end 
    end 
end 
addEventHandler ( "onPlayerMarkerHit", root, DDrepair ) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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