Jump to content
Sign in to follow this  
baldwin

Spawn any gage package at your crosshair

Recommended Posts

baldwin

Requires persisted _globals.lua from latest Pirate Perfection or just add this code before my code:

	--  GET XHAIR POS

	function get_crosshair_pos(penetrate)

		local ray = get_crosshair_ray(penetrate)

		if not ray then return false end

		return ray.hit_position

	end



	-- IN CROSSHAIR	

	function get_crosshair_ray(penetrate, slotMask)

	  if not slotMask then slotMask = "bullet_impact_targets" end

	  local player = managers.player:player_unit()

	  local fromPos = player:camera():position()

	  local mvecTo = Vector3()

	  mvector3.set(mvecTo, player:camera():forward())

	  mvector3.multiply(mvecTo, 20000)

	  mvector3.add(mvecTo, fromPos)

	  local colRay = World:raycast("ray", fromPos, mvecTo, "slot_mask", managers.slot:get_mask(slotMask))

	  if colRay and penetrate then

			  local offset = Vector3()

					mvector3.set(offset, player:camera():forward())

					mvector3.multiply(offset, 100)

			  mvector3.add(colRay.hit_position, offset)

	  end

	  return colRay

	end



Actual script (30apr update):


SpawnGagePackage = SpawnGagePackage or function(id) --Don't pass any argument for random package

  function tweak_data.gage_assignment:get_num_assignment_units() --Patches limit on spawning units. World:spawn_unit somehow obey this value.

    return 9999

  end

  local id_table = {

    Idstring("units/pd2_dlc_gage_jobs/pickups/gen_pku_gage_green/gen_pku_gage_green"),

    Idstring("units/pd2_dlc_gage_jobs/pickups/gen_pku_gage_yellow/gen_pku_gage_yellow"),

    Idstring("units/pd2_dlc_gage_jobs/pickups/gen_pku_gage_red/gen_pku_gage_red"),

    Idstring("units/pd2_dlc_gage_jobs/pickups/gen_pku_gage_blue/gen_pku_gage_blue"),

    Idstring("units/pd2_dlc_gage_jobs/pickups/gen_pku_gage_purple/gen_pku_gage_purple"),

}

  local pos = get_crosshair_pos()

  local rot = Rotation(managers.player:local_player():movement():m_head_rot():yaw(),0,0)

  if not pos or not rot then

    return

  end

  World:spawn_unit(id_table[id or math.random(1,5)], pos, rot )

end



SpawnGagePackage()

Enjoy :-)

  • Upvote 1

Share this post


Link to post
Share on other sites
PirateCaptain

Requires persisted _globals.lua from latest Pirate Perfection or just add this code before my code:

	--  GET XHAIR POS

	function get_crosshair_pos(penetrate)

		local ray = get_crosshair_ray(penetrate)

		if not ray then return false end

		return ray.hit_position

	end



	-- IN CROSSHAIR	

	function get_crosshair_ray(penetrate, slotMask)

	  if not slotMask then slotMask = "bullet_impact_targets" end

	  local player = managers.player:player_unit()

	  local fromPos = player:camera():position()

	  local mvecTo = Vector3()

	  mvector3.set(mvecTo, player:camera():forward())

	  mvector3.multiply(mvecTo, 20000)

	  mvector3.add(mvecTo, fromPos)

	  local colRay = World:raycast("ray", fromPos, mvecTo, "slot_mask", managers.slot:get_mask(slotMask))

	  if colRay and penetrate then

			  local offset = Vector3()

					mvector3.set(offset, player:camera():forward())

					mvector3.multiply(offset, 100)

			  mvector3.add(colRay.hit_position, offset)

	  end

	  return colRay

	end



Actual script:


SpawnGagePackage = SpawnGagePackage or function(id) --Don't pass argument for random package

  function tweak_data.gage_assignment:get_num_assignment_units() --Patches limit on spawning units. World:spawn_unit somehow obey this value.

    return 9999

  end

  local id_table = {

    Idstring("units/pd2_dlc_gage_jobs/pickups/gen_pku_gage_green/gen_pku_gage_green"),

    Idstring("units/pd2_dlc_gage_jobs/pickups/gen_pku_gage_yellow/gen_pku_gage_yellow"),

    Idstring("units/pd2_dlc_gage_jobs/pickups/gen_pku_gage_red/gen_pku_gage_red"),

    Idstring("units/pd2_dlc_gage_jobs/pickups/gen_pku_gage_blue/gen_pku_gage_blue"),

    Idstring("units/pd2_dlc_gage_jobs/pickups/gen_pku_gage_purple/gen_pku_gage_purple"),

}

  World:spawn_unit(id_table[id or math.random(1,5)], get_crosshair_pos(), Rotation(managers.player:local_player():movement():m_head_rot():yaw(),0,0) )

end



SpawnGagePackage()

Enjoy :-)

Thank you baldwin :) and i love the pictures hehehehe especially the tower of packages

Share this post


Link to post
Share on other sites
Guest cooper5000

Any chance of patching this code, once it only work when we are hosting the game? Other way the game CTD.

And a great thanks.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Stop being a peeping tom and join the community.... we got cookies

Join the crew now

Sign in

Already part of the crew? Board right here

Sign In Now
Sign in to follow this  

×