Jump to content

Need some pro's help with my repair scripts...


jingzhi

Recommended Posts

Hey guys! So I had this problem making my repairing marker. I'm a noobie so please don't go hard on me :)

  
local marker = createMarker(2064.46924,-1831.39221,13, "cylinder",2,255,255,0) 
addEventHandler("onMarkerHit",marker, 
function(thePlayer) 
    local veh = getPedOccupiedVehicle (thePlayer) 
    local fixVehicle(veh) 
    end 
end) 
  

Whats the problem in this script?

Link to comment
local marker = createMarker(2064.46924,-1831.39221,13, "cylinder",2,255,255,0) 
addEventHandler("onMarkerHit",marker, 
function(thePlayer) 
    if isElement( thePlayer ) and getElementType( thePlayer ) == "player" and getPedOccupiedVehicle( thePlayer ) then 
        local veh = getPedOccupiedVehicle(thePlayer) 
        fixVehicle(veh) 
    end 
end) 
  

Link to comment
local marker = createMarker(2064.46924,-1831.39221,13, "cylinder",2,255,255,0) 
addEventHandler("onMarkerHit",marker, 
function(thePlayer) 
    if isElement( thePlayer ) and getElementType( thePlayer ) == "player" and getPedOccupiedVehicle( thePlayer ) then 
        local veh = getPedOccupiedVehicle(thePlayer) 
        fixVehicle(veh) 
    end 
end) 
  

Still have the same problem, here is the debugscript

http://postimg.org/image/yaztoi3a3/

Link to comment
addEventHandler("onMarkerHit",marker, 
function(thePlayer) 
    if getElementType( thePlayer ) == "player" and isPedInVehicle( thePlayer ) then 
        local veh = getPedOccupiedVehicle(thePlayer) 
        if (veh) then 
        fixVehicle(veh) 
    end 
 end 
end) 
  

Link to comment
addEventHandler("onMarkerHit",marker, 
function(thePlayer) 
    if getElementType( thePlayer ) == "player" and isPedInVehicle( thePlayer ) then 
        local veh = getPedOccupiedVehicle(thePlayer) 
        if (veh) then 
        fixVehicle(veh) 
    end 
 end 
end) 
  

Thank you very much, now it works :) but I want to learn whats the usage of "if (veh) then", it won't work without it?

Link to comment
You're welcome.

Another problem pops up, it will still fix the vehicle when nobody is in the car :|

Also, I want to make the player pay for the repair depends on the vehicles HP, again my scripts won't work

local marker = createMarker(2064.46924,-1831.39221,12.6, "cylinder",4,255,255,0) 
addEventHandler("onMarkerHit",marker, 
function(thePlayer) 
    if  getElementType(thePlayer) =="player" and isPedInVehicle( thePlayer ) then 
        local veh = getPedOccupiedVehicle(thePlayer) 
        if (veh) then 
        VehH = math(1000 -getElementHealth(veh) 
        fixVehicle(veh) 
        outputChatBox("Your "..getVehicleName(veh).." was repaired for "..VehH.."$") 
        takePlayerMoney(thePlayer, VehH) 
    end  
 end 
end) 
  

Can you help me out?

Link to comment
local marker = createMarker(2064.46924,-1831.39221,12.6, "cylinder",4,255,255,0) 
addEventHandler("onMarkerHit",marker, 
function(thePlayer) 
    if  getElementType(thePlayer) =="player" and isPedInVehicle( thePlayer ) then 
        local veh = getPedOccupiedVehicle(thePlayer) 
        if (veh) then 
        money = getPlayerMoney(thePlayer)  
        if money >= 1000 then 
        fixVehicle(veh) 
        takePlayerMoney(thePlayer, 1000) 
        outputChatBox("Your "..getVehicleName(veh).." was repaired" ) 
      end 
    end 
  end 
 end) 
  
  
  

I rewrote some things in your code , because i didn't understand what you want at all . And VehH = math(1000 -getElementHealth(veh) doesn't make sense.

Link to comment
local marker = createMarker(2064.46924,-1831.39221,12.6, "cylinder",4,255,255,0) 
addEventHandler("onMarkerHit",marker, 
function(thePlayer) 
    if  getElementType(thePlayer) =="player" and isPedInVehicle( thePlayer ) then 
        local veh = getPedOccupiedVehicle(thePlayer) 
        if (veh) then 
        money = getPlayerMoney(thePlayer)  
        if money >= 1000 then 
        fixVehicle(veh) 
        takePlayerMoney(thePlayer, 1000) 
        outputChatBox("Your "..getVehicleName(veh).." was repaired" ) 
      end 
    end 
  end 
 end) 
  
  
  

I rewrote some things in your code , because i didn't understand what you want at all . And VehH = math(1000 -getElementHealth(veh) doesn't make sense.

Sorry for my bad explanation, what i mean is, player will pay for repair depends on how much the car got damaged, for example if its 1% damaged only, then pay 100, 50% damaged pay 500, and so on

Link to comment
                   function RepairMarker(hitElement) 
                   if (getElementType(hitElement) == "vehicle") then 
                   if (getElementHealth(hitElement) < 1000) then 
                   if (getVehicleOccupant(hitElement)) then 
                   local driver = getVehicleOccupant(hitElement) 
                   local charge = math.floor(1000-getElementHealth(hitElement)) 
                   if (getPlayerMoney(driver) >= charge) then 
                   outputChatBox("Your vehicle has been repaired for $"..charge..".",driver,255,255,0) 
                   fixVehicle(hitElement) 
                   takePlayerMoney(driver,charge) 
                 end 
              end 
            end 
        end 
    end 
addEventHandler("onMarkerHit",marker,RepairMarker) 
  

Link to comment
                   function RepairMarker(hitElement) 
                   if (getElementType(hitElement) == "vehicle") then 
                   if (getElementHealth(hitElement) < 1000) then 
                   if (getVehicleOccupant(hitElement)) then 
                   local driver = getVehicleOccupant(hitElement) 
                   local charge = math.floor(1000-getElementHealth(hitElement)) 
                   if (getPlayerMoney(driver) >= charge) then 
                   outputChatBox("Your vehicle has been repaired for $"..charge..".",driver,255,255,0) 
                   fixVehicle(hitElement) 
                   takePlayerMoney(driver,charge) 
                 end 
              end 
            end 
        end 
    end 
addEventHandler("onMarkerHit",marker,RepairMarker) 
  

Thank you so much :)

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