Jump to content

IAmKane

Alpha Tester
  • Posts

    9
  • Joined

  • Last visited

Posts posted by IAmKane

  1. I mean really all I wanted was an updated minimap that was more visible, customizable and user friendly than the cluttered tiny mess we've got stuck in the corner. I'm not trying to build bloody SkyNet, just add something that's in basically every first-person game by default.

  2. 54 minutes ago, SGCam said:

    I don't see them changing that decision, because being able to get the position of enemy ships would allow you to write combat autopilots that would be vastly superior to player pilots.  NQ is trying very hard to make the game not be dependent on lua, so I doubt they will add a feature that makes it mandatory in order to be competitive.

    In that case they should really change the element titles to something more appropriate and adjust the API library where this subject is concerned. At the moment it's quite misleading since it implies capability that doesn't actually exist.

  3. 3 hours ago, JayleBreak said:

    The removed the ability to get position information from the space radar as NQ felt that scripting would diminish game play. They added `getEntries()` recently I guess because 1) Its consensual, and 2) promotes gameplay(?).
    BTW:

    
    	for i,v in ipairs(Contacts) do
    		local cID = Contacts[i] -- construct ID for 'i'

    Can be simplified to:

    
    	for i,cID in ipairs(Contacts) do

     

    Thank you sir! Old table habits, I'm still learning Lua.

     

    I hope they rethink that decision in the future because the logic doesn't compute.

  4. Hello all. I've noticed there doesn't seem to be any kind of script out there for a Radar Plot yet so I decided to take a crack at it. Unsurprisingly I immediately ran into issues. I have a bunch of questions, but I'll start off with what I hope is a simple one:

     

    In this section of code I'm using getEntries() to get all the available IDs then looping through the IDs to get data for each contact. (I don't actually plan on using all this data, I just want to test and see what I can get to work and pare it down from there.)

    I'm getting the contact ID's to pull in in the debug but I'm getting errors reading any kind of data about those IDs. 

    Contacts = Radar.getEntries() --list of construct IDs
    if #Contacts >= 1 then
    	for i,v in ipairs(Contacts) do
    		local cID = Contacts[i] -- construct ID for 'i'
    		local cName = Radar.getConstructName(cID) --name of detected construct [id][name]
    		local pID = Radar.getConstructOwner(cID) --player ID # of construct owner [id][player]
    		local cOwner = database.getPlayer(pID) --resolve player name from player ID
    		local cSize = vec3(Radar.getConstructSize(cID)) --size of the construct bounding box [id][x,y,z]
    		local cType = Radar.getConstructType(cID) --type of construct [id][static/dynamic]
    		local cPos = vec3(Radar.getConstructPos(cID)) --local coordinates of the construct [id][x,y,z]
    		local cVel = vec3(Radar.getConstructVelocity(cID)) --local speed relative to absolute space [id][x,y,z]
    		local cSpeed = cVel:len() --rendered speed based on cVel info above
    		local cAcc = vec3(Radar.getConstructAcceleration(cID)) --local accel relative to absolute space [id][x,y,z]
    		local cWorldPos = vec3(Radar.getConstructWorldPos(cID)) --world coordinates of the construct [id][x,y,z]
    		local cWorldVel = vec3(Radar.getConstructWorldVelocity(cID)) --world speed relative to absolute space [id][x,y,z]
    		local cWorldAcc = vec3(Radar.getConstructWorldAcceleration(cID)) --world accel relative to absolute space [id][x,y,z]

    It's yelling at me for calling getConstructOwner() saying it's a nil variable. Testing all of the other variables relating to position and speed for the contacts yields the same error. Am I making a mistake in how I am calling them? I checked the API and it looks right to me but then I've been wrong before.

     

    As a reference here is the whole code in its current state:

    Spoiler
    
    --RADAR DISPLAY INIT--
    RadScreenButtons = {}
    RadScreenMouseX = 0
    RadScreenMouseY = 0
    RadScreenMouseDown = false
    RadScreenButtonSelected = 0
    local scanX = 0
    local scanY = 0
    local t = 0
    
    --GLOBAL VARS--
    ThresholdVel = 200.0 --only show contacts above this velocity in m/s
    SearchType = "Dynamic" --only show constructs of this type: Static/Dynamic/Both
    RadarMode = "Atmospheric" --type of radar being queried: Atmospheric/Space
    rcolor = "limegreen" --default color is for atmospheric mode
    RadarRange = 0.0 --default scan range for radar, set to '0.0' to use max range
    
    --Buttons for Velocity Up/Down, Search Type, Mode, Range Up/Down
    for i = 1,1 do --velocity up
    	local button = {id = ("b"..1), enabled=true, td="<td>", top=83/100, bottom=87/100, left=1/100, right=28/100}--~ height="50" width="250" y="850" x="15"
    	table.insert(RadScreenButtons, button)
    end
    for i = 2,2 do --velocity down
    	local button = {id = ("b"..2), enabled=true, td="<td>", top=89/100, bottom=93/100, left=1/100, right=30/100}--~ height="50" width="250" y="910" x="15"
    	table.insert(RadScreenButtons, button)
    end
    for i = 3,3 do --switch search type (static/dynamic/both)
        local button = {id = ("b"..3), enabled=true, td="<td>", top=94/100, bottom=98/100, left=1/100, right=28/100}--~ height="50" width="250" y="970" x="15"
    	table.insert(RadScreenButtons, button)
    end
    for i = 4,4 do --toggle mode (atmo/space)
        local button = {id = ("b"..4), enabled=true, td="<td>", top=83/100, bottom=87/100, left=75/100, right=100/100}--~ height="50" width="250" y="850" x="760"
    	table.insert(RadScreenButtons, button)
    end
    for i = 5,5 do --range increase
        local button = {id = ("b"..5), enabled=true, td="<td>", top=89/100, bottom=93/100, left=75/100, right=100/100}--~ height="50" width="250" y="910" x="760"
    	table.insert(RadScreenButtons, button)
    end
    for i = 6,6 do --range decrease
        local button = {id = ("b"..6), enabled=true, td="<td>", top=94/100, bottom=98/100, left=75/100, right=100/100}--~ height="50" width="250" y="970" x="760"
    	table.insert(RadScreenButtons, button)
    end
    for i = 7,7 do
        local button = {id = ("b"..7), enabled=true, td="<td>", top=90/100, bottom=100/100, left=40/100, right=60/100}
        table.insert(RadScreenButtons, button)
    end
    
    function evaluateButtons()
      local selected = 0
    
      if #RadScreenButtons >= 1 the
            for i, button in ipairs(RadScreenButtons) do
                if button.left < RadScreenMouseX and RadScreenMouseX < button.right and button.top < RadScreenMouseY and RadScreenMouseY < button.bottom then
                    if RadScreenMouseDown and RadScreenButtons == i then
                    end
                    selected = i
                end
                if not button.enabled then
                end
    
            end
      end
      return selected
    end
    
    function onButtonDown(buttonNo)
      local button = RadScreenButtons[buttonNo]
      if not button or not button.enabled then
    	return
      end
    end
    
    function onButtonUp(buttonNo)
      local button = RadScreenButtons[buttonNo]
      if not button or not button.enabled then
        return
      end
    
    function onClick(buttonNo)
      local button = RadScreenButtons[buttonNo]
      if not button or not button.enabled then
        return
      end
    end
    
    if buttonNo == 1 then --increase velocity search threshold
    	ThresholdVel = ThresholdVel + 25.0
    elseif buttonNo == 2 then --decrease velocity search threshold
    	ThresholdVel = ThresholdVel - 25.0
    elseif buttonNo == 3 then --toggle construct search type
    	if SearchType == "Dynamic" then
    		SearchType = "Both"
    	elseif SearchType == "Both" then
    		SearchType = "Static"
    	elseif SearchType == "Both" then
    		SearchType = "Dynamic"
    	end
    elseif buttonNo == 4 then --toggle radar search mode
    	if RadarMode == "Atmospheric" then
    		RadarMode = "Space"
    	elseif RadarMode == "Space" then
    		RadarMode = "Atmospheric"
    	end
    elseif buttonNo == 5 then --increase radar search range
    	RadarRange = RadarRange + 100.0
    elseif buttonNo == 6 then --decrease radar search range
    	RadarRange = RadarRange - 100.0
    elseif buttonNo == 7 then
      unit.exit()
      end
    end
    
    function updateScreen()
    if t = 360 then
    	t = 0
    else
    	t = t + 1
    end
    if RadarMode == "Atmpspheric" then
    	rcolor = "limegreen"
    elseif RadarMode == "Space" then
    	rcolor = "aqua"
    end
    
    scanX = math.floor(400 * math.cos(t*(3.14/180)))
    scanY = math.floor(400 * math.sin(t*(3.14/180)))
    
    maxRange = Radar.getRange()
    if RadarRange = 0.0 then
    	scanRange = maxRange
    elseif RadarRange > maxRange then
    	scanRange = maxRange
    	RadarRange = maxRange
    elseif RadarRange > 0.0 then
    	scanRange = RadarRange
    end
    
    html= ([[
    <svg class="bootstrap" viewBox="0 0 1024 1024" style="width:100%; height:100%">
    <circle cx="500" cy="500" r="400" stroke="]]..rcolor..[[" stroke-width="3" transform=""></circle>
    <circle cx="500" cy="500" r="350" stroke="]]..rcolor..[[" stroke-width="3" transform="" stroke-opacity="0.2"></circle>
    <circle cx="500" cy="500" r="300" stroke="]]..rcolor..[[" stroke-width="3" transform=""></circle>
    <circle cx="500" cy="500" r="250" stroke="]]..rcolor..[[" stroke-width="3" transform="" stroke-opacity="0.2"></circle>
    <circle cx="500" cy="500" r="200" stroke="]]..rcolor..[[" stroke-width="3" transform=""></circle>
    <circle cx="500" cy="500" r="150" stroke="]]..rcolor..[[" stroke-width="3" transform="" stroke-opacity="0.2"></circle>
    <circle cx="500" cy="500" r="100" stroke="]]..rcolor..[[" stroke-width="3" transform=""></circle>
    <circle cx="500" cy="500" r="50" stroke="]]..rcolor..[[" stroke-width="3" transform="" stroke-opacity="0.2"></circle>
    <circle cx="500" cy="500" r="20" stroke="]]..rcolor..[[" stroke-width="3" transform=""></circle>
    <circle cx="-0.00" cy="0" r="3" stroke="]]..rcolor..[[" stroke-width="1" fill="]]..rcolor..[[" transform="translate(500,500)"></circle>
    
    <text stroke="null" transform="matrix(0.7907331239400577,0,0,0.7600725676692406,3.135703637258853,5.731969683147472) " xml:space="preserve" text-anchor="start" font-family="Helvetica, Arial, sans-serif" font-size="20" id="svg_8" y="1150" x="55" stroke-width="0" fill="]]..rcolor..[[">Increase Vel.</text>
    <text stroke="null" transform="matrix(0.7907331239400577,0,0,0.7600725676692406,3.135703637258853,5.731969683147472) " xml:space="preserve" text-anchor="start" font-family="Helvetica, Arial, sans-serif" font-size="20" id="svg_14" y="1230" x="55" stroke-width="0" fill="]]..rcolor..[[">Decrease Vel.</text>
    <text stroke="null" transform="matrix(0.7907331239400577,0,0,0.7600725676692406,3.135703637258853,5.731969683147472) " xml:space="preserve" text-anchor="start" font-family="Helvetica, Arial, sans-serif" font-size="20" id="svg_17" y="1310" x="55" stroke-width="0" fill="]]..rcolor..[[">Search Type</text>
    <rect rx="10" id="svg_2" height="50" width="250" y="850" x="15" stroke-width="5" stroke="]]..rcolor..[[" fill="none"/>
    <rect rx="10" id="svg_3" height="50" width="250" y="910" x="15" stroke-width="5" stroke="]]..rcolor..[[" fill="none"/>
    <rect rx="10" id="svg_4" height="50" width="250" y="970" x="15" stroke-width="5" stroke="]]..rcolor..[[" fill="none"/>
    <text stroke="null" transform="matrix(0.7907331239400577,0,0,0.7600725676692406,3.135703637258853,5.731969683147472) " xml:space="preserve" text-anchor="start" font-family="Helvetica, Arial, sans-serif" font-size="20" id="svg_25" y="1150" x="997.163642" stroke-width="0" fill="]]..rcolor..[[">Radar Mode</text>
    <text stroke="null" transform="matrix(0.7907331239400577,0,0,0.7600725676692406,3.135703637258853,5.731969683147472) " xml:space="preserve" text-anchor="start" font-family="Helvetica, Arial, sans-serif" font-size="20" id="svg_27" y="1230" x="997.163642" stroke-width="0" fill="]]..rcolor..[[">Increase Range</text>
    <text stroke="null" transform="matrix(0.7907331239400577,0,0,0.7600725676692406,3.135703637258853,5.731969683147472) " xml:space="preserve" text-anchor="start" font-family="Helvetica, Arial, sans-serif" font-size="20" id="svg_28" y="1310" x="997.163642" stroke-width="0" fill="]]..rcolor..[[">Decrease Range</text>
    <rect rx="10" id="svg_5" height="50" width="250" y="850" x="760" stroke-width="5" stroke="]]..rcolor..[[" fill="none"/>
    <rect rx="10" id="svg_6" height="50" width="250" y="910" x="760" stroke-width="5" stroke="]]..rcolor..[[" fill="none"/>
    <rect rx="10" id="svg_7" height="50" width="250" y="970" x="760" stroke-width="5" stroke="]]..rcolor..[[" fill="none"/>
    
    <line stroke-linecap="undefined" stroke-linejoin="undefined" id="svg_1" y2="]]..scanY..[[" x2="]]..scanX..[[" y1="0" x1="0" transform="translate(500,500)" stroke-width="3" stroke="]]..rcolor..[[" fill="none"/>
    
    <text x="-470" y="-420" transform="translate(500,500)"fill="]]..rcolor..[[" font-size= "9vh" font-weight= "bold">TARGET VELOCITY:"]]..ThresholdVel..[["m/s</text>
    <text x="-420" y="-450" transform="translate(500,500)"fill="]]..rcolor..[[" font-size= "9vh" font-weight= "bold">RADAR RANGE:"]]..scanRange..[["m</text>
    <text x="-410" y="-480" transform="translate(500,500)"fill="]]..rcolor..[[" font-size= "9vh" font-weight= "bold">RADAR MODE:"]]..RadarMode..[["</text>
    
        ]])
    
    Contacts = Radar.getEntries() --list of construct IDs
    if #Contacts >= 1 then
    	for i,v in ipairs(Contacts) do
    		local cID = Contacts[i] -- construct ID for 'i'
    		local cName = Radar.getConstructName(cID) --name of detected construct [id][name]
    		local pID = Radar.getConstructOwner(cID) --player ID # of construct owner [id][player]
    		local cOwner = database.getPlayer(pID) --resolve player name from player ID
    		local cSize = vec3(Radar.getConstructSize(cID)) --size of the construct bounding box [id][x,y,z]
    		local cType = Radar.getConstructType(cID) --type of construct [id][static/dynamic]
    		local cPos = vec3(Radar.getConstructPos(cID)) --local coordinates of the construct [id][x,y,z]
    		local cVel = vec3(Radar.getConstructVelocity(cID)) --local speed relative to absolute space [id][x,y,z]
    		local cSpeed = cVel:len() --rendered speed based on cVel info above
    		local cAcc = vec3(Radar.getConstructAcceleration(cID)) --local accel relative to absolute space [id][x,y,z]
    		local cWorldPos = vec3(Radar.getConstructWorldPos(cID)) --world coordinates of the construct [id][x,y,z]
    		local cWorldVel = vec3(Radar.getConstructWorldVelocity(cID)) --world speed relative to absolute space [id][x,y,z]
    		local cWorldAcc = vec3(Radar.getConstructWorldAcceleration(cID)) --world accel relative to absolute space [id][x,y,z]
    
    --~ 		rendered coords:
    		if SearchType == "Both" then
    			if cSpeed >= ThresholdVel then
    				local newcoordx = (cPos.x/scanRange)*400
    				local newcoordy = (cPos.y/scanRange)*400
    
    				html = html..[[<circle cx="]]..newcoordx..[[" cy="]]..newcoordy..[[" r="5" stroke="black" stroke-width="1" fill="]]..rcolor..[[" transform="translate(500,500)"></circle>
    				<text x="]]..newcoordx..[[" y="]]..newcoordy..[[" transform="translate(500,500)"fill="]]..rcolor..[[" font-size= "4.5vh" font-weight= "bold">"]]..cOwner..[["</text>]]
    			end
    		elseif SearchType = cType then
    			if SearchType == "Dynamic" then
    				if cSpeed >= ThresholdVel then
    					local newcoordx = (cPos.x/scanRange)*400
    					local newcoordy = (cPos.y/scanRange)*400
    
    					html = html..[[<circle cx="]]..newcoordx..[[" cy="]]..newcoordy..[[" r="5" stroke="black" stroke-width="1" fill="]]..rcolor..[[" transform="translate(500,500)"></circle>
    					<text x="]]..newcoordx..[[" y="]]..newcoordy..[[" transform="translate(500,500)"fill="]]..rcolor..[[" font-size= "4.5vh" font-weight= "bold">"]]..cOwner..[["</text>]]
    				end
    			elseif SearchType == "Static" then
    				local newcoordx = (cPos.x/scanRange)*400
    				local newcoordy = (cPos.y/scanRange)*400
    
    				html = html..[[<circle cx="]]..newcoordx..[[" cy="]]..newcoordy..[[" r="5" stroke="black" stroke-width="1" fill="]]..rcolor..[[" transform="translate(500,500)"></circle>
    				<text x="]]..newcoordx..[[" y="]]..newcoordy..[[" transform="translate(500,500)"fill="]]..rcolor..[[" font-size= "4.5vh" font-weight= "bold">"]]..cOwner..[["</text>]]
    			end
    		end
    	end
    end
    
    html = html..[[
    </svg>]]
    screen.setHTML(html)
    end
    unit.setTimer("radardisplay",.08)

     

     

  5. 21 hours ago, PlasmaFlow said:

    Can you post the final working code?

    It's the same as in the OP, just with constructVelocity:len() replacing constructVelocity.  It goes into the flush() of my ship inside of the if-then for determining whether it is in atmosphere or not when it is complied as a 'flying' type construct.

     

    Basically like this:

    
    	local autoRollVelThreshold = 50.0 --export: velocity below which the creaft will auto-roll the wings level to aid in landing =====NEW=====
    
    -- In atmosphere?
    	if worldVertical:len() > 0.01 and unit.getAtmosphereDensity() > 0.0 then
    		local autoRollRollThreshold = 1.0
    		-- autoRoll on AND currentRollDeg is big enough AND player is not rolling
    		if autoRoll == true and currentRollDegAbs > autoRollRollThreshold and finalRollInput == 0 then
    			local targetRollDeg = utils.clamp(0,currentRollDegAbs-30, currentRollDegAbs+30);  -- we go back to 0 within a certain limit
    			if (rollPID == nil) then
    				rollPID = pid.new(autoRollFactor * 0.01, 0, autoRollFactor * 0.1) -- magic number tweaked to have a default factor in the 1-10 range
    			end
    			rollPID:inject(targetRollDeg - currentRollDeg)
    			local autoRollInput = rollPID:get()
    
    			targetAngularVelocity = targetAngularVelocity + autoRollInput * constructForward
    		end
    		-- =====START NEW=====autolevel
    		-- rolls wings level if velocity is below a certain limit
    		if constructVelocity:len() < autoRollVelThreshold then
    			local targetRollDeg = utils.clamp(0,currentRollDegAbs-30, currentRollDegAbs+30);  -- we go back to 0 within a certain limit
    			if (rollPID == nil) then
    				rollPID = pid.new(autoRollFactor * 0.01, 0, autoRollFactor * 0.1) -- magic number tweaked to have a default factor in the 1-10 range
    			end
    			rollPID:inject(targetRollDeg - currentRollDeg)
    			local autoRollInput = rollPID:get()
    
    			targetAngularVelocity = targetAngularVelocity + autoRollInput * constructForward
    		end
    		-- =====STOP NEW=====autolevel
    		local turnAssistRollThreshold = 20.0
    		-- turnAssist AND currentRollDeg is big enough AND player is not pitching or yawing
    		if turnAssist == true and currentRollDegAbs > turnAssistRollThreshold and finalPitchInput == 0 and finalYawInput == 0 then
    			local rollToPitchFactor = turnAssistFactor * 0.1 -- magic number tweaked to have a default factor in the 1-10 range
    			local rollToYawFactor = turnAssistFactor * 0.025 -- magic number tweaked to have a default factor in the 1-10 range
    
    			-- rescale (turnAssistRollThreshold -> 180) to (0 -> 180)
    			local rescaleRollDegAbs = ((currentRollDegAbs - turnAssistRollThreshold) / (180 - turnAssistRollThreshold)) * 180
    			local rollVerticalRatio = 0
    			if rescaleRollDegAbs < 90 then
    				rollVerticalRatio = rescaleRollDegAbs / 90
    			elseif rescaleRollDegAbs < 180 then
    				rollVerticalRatio = (180 - rescaleRollDegAbs) / 90
    			end
    
    			rollVerticalRatio = rollVerticalRatio * rollVerticalRatio
    
    			local turnAssistYawInput = - currentRollDegSign * rollToYawFactor * (1.0 - rollVerticalRatio)
    			local turnAssistPitchInput = rollToPitchFactor * rollVerticalRatio
    
    			targetAngularVelocity = targetAngularVelocity
    								+ turnAssistPitchInput * constructRight
    								+ turnAssistYawInput * constructUp
    		end
    	end

    Sorry it's so messy, the auto-formatting really didn't like this snippet.

  6. Like the title says, this is probably a simple question but I'm having an issue getting any kind of custom tweaking done in my ship. Hopefully one of you knowledgeable folks can let me know where I've gone wrong.

     

    Currently my ship is setup as a flying construct with the mouse-point control method. I figured I'd start with some 'simple' adjustments so that the ship behaved differently when below a certain speed to simplify the landing process. Apparently I was too ambitious, because when I try to fly the ship it locks up the controls and I get a lovely red "LUA Error" message.

     

    I did my best to stick to pretty simple code based on what was already in the script so I'm pretty sure my syntax is correct, but I'm new to LUA so I could be way off base.

     

    Here's the code I've tried starting with:

    local autoRollVelThreshold = 50.0 --my created variable
    local constructVelocity = vec3(core.getWorldVelocity()) --pre-existing variable 
    
    -- rolls wings level if velocity is below a certain limit defined by the variable autoRollVelThreshold
    if constructVelocity < autoRollVelThreshold then
      local targetRollDeg = utils.clamp(0,currentRollDegAbs-30, currentRollDegAbs+30);  -- we go back to 0 within a certain limit
      if (rollPID == nil) then
         rollPID = pid.new(autoRollFactor * 0.01, 0, autoRollFactor * 0.1) -- magic number tweaked to have a default factor in the 1-10 range
      end
         rollPID:inject(targetRollDeg - currentRollDeg)
         local autoRollInput = rollPID:get()
         targetAngularVelocity = targetAngularVelocity + autoRollInput * constructForward
    end

    It's based on the pre-existing code for the auto-roll parameter, except instead of using the true/false autoRoll variable I'm using the local variable constructVelocity defined elsewhere in flush() alongside my local variable autoRollVelThreshold which sets the speed at which the action takes place.  

     

    I thought this would be a simple start to something more complex but it appears I've got some basic issues I still need to get sorted. Any help would be greatly appreciated, thanks.

×
×
  • Create New...