Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function init()
- RegisterTool("P90", "P90", "MOD/vox/P90.vox")
- SetBool("game.tool.P90.enabled", true)
- SetFloat("game.tool.P90.ammo", 101)
- unlimited_ammo = GetBool("savegame.mod.unlimitedammo")
- unlimited_clip = GetBool("savegame.mod.unlimitedclip")
- input_mode = GetString("savegame.mod.mode_input")
- input_type = GetString("savegame.mod.type_input")
- input_scope = GetString("savegame.mod.scope_input")
- smoke_firing = GetFloat("savegame.mod.smoke_firing")
- smoke_impact = GetFloat("savegame.mod.smoke_impact")
- bullet_spread = GetFloat("savegame.mod.bullet_spread")
- if input_mode == "" then input_mode = "C" end
- if input_type == "" then input_type = "V" end
- if input_scope == "" then input_scope = "T" end
- if smoke_firing == 0 then smoke_firing = 5 end
- if smoke_impact == 0 then smoke_impact = 20 end
- if smoke_firing == 0.1 then smoke_firing = 0 end
- if smoke_impact == 0.1 then smoke_impact = 0 end
- aim_progress = 0
- shoot_timer = 0
- automatic = true
- bullets = {}
- bullet_step = 3
- ammo = 50
- clip = 50*10
- reload_timer = 0
- full_reload_timer = 0
- ammo_type = 0
- ammo_needed_reload = 0
- scope_type = 0
- firing_sound = LoadSound("MOD/snd/Firing.ogg")
- reloading_sound = LoadSound("MOD/snd/Reloading.ogg")
- changing_mode_sound = LoadSound("MOD/snd/ChangingMode.ogg")
- end
- function Shoot()
- camera = GetPlayerCameraTransform()
- if not unlimited_ammo then ammo = ammo - 1 end
- local smokepos = 0
- if aim_progress == 0 then smokepos = TransformToParentPoint(camera, VecSub(Vec(0, -0.2, -1.75), Vec(-0.325, 0.225, 0.20))) else smokepos = TransformToParentPoint(camera, Vec(0, -0.2, -1.75)) end
- if smoke_firing > 0 then for i = 1, smoke_firing do
- local smokedir = TransformToParentVec(camera, Vec(math.random(-1, 1), math.random(-1, 1), -5))
- smokedir = VecAdd(smokedir, VecScale(GetPlayerVelocity(), 0.25))
- SpawnParticle("darksmoke", smokepos, smokedir, .075, 1)
- end end
- if bullet_spread ~= 0 then
- angle = math.random() * 2 * math.pi
- radius = math.random() * (bullet_spread / 200)
- spread_x = math.cos(angle) * radius
- spread_y = math.sin(angle) * radius
- else
- spread_x = 0
- spread_y = 0
- end
- table.insert(bullets, {smokepos, TransformToParentVec(camera, Vec(spread_x, spread_y, -1)), 0})
- PlaySound(firing_sound, camera.pos)
- end
- function tick(dt)
- if GetString("game.player.tool") == "P90" and GetPlayerVehicle() == 0 then
- if InputDown("lmb") and grabing then
- grabing = 1
- else
- grabing = GetPlayerGrabShape()
- end
- if InputPressed(input_mode) then
- automatic = not automatic
- PlaySound(changing_mode_sound, GetPlayerCameraTransform().pos)
- end
- if InputPressed(input_type) then
- ammo_type = ammo_type+1
- if ammo_type == 3 then ammo_type = 0 end
- end
- if grabing > 0 then grabing = true else grabing = false end
- if InputDown("rmb") and not grabing then
- aim_progress = math.min(aim_progress + dt * 5, 1)
- if scope_type == 1 and not(InputDown("right") or InputDown("left") or InputDown("up") or InputDown("down") or InputDown("jump")) then SetCameraFov(10) end
- else
- aim_progress = math.max(aim_progress - dt * 5, 0)
- end
- local P90_Shapes = GetBodyShapes(GetToolBody())
- local Scope_Shape = P90_Shapes[2]
- local Laser_Shape = P90_Shapes[3]
- local Scope_Clean_Shape = P90_Shapes[4]
- local move_vec
- if scope_type == 1 then
- move_vec = {-0.325, 0.025, 0.2}
- if aim_progress == 1 and not(InputDown("right") or InputDown("left") or InputDown("up") or InputDown("down") or InputDown("jump")) then
- SetShapeLocalTransform(Scope_Shape, Transform(Vec(0, 0, 999999), QuatEuler(-90, 0, 0)))
- SetShapeLocalTransform(Scope_Clean_Shape, Transform(Vec(0.25, -0.15, -1.1), QuatEuler(-90, 0, 0)))
- SetShapeLocalTransform(Laser_Shape, Transform(Vec(0, 0, 999999), QuatEuler(-90, 0, 0)))
- else
- SetShapeLocalTransform(Scope_Shape, Transform(Vec(0.25, -0.15, -1.1), QuatEuler(-90, 0, 0)))
- SetShapeLocalTransform(Scope_Clean_Shape, Transform(Vec(0, 0, 999999), QuatEuler(-90, 0, 0)))
- SetShapeLocalTransform(Laser_Shape, Transform(Vec(0, 0, 999999), QuatEuler(-90, 0, 0)))
- end
- elseif scope_type == 2 then
- move_vec = {-0.325, 0.025, 0.4}
- SetShapeLocalTransform(Scope_Shape, Transform(Vec(0, 0, 999999), QuatEuler(-90, 0, 0)))
- SetShapeLocalTransform(Scope_Clean_Shape, Transform(Vec(0, 0, 99999), QuatEuler(-90, 0, 0)))
- SetShapeLocalTransform(Laser_Shape, Transform(Vec(0.25, -0.15, -1.25), QuatEuler(-90, 0, 0)))
- else
- move_vec = {-0.325, 0.225, 0.20}
- SetShapeLocalTransform(Scope_Shape, Transform(Vec(0, 0, 999999), QuatEuler(-90, 0, 0)))
- SetShapeLocalTransform(Scope_Clean_Shape, Transform(Vec(0, 0, 999999), QuatEuler(-90, 0, 0)))
- SetShapeLocalTransform(Laser_Shape, Transform(Vec(0, 0, 99999), QuatEuler(-90, 0, 0)))
- end
- tool_transform = Transform()
- tool_transform.pos = VecAdd(tool_transform.pos, VecScale(Vec(move_vec[1], move_vec[2], move_vec[3]), aim_progress))
- tool_transform.pos = VecAdd(tool_transform.pos, Vec(0, 0, shoot_timer))
- SetToolTransform(tool_transform)
- if (InputDown("lmb") and automatic) or (InputPressed("lmb") and not automatic) then
- if shoot_timer < 0.001 and ammo > 0 and reload_timer == 0 and not grabing then
- Shoot()
- shoot_timer = 0.050
- end
- end
- if shoot_timer > 0 then shoot_timer = shoot_timer - dt else shoot_timer = 0 end
- if InputDown("R") and ammo ~= 50 and reload_timer == 0 then
- if unlimited_clip then
- PlaySound(reloading_sound, GetPlayerCameraTransform().pos, 1, false)
- reload_timer = 2.5
- ammo = 0
- ammo_needed_reload = 50
- else
- full_reload_timer = full_reload_timer + dt
- if ammo == 0 then full_reload_timer = 3 end
- end
- end
- if (InputReleased("R") or full_reload_timer >= 3) and not unlimited_clip and full_reload_timer ~= 0 then
- PlaySound(reloading_sound, GetPlayerCameraTransform().pos, 1, false)
- reload_timer = 2.5
- if full_reload_timer >= 3 then
- ammo_needed_reload = 50-ammo
- else
- ammo_needed_reload = 50
- end
- full_reload_timer = 0
- end
- if InputPressed(input_scope) and aim_progress == 0 then
- scope_type = scope_type + 1
- if scope_type == 3 then scope_type = 0 end
- end
- if reload_timer > 0 then
- reload_timer = reload_timer - dt
- if reload_timer <= 0 then
- reload_timer = 0
- ammo = math.min(ammo+ammo_needed_reload, math.min(clip, 50))
- if not unlimited_clip then clip = math.max(clip - ammo_needed_reload, 0) end
- end
- end
- end
- local delete_bullet = {}
- for i = 1, #bullets do
- local hit, dis = QueryRaycast(bullets[i][1], bullets[i][2], bullet_step+0.1, 0.025)
- if hit then
- if ammo_type == 0 then MakeHole(VecAdd(bullets[i][1], VecScale(bullets[i][2], dis)), 1, 0.75, 0.50) --Normal Ammo
- elseif ammo_type == 1 then Explosion(VecAdd(bullets[i][1], VecScale(bullets[i][2], dis)), 1) --Explosive Ammo
- else MakeHole(VecAdd(bullets[i][1], VecScale(bullets[i][2], dis)), 0.25, 0.15, 0.15) end --Small Ammo
- table.insert(delete_bullet, 1, i)
- if smoke_impact > 0 then for u = 1, smoke_impact do
- SpawnParticle("smoke", VecAdd(bullets[i][1], VecScale(bullets[i][2], dis)), VecNormalize(Vec(math.random(-1, 1), math.random(-1, 1), math.random(-1, 1))), .75, 2)
- end end
- else
- bullets[i][1] = VecAdd(bullets[i][1], VecScale(bullets[i][2], bullet_step))
- bullets[i][3] = bullets[i][3] + 1
- DrawLine(VecSub(bullets[i][1], bullets[i][2]), bullets[i][1])
- end
- if bullets[i][3] >= 100 then table.insert(delete_bullet, 1, i) end
- end
- if #delete_bullet ~= 0 then
- for i = 1, #delete_bullet do
- table.remove(bullets, delete_bullet[i])
- end
- end
- end
- function draw()
- if GetString("game.player.tool") == "P90" and GetPlayerVehicle() == 0 then
- UiPush()
- UiTranslate(UiCenter(), UiHeight()-60)
- UiAlign("center middle")
- UiColor(1, 1, 1)
- UiFont("bold.ttf", 32)
- UiTextOutline(0,0,0,1,0.1)
- local clip_text
- local ammo_text
- if unlimited_clip then clip_text = "inf" else clip_text = clip end
- if unlimited_ammo then ammo_text = "inf" else ammo_text = ammo end
- if reload_timer == 0 then UiText(ammo_text .. "/"..clip_text) else UiText("Reloading...") end
- UiPop()
- UiPush()
- if aim_progress == 1 and scope_type == 2 then
- local start_pos = TransformToParentPoint(GetPlayerCameraTransform(), Vec(0, -0.2, -1.75))
- local Vo = TransformToParentVec(GetPlayerCameraTransform(), Vec(0, 0, -1))
- local hit, dis = QueryRaycast(start_pos, Vo, 50, 0.025)
- if hit then
- hit_pos = VecAdd(start_pos, VecScale(Vo, dis))
- x, y, dist = UiWorldToPixel(hit_pos)
- UiTranslate(x-(5-dis/10), y-(5-dis/10))
- UiScale(1-dis/50)
- if scope_type == 2 and dis > 1.05 then UiImage("MOD/img/GreenDot.png") end
- end
- end
- --RayCast for scope, disabled because of lag issues.
- --[[
- if aim_progress == 1 and scope_type == 1 and not(InputDown("right") or InputDown("left") or InputDown("up") or InputDown("down") or InputDown("jump")) and math.abs(InputValue("mousedx"))+math.abs(InputValue("mousedy")) < 2 then
- local start_pos = TransformToParentPoint(GetPlayerCameraTransform(), Vec(0, -0.2, -1.75))
- local Vo = TransformToParentVec(GetPlayerCameraTransform(), Vec(0, 0, -1))
- local hit, dis = QueryRaycast(start_pos, Vo, 300, 0.025)
- if hit then
- hit_pos = VecAdd(start_pos, VecScale(Vo, dis))
- x, y, dist = UiWorldToPixel(hit_pos)
- UiTranslate(x-30, y-30)
- if scope_type == 1 and dis > 8.8 then UiImage("MOD/img/ScopeHit.png") end
- end
- end
- ]]
- UiPop()
- UiPush()
- UiTranslate(UiCenter(), UiHeight()-120)
- UiAlign("center middle")
- UiColor(1, 1, 1)
- UiFont("bold.ttf", 32)
- UiTextOutline(0,0,0,1,0.1)
- local type_text
- if ammo_type == 0 then type_text = "Normal Ammo" elseif ammo_type == 1 then type_text = "Explosive Ammo" else type_text = "Small Ammo" end
- local mode_text
- if automatic then mode_text = "Automatic" else mode_text = "Semi-Auto" end
- UiText(type_text.." | "..mode_text)
- UiPop()
- if full_reload_timer ~= 0 then
- UiPush()
- UiTranslate(UiCenter(), UiHeight()-180)
- UiAlign("center middle")
- UiColor(1, 1, 1)
- UiFont("bold.ttf", 32)
- UiTextOutline(0,0,0,1,0.1)
- UiText(math.floor(math.min(full_reload_timer/3*100, 100)).."%")
- UiPop()
- end
- end
- end
Add Comment
Please, Sign In to add comment