Jump to content

script error


Monty

Recommended Posts

what's wrong in this script???

client

local marker = createMarker( 1037.8309326172, -1029.5063476563, 31.1015625, "Cylinder", 1.5, 255, 153, 0, 150) 
--- marker createMarker ( float x, float y, float z, [string theType, float size, int r, int g, int b, int a] ) 
  
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,"Mchanic job") 
    guiSetVisible(windowjob, false) 
    GUIEditor_Button[1] = guiCreateButton(22,200,108,35,"Mechanic 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 Mecjob(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, Mecjob) 
      
    function Mecjobleave(leaveElement) 
         if getElementType(leaveElement) == "player" and (leaveElement == localPlayer) then 
              if guiGetVisible(windowjob) then 
                   guiSetVisible(windowjob, false) 
                   showCursor(false) 
              end 
         end 
    end 
    addEventHandler("onClientMarkerLeave", marker, Mecjobleave) 
      
    function joinTeam() 
         triggerServerEvent("setMec",localPlayer) 
         guiSetVisible(windowjob, false) 
         showCursor(false) 
    end 
    addEventHandler("onClientGUIClick", GUIEditor_Button[1] , joinTeam, false) 
      
    function removeMedicWindow() 
         guiSetVisible(windowjob, false) 
         showCursor(false) 
    end 
    addEventHandler("onClientGUIClick", GUIEditor_Button[2] , removeMedicWindow, false) 
  
addEventHandler("onClientPlayerDamage", localVehicle, 
    local localVehicle = getPedOccupiedVehicle(localPlayer) 
function(attacker, weapon, bodypart, loss) 
team = getPlayerTeam(attacker) 
   if (attacker and getElementType(attacker) == "player" and weapon == 42 and team and getTeamName(team) == "Mechanic") then 
      cancelEvent() -- Cancels the damage cause by the spray 
     if (not isTimer(pause)) then  
         if (health < 99) then 
         triggerServerEvent("mechanic:repair", localVehicle, 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 

server

createBlip ( 1036.1654052734, -1027.8570556641, 32.1015625, 27 ) 
  
function createMechanicTeam () 
    mecTeam = createTeam ("Mechanic", 255, 153, 0) 
end 
addEventHandler ("onResourceStart", resourceRoot, createMechanicTeam) 
  
function joinMec() 
     setPlayerTeam(source,mecTeam) 
     setElementModel(source, 50) 
      giveWeapon ( source, 42, 999 ) 
     setElementData( source, "Occupation", "Mechanic", true ) 
     outputChatBox("You are now Mechanic.",source,0,255,0) 
end 
addEvent("setMec", true) 
addEventHandler("setMec", root, joinMec ) 
 addEvent("mechanic:repair", true) 
 addEventHandler("mechanic:repair", root, 
 function (mechanic) 
    if (getElementHealth(localVehicle) < 100) then 
        local Heal = getElementHealth(localVehicle) + 10 -- New health 
        setElementHealth(localVehicle, Heal)  
       if (Heal > 100) then 
             setElementHealth(localVehicle, 1000) 
      end 
     givePlayerMoney(mechanic, 1000) -- Gives 100$ to the medic each time the function is executed 
    end 
end 
  

Link to comment

try this,

Server:

createBlip ( 1036.1654052734, -1027.8570556641, 32.1015625, 27 ) 
  
function createMechanicTeam () 
    mecTeam = createTeam ("Mechanic", 255, 153, 0) 
end 
addEventHandler ("onResourceStart", resourceRoot, createMechanicTeam) 
  
function joinMec() 
    setPlayerTeam(client,mecTeam) 
    setElementModel(client, 50) 
    giveWeapon ( client, 42, 999 ) 
    setElementData( client, "Occupation", "Mechanic") 
    outputChatBox("You are now a Mechanic.",client,0,255,0) 
end 
addEvent("setMec", true) 
addEventHandler("setMec", root, joinMec ) 
  
addEvent("mechanic:repair", true) 
addEventHandler("mechanic:repair", root,function(mechanic) 
    if (getElementHealth(source) < 100) then 
        local Heal = getElementHealth(source) + 10 -- New health 
        setElementHealth(source, Heal) 
        if (Heal > 100) then 
            setElementHealth(source, 1000) 
        end 
        givePlayerMoney(mechanic, 1000) -- Gives 100$ to the medic each time the function is executed 
    end 
end) 

Client:

local marker = createMarker( 1037.8309326172, -1029.5063476563, 31.1015625, "Cylinder", 1.5, 255, 153, 0, 150) 
--- marker createMarker ( float x, float y, float z, [string theType, float size, int r, int g, int b, int a] ) 
  
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,"Mchanic job") 
guiSetVisible(windowjob, false) 
GUIEditor_Button[1] = guiCreateButton(22,200,108,35,"Mechanic 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) 
guiMemoSetReadOnly(GUIEditor_Memo[1],true) --It's a memo not an edit 
      
function Mecjob(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, Mecjob) 
      
function Mecjobleave(leaveElement) 
    if getElementType(leaveElement) == "player" and (leaveElement == localPlayer) then 
        if guiGetVisible(windowjob) then 
            guiSetVisible(windowjob, false) 
            showCursor(false) 
        end 
    end 
end 
addEventHandler("onClientMarkerLeave", marker, Mecjobleave) 
      
function joinTeam() 
    triggerServerEvent("setMec",localPlayer) 
    guiSetVisible(windowjob, false) 
    showCursor(false) 
end 
addEventHandler("onClientGUIClick", GUIEditor_Button[1] , joinTeam, false) 
      
function removeMedicWindow() 
    guiSetVisible(windowjob, false) 
    showCursor(false) 
end 
addEventHandler("onClientGUIClick", GUIEditor_Button[2] , removeMedicWindow, false) 
  
addEventHandler("onClientPlayerDamage",root,function()function(attacker, weapon, bodypart, loss) 
    local localVehicle = getPedOccupiedVehicle(source) 
    team = getPlayerTeam(attacker) 
    if (attacker and getElementType(attacker) == "player" and weapon == 42 and team and getTeamName(team) == "Mechanic") then 
        cancelEvent() -- Cancels the damage cause by the spray 
        if (not isTimer(pause)) then 
            if (health <= 99) then 
                triggerServerEvent("mechanic:repair", localVehicle, 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) 

Link to comment
  • 2 months later...

Try this clientside

local marker = createMarker( 1037.8309326172, -1029.5063476563, 31.1015625, "Cylinder", 1.5, 255, 153, 0, 150) 
--- marker createMarker ( float x, float y, float z, [string theType, float size, int r, int g, int b, int a] ) 
  
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,"Mchanic job") 
guiSetVisible(windowjob, false) 
GUIEditor_Button[1] = guiCreateButton(22,200,108,35,"Mechanic 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) 
guiMemoSetReadOnly(GUIEditor_Memo[1],true) --It's a memo not an edit 
      
function Mecjob(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, Mecjob) 
      
function Mecjobleave(leaveElement) 
    if getElementType(leaveElement) == "player" and (leaveElement == localPlayer) then 
        if guiGetVisible(windowjob) then 
            guiSetVisible(windowjob, false) 
            showCursor(false) 
        end 
    end 
end 
addEventHandler("onClientMarkerLeave", marker, Mecjobleave) 
      
function joinTeam() 
    triggerServerEvent("setMec",localPlayer) 
    guiSetVisible(windowjob, false) 
    showCursor(false) 
end 
addEventHandler("onClientGUIClick", GUIEditor_Button[1] , joinTeam, false) 
      
function removeMedicWindow() 
    guiSetVisible(windowjob, false) 
    showCursor(false) 
end 
addEventHandler("onClientGUIClick", GUIEditor_Button[2] , removeMedicWindow, false) 
  
addEventHandler("onClientPlayerDamage",root,function(attacker, weapon, bodypart, loss) 
    local localVehicle = getPedOccupiedVehicle(source) 
    team = getPlayerTeam(attacker) 
    if (attacker and getElementType(attacker) == "player" and weapon == 42 and team and getTeamName(team) == "Mechanic") then 
        cancelEvent() -- Cancels the damage cause by the spray 
        if (not isTimer(pause)) then 
            if (health <= 99) then 
                triggerServerEvent("mechanic:repair", localVehicle, 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) 

Link to comment
now i see marker and GUI but how to fix car?(how the job works?)
health is not defined here (client)
if (health <= 99) then 

and the trigger wrong

triggerServerEvent("mechanic:repair", localVehicle, attacker) 

should be

triggerServerEvent("mechanic:repair", attacker, localVehicle) 

Link to comment
addEvent("mechanic:repair", true) 
addEventHandler("mechanic:repair", root,function(mechanic) 
    if (getElementHealth(source) < 100) then 
        local Heal = getElementHealth(source) + 10 -- New health 
        setElementHealth(source, Heal) 
        if (Heal > 100) then 
            setElementHealth(source, 1000) 
        end 
        givePlayerMoney(mechanic, 1000) -- Gives 100$ to the medic each time the function is executed 
    end 
end) 

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