Author Topic: Objects that emit a player detecting radius  (Read 1765 times)

I'm in the middle of making a new gamemode, and I've stumbled on a bump in the road for the first time so far. I'm trying to find a way to have a block that an administrator can place; say, in a building. And it will create a circular zone around it that can alter a client variable when said player enters the zone.

I know similar things have been done, but at the moment I simply cannot find them, any ideas?


I was told about those, but don't they have to be stepped on to activate?

I'm planning on the block to be placed in a building, and upon entering the building you will gain radiation. I don't want the player to have to activate the block for it to start to effect variables.

Think of it as a radioactive zone.

Reminds me of Fallout!


Yeah, triggers. Triggers are what help zone bricks do what they do, I'm pretty sure.

I can't help you much with how they work though, all I know is that on TGB, you assign the trigger a class then you have class::onEnter(%this, %obj)

Reminds me of Fallout!


Yeah, triggers. Triggers are what help zone bricks do what they do, I'm pretty sure.

I can't help you much with how they work though, all I know is that on TGB, you assign the trigger a class then you have class::onEnter(%this, %obj)

Thanks, I'll keep looking around then. And yes, it's going to be a Post Nuclear RPG

I was told about those, but don't they have to be stepped on to activate?

I'm planning on the block to be placed in a building, and upon entering the building you will gain radiation. I don't want the player to have to activate the block for it to start to effect variables.

Think of it as a radioactive zone.
Triggers are always active.
you get a script notification / callback whenever a player enters or leaves a trigger.

If you want placing a brick to create a trigger, make sure your script also deletes the trigger when the brick is removed.  Otherwise you will get weird effects and odd errors from your triggers activating when there are no bricks around.

You will have 2 methods for your trigger class -- onEnterTrigger  and onTickTrigger  You can look up examples and explanations on the garagegames site.

Triggers are always active.
you get a script notification / callback whenever a player enters or leaves a trigger.

If you want placing a brick to create a trigger, make sure your script also deletes the trigger when the brick is removed.  Otherwise you will get weird effects and odd errors from your triggers activating when there are no bricks around.

You will have 2 methods for your trigger class -- onEnterTrigger  and onTickTrigger  You can look up examples and explanations on the garagegames site.

Thanks a ton, I'll defiantly be using these now. I'll be posting a sneak-peek of the mod later on today.

Code: [Select]
package radZone
{
function createRadZone(%brick, %owner)
{
if(!isobject(%brick)) return;
%position = %brick.getboxcenter();
%trigger = new trigger()
{
datablock = brickFalloutRadArea;
owner = %owner;
};
%trigger.settransform(%position);
%trigger.setscale(30);
}

function fxDtsBrick::onPlant(%brick)
{
echo("Radzone brick planted!");
echo(%brick @ "Was planted!");
createRadZone(%brick, %owner);
}

function brickFalloutRadArea::OnEnterTrigger(%this, %trigger, %obj)
{
echo("HOLY stuff YOUR IN A RAD ZONEEEEEEEEEEEEEEEEEEEEEEEEEEE");
echo( %client.Name @ " is in deep stuff.");
}
};
activatePackage(radZone);

Well, this is mostly just a random stab at having a placed brick spawn a trigger around it. It didn't work because half of this made up.

If you have any obvious errors/comments to make on it, please feel free to do so. I'll continue doing this in the morning, since right now I just don't have the mind for this. Good night.

Umm, well, i'm pretty sure your script will, every time you plant a brick, say "Radzone brick was planted!".
it will then commence to create rad zones on every brick you plant.

plus, i think you would have to define %owner before you use it in the function.

You broke onPlant because you didn't call the parent.

The trigger should be having a class, not a datablock.

I'd strongly recommend looking for a certain type of brick or a variable on the client flagging if they said they're trying to plant rad areas, instead of EVERY SINGLE BRICK being one.

%owner was never defined, should be %brick.client.
« Last Edit: June 11, 2011, 01:11:42 PM by otto-san »

Umm, well, i'm pretty sure your script will, every time you plant a brick, say "Radzone brick was planted!".
it will then commence to create rad zones on every brick you plant.

plus, i think you would have to define %owner before you use it in the function.

Yes, it will. I was actually just trying to figure out what exactly %brick was by putting it in the echo. It came out as seemingly random numbers, so I didn't know what to do. And I'll look at defining %owner right now. Thanks for the input.



You broke onPlant because you didn't call the parent.

The trigger should be having a class, not a datablock.

I'd strongly recommend looking for a certain type of brick or a variable on the client flagging if they said they're trying to plant rad areas, instead of EVERY SINGLE BRICK being one.

%owner was never defined, should be %brick.client.

I've always been confused with the needs oh having to call the parent, what exactly does that do? As for the fact that every block would place a radzone, I know that I did that, for I was checking what exactly %brick was calling. Thanks for clearing up what %owner was, I'll try that out now.

It's what you use with existing functions so that you can call the function that is not what you are packaging it for.

like

Code: [Select]
function thingy()
{
  echo("The thingy happened.");
}

package nothingy
{
  function thingy()
  {
     if($thingNot)
     {
        echo("nothing.");
        return;
      }
      parent::thingy();
   }
};
activatePackage(nothingy);

$thingyNot = 1;

if you do thingy(); then, it'll echo nothing instead.

Thanks for clearing that up a bit, adding the line that calls the parent did fix several errors that I did not understand, but when I actually get to creating the Trigger, the game does not  know what half of the functions I used are. I'm looking through some old gamemode for a reference.

Yes, it will. I was actually just trying to figure out what exactly %brick was by putting it in the echo. It came out as seemingly random numbers, so I didn't know what to do. And I'll look at defining %owner right now. Thanks for the input.
These seemingly random numbers are actually the brick's ID. If you look at anything in the game and then say /getid, you'll come up with said seemingly random numbers (including yourself). Try planting a brick, /getid 'ing it and then going into the console, inserting the result, and add .delete(); to the end of it. It'll delete it. I honestly don't know if there's a function like idtoname (there's nametoid) but yeah. Also, I believe if you were to echo findclientbyname(obibital) you'd get somewhat similar numbers... not quite sure about that one though.

These seemingly random numbers are actually the brick's ID. If you look at anything in the game and then say /getid, you'll come up with said seemingly random numbers (including yourself). Try planting a brick, /getid 'ing it and then going into the console, inserting the result, and add .delete(); to the end of it. It'll delete it. I honestly don't know if there's a function like idtoname (there's nametoid) but yeah. Also, I believe if you were to echo findclientbyname(obibital) you'd get somewhat similar numbers... not quite sure about that one though.

Thanks for explanation on that, but I've given up on making the trigger for now, unless someone can point out the errors in this snippet of code.

Snippet From Datablocks.cs

Code: [Select]
datablock fxDTSBrickData(brickFalloutRadArea)
{
brickFile = "blar2.blb";
category = "Fallout";
subCategory = "Admin";
uiName = "RadArea";
iconName = "add-ons/brickIcons/none";
collisionShapeName = "base/data/shapes/bricks/2x2Fround.dts";
brickSizeX=1;
brickSizeY=2;
brickSizeZ=1;
};

Snippet From Radiation.cs

Code: [Select]
package radZone
{
function createRadZone(%brick)
{
if(!isobject(%brick)) return;
%trigger = new trigger("radZone")
{
datablock = brickFalloutRadArea;
owner = %brick.client;
};
%trigger.settransform(%brick.getTransform());
%trigger.setscale("15 15 15");
}

function fxDtsBrick::onPlant(%brick)
{
Parent::onPlant(%brick);
//echo("Radzone brick planted!");
echo(%brick @ "Was planted!");
createRadZone(%brick);
}

function radZone::OnEnterTrigger(%this, %trigger, %obj)
{
echo("HOLY stuff YOUR IN A RAD ZONEEEEEEEEEEEEEEEEEEEEEEEEEEE");
echo( %client.Name @ " is in deep stuff.");
}
};
activatePackage(radZone);

Good luck, and thank you in advance if you are able to find the error.

Whenever this runs, the game tells me that It cannot find what setTransform, setScale, and whatnot are.
« Last Edit: June 11, 2011, 05:37:10 PM by Obibital »