Jump to content

Tron

Members
  • Posts

    16
  • Joined

  • Last visited

About Tron

  • Birthday 16/02/2000

Details

  • Gang
    [Hero]
  • Location
    Bahrain
  • Occupation
    Scripting

Recent Profile Visitors

971 profile views

Tron's Achievements

Square

Square (6/54)

3

Reputation

  1. Tron

    Team script error

    Nvm fixed it already, had to pass as function instead of calling in the same line. Thanks alot for helping out buddy i'll let you know if i get more bugs with the arena script.
  2. Tron

    Team script error

    Client.lua codes of the arena system: local sx, sy = guiGetScreenSize () local relposx = sx/2 local medX = sx/2 local ancho = -3780 local sizeX = ancho/3 local mitSize = sizeX*0.5 local botX = medX-mitSize local relposx = sy/2 local medX2 = sy/2 local ancho2 = -2160 local sizeX2 = ancho2/3 local mitSize2 = sizeX2*0.5 local botX2 = medX2-mitSize2 local TimesInRespawnText = 5 local mainFont = dxCreateFont("Arquivos/Fontes/mainFont.ttf", 10) local mainFont2 = dxCreateFont("Arquivos/Fontes/mainFont.ttf", 13) local text = "" local screenW,screenH = guiGetScreenSize() local resW,resH = 1280,720 local sW,sH = (screenW/resW), (screenH/resH) function commandGM (_, event) if not event then if isEventAdded then showChat(true) removeEventHandler ("onClientRender", root, selectedItem) else addEventHandler ("onClientRender", root, selectedItem) end isEventAdded = not isEventAdded showCursor (isEventAdded) elseif event == "hydra" then triggerServerEvent(getResourceName(getThisResource())..": addPlayerHydra", localPlayer) elseif event == "hunter" then triggerServerEvent(getResourceName(getThisResource())..": addPlayerHunter", localPlayer) end end addCommandHandler("openarena", commandGM, true) addCommandHandler("arena", commandGM, true) addEventHandler("onClientClick",root, function (button, state) showChat(true) if (isEventAdded) then if (button == "left" and state == "down") then if (isCursorOnElement(280*sW,370*sH,225*sW, 50*sH)) then triggerServerEvent(getResourceName(getThisResource())..": addPlayerHunter", localPlayer) isEventAdded = false removeEventHandler ("onClientRender", root, selectedItem) showCursor (isEventAdded) elseif (isCursorOnElement(35*sW,370*sH,225*sW, 50*sH)) then triggerServerEvent(getResourceName(getThisResource())..": addPlayerHydra", localPlayer) isEventAdded = false removeEventHandler ("onClientRender", root, selectedItem) showCursor (isEventAdded) elseif (isCursorOnElement (1245*sW,1*sH,30*sW,17*sH)) then isEventAdded = false removeEventHandler ("onClientRender", root, selectedItem) showCursor (isEventAdded) end end end end ) function selectedItem () showChat(false) dxDrawImage ( 1*sW, 1*sH, 1278*sW, 718*sH, 'background.png', angle, 0, -120 ) dxDrawRectangle(1*sW, 1*sH, 1278*sW, 718*sH, tocolor(0, 0, 0, 200), true) dxDrawRectangle(1*sW, 1*sH, 1278*sW, 20*sH, tocolor(185, 122, 87, 180), true) dxDrawText("Arena Selection Menu", 539*sW, -4*sH, 911*sW, 27*sH, tocolor(255, 127, 39, 255), 1.3, 'default-bold', 'left', 'center', false, false, true, false, false) dxDrawText("X",1255*sW,26*sH, 911*sW, -2*sH, isCursorOnElement(1245*sW,1*sH,30*sW,17*sH) and tocolor(255, 255, 255, 255) or tocolor(255, 127, 39, 255), 1.4, 'default-bold', 'left', 'center', false, false, true, false, false) dxDrawText("Hydra Blast v1.0", 1109*sW, 94*sH, 911*sW, 27*sH, tocolor(255, 255, 255, 255), 1.2, 'arial', 'left', 'center', false, false, true, false, false) dxDrawImage(30*sW,34*sH, 180*sW, 60*sH, "arena.png", 0, 0, 0, tocolor(255, 255, 255, 255), true) dxDrawText("Select an arena to play on", 79*sW, 210*sH, 911*sW, 27*sH, tocolor(255, 255, 255, 255), 1.4, 'clear', 'left', 'center', false, false, true, false, false) dxDrawImage(35*sW,140*sH, 225*sW, 282*sH, "Img/dogfight.png", 0, 0, 0, tocolor(255, 255, 255, 255), true) dxDrawImage(280*sW,140*sH, 225*sW, 282*sH, "Img/hunter.png", 0, 0, 0, tocolor(255, 255, 255, 255), true) dxDrawImage(525*sW,140*sH, 225*sW, 282*sH, "Img/stunt.png", 0, 0, 0, tocolor(255, 255, 255, 255), true) dxDrawImage(770*sW,140*sH, 225*sW, 282*sH, "Img/freeroam.png", 0, 0, 0, tocolor(255, 255, 255, 255), true) dxDrawImage(1015*sW,140*sH, 225*sW, 282*sH, "Img/minigames.png", 0, 0, 0, tocolor(255, 255, 255, 255), true) dxDrawText("Dogfight Arena",87*sW,792*sH,911*sW, -2*sH, isCursorOnElement(35*sW,370*sH,225*sW, 50*sH) and tocolor(30, 170, 66, 255) or tocolor(136, 0, 21, 255), 1.4, 'default-bold', 'left', 'center', false, false, true, false, false) dxDrawText("Protect the City",340*sW,792*sH,911*sW, -2*sH, isCursorOnElement(280*sW,370*sH,225*sW, 50*sH) and tocolor(30, 170, 66, 255) or tocolor(136, 0, 21, 255), 1.4, 'default-bold', 'left', 'center', false, false, true, false, false) dxDrawImage(30*sW,450*sH, 180*sW, 60*sH, "donate.png", 0, 0, 0, tocolor(255, 255, 255, 255), true) dxDrawText("By donation towards our community you are supporting the future of", 79*sW, 1050*sH, 911*sW, 27*sH, tocolor(255, 255, 255, 255), 1.4, 'arial', 'left', 'center', false, false, true, false, false) dxDrawText("Hydra Blast [HB]. Our goal is to create a cozy and comfortable", 79*sW, 1090*sH, 911*sW, 27*sH, tocolor(255, 255, 255, 255), 1.4, 'arial', 'left', 'center', false, false, true, false, false) dxDrawText("atmosphere for gaming on MTA. Even a small amount of money that", 79*sW, 1130*sH, 911*sW, 27*sH, tocolor(255, 255, 255, 255), 1.4, 'arial', 'left', 'center', false, false, true, false, false) dxDrawText("you have donated will help us to keep our server alive and running.", 79*sW, 1170*sH, 911*sW, 27*sH, tocolor(255, 255, 255, 255), 1.4, 'arial', 'left', 'center', false, false, true, false, false) dxDrawText("To donate and recieve the benifits of 'Contributor' status go to our", 79*sW, 1210*sH, 911*sW, 27*sH, tocolor(255, 255, 255, 255), 1.4, 'arial', 'left', 'center', false, false, true, false, false) dxDrawText("website at: coming soon!", 79*sW, 1250*sH, 911*sW, 27*sH, tocolor(255, 255, 255, 255), 1.4, 'arial', 'left', 'center', false, false, true, false, false) dxDrawImage(690*sW,450*sH, 180*sW, 60*sH, "statistics.png", 0, 0, 0, tocolor(255, 255, 255, 255), true) dxDrawImage(790*sW,520*sH, 180*sW, 60*sH, "BAR.png", 0, 0, 0, tocolor(255, 255, 255, 255), true) dxDrawImage(1000*sW,515*sH, 60*sW, 60*sH, "BAR2.png", 0, 0, 0, tocolor(255, 255, 255, 255), true) dxDrawImage(790*sW,600*sH, 180*sW, 60*sH, "BAR.png", 0, 0, 0, tocolor(255, 255, 255, 255), true) dxDrawImage(1000*sW,595*sH, 60*sW, 60*sH, "BAR2.png", 0, 0, 0, tocolor(255, 255, 255, 255), true) local count=getPlayerCount() dxDrawText("Online Players", 819*sW, 1060*sH, 911*sW, 27*sH, tocolor(255, 255, 255, 255), 1.4, 'arial', 'left', 'center', false, false, true, false, false) dxDrawText(count, 1025*sW, 1065*sH, 911*sW, 27*sH, tocolor(255, 255, 255, 255), 1.6, 'arial', 'left', 'center', false, false, true, false, false) dxDrawText("Online Staffs", 819*sW, 1220*sH, 911*sW, 27*sH, tocolor(255, 255, 255, 255), 1.4, 'arial', 'left', 'center', false, false, true, false, false) dxDrawText("#", 1025*sW, 1225*sH, 911*sW, 27*sH, tocolor(255, 255, 255, 255), 1.6, 'arial', 'left', 'center', false, false, true, false, false) end local originalGetPlayerCount = getPlayerCount -- Store the original getPlayerCount function to a variable function getPlayerCount() -- If originalGetPlayerCount is defined, that means that this function is executed serverside. -- The next line returns the result of the original function if it's defined. If not, it counts the number of player elements (to also work clientside). return originalGetPlayerCount and originalGetPlayerCount() or #getElementsByType("player") end function textScreenDx () dxDrawText(text, botX+sizeX+380, botX2+sizeX2+600, 50, 50, tocolor(255, 255, 255, 255), 2, "default-bold", "left", "top", false, false, true, true, false) end function respawnText () dxDrawText("Respawning in: #00ff88"..TimesInRespawnText, botX+sizeX+440, botX2+sizeX2+500, 50, 50, tocolor(255, 255, 255, 255), 2, "default-bold", "left", "top", false, false, true, true) end function respawnPlayer () if (getElementData(localPlayer, "MultiGM") == "Hunter" ) and getElementDimension(localPlayer) == 2 then addEventHandler("onClientRender", root, respawnText) setElementData(localPlayer, "Morreu", 1) setTimeSeconds = setTimer ( function () TimesInRespawnText = TimesInRespawnText - 1 if TimesInRespawnText == 0 then removeEventHandler("onClientRender", root, respawnText) killTimer(setTimeSeconds) triggerServerEvent(getResourceName(getThisResource())..": respawnPlayer", localPlayer) TimesInRespawnText = 5 end end, 1000, 0) elseif (getElementData(localPlayer, "MultiGM") == "Hydra") and getElementDimension(localPlayer) == 1 then addEventHandler("onClientRender", root, respawnText) setElementData(localPlayer, "Morreu", 1) setTimeSeconds = setTimer ( function () TimesInRespawnText = TimesInRespawnText - 1 if TimesInRespawnText == 0 then setElementData(localPlayer, "Morreu", 2) removeEventHandler("onClientRender", root, respawnText) killTimer(setTimeSeconds) triggerServerEvent(getResourceName(getThisResource())..": respawnPlayer", localPlayer) TimesInRespawnText = 5 end end, 1000, 0) end end --Tron Progress Bar --local per = 0 --addEventHandler ( 'onClientRender', root, function ( ) -- dxDrawRectangle ( 0, 0, per*2, 20 ) -- if ( per < 100 ) then per = per + 1 end --end ) --local hpMin = 176 --local hpMax = 135 -- local hpRate = hpMin-hpMax -- local hp = hpMin-((getElementHealth(getLocalPlayer())*hpRate)/100) -- dxDrawCircle( 220,796,110, 15,0.01,hp,hpMin,tocolor(255,0,0,255)) addEvent(getResourceName(getThisResource())..": respawnPlayer", true) addEventHandler(getResourceName(getThisResource())..": respawnPlayer", root, respawnPlayer) function textScreen (inp) text = inp addEventHandler("onClientRender", root, textScreenDx) setTimer( function () removeEventHandler("onClientRender", root, textScreenDx) end, 3000, 1) end addEvent(getResourceName(getThisResource())..": textScreen", true) addEventHandler(getResourceName(getThisResource())..": textScreen", root, textScreen) function onClientKey (press, button) if (press) then if (getElementData(localPlayer, "MultiGM") and button == "F1") then cancelEvent() end end end function isCursorOnElement(x,y,w,h) if (not isCursorShowing()) then return false; end local mx, my = getCursorPosition (); cursorx, cursory = mx*sx, my*sy; if cursorx > x and cursorx < x + w and cursory > y and cursory < y + h then return true; else return false; end end Server.lua codes of the arena system:
  3. There's a error in the script at line 93 https://imgur.com/a/V5VWH
  4. Tron

    Team script error

    I''ve exported the function commandGM and called it in freeroam client under the arena button but it shows when every player reconnects instead of showing on clicking the button. It doesn't shows anything when you click the button. Here's the codes: Arena Menu's client file: [Exported function] -------------------------------------- ---- Arena menu ---- -------------------------------------- function commandGM (_, event) if not event then if isEventAdded then showChat(true) removeEventHandler ("onClientRender", root, selectedItem) else addEventHandler ("onClientRender", root, selectedItem) end isEventAdded = not isEventAdded showCursor (isEventAdded) elseif event == "hydra" then triggerServerEvent(getResourceName(getThisResource())..": addPlayerHydra", localPlayer) elseif event == "hunter" then triggerServerEvent(getResourceName(getThisResource())..": addPlayerHunter", localPlayer) end end addCommandHandler("openarena", commandGM, true) addCommandHandler("arena", commandGM, true) Arena menu's meta file[Exported the function commandGM]:- <export function="commandGM" type="client"/> Freeroam's client file:- wndMain = { 'wnd', text = 'Hydra Blast Console', x = 10, y = 150, width = 280, alpha = 1.0, controls = { {'lbl', id='nmlbl', text='Name :'}, {'lbl', id='plrname', text=getPlayerName( g_Me ), width=200, height = 20}, {'br'}, {'lbl', id='Pinglbl', text='Ping :'}, {'lbl', id='plrPing', text=getPlayerPing( g_Me ), width=80, height = 20}, {'br'}, {'lbl', id='Moneylbl', text='Money :'}, {'lbl', id='plrMoney', text=getPlayerMoney( g_Me ), width=80, height = 20}, {'br'}, {'lbl', id='myPos', text='Position:', width=80, height = 20}, {'lbl', id='xpos', text='x', width=45}, {'lbl', id='ypos', text='y', width=45}, {'lbl', id='zpos', text='z', width=45}, {'br'}, {'lbl', id='linelbl1', text='====================================================', width=250, height = 20}, {'br'}, {'btn', id='Kill', onclick=killLocalPlayer, width=80, height = 20}, {'btn', id='Skin', window=wndSkin, width=80, height = 20}, {'btn', id='Anim', window=wndAnim, width=80, height = 20}, {'btn', id='Clothes', window=wndClothes, width=80, height = 20}, {'btn', id='Weapons', window=wndWeapon, width=80, height = 20}, {'btn', id='Arenas', onclick=exports[ "[Test]Multigamemode" ]:commandGM(_,event), width=80, height = 20}, {'btn', id='Stats', window=wndStats, width=80, height = 20}, {'br'}, {'chk', id='falloff', text='Fall off bike', onclick=toggleFallOffBike, width=150, height = 20}, {'chk', id='togglewarptme', text='Block warp to me', onclick=togglewarptome, width=1000, height = 20}, {'br'}, {'lbl', id='linelbl2', text='====================================================', width=250, height = 20}, {'br'}, {'btn', id='setpos', text='Map', window=wndSetPos, width=80, height = 20}, {'br'}, {'lbl', id='linelbl3', text='====================================================', width=250, height = 20}, {'br'}, {'lbl', id='vehlbl', text='Vehicle:', width=80, height = 20}, {'br'}, {'lbl', id='curlbl', text='Current:', width=80, height = 20}, {'lbl', id='curvehicle', width=80, height = 20}, {'br'}, {'btn', id='createvehicle', window=wndCreateVehicle, text='Create', width=80, height = 20}, {'btn', id='Repair', onclick=repairVehicle, width=80, height = 20}, {'btn', id='Flip', onclick=flipVehicle, width=80, height = 20}, {'btn', id='Upgrades', window=wndUpgrades, width=80, height = 20}, {'btn', id='Color', onclick=openColorPicker, width=80, height = 20}, {'btn', id='Paintjob', window=wndPaintjob, width=80, height = 20}, {'br'}, {'chk', id='lightson', text='Lights on', onclick=forceLightsOn, width=87, height = 20}, {'chk', id='lightsoff', text='Lights off', onclick=forceLightsOff, width=87, height = 20}, }, oncreate = mainWndShow, onclose = mainWndClose }
  5. Tron

    Team script error

    Now its working fine. I wanted to add the arena menu in f1(freeroam console). When you click the 'Arenas' button it must open the arena menu of the resource. The arena resource is named as '[Test]Multigamemode'. Incase if the player is already in arena and he clicks the arena button it must show something like "You are already in a arena, please use /exitarena to exit and join again". Currently /arena is used to open the arena selection menu. https://imgur.com/a/JDZ8r
  6. Tron

    Team script error

    Here's the result: https://imgur.com/a/BVkbj
  7. Hello out there, https://imgur.com/a/Pkkdn As you can see in the above link that the hydra lock appears when you lock via handbrake, but the problem is when you shoot the missiles it never kills the opponent. It reduces the hp of the opponent a bit. I wanted it so that the missiles have 90% chance of killing the opponent. Here's the script of the lock on fire : ----User settings--- local SHOOT_COOLDOWN = 1500 --Cooldown between homing shots local LOCKON_TIME = 1500 --Time required to lock on to a target local LOCK_RANGE = 330 --Maximum distance between you and the target local LOCK_ANGLE = 0.95 --(in radians) We cannot lock on targets unless they are within this angle of the front of the hydra local VALID_TARGET_FUNCTION = function (vehicle) --Used to decide whether a vehicle should appear as a lock-on option -- local targetTeam = vehicle.controller and vehicle.controller.team -- local ourTeam = localPlayer.team -- if targetTeam and ourTeam and targetTeam == ourTeam then -- return false --The target vehicle has someone driving, and both of you are on the same team -- end return true end --[[ to implement team tagging, or to disallow certain vehicles from being targetted, define the VALID_TARGET_FUNCTION VALID_TARGET_FUNCTION should take as parameter a vehicle, and return a boolean (true means it can be targetted) Here is an example of a function that will only let us target HYDRAS of OTHER TEAMS that are MORE THAN 50m AWAY and are DIRECTLY VISIBLE local VALID_TARGET_FUNCTION = function(vehicle) local targetTeam = vehicle.controller and vehicle.controller.team local ourTeam = localPlayer.team if targetTeam and ourTeam and targetTeam == ourTeam then return false --The target vehicle has someone driving, and both of you are on the same team end if vehicle.model ~= 520 then return false --Target is not a hydra, so it's not allowed end if (vehicle.position-localPlayer.position).length < 50 then return false --Closer than 50 metres end if not isLineOfSightClear(localPlayer.position, vehicle.position, true, false) then return false --Not directly visible --(Remember to account for your own vehicle and the target blocking the line) end return true --Target satisfied all criteria end ]] local validTarget = VALID_TARGET_FUNCTION or function() return true end LOCK_ANGLE = math.cos(LOCK_ANGLE) local inHydra = false local firestate = nil local visibleVehicle = {} local targetVehicle = nil local nearbyVehicles = {} getNearbyVehicles = function() return nearbyVehicles end --Used by other files local currentHydra = nil local function getTarget() -- Look for the nearest targets and lock on local nearestVehicle = nil local shortestDistance = LOCK_RANGE for _, vehicle in ipairs(nearbyVehicles) do local targPos = vehicle.position local myPos = localPlayer.position local displacement = targPos-myPos local dist = displacement.length if vehicle ~= localPlayer.vehicle and dist < shortestDistance then shortestDistance = dist nearestVehicle = vehicle end end return nearestVehicle end local function checkForLockout(vehicle) if visibleVehicle[vehicle] then triggerEvent("onClientHydraMissilesSystemLockout", localPlayer, vehicle) visibleVehicle[vehicle] = nil lockedVehicle = nil targetVehicle = nil end end local lastShot = SHOOT_COOLDOWN*-2 local function shootMissile() if not inHydra then return end local target = lockedVehicle if not target or getTickCount() < lastShot + SHOOT_COOLDOWN then return end lastShot = getTickCount() local hydra = localPlayer.vehicle local vX, vY, vZ = hydra.velocity -- Shoot missile createProjectile( hydra, 20, hydra.position, 5000, target, _, _, _, vX+5000, vY, vZ) -- dxDrawText ( playerZoneName, 44, screenHeight - 43, screenWidth, screenHeight, tocolor ( 255, 255, 255, 255 ), 1, "pricedown" ) DRAW WARNING ON PLAYER SCREEN lockedVehicle = nil targetVehicle = nil visibleVehicle[target] = nil end local function update() local curtime = getTickCount() if not localPlayer.vehicle then --idk why, but sometimes the player has no vehicle sometime before vehicle exit event is fired stopHydra() --The Avengers return end local vehicle = targetVehicle if not vehicle then return end local visibleNow = false if vehicle ~= localPlayer.vehicle and not vehicle.blown and validTarget(vehicle) then local targPos = vehicle.position local myPos = localPlayer.position local displacement = targPos-myPos local dist = displacement.length local cosAngle = localPlayer.vehicle.matrix.forward:dot(displacement)/dist if dist < LOCK_RANGE and cosAngle>LOCK_ANGLE and firestate then local aX, aY = getScreenFromWorldPosition(targPos) if (aX and aY) then visibleNow = true --Draw the corners of the target box outline if lockedVehicle == vehicle then dxDrawImage (aX-118,aY-118, 246, 246, 'lock.png') else dxDrawImage (aX-118, aY-118, 246, 246, 'lock2.png') end end end end if not visibleNow then checkForLockout() elseif visibleVehicle[vehicle] then if curtime - visibleVehicle[vehicle] > LOCKON_TIME then lockedVehicle = vehicle end else visibleVehicle[vehicle] = curtime end end local function homingState(key,state) if not inHydra then return end if state == "down" then targetVehicle = getTarget() firestate = isControlEnabled("vehicle_secondary_fire") toggleControl("vehicle_secondary_fire",false) bindKey("vehicle_secondary_fire","down",shootMissile) else targetVehicle = nil lockedVehicle = nil toggleControl("vehicle_secondary_fire",firestate) firestate = nil unbindKey("vehicle_secondary_fire","down",shootMissile) end end local function vehicleGoneHandler() --This also triggers on localPlayer's vehicle, and does nothing to it removeEventHandler("onClientElementDestroy", source, vehicleGoneHandler) removeEventHandler("onClientElementStreamOut", source, vehicleGoneHandler) if getElementType( source ) == "vehicle" then for i, v in ipairs(nearbyVehicles) do if v == source then checkForLockout(source) table.remove(nearbyVehicles, i) return end end end end local function prepAfterStreamIn(vehicle) addEventHandler("onClientElementStreamOut", vehicle, vehicleGoneHandler) addEventHandler("onClientElementDestroy", vehicle, vehicleGoneHandler) end local function streamInHandler() if getElementType( source ) == "vehicle" then table.insert(nearbyVehicles, source) prepAfterStreamIn(source) end end local function startHydra(vehicle) if not inHydra and vehicle and isElement(vehicle) and vehicle.model == 520 then nearbyVehicles = getElementsByType("vehicle", root, true) for i, v in ipairs(nearbyVehicles) do prepAfterStreamIn(v) end addEventHandler("onClientElementStreamIn", root, streamInHandler) addEventHandler("onClientVehicleExplode", vehicle, stopHydra) addEventHandler("onClientElementDestroy", vehicle, stopHydra) addEventHandler("onClientElementStreamOut", vehicle, stopHydra) --Is this even possible? inHydra = isControlEnabled("handbrake") currentHydra = vehicle --To remove the listeners later toggleControl("handbrake", false) bindKey("handbrake","down",homingState) bindKey("handbrake","up",homingState) addEventHandler( "onClientRender", root, update) end end function stopHydra() if inHydra then local target = getTarget() for i, v in ipairs(nearbyVehicles) do if v ~= target then removeEventHandler("onClientElementDestroy", v, vehicleGoneHandler) removeEventHandler("onClientElementStreamOut", v, vehicleGoneHandler) checkForLockout(v) end end checkForLockout(target) if target then removeEventHandler("onClientElementDestroy", target, vehicleGoneHandler) removeEventHandler("onClientElementStreamOut", target, vehicleGoneHandler) end removeEventHandler("onClientRender", root, update) unbindKey("handbrake","down",homingState) unbindKey("handbrake","up",homingState) if firestate ~= nil then homingState("handbrake","up") end local vehicle = currentHydra currentHydra = nil toggleControl("handbrake", inHydra) inHydra = false removeEventHandler("onClientElementStreamIn", root, streamInHandler) if isElement(vehicle) then removeEventHandler("onClientVehicleExplode", vehicle, stopHydra) removeEventHandler("onClientElementDestroy", vehicle, stopHydra) removeEventHandler("onClientElementStreamOut", vehicle, stopHydra) end end end local function initScript() if localPlayer.vehicle and localPlayer.vehicle.model == 520 then startHydra(localPlayer.vehicle) end addEventHandler("onClientResourceStop", resourceRoot, stopHydra) addEventHandler("onClientPlayerVehicleExit",localPlayer,stopHydra) addEventHandler("onClientPlayerWasted",localPlayer,stopHydra) addEventHandler("onClientPlayerVehicleEnter",localPlayer,startHydra) end addEventHandler("onClientResourceStart",resourceRoot,initScript)
  8. Tron

    Team script error

    nvm there was a mistake in line 172: replaced '-' with '='. ? aPlayers[source] - nil After joining the arena when you execute /exitarena it doesn't adds you back in your previous clan. Player remains clan less. Changing nick while in arena is creating some sort of bugs too, i've a script of clan tag on, if you put on the tag of the clan you will be added in the clan. I guess it would be better if changing nick while in arena is blocked for all the arenas. Player must see a msg on the chatbox something like ("You can't change your nick while in arena, please exit the arena inorder to change your nick).
  9. Tron

    Team script error

    it shows error in the debug script. https://imgur.com/a/zl0Gi
  10. Tron

    Team script error

    Now that bug is fixed. There's another problem now, sometimes when you execute /exitarena it removes you from the arena and team but adds again into a team from those 3 teams eventhough you aren't in the arena. Sometimes its not even adding you in your previous team if you execute /exitarena and join again repeatedly. There are no errors in debugscript 3 I've updated the respawn function, also how can i set the teams so that the equality of members is approximately maintained rather than having unequal members in every team. addEventHandler ("onResourceStart", getResourceRootElement(getThisResource()), function() local allGreenzones = getElementsByType ("radararea") for i,v in ipairs (allGreenzones) do local r, g, b, a = getRadarAreaColor (v) if (r == 255) and (g == 0) and (b == 0) and (a == 255) then local x, y = getElementPosition (v) local sx, sy = getRadarAreaSize (v) setRadarAreaFlashing(v, true) local col = createColCuboid (x, y, -50, sx, sy, 7500) setElementID (col, "ColShapeMultiGameMode") end end end ) spawnVehPositions = { {-1292.8455810547, -364.38061523438, 15.8}, {-1350.6311035156, -258.98291015625, 14.14396572113}, {-1467.52734375, -190.3069152832, 14.1484375}, {-1620.8626708984, -51.465915679932, 3.5595684051514}, {-1620.2762451172, -590.58685302734, 14.1484375}, } spawnarena2Positionsmilitants = { {789.79999, -2120.3999, 14.1484375}, {795.5, -2228, 15.4}, {795.70001, -2218.8, 15.2}, } spawnarena2Positionsinvaders = { {649.29999, -2409.3, 83}, {623.40002, -2498.3999, 71.9}, {623.70001, -2497.8, 71.9}, } spawnarena2Positionsinsurgents = { {502.20001, -2297.2, 124.6}, {456.60001, -2256.8999, 128.3}, {450.29999, -2258.3, 128.3}, } addEventHandler("onColShapeLeave", root, function (Jogador) if (getElementData(Jogador, "MultiGM") and getElementByID("ColShapeMultiGameMode")) then if (not getElementData(Jogador, "Morreu")) then if (Vehicle[Jogador] and isElement(Vehicle[Jogador])) then destroyElement(Vehicle[Jogador]) triggerClientEvent(Jogador, getResourceName(getThisResource())..": textScreen", root, "#ffffffWarning:-You've crossed the arena boundary!") end removeElementData(Jogador, "MultiGM") end end end ) addEventHandler("onColShapeHit", root, function (Jogador) if (not getElementData(Jogador, "MultiGM")) and getElementByID("ColShapeMultiGameMode") then if ( getElementDimension(Jogador) == 1 ) then setElementData(Jogador, "MultiGM", "Hydra") elseif ( getElementDimension(Jogador) == 2) then setElementData(Jogador, "MultiGM", "Hunter") end end end ) Vehicle = {} function spawnVehMarker (Jogador) if (getElementDimension(Jogador) == 2) then if (Vehicle[Jogador] and isElement(Vehicle[Jogador])) then destroyElement(Vehicle[Jogador]) end local x, y, z = getElementPosition(Jogador) Vehicle[Jogador] = createVehicle(425, x, y, z+1) --warpPedIntoVehicle(Jogador, Vehicle[Jogador]) setElementData(Jogador, "MultiGM", "Hunter") elseif ( getElementDimension(Jogador) == 1 ) then if (Vehicle[Jogador] and isElement(Vehicle[Jogador])) then destroyElement(Vehicle[Jogador]) end local x, y, z = getElementPosition(Jogador) Vehicle[Jogador] = createVehicle(520, x, y, z+1) --warpPedIntoVehicle(Jogador, Vehicle[Jogador]) setElementData(Jogador, "MultiGM", "Hydra") end end for _, v in ipairs (spawnVehPositions) do MarkerHunter = createMarker(v[1], v[2], v[3]+0.6, "checkpoint", 1, 185, 122, 87, 255 ) MarkerHydra = createMarker(v[1], v[2], v[3]+0.6, "checkpoint", 1, 185, 122, 87, 255 ) setElementDimension(MarkerHunter, 2) setElementDimension(MarkerHydra, 1) addEventHandler("onMarkerHit", MarkerHunter, spawnVehMarker) addEventHandler("onMarkerHit", MarkerHydra, spawnVehMarker) end addEvent(getResourceName(getThisResource())..": respawnPlayer", true) addEventHandler(getResourceName(getThisResource())..": respawnPlayer", root, function () if getElementData(source, "Morreu") == 1 then local pX, pY, pZ = unpack(spawnVehPositions[math.random(#spawnVehPositions)]) --setElementPosition(source, pX, pY, pZ) local activeteam = getPlayerTeam (source) if activeteam and getTeamName(activeteam)=="Militants" then local mX, mY, mZ = unpack(spawnarena2Positionsmilitants[math.random(#spawnarena2Positionsmilitants)]) setElementPosition(source, mX, mY, mZ) elseif activeteam and getTeamName(activeteam)=="Invaders" then local inX, inY, inZ = unpack(spawnarena2Positionsinvaders[math.random(#spawnarena2Positionsinvaders)]) setElementPosition(source, inX, inY, inZ) elseif activeteam and getTeamName(activeteam)=="Insurgents"then local isX, isY, isZ = unpack(spawnarena2Positionsinsurgents[math.random(#spawnarena2Positionsinsurgents)]) setElementPosition(source, isX, isY, isZ) end setElementDimension(source, 2) removeElementData(source, "Morreu") elseif getElementData(source, "Morreu") == 2 then --local pX, pY, pZ = unpack(spawnVehPositions[math.random(#spawnVehPositions)]) setElementPosition(source, pX, pY, pZ) setElementDimension(source, 1) removeElementData(source, "Morreu") end end ) local newTeam1 local newTeam2 local newTeam3 local originalteam -- to store the team of player before joining the arena addEvent(getResourceName(getThisResource())..": addPlayerHunter", true) addEventHandler(getResourceName(getThisResource())..": addPlayerHunter", root, function () if (getPedOccupiedVehicle(source)) then return triggerClientEvent(source, getResourceName(getThisResource())..": textScreen", root, "Get out of your current vehicle to get into GM!") elseif (getElementData(source, "MultiGM") == "Hydra") then removeElementData(source, "MultiGM") end originalteam = getPlayerTeam (source) local teams = {"Militants","Invaders","Insurgents"} if not getTeamFromName(teams[1]) then newTeam1 = createTeam ( "Militants", 0, 255, 0 ) newTeam2 = createTeam ( "Invaders", 100, 0, 20) newTeam3 = createTeam ( "Insurgents", 50, 100, 50) end local randomteam = teams[math.random(#teams)] setPlayerTeam(source, getTeamFromName(randomteam)) local activeteam = getPlayerTeam (source) -- joined team if activeteam and getTeamName(activeteam)=="Militants" then local mX, mY, mZ = unpack(spawnarena2Positionsmilitants[math.random(#spawnarena2Positionsmilitants)]) setElementPosition(source, mX, mY, mZ) elseif activeteam and getTeamName(activeteam)=="Invaders" then local inX, inY, inZ = unpack(spawnarena2Positionsinvaders[math.random(#spawnarena2Positionsinvaders)]) setElementPosition(source, inX, inY, inZ) elseif activeteam and getTeamName(activeteam)=="Insurgents"then local isX, isY, isZ = unpack(spawnarena2Positionsinsurgents[math.random(#spawnarena2Positionsinsurgents)]) setElementPosition(source, isX, isY, isZ) end triggerClientEvent(source, getResourceName(getThisResource())..": textScreen", root, "You entered the Hunter Arena. To exit just type /exitarena") setElementData(source, "MultiGM", "Hunter") --setElementPosition(source, pX, pY, pZ) setElementDimension(source, 2) end ) addEvent(getResourceName(getThisResource())..": addPlayerHydra", true) addEventHandler(getResourceName(getThisResource())..": addPlayerHydra", root, function () if (getPedOccupiedVehicle(source)) then return triggerClientEvent(source, getResourceName(getThisResource())..": textScreen", root, "Get out of your current vehicle to get into GM!") elseif (getElementData(source, "MultiGM") == "Hunter") then elseif (getElementData(source, "MultiGM") == "Hunter") then removeElementData(source, "MultiGM") end triggerClientEvent(source, getResourceName(getThisResource())..": textScreen", root, "You entered the Dogfight Arena. To exit just type /exitarena") local pX, pY, pZ = unpack(spawnVehPositions[math.random(#spawnVehPositions)]) setElementData(source, "MultiGM", "Hydra") setElementPosition(source, pX, pY, pZ) setElementDimension(source, 1) end ) addEventHandler("onPlayerWasted", root, function (_, attacker) if (getElementData(source, "MultiGM")) then triggerClientEvent(source, getResourceName(getThisResource())..": respawnPlayer", root) if (attacker) then if (getElementType(attacker) == "player" and getElementData(attacker, "MultiGM")) then triggerClientEvent(attacker, getResourceName(getThisResource())..": textScreen", root, "You've killed: "..getPlayerName(source).."!") triggerClientEvent(source, getResourceName(getThisResource())..": textScreen", root, "You've been killed by: "..getPlayerName(attacker).."!") elseif (getElementType(attacker) == "vehicle" and getElementData(getVehicleOccupant(attacker), "MultiGM")) then triggerClientEvent(getVehicleOccupant(attacker), getResourceName(getThisResource())..": textScreen", root, "You've killed: "..getPlayerName(source).."!") triggerClientEvent(source, getResourceName(getThisResource())..": textScreen", root, "You've been killed by: "..getPlayerName(getVehicleOccupant(attacker)).."!") end else triggerClientEvent(source, getResourceName(getThisResource())..": textScreen", root, "#ffffffYou've committed suicide!") end end end ) addCommandHandler("exitarena", function (Jogador) if (getElementData(Jogador, "MultiGM")) then if Vehicle[Jogador] and isElement(Vehicle[Jogador]) then destroyElement(Vehicle[Jogador]) end removeElementData(Jogador, "MultiGM") setElementDimension(Jogador, 0) killPed(Jogador) triggerClientEvent(Jogador, getResourceName(getThisResource())..": textScreen", root, "You've left the arena successfully!") local currentteam = getPlayerTeam (Jogador) -- gets the current players team if (currentteam ) then --checks if the player is in a team by checking if playerTeam returned true setPlayerTeam (Jogador, originalteam) -- sets the team to the one which the player had previously before joining the arena end local count1 = countPlayersInTeam (newTeam1) local count2 = countPlayersInTeam (newTeam2) local count3 = countPlayersInTeam (newTeam3) if count1==0 then destroyElement(newTeam1) outputChatBox ( "Miltants have been eliminated." ) end if count2==0 then destroyElement(newTeam2) outputChatBox ( "Invaders have been eliminated." ) end if count3==0 then destroyElement(newTeam3) outputChatBox ( "Insurgents have been eliminated." ) end end end )
  11. Tron

    Team script error

    It works perfectly for first time when you join the arena. When you type /exitarena it removes you from arena and spawns you back in your previous clan. Till there its fine tho the problem is when you join the arena again it dont spawn and it doesn't adds you anymore in one of the 3 teams. Here's the entire code:- addEventHandler ("onResourceStart", getResourceRootElement(getThisResource()), function() local allGreenzones = getElementsByType ("radararea") for i,v in ipairs (allGreenzones) do local r, g, b, a = getRadarAreaColor (v) if (r == 255) and (g == 0) and (b == 0) and (a == 255) then local x, y = getElementPosition (v) local sx, sy = getRadarAreaSize (v) setRadarAreaFlashing(v, true) local col = createColCuboid (x, y, -50, sx, sy, 7500) setElementID (col, "ColShapeMultiGameMode") end end end ) spawnVehPositions = { {-1292.8455810547, -364.38061523438, 15.8}, {-1350.6311035156, -258.98291015625, 14.14396572113}, {-1467.52734375, -190.3069152832, 14.1484375}, {-1620.8626708984, -51.465915679932, 3.5595684051514}, {-1620.2762451172, -590.58685302734, 14.1484375}, } spawnarena2Positionsmilitants = { {789.79999, -2120.3999, 14.1484375}, {795.5, -2228, 15.4}, {795.70001, -2218.8, 15.2}, } spawnarena2Positionsinvaders = { {649.29999, -2409.3, 83}, {623.40002, -2498.3999, 71.9}, {623.70001, -2497.8, 71.9}, } spawnarena2Positionsinsurgents = { {502.20001, -2297.2, 124.6}, {456.60001, -2256.8999, 128.3}, {450.29999, -2258.3, 128.3}, } addEventHandler("onColShapeLeave", root, function (Jogador) if (getElementData(Jogador, "MultiGM") and getElementByID("ColShapeMultiGameMode")) then if (not getElementData(Jogador, "Morreu")) then if (Vehicle[Jogador] and isElement(Vehicle[Jogador])) then destroyElement(Vehicle[Jogador]) triggerClientEvent(Jogador, getResourceName(getThisResource())..": textScreen", root, "#ffffffWarning:-You've crossed the arena boundary!") end removeElementData(Jogador, "MultiGM") end end end ) addEventHandler("onColShapeHit", root, function (Jogador) if (not getElementData(Jogador, "MultiGM")) and getElementByID("ColShapeMultiGameMode") then if ( getElementDimension(Jogador) == 1 ) then setElementData(Jogador, "MultiGM", "Hydra") elseif ( getElementDimension(Jogador) == 2) then setElementData(Jogador, "MultiGM", "Hunter") end end end ) Vehicle = {} function spawnVehMarker (Jogador) if (getElementDimension(Jogador) == 2) then if (Vehicle[Jogador] and isElement(Vehicle[Jogador])) then destroyElement(Vehicle[Jogador]) end local x, y, z = getElementPosition(Jogador) Vehicle[Jogador] = createVehicle(425, x, y, z+1) --warpPedIntoVehicle(Jogador, Vehicle[Jogador]) setElementData(Jogador, "MultiGM", "Hunter") elseif ( getElementDimension(Jogador) == 1 ) then if (Vehicle[Jogador] and isElement(Vehicle[Jogador])) then destroyElement(Vehicle[Jogador]) end local x, y, z = getElementPosition(Jogador) Vehicle[Jogador] = createVehicle(520, x, y, z+1) --warpPedIntoVehicle(Jogador, Vehicle[Jogador]) setElementData(Jogador, "MultiGM", "Hydra") end end for _, v in ipairs (spawnVehPositions) do MarkerHunter = createMarker(v[1], v[2], v[3]+0.6, "checkpoint", 1, 185, 122, 87, 255 ) MarkerHydra = createMarker(v[1], v[2], v[3]+0.6, "checkpoint", 1, 185, 122, 87, 255 ) setElementDimension(MarkerHunter, 2) setElementDimension(MarkerHydra, 1) addEventHandler("onMarkerHit", MarkerHunter, spawnVehMarker) addEventHandler("onMarkerHit", MarkerHydra, spawnVehMarker) end addEvent(getResourceName(getThisResource())..": respawnPlayer", true) addEventHandler(getResourceName(getThisResource())..": respawnPlayer", root, function () if getElementData(source, "Morreu") == 1 then local pX, pY, pZ = unpack(spawnVehPositions[math.random(#spawnVehPositions)]) setElementPosition(source, pX, pY, pZ) setElementDimension(source, 2) removeElementData(source, "Morreu") elseif getElementData(source, "Morreu") == 2 then local pX, pY, pZ = unpack(spawnVehPositions[math.random(#spawnVehPositions)]) setElementPosition(source, pX, pY, pZ) setElementDimension(source, 1) removeElementData(source, "Morreu") end end ) local newTeam1 = createTeam ( "Militants", 0, 255, 0 ) local newTeam2 = createTeam ( "Invaders", 100, 0, 20) local newTeam3 = createTeam ( "Insurgents", 50, 100, 50) local originalteam -- to store the team of player before joining the arena addEvent(getResourceName(getThisResource())..": addPlayerHunter", true) addEventHandler(getResourceName(getThisResource())..": addPlayerHunter", root, function () if (getPedOccupiedVehicle(source)) then return triggerClientEvent(source, getResourceName(getThisResource())..": textScreen", root, "Get out of your current vehicle to get into GM!") elseif (getElementData(source, "MultiGM") == "Hydra") then removeElementData(source, "MultiGM") end originalteam = getPlayerTeam (source) or nil local teams = {newTeam1,newTeam2,newTeam3} local randomteam = teams[math.random(#teams)] setPlayerTeam(source, randomteam) local activeteam = getPlayerTeam (source) -- joined team if activeteam and getTeamName(activeteam)=="Militants" then local mX, mY, mZ = unpack(spawnarena2Positionsmilitants[math.random(#spawnarena2Positionsmilitants)]) setElementPosition(source, mX, mY, mZ) elseif activeteam and getTeamName(activeteam)=="Invaders" then local inX, inY, inZ = unpack(spawnarena2Positionsinvaders[math.random(#spawnarena2Positionsinvaders)]) setElementPosition(source, inX, inY, inZ) elseif activeteam and getTeamName(activeteam)=="Insurgents"then local isX, isY, isZ = unpack(spawnarena2Positionsinsurgents[math.random(#spawnarena2Positionsinsurgents)]) setElementPosition(source, isX, isY, isZ) end triggerClientEvent(source, getResourceName(getThisResource())..": textScreen", root, "You entered the Hunter Arena. To exit just type /exitarena") setElementData(source, "MultiGM", "Hunter") --setElementPosition(source, pX, pY, pZ) --setElementDimension(source, 2) end ) addEvent(getResourceName(getThisResource())..": addPlayerHydra", true) addEventHandler(getResourceName(getThisResource())..": addPlayerHydra", root, function () if (getPedOccupiedVehicle(source)) then return triggerClientEvent(source, getResourceName(getThisResource())..": textScreen", root, "Get out of your current vehicle to get into GM!") elseif (getElementData(source, "MultiGM") == "Hunter") then elseif (getElementData(source, "MultiGM") == "Hunter") then removeElementData(source, "MultiGM") end triggerClientEvent(source, getResourceName(getThisResource())..": textScreen", root, "You entered the Dogfight Arena. To exit just type /exitarena") local pX, pY, pZ = unpack(spawnVehPositions[math.random(#spawnVehPositions)]) setElementData(source, "MultiGM", "Hydra") setElementPosition(source, pX, pY, pZ) setElementDimension(source, 1) end ) addEventHandler("onPlayerWasted", root, function (_, attacker) if (getElementData(source, "MultiGM")) then triggerClientEvent(source, getResourceName(getThisResource())..": respawnPlayer", root) if (attacker) then if (getElementType(attacker) == "player" and getElementData(attacker, "MultiGM")) then triggerClientEvent(attacker, getResourceName(getThisResource())..": textScreen", root, "You've killed: "..getPlayerName(source).."!") triggerClientEvent(source, getResourceName(getThisResource())..": textScreen", root, "You've been killed by: "..getPlayerName(attacker).."!") elseif (getElementType(attacker) == "vehicle" and getElementData(getVehicleOccupant(attacker), "MultiGM")) then triggerClientEvent(getVehicleOccupant(attacker), getResourceName(getThisResource())..": textScreen", root, "You've killed: "..getPlayerName(source).."!") triggerClientEvent(source, getResourceName(getThisResource())..": textScreen", root, "You've been killed by: "..getPlayerName(getVehicleOccupant(attacker)).."!") end else triggerClientEvent(source, getResourceName(getThisResource())..": textScreen", root, "#ffffffYou've committed suicide!") end end end ) addCommandHandler("exitarena", function (Jogador) if (getElementData(Jogador, "MultiGM")) then if Vehicle[Jogador] and isElement(Vehicle[Jogador]) then destroyElement(Vehicle[Jogador]) end removeElementData(Jogador, "MultiGM") setElementDimension(Jogador, 0) killPed(Jogador) triggerClientEvent(Jogador, getResourceName(getThisResource())..": textScreen", root, "You've left the arena successfully!") local currentteam = getPlayerTeam (Jogador) -- gets the current players team if (currentteam ) then --checks if the player is in a team by checking if playerTeam returned true setPlayerTeam (Jogador, originalteam) -- sets the team to the one which the player had previously before joining the arena end local count1 = countPlayersInTeam (newTeam1) local count2 = countPlayersInTeam (newTeam2) local count3 = countPlayersInTeam (newTeam3) if count1==0 then destroyElement(newTeam1) outputChatBox ( "Miltants have been eliminated." ) end if count2==0 then destroyElement(newTeam2) outputChatBox ( "Invaders have been eliminated." ) end if count3==0 then destroyElement(newTeam3) outputChatBox ( "Insurgents have been eliminated." ) end end end )
  12. Tron

    Team script error

    Still same when any player joins hunter arena he is placed in one of the teams created randomly but it adds other players(non participators) too in one of those 3 clans
  13. Hello out there, The problem is it doesn't adds players who joined the arena into the arena based teams. This is how it should work: when the player joins hunter arena, 3 teams named as 'Militants', 'Insurgents' and 'Invaders' are created. I want it to be like all the players who joins the hunter arena will be entered into random team from those 3 teams created on event startup. Non participators must stay in their own clan without any changes. local newTeam1 local newTeam2 local newTeam3 local originalteam -- to store the team of player before joining the arena addEvent(getResourceName(getThisResource())..": addPlayerHunter", true) addEventHandler(getResourceName(getThisResource())..": addPlayerHunter", root, function () if (getPedOccupiedVehicle(source)) then return triggerClientEvent(source, getResourceName(getThisResource())..": textScreen", root, "Get out of your current vehicle to get into GM!") elseif (getElementData(source, "MultiGM") == "Hydra") then removeElementData(source, "MultiGM") end --local pX, pY, pZ = unpack(spawnarena2Positions[math.random(#spawnarena2Positions)]) local mX, mY, mZ = unpack(spawnarena2Positionsmilitants[math.random(#spawnarena2Positionsmilitants)]) local inX, inY, inZ = unpack(spawnarena2Positionsinvaders[math.random(#spawnarena2Positionsinvaders)]) local isX, isY, isZ = unpack(spawnarena2Positionsinsurgents[math.random(#spawnarena2Positionsinsurgents)]) originalteam = getPlayerTeam (source) -- store the team of player before he joined the arena if (originalteam ) then --if he has team else originalteam = nil --if he dont have a team previously then set it as nil end newTeam1 = createTeam ( "Militants", 0, 255, 0 ) -- create a new team with the specified name newTeam2 = createTeam ( "Invaders", 100, 0, 20) newTeam3 = createTeam ( "Insurgents", 50, 100, 50) local teams = {newTeam1,newTeam2,newTeam3} for _, Jogador in ipairs(getElementsByType("player")) do -- THERE MIGHT BE A MISTAKE HERE HUH?. local randomteam = teams[math.random(#teams)] setPlayerTeam(source, randomteam) end local activeteam = getPlayerTeam (source) -- joined team if (activeteam) then if activeteam=="Militants" then setElementPosition(source, mX, mY, mZ) elseif activeteam=="Invaders" then setElementPosition(source, inX, inY, inZ) elseif activeteam=="Insurgents"then setElementPosition(source, isX, isY, isZ) else end end triggerClientEvent(source, getResourceName(getThisResource())..": textScreen", root, "You entered the Hunter Arena. To exit just type /exitarena") setElementData(source, "MultiGM", "Hunter") --setElementPosition(source, pX, pY, pZ) --setElementDimension(source, 2) end )
  14. Hello out there, I wanted to edit the following hydra lock script so that you have to press handbrake only once to lock a vehicle. Lock will be turned off when the opponent goes out of range or when you press handbrake again. Any help regarding this would be much appreciated. --[[ Luca aka specahawk aka spopo aka Anirudh Katoch (All rights reserved) MIT License - Do whatever you want. ]] ----User settings--- local SHOOT_COOLDOWN = 1500 --Cooldown between homing shots local LOCKON_TIME = 1500 --Time required to lock on to a target local LOCK_RANGE = 330 --Maximum distance between you and the target local LOCK_ANGLE = 0.95 --(in radians) We cannot lock on targets unless they are within this angle of the front of the hydra local VALID_TARGET_FUNCTION = function (vehicle) --Used to decide whether a vehicle should appear as a lock-on option -- local targetTeam = vehicle.controller and vehicle.controller.team -- local ourTeam = localPlayer.team -- if targetTeam and ourTeam and targetTeam == ourTeam then -- return false --The target vehicle has someone driving, and both of you are on the same team -- end return true end --[[ to implement team tagging, or to disallow certain vehicles from being targetted, define the VALID_TARGET_FUNCTION VALID_TARGET_FUNCTION should take as parameter a vehicle, and return a boolean (true means it can be targetted) Here is an example of a function that will only let us target HYDRAS of OTHER TEAMS that are MORE THAN 50m AWAY and are DIRECTLY VISIBLE local VALID_TARGET_FUNCTION = function(vehicle) local targetTeam = vehicle.controller and vehicle.controller.team local ourTeam = localPlayer.team if targetTeam and ourTeam and targetTeam == ourTeam then return false --The target vehicle has someone driving, and both of you are on the same team end if vehicle.model ~= 520 then return false --Target is not a hydra, so it's not allowed end if (vehicle.position-localPlayer.position).length < 50 then return false --Closer than 50 metres end if not isLineOfSightClear(localPlayer.position, vehicle.position, true, false) then return false --Not directly visible --(Remember to account for your own vehicle and the target blocking the line) end return true --Target satisfied all criteria end ]] local validTarget = VALID_TARGET_FUNCTION or function() return true end LOCK_ANGLE = math.cos(LOCK_ANGLE) local inHydra = false local firestate = nil local visibleVehicle = {} local targetVehicle = nil local nearbyVehicles = {} getNearbyVehicles = function() return nearbyVehicles end --Used by other files local currentHydra = nil local function getTarget() -- Look for the nearest targets and lock on local nearestVehicle = nil local shortestDistance = LOCK_RANGE for _, vehicle in ipairs(nearbyVehicles) do local targPos = vehicle.position local myPos = localPlayer.position local displacement = targPos-myPos local dist = displacement.length if vehicle ~= localPlayer.vehicle and dist < shortestDistance then shortestDistance = dist nearestVehicle = vehicle end end return nearestVehicle end local function checkForLockout(vehicle) if visibleVehicle[vehicle] then triggerEvent("onClientHydraMissilesSystemLockout", localPlayer, vehicle) visibleVehicle[vehicle] = nil lockedVehicle = nil targetVehicle = nil end end local lastShot = SHOOT_COOLDOWN*-2 local function shootMissile() if not inHydra then return end local target = lockedVehicle if not target or getTickCount() < lastShot + SHOOT_COOLDOWN then return end lastShot = getTickCount() local hydra = localPlayer.vehicle local vX, vY, vZ = hydra.velocity -- Shoot missile createProjectile( hydra, 20, hydra.position, 5000, target, _, _, _, vX+5000, vY, vZ) -- dxDrawText ( playerZoneName, 44, screenHeight - 43, screenWidth, screenHeight, tocolor ( 255, 255, 255, 255 ), 1, "pricedown" ) DRAW WARNING ON PLAYER SCREEN lockedVehicle = nil targetVehicle = nil visibleVehicle[target] = nil end local function update() local curtime = getTickCount() if not localPlayer.vehicle then --idk why, but sometimes the player has no vehicle sometime before vehicle exit event is fired stopHydra() --The Avengers return end local vehicle = targetVehicle if not vehicle then return end local visibleNow = false if vehicle ~= localPlayer.vehicle and not vehicle.blown and validTarget(vehicle) then local targPos = vehicle.position local myPos = localPlayer.position local displacement = targPos-myPos local dist = displacement.length local cosAngle = localPlayer.vehicle.matrix.forward:dot(displacement)/dist if dist < LOCK_RANGE and cosAngle>LOCK_ANGLE and firestate then local aX, aY = getScreenFromWorldPosition(targPos) if (aX and aY) then visibleNow = true --Draw the corners of the target box outline if lockedVehicle == vehicle then dxDrawImage (aX-118,aY-118, 246, 246, 'lock.png') else dxDrawImage (aX-118, aY-118, 246, 246, 'lock2.png') end end end end if not visibleNow then checkForLockout() elseif visibleVehicle[vehicle] then if curtime - visibleVehicle[vehicle] > LOCKON_TIME then lockedVehicle = vehicle end else visibleVehicle[vehicle] = curtime end end local function homingState(key,state) if not inHydra then return end if state == "down" then targetVehicle = getTarget() firestate = isControlEnabled("vehicle_secondary_fire") toggleControl("vehicle_secondary_fire",false) bindKey("vehicle_secondary_fire","down",shootMissile) else targetVehicle = nil lockedVehicle = nil toggleControl("vehicle_secondary_fire",firestate) firestate = nil unbindKey("vehicle_secondary_fire","down",shootMissile) end end local function vehicleGoneHandler() --This also triggers on localPlayer's vehicle, and does nothing to it removeEventHandler("onClientElementDestroy", source, vehicleGoneHandler) removeEventHandler("onClientElementStreamOut", source, vehicleGoneHandler) if getElementType( source ) == "vehicle" then for i, v in ipairs(nearbyVehicles) do if v == source then checkForLockout(source) table.remove(nearbyVehicles, i) return end end end end local function prepAfterStreamIn(vehicle) addEventHandler("onClientElementStreamOut", vehicle, vehicleGoneHandler) addEventHandler("onClientElementDestroy", vehicle, vehicleGoneHandler) end local function streamInHandler() if getElementType( source ) == "vehicle" then table.insert(nearbyVehicles, source) prepAfterStreamIn(source) end end local function startHydra(vehicle) if not inHydra and vehicle and isElement(vehicle) and vehicle.model == 520 then nearbyVehicles = getElementsByType("vehicle", root, true) for i, v in ipairs(nearbyVehicles) do prepAfterStreamIn(v) end addEventHandler("onClientElementStreamIn", root, streamInHandler) addEventHandler("onClientVehicleExplode", vehicle, stopHydra) addEventHandler("onClientElementDestroy", vehicle, stopHydra) addEventHandler("onClientElementStreamOut", vehicle, stopHydra) --Is this even possible? inHydra = isControlEnabled("handbrake") currentHydra = vehicle --To remove the listeners later toggleControl("handbrake", false) bindKey("handbrake","down",homingState) bindKey("handbrake","up",homingState) addEventHandler( "onClientRender", root, update) end end function stopHydra() if inHydra then local target = getTarget() for i, v in ipairs(nearbyVehicles) do if v ~= target then removeEventHandler("onClientElementDestroy", v, vehicleGoneHandler) removeEventHandler("onClientElementStreamOut", v, vehicleGoneHandler) checkForLockout(v) end end checkForLockout(target) if target then removeEventHandler("onClientElementDestroy", target, vehicleGoneHandler) removeEventHandler("onClientElementStreamOut", target, vehicleGoneHandler) end removeEventHandler("onClientRender", root, update) unbindKey("handbrake","down",homingState) unbindKey("handbrake","up",homingState) if firestate ~= nil then homingState("handbrake","up") end local vehicle = currentHydra currentHydra = nil toggleControl("handbrake", inHydra) inHydra = false removeEventHandler("onClientElementStreamIn", root, streamInHandler) if isElement(vehicle) then removeEventHandler("onClientVehicleExplode", vehicle, stopHydra) removeEventHandler("onClientElementDestroy", vehicle, stopHydra) removeEventHandler("onClientElementStreamOut", vehicle, stopHydra) end end end local function initScript() if localPlayer.vehicle and localPlayer.vehicle.model == 520 then startHydra(localPlayer.vehicle) end addEventHandler("onClientResourceStop", resourceRoot, stopHydra) addEventHandler("onClientPlayerVehicleExit",localPlayer,stopHydra) addEventHandler("onClientPlayerWasted",localPlayer,stopHydra) addEventHandler("onClientPlayerVehicleEnter",localPlayer,startHydra) end addEventHandler("onClientResourceStart",resourceRoot,initScript)
×
×
  • Create New...