~DarkRacer~ Posted February 28, 2013 Posted February 28, 2013 Hi, i'm a beginner in LUA scripting, i've made a code and i don't know what's wrong...? function changeCar( player ) if ( getPlayerTeam ( player ) ) then local r, g, b = getTeamColor ( getPlayerTeam ( player ) ) setVehicleColor ( source, r, g, b ) end end addEventHandler( "onVehicleEnter", root,changeCar) the code is so simple it makes your car's color as same as your team's color. BTW i make it only for race (DM) this is the meta: <meta> <info name="CarCOLOR" description="blaBla" author="DarkRACER" type="script" version="1.0" /> <script scr="car.lua" /> </meta> please if you noticed anything wrong in this code reply as soon as you can, thanks.
X-SHADOW Posted February 28, 2013 Posted February 28, 2013 addEventHandler('onVehicleEnter', root, function(player) if (getPlayerTeam (player) ) then local r, g, b = getTeamColor (getPlayerTeam( player )) setVehicleColor( player, r, g, b) outputChatBox('Car Color Has Been Set!', player, 255, 0 ,0) end end )
X-SHADOW Posted February 28, 2013 Posted February 28, 2013 addEventHandler('onVehicleEnter', root, function(player) if (getPlayerTeam (player) ) then local r, g, b = getTeamColor (getPlayerTeam( player )) setVehicleColor( player, r, g, b) outputChatBox('Car Color Has Been Set!', player, 255, 0 ,0) end end )
PaiN^ Posted February 28, 2013 Posted February 28, 2013 > name="CarCOLOR" description="blaBla" author="DarkRACER" type="script" version="1.0" /> ="car.lua" type="server"/>> + addEventHandler('onVehicleEnter', root, function(player) if (getPlayerTeam (player) ) then local r, g, b = getTeamColor (getPlayerTeam( player )) setVehicleColor( player, r, g, b) outputChatBox('Car Color Has Been Set!', player, 255, 0 ,0) end end ) How outputChatBox will fix any thing -_-" ??!!!
iPrestege Posted February 28, 2013 Posted February 28, 2013 The problem has been resolved in another topic! In another section! In the Arab section.
Anderl Posted February 28, 2013 Posted February 28, 2013 > name="CarCOLOR" description="blaBla" author="DarkRACER" type="script" version="1.0" /> ="car.lua" type="server"/>> + addEventHandler('onVehicleEnter', root, function(player) if (getPlayerTeam (player) ) then local r, g, b = getTeamColor (getPlayerTeam( player )) setVehicleColor( player, r, g, b) outputChatBox('Car Color Has Been Set!', player, 255, 0 ,0) end end ) How outputChatBox will fix any thing -_-" ??!!! If a 'script' node doesn't have type defined, it is defaulted to server so there is no need to add " type='server' ", neither it's going to fix anything.
~DarkRacer~ Posted March 2, 2013 Author Posted March 2, 2013 hi, the code is working just fine ... but i noticed an issue: whenever i hit a VehicleChange pickup the color of the car changes to a random one i hope if there's any other event can solve this issue.
Anderl Posted March 2, 2013 Posted March 2, 2013 You can use the event onPlayerPickUpRacePickup and check if the pickup is the 'vehiclechange' one, then you set vehicle's color back to the original.
~DarkRacer~ Posted March 2, 2013 Author Posted March 2, 2013 It didn't work this is the code: addEventHandler( "onPlayerPickUpRacePickup", root, function() if ( getPlayerTeam ( getLocalPlayer() ) ) then local r, g, b = getTeamColor ( getPlayerTeam ( getLocalPlayer ) ) setVehicleColor ( getPedOccupiedVehicle(getLocalPlayer()), r, g, b ) end end )
~DarkRacer~ Posted March 2, 2013 Author Posted March 2, 2013 What do you mean by server? it's already on server side.
~DarkRacer~ Posted March 2, 2013 Author Posted March 2, 2013 Ok thanks for the advice, so what do you think i should do?
Anderl Posted March 2, 2013 Posted March 2, 2013 It didn't work this is the code: addEventHandler( "onPlayerPickUpRacePickup", root, function() if ( getPlayerTeam ( getLocalPlayer() ) ) then local r, g, b = getTeamColor ( getPlayerTeam ( getLocalPlayer ) ) setVehicleColor ( getPedOccupiedVehicle(getLocalPlayer()), r, g, b ) end end ) Wrong for three reasons: 1. "getLocalPlayer" is client-side only. 2. You must check if the pickup is "vehiclechange" (unless it's changing color when picking any kind of pickup). 3. You need to add the event with addEvent, since it's not a MTA predefined event (perhaps it's not needed in newer MTA versions, I'm not sure about now but before it was).
~DarkRacer~ Posted March 3, 2013 Author Posted March 3, 2013 Thanks Anderl i'm really learning new stuff but i have a question : how can i make sure if the pickup is a "VehicleChange"?
Wei Posted March 3, 2013 Posted March 3, 2013 https://wiki.multitheftauto.com/wiki/Resource:Race You have onPlayerPickUpRacePickup parameters somewhere at the botom And the second parameter is PickupType so check it with script if the type is "vehiclechange".
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