-- LUA Script - precede every function and global member with lowercase name of script + '_main' -- Player Collects Weapon --how long you need to hold e for before the mine is placed (in seconds) local placement_time = 1.5 --how long before the mine explodes once triggered (in seconds) local explosion_delay = 1 --how close an entity needs to get before the mine is triggered local trigger_dist = 80 --how far away the player needs to be before the mine can be triggered by an enemy (so the player isn't caught in the explosion) local player_safe_dist = 500 --only change this if you are having issues with the mine triggering at wrong entities local minimum_HP = 25 local weapon_name = "Proximity Mine" local mines = 0 local mine_state = {} local timer_running = {} local pressed = 0 local temp = 0 local StartTime = {} local proximine_started={} function proximine_pickup_init(e) mine_state[e] = "collect" timer_running[e] = 0 StartTime[e] = 0 end function proximine_pickup_main(e) if mine_state[e] == "collect" then if PlayerLooking(e,150,5) == 1 then Prompt ("Press E To pick up the " .. weapon_name) if g_KeyPressE == 1 and pressed == 0 then pressed = 1 PromptDuration("Collected the " .. weapon_name,3000) PlaySound(e,1) mines = mines + 1 mine_state[e] = "collected" ActivateIfUsed(e) timer_running[e] = 0 end end elseif mine_state[e] == "collected" then ResetPosition(e,g_PlayerPosX,g_PlayerPosY+100,g_PlayerPosZ) if g_KeyPressE == 1 and pressed == 0 then Prompt("Placing Mine") if timer_running[e] == 0 then StartTime[e] = GetTimer(e) + (placement_time * 1000) timer_running[e] = 1 temp = 0 else if GetTimer(e) > StartTime[e] and temp == 0 then temp = 1 ResetPosition(e,g_PlayerPosX,GetTerrainHeight(g_PlayerPosX,g_PlayerPosZ)+1,g_PlayerPosZ) mines = mines - 1 Show(e) proximine_started[e] = 0 mine_state[e] = "placed" pressed = 1 end end end elseif mine_state[e] == "placed" then if proximine_started[e] == 0 then for a = 1, 2999 do if g_Entity[a] ~= nil then if g_Entity[a]['health'] > 25 then MineDX = g_Entity[a]['x'] - g_Entity[e]['x']; MineDY = g_Entity[a]['y'] - g_Entity[e]['y']; MineDZ = g_Entity[a]['z'] - g_Entity[e]['z']; MineDist = (MineDX*MineDX)+(MineDY*MineDY)+(MineDZ*MineDZ); if MineDist < trigger_dist*trigger_dist and proximine_started[e] == 0 and GetPlayerDistance(e) > player_safe_dist then proximine_started[e] = GetTimer(e)+ (explosion_delay * 1000) PlaySound(e,0) end end end end else if GetTimer(e) > proximine_started[e] then SetEntityHealth(e,0) end end end if g_KeyPressE == 0 then timer_running[e] = 0 pressed = 0 temp = 0 end end function PlayerLooking(e,dis,v) if g_Entity[e] ~= nil then if dis == nil then dis = 3000 end if v == nil then v = 0.5 end if GetPlayerDistance(e) <= dis then local destx = g_Entity[e]['x'] - g_PlayerPosX local destz = g_Entity[e]['z'] - g_PlayerPosZ local angle = math.atan2(destx,destz) angle = angle * (180.0 / math.pi) if angle <= 0 then angle = 360 + angle elseif angle > 360 then angle = angle - 360 end while g_PlayerAngY < 0 or g_PlayerAngY > 360 do if g_PlayerAngY <= 0 then g_PlayerAngY = 360 + g_PlayerAngY elseif g_PlayerAngY > 360 then g_PlayerAngY = g_PlayerAngY - 360 end end local L = angle - v local R = angle + v if L <= 0 then L = 360 + L elseif L > 360 then L = L - 360 end if R <= 0 then R = 360 + R elseif R > 360 then R = R - 360 end if (L < R and math.abs(g_PlayerAngY) > L and math.abs(g_PlayerAngY) < R) then return 1 elseif (L > R and (math.abs(g_PlayerAngY) > L or math.abs(g_PlayerAngY) < R)) then return 1 else return 0 end else return 0 end end end