Mizudori Posted December 30, 2014 Share Posted December 30, 2014 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
ViRuZGamiing Posted December 30, 2014 Share Posted December 30, 2014 You are using compatible upgrades, So that means you check for every upgrade POSSIBLE on the vehicle, I think you search getVehicleUpgrades. Link to comment
Mizudori Posted December 30, 2014 Author Share Posted December 30, 2014 Oh yeah I am so dumb Thank for the help ^^ Next time I need to read the description more carefully Link to comment
ViRuZGamiing Posted December 30, 2014 Share Posted December 30, 2014 No problem. ~ Mistakes were made Link to comment
Mizudori Posted January 1, 2015 Author Share Posted January 1, 2015 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
ViRuZGamiing Posted January 2, 2015 Share Posted January 2, 2015 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
Mizudori Posted January 2, 2015 Author Share Posted January 2, 2015 Still nothing, this is interesting is shows that table upgrades is empty. I am using debugger 3 no errors. screens from 2 vehicles http://oi60.tinypic.com/2dt86ee.jpg http://oi59.tinypic.com/ib9el1.jpg 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now