~DarkRacer~ Posted February 28, 2013 Share 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. Link to comment
X-SHADOW Posted February 28, 2013 Share 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 ) Link to comment
X-SHADOW Posted February 28, 2013 Share 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 ) Link to comment
PaiN^ Posted February 28, 2013 Share 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 -_-" ??!!! Link to comment
iPrestege Posted February 28, 2013 Share Posted February 28, 2013 The problem has been resolved in another topic! In another section! In the Arab section. Link to comment
~DarkRacer~ Posted February 28, 2013 Author Share Posted February 28, 2013 ThanQ ALL. Link to comment
Anderl Posted February 28, 2013 Share 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. Link to comment
PaiN^ Posted February 28, 2013 Share Posted February 28, 2013 Thanx Anderl + I just saw my errors .. Link to comment
~DarkRacer~ Posted March 2, 2013 Author Share 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. Link to comment
Anderl Posted March 2, 2013 Share 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. Link to comment
~DarkRacer~ Posted March 2, 2013 Author Share 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 ) Link to comment
~DarkRacer~ Posted March 2, 2013 Author Share Posted March 2, 2013 What do you mean by server? it's already on server side. Link to comment
iPrestege Posted March 2, 2013 Share Posted March 2, 2013 getLocalPlayer = clientOnly. Link to comment
~DarkRacer~ Posted March 2, 2013 Author Share Posted March 2, 2013 Ok thanks for the advice, so what do you think i should do? Link to comment
Anderl Posted March 2, 2013 Share 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). Link to comment
~DarkRacer~ Posted March 3, 2013 Author Share 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"? Link to comment
Wei Posted March 3, 2013 Share 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". 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