Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SOLVED] keep getting nil value when attempting to use a repeat loop  (Read 928 times)

0 Members and 1 Guest are viewing this topic.

Offline Dazza-chan

  • *
  • +1% chance to make useful post
  • Dazza-chan has no influence.
Ok so I'm not gonna beat around the bush, i'm pretty shit at lua.
I've been working on a lua based replacement for the randomspawn section, the most integral function is actually something i found in smod redux final,



Code: [Select]
function GetRandomNodePosition()

local nodes = HL2.GetNodeCounts()
local retorg = nil

    if nodes >= 1 then
local node  = HL2.GetNodeData(HL2.RandomInt(0,nodes-1))
if node ~= nil then
retorg = HL2.Vector(node.x, node.y + 16, node.z)
end
end

return retorg

end

that is obviously used to find a random node when called by another function, and return the position of the node as an origin.

trouble is, when finding nodes in poorly noded, or cluttered maps, npcs can end up spawned in walls, or within eachother etc.

To remedy this i tried to insert a simple repeat loop with a HL2.CheckRoom in order to make sure there is room enough for the standard human_hull, if there isn't enough room at the node, then the block is to repeat and select a new node. however whenever this edited function is called, it fails and simply returns a nil value in the console.

The function is as follows

Code: [Select]
function GetRandomNodePosition()

local nodes = HL2.GetNodeCounts()
local retorg = nil
local node = nil
local hasroom = 0
local MINS = (0, 0, 0)
local MAX = (0, 0, 0)

if nodes >= 1 then
while hasroom == 0 do
node = HL2.GetNodeData(HL2.RandomInt(0,nodes-1))
if node ~= nil then
hasroom = HL2.CheckRoom(node, MINS, MAX)
end
if hasroom == 0 then
end
if hasroom == 1 break end
retorg = HL2.Vector(node.x, node.y + 16, node.z)
end
return retorg
end
end

I'm utter shite at this, and i'm sorry if this turns out to be an easy fix. But its 1:30am here and my head isn't functioning enough to do this alone.
« Last Edit: August 11, 2018, 04:02:34 AM by Dazza-chan »

Offline Dazza-chan

  • *
  • +1% chance to make useful post
  • Dazza-chan has no influence.
Re: [LUA] keep getting nil value when attempting to use a repeat loop
« Reply #1 on: August 10, 2018, 02:06:55 AM »
So it turns out the issue is actually how im using HL2.CheckRoom, i'm not sure what i'm doing wrong however.

bool = HL2.CheckRoom(0 0 0, 1 1 1, 2 2 2)

even something as simple as this spits out a nil value in console. Am i incorrectly stating the origins, mins, and maxs?
« Last Edit: August 10, 2018, 02:16:57 AM by Dazza-chan »

Offline Dazza-chan

  • *
  • +1% chance to make useful post
  • Dazza-chan has no influence.
Re: [SOLVED] keep getting nil value when attempting to use a repeat loop
« Reply #2 on: August 11, 2018, 04:02:50 AM »
Fixed, after a long time debugging.

Offline Aenfonai

  • *
  • +1% chance to make useful post
  • Aenfonai has no influence.
Re: [SOLVED] keep getting nil value when attempting to use a repeat loop
« Reply #3 on: August 14, 2018, 09:40:36 AM »
We sincerely hope that this discussion will make it even more clear.

Offline Alogzasud

  • *
  • +1% chance to make useful post
  • Alogzasud has no influence.
Re: [SOLVED] keep getting nil value when attempting to use a repeat loop
« Reply #4 on: October 18, 2018, 08:22:43 AM »
This article is good, I read already. And have knowledge