Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Conditional Hooks
- $State: GS_STATE_GAME_PLAY
- $On Frame:
- [
- --start collecting the position of the parent once the signal is received
- if int_position_record_index ~= nil then
- vect_option_parent_current_pos = ship_optionParent.Position
- if int_position_record_index == 0 then -- it was initialized
- int_position_record_index = 1
- local temp = ship_optionParent.Position
- for i=1, const_int_bufferLength do --fill the array with the player's current position so that there is not an empty buffer positions
- list_position_buffer[i] = temp
- end
- else
- --If the player is in "idle" position don't bother updating the buffer.
- if (vect_option_parent_current_pos["y"] ~= (vect_option_parent_previous_pos["y"] + (ba.getFrametime(false)*floatScrollY)) or vect_option_parent_current_pos["z"] ~= (vect_option_parent_previous_pos["z"] + (ba.getFrametime(false)*floatScrollZ))) then
- if ship_optionParent.Physics.Velocity["z"] ~= shmup_idle_pscroll_speed["z"] or ship_optionParent.Physics.Velocity["y"] ~= shmup_idle_pscroll_speed["y"] then
- list_position_buffer[int_position_record_index] = ship_optionParent.Position
- int_position_record_index = int_position_record_index + 1
- if int_position_record_index == #list_position_buffer then
- int_position_record_index = 1 --restart the buffer
- end
- end
- end
- end
- if #list_options > 0 then --if the guy has no options, don't even bother.
- for i=1, #list_options do
- assignment_vector = getOptionCoordinate(i*10)
- if assignment_vector ~= nil then
- --if the player isn't moving, don't update the option's position at all.
- if (vect_option_parent_current_pos["y"] ~= (vect_option_parent_previous_pos["y"] + (ba.getFrametime(false)*floatScrollY)) or vect_option_parent_current_pos["z"] ~= (vect_option_parent_previous_pos["z"] + (ba.getFrametime(false)*floatScrollZ))) then
- if ship_optionParent.Physics.Velocity["z"] ~= shmup_idle_pscroll_speed["z"] or ship_optionParent.Physics.Velocity["y"] ~= shmup_idle_pscroll_speed["y"] then
- assignment_vector["x"] = ship_optionParent.Position["x"] --make sure the options are on the same x position as the player at all times.
- list_options[i].Position = assignment_vector
- end
- end
- end
- end
- end
- vect_option_parent_previous_pos = vect_option_parent_current_pos
- gr.setColor(255, 255, 255)
- gr.drawString("Options Fired: " .. tostring(boolean_option_fired), 10, 130)
- gr.drawString("O1: " .. tostring(getOptionCoordinate((1*30))), 10, 150)
- gr.drawString("O2: " .. tostring(getOptionCoordinate((2*30))), 10, 160)
- gr.drawString("O3: " .. tostring(getOptionCoordinate((3*30))), 10, 170)
- gr.drawString("O4: " .. tostring(getOptionCoordinate((4*30))), 10, 180)
- end
- --starts the buffer for collecting the player position
- function startPosCollect()
- int_position_record_index = 0 --zero means not used yet signal.
- list_options = {} --blank array at the start of the mission.
- list_position_buffer = {} --blank array for storing parent positions
- ship_optionParent = hv.Player --Can be changed to anything you want, but the player is prolly the best person for this.
- const_int_bufferLength = (60*4) --4 seconds at 60 FPS
- vect_option_parent_current_pos = ship_optionParent.Position
- vect_option_parent_previous_pos = ship_optionParent.LastPosition
- vect_option_no_speed = ba.createVector(0,0,0)
- boolean_option_fired = false
- end
- --adds option to the man's collection.
- function addOption(optionName)
- ship_option_to_add = mn.Ships[optionName]
- if ship_option_to_add ~= nil then
- list_options[#list_options+1] = ship_option_to_add
- end
- end
- --Some bastard Option Hunter stole my option(s)!
- function removeOption(optionName)
- option_to_remove = mn.Ships[optionName]
- local index_to_nil = 0
- if option_to_remove ~= nil then
- for i=1,#list_options do
- if list_options[i] == option_to_remove then --break out once the option is found.
- index_to_nil = i
- list_options[i] = nil
- break
- end
- end
- --since the nasty Option Hunter steals everything down the chain it catches, we are only going to rebuild the array up until the index before the option was stolen.
- local temp_array = {}
- for i=1,index_to_nil do
- if i == index_to_nil then --just in case
- break
- else
- temp_array[i] = list_options[i]
- end
- end
- list_options = temp_array --reassign the new array to this.
- end
- end
- --DO NOT CALL THIS IN FRED.
- --helper function for the for loop in the $On Frame section.
- --Determines the position of option
- --Returns a vector of the position the option should be.
- function getOptionCoordinate(int_distance_p)
- local int_idx = 0
- int_idx = int_position_record_index - int_distance_p
- if int_idx < 0 then
- int_idx = int_idx + #list_position_buffer
- elseif int_idx > (#list_position_buffer-5) then
- int_idx = (#list_position_buffer-5)
- end
- return list_position_buffer[int_idx]
- end
- ]
- $On Weapon Fired:
- [
- if hv.User == ship_optionParent and #list_options > 0 then --be sure the person firing is the parent of the options and that there are options there.
- for i=1, #list_options do
- list_options[i]:firePrimary()
- end
- boolean_option_fired = true
- else
- boolean_option_fired = false
- end
- ]
- $On Death:
- [
- local dyingShip = hv.Self
- if dyingShip == hv.Player then --Do not disable the options if it's not the player who's blowing up!!
- int_position_record_index = nil
- end
- ]
- $On Mission End:
- [
- int_position_record_index = nil --force it off when a mission ends.
- ]
- #End
Advertisement
Add Comment
Please, Sign In to add comment