Jump to content

Script error :( help


Monty

Recommended Posts

hi i made this script, but no marker spawned :(

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) 

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) 

meta.xml

<meta> 
    <info author="stolka" name="mec" version="1.0" type="script"/> 
    <script src="mecc.lua" type="client"/> 
    <script src="mecs.lua" type="server"/> 
</meta> 
  

Link to comment

it's wrong type

'Cylinder'
Lua is case sensitive. Type marker should be 'cylinder'.
theType: The visual type of the marker to be created. Possible values:

"checkpoint": A race checkpoint. These are very tall, but not infinite, light pillars. Checkpoints snap to ground and become invisible after going over a certain Z height.

"ring": Doughnut shaped ring, normally used for aircraft.

"cylinder": Small glowing ground ring. These are the glow markers you walk into to activate missions or events in single player.

"arrow": Arrow pointing down. These are the arrows on the doors you can enter in single player, except MTA's are not animated by default.

"corona": A glowing ball of light.

Link to comment

try this,

Server:

local marker = createMarker( 1037.8309326172, -1029.5063476563, 31.1015625, "cylinder", 1.5, 255, 153, 0, 150) 
           createBlip ( 1036.1654052734, -1027.8570556641, 32.1015625, 27 ) 
    function Mecjob(hitElement) 
        if getElementType(hitElement) == "player" then 
            triggerClientEvent(hitElement,"marker",leaveElement,true) 
        end 
    end 
    addEventHandler("onMarkerHit", marker, Mecjob) 
          
    function Mecjobleave(leaveElement) 
        if getElementType(leaveElement) == "player" then 
            triggerClientEvent(leaveElement,"marker",leaveElement,false) 
        end 
    end 
    addEventHandler("onMarkerLeave", marker, Mecjobleave) 
          
        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:

    
    --- 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 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) 
     
    addEvent("marker",true) 
    addEventHandler("marker",root,function(bool) 
        if(bool)then 
            guiSetVisible(windowjob, bool) 
            showCursor(bool) 
        end 
    end) 

Edited by Guest
Link to comment
windowjob = guiMyCwindow(301,250,"Mchanic job") 

what is that ?

Use:

function centerWindow(center_window) 
    local screenW,screenH=guiGetScreenSize() 
    local windowW,windowH=guiGetSize(center_window,false) 
    local x,y = (screenW-windowW)/2,(screenH-windowH)/2 
    guiSetPosition(center_window,x,y,false) 
end 
windowjob = (0,0,301,250,"Mchanic job", false) 
centerWindow( windowjob ) 
  

Link to comment
Guest Guest4401

@Jaysds1

In your code you everytime I see guiSetVisible(windowjob, false). Even when you trigger that "marker" event you are triggering false everytime. So as a result, the gui is never visible, but is created.

Also, in onMarkerHit event's attached function, you have mentioned the 1st parameter as hitElement, but while triggering you wrote leaveElement instead of hitElement. So this will give an error:

    function Mecjob(hitElement) 
        if getElementType(hitElement) == "player" then 
            triggerClientEvent(leaveElement,"marker",leaveElement,false) 
        end 
    end 
    addEventHandler("onMarkerHit", marker, Mecjob) 

@Blazy

The problem is not with creating the window. guiMyCwindow will work, because there is such a function made.

    function guiMyCwindow(w,h,t) 
        local x,y = guiGetScreenSize() 
        return guiCreateWindow((x-w)/2,(y-h)/2,w,h,t,false) 
    end 

You forgot guiCreateWindow here:

windowjob = (0,0,301,250,"Mchanic job", false) 

Link to comment
  • 1 year later...

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