Monty Posted May 25, 2012 Share Posted May 25, 2012 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
Kenix Posted May 25, 2012 Share Posted May 25, 2012 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
Jaysds1 Posted May 25, 2012 Share Posted May 25, 2012 (edited) 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 May 26, 2012 by Guest Link to comment
Monty Posted May 26, 2012 Author Share Posted May 26, 2012 the gui doesn't get created Link to comment
Wei Posted May 26, 2012 Share Posted May 26, 2012 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 Posted May 26, 2012 Share Posted May 26, 2012 @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
Jaysds1 Posted May 26, 2012 Share Posted May 26, 2012 lol, thanks for telling karthik... I think this week is a bad week for me... Anyways, I've edited the script again, try it again Monty Link to comment
TAPL Posted October 26, 2013 Share Posted October 26, 2013 Double function? addEventHandler("onClientPlayerDamage",root,function()function(attacker, weapon, bodypart, loss) Edit: The script itself make no sense, what have mechanic job to do with event onClientPlayerDamage and health 100 and Heal > 100 and + 10 and even health not defined here if (health <= 99) then. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now