Jump to content

I need help with mechanic script


damien111

Recommended Posts

im new to this lua stuff, but i can code java script so i have a pretty good idea how stuff works. My Mechanic script creates a marker and a team. and when you are in the marker a GUI pops up. when you click the button it gives you a skin and switches your team. My medic script works the same way but gets a spray can that can heal with some other code. i am not sure how to make it when mechanic enters it fixes the car. heres my code atm.

Mechanic-server.lua:

function createMechanicTeam () 
    MechanicTeam = createTeam ("Mechanic", 6, 183, 248) 
end 
addEventHandler ("onResourceStart", resourceRoot, createMechanicTeam) 
  
function joinMechanic() 
     setPlayerTeam(source,MechanicTeam) 
     setElementModel(source,268) 
     setElementData( source, "Occupation", "Mechanic", true ) 
     outputChatBox("You are now Mechanic.",source,0,255,0) 
end 
addEvent("setMechanic", true) 
addEventHandler("setMechanic",root,joinMechanic) 
addEvent("Mechanic:fixing", true) 
addEventHandler("Mechanic:fixing", root, 
function (Mechanic) 
    if (getElementHealth(vechile) < 100) then 
        fixVehicle(getPedOccupiedVehicle(getPlayerFromName(who))) --fixvechile if gets occupied  
        if (VehHeal > 100) then 
             setElementHealth(vechile, 100) 
        end 
        givePlayerMoney(Mechanic, 100) -- Gives 100$ to the Mechanic each time the function is executed 
        takePlayerMoney(source, 100) -- Takes 100$ from the source when he get healed 
    end 
end) 

 

mechanicj.lua:

local marker = createMarker(1940.97, 2166.40, 10.82, "Cylinder", 2, 6, 183, 248, 153) 
  
GUIEditor_Button = {} 
    GUIEditor_Memo = {} 
    GUIEditor_Label = {} 
      
    function guiMyCwindow(w,h,t) 
      local x,y = guiGetScreenSize() 
      return guiCreateWindow((x-w)/2,(y-h)/2,w,h,t,false) 
    end 
      
    windowjob = guiMyCwindow(301,250,"Mechanic job") 
    guiSetVisible(windowjob, false) 
    GUIEditor_Button[1] = guiCreateButton(22,200,108,35,"Take job",false,windowjob) 
    GUIEditor_Label[1] = guiCreateLabel(193,-103,5,5,"",false,windowjob) 
    GUIEditor_Button[2] = guiCreateButton(179,200,110,36,"Cancel",false,windowjob) 
    GUIEditor_Memo[1] = guiCreateMemo(19,33,273,100,"To take Mechanic job, press Take job.\n\nIf you don't want to, press Cancel.",false,windowjob) 
     guiEditSetReadOnly(GUIEditor_Memo[1],true) 
      
    function Mechanicjob(hitElement) 
         if getElementType(hitElement) == "player" and (hitElement == localPlayer) then 
              if not guiGetVisible(windowjob) then 
                   guiSetVisible(windowjob, true) 
                   showCursor(true) 
              end 
         end 
    end 
    addEventHandler("onClientMarkerHit", marker, Mechanicjob) 
      
    function Mechanicjobleave(leaveElement) 
         if getElementType(leaveElement) == "player" and (leaveElement == localPlayer) then 
              if guiGetVisible(windowjob) then 
                   guiSetVisible(windowjob, false) 
                   showCursor(false) 
              end 
         end 
    end 
    addEventHandler("onClientMarkerLeave", marker, Mechanicjobleave) 
      
    function joinTeam() 
         triggerServerEvent("setMechanic",localPlayer) 
         guiSetVisible(windowjob, false) 
         showCursor(false) 
    end 
    addEventHandler("onClientGUIClick", GUIEditor_Button[1] , joinTeam, false) 
      
    function removeMechanicWindow() 
         guiSetVisible(windowjob, false) 
         showCursor(false) 
    end 
    addEventHandler("onClientGUIClick", GUIEditor_Button[2] , removeMechanicWindow, false) 
    addEventHandler("onClientPlayerDamage", localVechile, 
function(attacker, weapon, bodypart, loss) 
team = getPlayerTeam(attacker) 
    if (attacker and getElementType(attacker) == "player" and weapon == 41 and team and getTeamName(team) == "Mechanic") then -- Checks if the player is using spray and is into Mechanic team 
        cancelEvent() -- Cancels the damage cause by the spray 
        if (not isTimer(pause)) then  
            local health = getElementHealth(localVechile) 
            if (health < 99) then 
            triggerServerEvent("Mechanic:fixing", localVechile, attacker) -- Calls the Server Event 
            pause = setTimer(function() end, 1000, 1) -- Makes a timer for the function so it won't fully heal in the first time 
            end 
        end 
    end 
end) 
  

meta:

    "Damien" name="mechanic" version="0.1" type="script"/> 
    

Edited by Guest
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...