Author Topic: Radios  (Read 1300 times)

I am trying to make a Radio thing for Survival RP, but right now I've hit a snag. I use this part to search for other radios, and then the radios found search their radius for people to message with the original message from the source radio. Right now, it only messages the source radio with it's own message. I'm thinking this problem has something to do with the while loops not being closed before the next. But if I close them, it won't work properly. Or will it? Yeah, it doesn't work if I close them. How could I make this work?
Code: [Select]
    if(strstr(%text, ", over") > -1)//This checks to see if it's actually in the sentence
    { //^That makes it so I don't get errors saying there's a -1 starting point
if(getSubStr(%text, strlen(%text) - strlen(", over"), strlen(%text)) $= ", over")
{
//echo("This part worked");
InitContainerRadiusSearch(%speakerpos,$Survival::ChatRange, $TypeMasks::FxBrickAlwaysObjectType);
while((%radio = ContainerSearchNext()) != 0)
{
   if(%radio.getDatablock().getName() $= "RadioBrick" && isObject(%radio.attachment))
   {
      %Radiopos = %radio.getTransform();
      RadioSearch(%RadioPos,%CPrefix,%CName,%CSuffix,%text);
    }
}
      }
   }
}
     }
And the functions that go with it:
Code: [Select]
//These are some functions for the search
function RadioSearch(%Pos,%CPrefix,%CName,%CSuffix,%text)
{
   InitContainerRadiusSearch(%Pos, $Survival::RadioRange, $TypeMasks::FxBrickAlwaysObjectType);
   while((%oRadio = ContainerSearchNext()) != 0)
      {
         if(%oRadio.getDatablock().getName() $= "RadioBrick" && isObject(%oRadio.attachment))
            {
       %oRadioPos = %oRadio.getTransform();
       RadioPSearch(%oRadioPos,%CPrefix,%CName,%CSuffix,%text);
    }
      }
}

function RadioPSearch(%Pos,%CPrefix,%Cname,%CSuffix,%text)
{
   InitContainerRadiusSearch(%Pos, $Survival::ChatRange, $TypeMasks::PlayerObjectType);
   while((%RListener = ContainerSearchNext()) != 0)
      {
      messageClient(%RListener.client,"","\c5[Local] \c7"@ %Cprefix @"\c3"@ %Cname @"\c7"@ %Csuffix @"\c6: "@ %text);
      }
}
I don't know why this doesn't work, please help.
« Last Edit: June 18, 2009, 08:18:21 PM by AGlass0fMilk »

//These are some functions for the search
function RadioSearch(%Pos,%CPrefix,%CName,%CSuffix,%text)
{
   InitContainerRadiusSearch(%Pos, $Survival::RadioRange, $TypeMasks::FxBrickAlwaysObjectType);
   while((%oRadio = ContainerSearchNext()) != 0)

oRadio? Idk if I'm being an idiot or not, but where did oRadio come in?

Note the equals sign. He is assigning an object to %oRadio with that.


Bump, I still need help.

Echo %radio, %oRadio and %rListener in each loop, then echo %radio.getDatablock().getName() etc.

Are you sure it's "RadioBrick"? It might be "RadioBrickData" or something similar...

For some reason, the RadioPSearch in the Radio Search function doesn't activate, I tried to make it echo stuff, but it never got to that function. I'll try to fix that, but is there any reason that it doesn't activate?
« Last Edit: June 21, 2009, 08:58:13 PM by AGlass0fMilk »

Ok, I have decided to move on from a radius search, unless someone can fix that. It sorta works, but it isn't reliable. I am going to make a script object/store it on the clients group, and then loop through all of those to message people. I am wondering how I would store an object into a script object so I could loop through all of those objects later, and then do stuff.

Use a SimSet. It's exactly the same as a SimGroup except objects can be in multiple SimSets and it doesn't remove them from their existing SimGroup - so you can keep your radios in BrickRadioSet while leaving them in BrickGroup_whatever for their client to own them as normal.

I don't even know how to do that. I am barely familiar with script objects. I will probably just loop through MainBrickGroup, and then just see if the bricks that I am looping through are radios, but I don't know if that would be laggy with a lot of bricks on the server. How would I create the simset, and then just add radios objects to them?

Creation code
Code: [Select]
if(!isObject(BrickRadioSet))
   new SimSet(BrickRadioSet);

Add object to set
Code: [Select]
BrickRadioSet.add(%obj);
Remove object from set (objects are automatically removed if they are deleted)
Code: [Select]
BrickRadioSet.remove(%obj);
Loop through set
Code: [Select]
for(%i=0;%i<BrickRadioSet.getCount();%i++)
{
   %radio = BrickRadioSet.getObject(%i);
   //do stuff to %radio
}

If you can use MainBrickGroup then you can use a SimSet.

Thank you, I will find this useful since the radius search is very buggy and unreliable. It only sometimes messages the person. I might be able to fix this in later version of the Survival RP mod.

A set will probably be better than a million laggy searches, anyway.

Also, could I put a remove code in the Death and remove parents anyway? Or would it cause errors. I should prolly just leave it out.

Would it be possible to create a new Typemask, and add the radio to it? I am planning to make it so you can't place another Radio brick within chat range of another, but I don't know if searching through all bricks in that range would be laggy or not. I will try my way first.