Author Topic: I got a problem with finding containers that are near in script?!  (Read 534 times)

ninekorn

  • Newbie
  • *
  • Posts: 41
    • View Profile
Hi,

So im working on drone commands "utilities" like "go pickup containers that are near". But theres one big issue. Ive tried to find a function in the Scripting API that gives me access to all the objects tags in the system or all the objects in the system or all objects in scope but theres nothing like that in the Scripting API. So i've decided to search with Notepad++ all the scripts for any functions that started with "generator." and found generator.AreThereAnyObjects(sys_idNPC, direction.x, direction.y, 25, { except_ships: true}); and that turns out to give Boolean true or false. I thought at first it could be meaningless since i dont need booleans but more the ID of the Objects... So I went ahead and found out I just could do this function. It pretty much does the same as the original function but instead i limit the range to 1 unit and just use a ForLoop with 15 radius in +x -x +y -y to get me the exact position where there are objects. I thought that would solve my problem... Lol the thing is generator.AreThereAnyObjects() doesnt take into consideration containers... so im stuck.  It does give me the position of any other objects though except containers + even IF i had the containers position there doesnt seem to be a function that gives me the gameObjectID at coordx-coordy. so Id still be stuck. I can't get the containerID without the ObjectID and i cant get the ObjectID without a function to help me find those IDs. If generator.AreThereAnyObjects() would also consider containers and also returning the ID of the object it finds then bam we would have a function that does exactly ship.ScopeObjects that isnt in the Scripting API. helllpppp.

Code: [Select]
function goPickContainers()
{

var player_id = npc.GetTag(SHIP_ID, "ownerPlayerShipId");

var sys_idNPC = npc.GetCurrentSystemID(SHIP_ID);

var direction = ship.GetCoordinates(SHIP_ID);

for (var x = 0; x < 15; x++)
{
for (var y = 0; y < 15; y++)
{
var objectsID0 = generator.AreThereAnyObjects(sys_idNPC, direction.x+x, direction.y+y, 1, { except_ships: true});
var objectsID1 = generator.AreThereAnyObjects(sys_idNPC, direction.x-x, direction.y+y, 1, { except_ships: true});
var objectsID2 = generator.AreThereAnyObjects(sys_idNPC, direction.x+x, direction.y-y, 1, { except_ships: true});
var objectsID3 = generator.AreThereAnyObjects(sys_idNPC, direction.x-x, direction.y-y, 1, { except_ships: true});

if (objectsID0 == true)
{
npc.FaceCoord(SHIP_ID,direction.x+x,direction.y+y);
}
if (objectsID1 == true )
{
npc.FaceCoord(SHIP_ID,direction.x-x,direction.y+y);
}
if ( objectsID2 == true )
{
npc.FaceCoord(SHIP_ID,direction.x+x,direction.y-y);
}
if (objectsID3 == true)
{
npc.FaceCoord(SHIP_ID,direction.x-x,direction.y-y);
}
}
}
}



« Last Edit: August 03, 2017, 07:28:39 pm by ninekorn »

ai_enabled

  • AtomicTorch Founder
  • Hero Member
  • *****
  • Posts: 989
    • View Profile
Re: I got a problem with finding containers that are near in script?!
« Reply #1 on: August 03, 2017, 09:50:34 pm »
So, you need just an API method to get the crate containers nearby your ship - something like npc.GetAsteroidsByDistanceToN PC() but for crate containers?

ninekorn

  • Newbie
  • *
  • Posts: 41
    • View Profile
Re: I got a problem with finding containers that are near in script?!
« Reply #2 on: August 03, 2017, 09:59:43 pm »
yes exactly!

ai_enabled

  • AtomicTorch Founder
  • Hero Member
  • *****
  • Posts: 989
    • View Profile
Re: I got a problem with finding containers that are near in script?!
« Reply #3 on: August 03, 2017, 10:06:51 pm »
Ok, I will send you a build with this new API method later.

ninekorn

  • Newbie
  • *
  • Posts: 41
    • View Profile
Re: I got a problem with finding containers that are near in script?!
« Reply #4 on: August 03, 2017, 10:18:41 pm »
Thank you so much! with this the drones will have a couple usefull functions Under their belt!

Im working on also fixing some stuff in the Galaxy Market Mod but for some reasons I can't find where the threading bug occurs. At least I seem to have fixed the quantities a player can buy and correct amount is transfered. I still need to test more though.

I also have a lag issue of 1-2 seconds when I first spawn my Drones. Im wondering if its just me using something i shouldnt in the code. I will investigate that.

I will check how to send a Google drive link tonight and ill then be able to send you the market mods consisting of 3 scripts for you guys at Atomic Torch to check it out before I release. I wont release it on steam workshop this week though.

ai_enabled

  • AtomicTorch Founder
  • Hero Member
  • *****
  • Posts: 989
    • View Profile
Re: I got a problem with finding containers that are near in script?!
« Reply #5 on: August 03, 2017, 10:34:36 pm »
Ok, sent you the build with new scripting API methods.