Jump to content

car limit bug in script


zombienation

Recommended Posts

hello,

i have found a small bug in a vehicle panel, the script says there is a limit of 2 spawns, but the limit dont work

the same script file have something that blocks rhino and hunter, that works, but the limit not,

is there somebody who could tell me how i can fix this please??

thank you

----------------------------------------------------------------------------------- 
---------------------------------------------------------------------------------- 
---------------------------------------------------------------- 
----------------------------------------------------------------------------------- 
---------------------------------------------------------------------------------- 
------------------SCRIPT BY TAALASMAA (C) DO NOT EDIT THIS WITHOUT PERMISSIONS----- 
----------------------------------------------------------------------------------- 
disallowedVehicle = {{425},{432}} -- RHINO AND HUNTER -- 
----------------------------------------- 
---------------------------------------- 
--------CARSPAWN LIMIT------------------ 
carSpawnLimit = {{"2"}} -- can be changed -- NOT IN USE IN 0.1!!!!!! --- 
---------------------------------------- 
---------------------------------------- 
-------------------------- 
------------------------- 
function spawnAcar(carID) 
    for i,v in ipairs (disallowedVehicle) do 
        if (v[1] == carID) then 
            outputChatBox("This is disallowed vehicle!",source,255,0,0) 
            return false 
        end 
    end 
    playerX,playerY,playerZ = getElementPosition(source) 
    vehicle = createVehicle(carID,playerX + 2,playerY +2, playerZ) 
end 
addEvent("onPlayerWantToSpawn",true); 
addEventHandler("onPlayerWantToSpawn",getRootElement(),spawnAcar) 
  
----------------------------------------------------------------------------------- 
----------------------------------------------------------------------------------- 

Edited by Guest
Link to comment

theres no check for the amount of times u spawn a car in your script.

u can easily make ur own counter tho.

try this....

local root = getRootElement() 
local disallowedVehicle = { [425]=true, [432]=true }   -- add any other vehicle ID's here that u need to disallow 
local vehicleSpawnCounter = {} 
local vehicleSpawnLimit = 2               -- set to 2 vehicle spawns, change as required 
addEvent("onPlayerWantToSpawn",true) 
  
function spawnMyVehicle(carID) 
    if disallowedVehicle[carID] then 
        outputChatBox("This is disallowed vehicle!",source,255,0,0) 
    else 
        if carSpawnCounter[source] <= vehicleSpawnLimit then 
            local x,y,z = getElementPosition(source) 
            local vehicle = createVehicle(carID,x + 2,y +2, z) 
            vehicleSpawnCounter[source] = vehicleSpawnCounter[source] + 1 
        else 
            outputChatBox("Vehicle Spawn Limit Reached!",source,255,0,0) 
        end 
    end 
end 
addEventHandler("onPlayerWantToSpawn",root,spawnMyVehicle) 
  
function playerJoined()  
    vehicleSpawnCounter[source] = 0 
end 
addEventHandler( "onPlayerJoin", root, playerJoined ) 
  
function playerQuit()    
    vehicleSpawnCounter[source] = nil 
end 
addEventHandler( "onPlayerQuit", root, playerQuit ) 

im not familiar with your script and i dont know what gamemode your using so i havent tested this.

try it out and let me know if theres any problems.

Link to comment
theres no check for the amount of times u spawn a car in your script.

u can easily make ur own counter tho.

try this....

local root = getRootElement() 
local disallowedVehicle = { [425]=true, [432]=true }   -- add any other vehicle ID's here that u need to disallow 
local vehicleSpawnCounter = {} 
local vehicleSpawnLimit = 2               -- set to 2 vehicle spawns, change as required 
addEvent("onPlayerWantToSpawn",true) 
  
function spawnMyVehicle(carID) 
    if disallowedVehicle[carID] then 
        outputChatBox("This is disallowed vehicle!",source,255,0,0) 
    else 
        if carSpawnCounter[source] <= vehicleSpawnLimit then 
            local x,y,z = getElementPosition(source) 
            local vehicle = createVehicle(carID,x + 2,y +2, z) 
            vehicleSpawnCounter[source] = vehicleSpawnCounter[source] + 1 
        else 
            outputChatBox("Vehicle Spawn Limit Reached!",source,255,0,0) 
        end 
    end 
end 
addEventHandler 
("onPlayerWantToSpawn",root,spawnMyVehicle) 
  
function playerJoined()  
    vehicleSpawnCounter[source] = 0 
end 
addEventHandler( "onPlayerJoin", root, playerJoined ) 
  
function playerQuit()    
    vehicleSpawnCounter[source] = nil 
end 
addEventHandler( "onPlayerQuit", root, playerQuit ) 

im not familiar with your script and i dont know what gamemode your using so i havent tested this.

try it out and let me know if theres any problems.

Thanks man. i will test this right after work and let u know about it :)

Link to comment

sorry my bad, carSpawnCounter should read vehicleSpawnCounter,

i changed it after writing it since i thought u might be allowing vehicles other than cars.

the line should read:

         if vehicleSpawnCounter[source] <= vehicleSpawnLimit then 

sorry about that. :mrgreen:

Link to comment
sorry my bad, carSpawnCounter should read vehicleSpawnCounter,

i changed it after writing it since i thought u might be allowing vehicles other than cars.

the line should read:

         if vehicleSpawnCounter[source] <= vehicleSpawnLimit then 

sorry about that. :mrgreen:

No problem :D thx man i will test it after work :)

Link to comment

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