Jump to content

Help with getVehicleCompatibleUpgrades


Mizudori

Recommended Posts

Hello, last day I decided to write script for car shop upgrades. So I went to wiki so see if there is any good function which will help me out with it and I did find the getVehicleCompatibleUpgrades(). I created lua script to test it up (the script from example on wiki).

When I entered the car(banshee) it shown me a spoiler which cleary are not part of this car. When I entered other car which doesn't have a spoilers it shown me spoilers as well.

I did not change any line in the code I copied paste it.

This is how my lua file looks like. It's server side.

meta script is typ of "server"

function scriptOnPlayerEnterVehicle ( invehicle, seat, jacked ) 
  local upgrades = getVehicleCompatibleUpgrades ( invehicle ) 
  for upgradeKey, upgradeValue in ipairs ( upgrades ) do 
    outputChatBox ( getVehicleUpgradeSlotName ( upgradeValue ) .. ": " .. upgradeValue ) 
  end 
end 
addEventHandler ( "onPlayerVehicleEnter", getRootElement(), scriptOnPlayerEnterVehicle ) 

I am doing something wrong or this funcions doesn't work correclty?

Link to comment

Hi, so I used the function which you gave me..

I copied paste it as the previous

server-side

  
function scriptOnPlayerEnterVehicle ( theVehicle, seat, jacked ) 
    local upgrades = getVehicleUpgrades ( theVehicle ) 
    for upgradeKey, upgradeValue in ipairs ( upgrades ) do 
        outputChatBox ( getVehicleUpgradeSlotName ( upgradeKey - 1 ) .. ": " .. upgradeValue ) 
    end 
end 
addEventHandler ( "onPlayerVehicleEnter", getRootElement(), scriptOnPlayerEnterVehicle ) 
  

when I enter any car I doesn't show the upgrades now -,- For first I tought it's maybe me doing something wrong with function but when I tried simple

  
function scriptOnPlayerEnterVehicle ( theVehicle, seat, jacked ) 
  
        outputChatBox ("Does it works?") 
  
end 
addEventHandler ( "onPlayerVehicleEnter", getRootElement(), scriptOnPlayerEnterVehicle ) 
  

It shown me a message in chatbox.

Link to comment
function scriptOnPlayerEnterVehicle ( theVehicle, seat, jacked ) 
    local upgrades = getVehicleUpgrades ( theVehicle ) 
    for _, upgrade in ipairs ( upgrades ) do 
        outputChatBox ( getVehicleUpgradeSlotName ( upgrade ) .. ": " .. upgrade ) 
    end 
end 
addEventHandler ( "onPlayerVehicleEnter", getRootElement(), scriptOnPlayerEnterVehicle ) 

Link to comment

Still nothing, this is interesting is shows that table upgrades is empty.

I am using debugger 3 no errors.

screens from 2 vehicles

  
  
function table.empty( a ) 
    if type( a ) ~= "table" then 
        return false 
    end 
     
    return not next( a ) 
end 
  
  
function scriptOnPlayerEnterVehicle ( theVehicle, seat, jacked ) 
    local upgrades = getVehicleUpgrades ( theVehicle ) 
    for _, upgrade in ipairs ( upgrades ) do 
        outputChatBox ( getVehicleUpgradeSlotName ( upgrade ) .. ": " .. upgrade ) 
    end 
  
    local isempty = table.empty(upgrades) 
    if(isempty)then 
        outputChatBox("Table is empty") 
    else 
        outputChatBox("Table is not emepty") 
    end 
  
  
end 
addEventHandler ( "onPlayerVehicleEnter", getRootElement(), scriptOnPlayerEnterVehicle ) 
  
  
  

I really don't understand what is wrong, for dem tries I tried to use "getVehicleCompatibleUpgrades". It works fine. It shows that table is not empty and retrieves tables.

  
function table.empty( a ) 
    if type( a ) ~= "table" then 
        return false 
    end 
     
    return not next( a ) 
end 
  
  
function scriptOnPlayerEnterVehicle ( invehicle, seat, jacked ) 
  local upgrades = getVehicleCompatibleUpgrades ( invehicle ) 
  for upgradeKey, upgradeValue in ipairs ( upgrades ) do 
    outputChatBox ( getVehicleUpgradeSlotName ( upgradeValue ) .. ": " .. upgradeValue ) 
  end 
  
    local isempty = table.empty(upgrades) 
    if(isempty)then 
        outputChatBox("Table is empty") 
    else 
        outputChatBox("Table is not emepty") 
    end 
  
  
end 
addEventHandler ( "onPlayerVehicleEnter", getRootElement(), scriptOnPlayerEnterVehicle ) 
  
  
  

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