local offsetx = {} local offsety = {} local offsetz = {} projectile_speed = {} projectile_damage = {} projectile_ammo = {} max_projectile_ammo = {} local firing = 0 local fire_delay = {} local got_decal = {} fired = {} local x1 = {} local y1 = {} local z1 = {} local x2 = {} local y2 = {} local z2 = {} local text_showing = 0 state = {} gun_number = 1 --currently held gun (used in stats below) --gun stats projectile_speed[1] = 900 --how fast the projectile moves forward projectile_damage[1] = 50 --damage per hit fire_delay[1] = 200 --in milliseconds --use these 2 values for your hud projectile_ammo[1] = 100 --starting ammo max_projectile_ammo[1] = 1000 --upper ammo limit function thirdp_projectile_init_name(e,name) weapon_name[e] = name state[e] = "wait" got_decal[e] = nil offsetx[e] = 0 offsety[e] = 10 offsetz[e] = 0 fired[e] = 0 end function thirdp_projectile_main(e) --SetRotation(GetGamePlayerControlThirdpersonCharactere(),0,g_PlayerAngY,0) if got_decal[e] == nil then got_decal[e] = 1 return elseif got_decal[e] == 1 then for a,_ in pairs (isdecal) do if isdecal[a] == -1 then isdecal[a] = e got_decal[e] = 2 break end end firing = g_Time+250 --can set a delay here so gun isn't instantly ready to fire on level load else if state[e] == "wait" then Hide(e) CollisionOff(e) SetPosition(e,g_PlayerPosX+offsetx[e],g_PlayerPosY+offsety[e],g_PlayerPosZ+offsetz[e]) SetRotation(e,g_Entity[e]['anglex'],g_PlayerAngY,g_Entity[e]['anglez']) if g_PlayerGunName ~= "" then if string.find(g_PlayerGunName,weapon_name[e]) ~= nil then if text_showing == 0 or text_showing == e then Text(1,70,4,projectile_ammo[gun_number].." / "..max_projectile_ammo[gun_number]) text_showing = e end if g_PlayerHealth > 0 then if g_MouseClick == 1 then if g_Time >= firing then if fired[e] == 0 then if projectile_ammo[gun_number] > 0 then projectile_ammo[gun_number] = projectile_ammo[gun_number] - 1 state[e] = "fired" PlaySound(e,0) firing = g_Time+fire_delay[gun_number] fired[e] = fire_delay[gun_number] end end end end end end end elseif state[e] == "fired" then if text_showing == e then text_showing = 0 end Show(e) MoveForward(e,projectile_speed[gun_number]) x1[e] = GetEntityPositionX(e) y1[e] = GetEntityPositionY(e)+1 z1[e] = GetEntityPositionZ(e) local new_y = math.rad(g_Entity[e]['angley']) x2[e] = x1[e]+(math.sin(new_y)*15) y2[e] = GetEntityPositionY(e) z2[e] = z1[e]+(math.cos(new_y)*15) if GetPlayerDistance(e) > 100 then if x1[e] ~= x2[e] or z1[e] ~= z2[e] then thit = RayTerrain(x1[e],y1[e],z1[e],x2[e],y2[e],z2[e]) if thit ~= 1 then hit = IntersectAll(x1[e],y1[e],z1[e],x2[e],y2[e],z2[e],g_Entity[e]['obj']) if hit == nil then new_y = math.rad(g_Entity[e]['angley']-5) x2[e] = x1[e]+(math.sin(new_y)*15) y2[e] = GetEntityPositionY(e) z2[e] = z1[e]+(math.cos(new_y)*15) hit = IntersectAll(x1[e],y1[e],z1[e],x2[e],y2[e],z2[e],g_Entity[e]['obj']) if hit == nil then new_y = math.rad(g_Entity[e]['angley']+5) x2[e] = x1[e]+(math.sin(new_y)*15) y2[e] = GetEntityPositionY(e) z2[e] = z1[e]+(math.cos(new_y)*15) hit = IntersectAll(x1[e],y1[e],z1[e],x2[e],y2[e],z2[e],g_Entity[e]['obj']) if hit == nil then hit = 0 end end end end if hit ~= 0 then for a,_ in pairs (ai_bot_state) do if g_Entity[a]['obj'] == hit then SetEntityHealth(a,g_Entity[a]['health']-projectile_damage[gun_number]) break end end for a,_ in pairs (projectile_damage) do if g_Entity[a]['obj'] == hit then hit = 0 break end end for a,_ in pairs (isdecal) do if g_Entity[a]['obj'] == hit then hit = 0 break end end if hit == g_Entity[GetGamePlayerControlThirdpersonCharactere()]['obj'] then hit = 0 end if hit ~= 0 then for a,_ in pairs (isdecal) do if isdecal[a] == e then SetPosition(a,GetIntersectCollisionX(),GetIntersectCollisionY(),GetIntersectCollisionZ()) SetRotation(a,0,g_Entity[e]['angley']+180,0) --MoveForward(a,30) state[a] = "show" --PromptDuration(hit,4000) break end end state[e] = "wait" fired[e] = 0 end elseif GetPlayerDistance(e) > 2000 then state[e] = "wait" fired[e] = 0 end end end end end --PromptDuration(g_Entity[GetGamePlayerControlThirdpersonCharactere()]['obj'],4000) end function thirdp_projectile_exit(e) end function AngleToPoint(e,x,z) if g_Entity[e] ~= nil and x > 0 and z > 0 then local destx = x - g_Entity[e]['x'] local destz = z - g_Entity[e]['z'] 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 --SetRotation(e,0,angle,0) return angle end end