Jump to content

HELP PLEASE :-\


~DarkRacer~

Recommended Posts

Posted

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.

Posted
  
  
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 
) 

My ingame nickname : Ops!

-DeathMatch GameMode By Ops! : 5%

Posted
  
  
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 
) 

My ingame nickname : Ops!

-DeathMatch GameMode By Ops! : 5%

Posted

 >    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 -_-" ??!!!

" Keep Thinking Different . " - Steve Jops

--------------------

Don't send me PMs asking for help, I Won't reply !

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

"[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007

Posted

Thanx Anderl

+

I just saw my errors ..

" Keep Thinking Different . " - Steve Jops

--------------------

Don't send me PMs asking for help, I Won't reply !

Posted

You're welcome.

"[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007

Posted

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.

Posted

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.

"[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007

Posted

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 
) 
  

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

"[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007

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