Author Topic: Packaging ServerCmdGetID  (Read 994 times)

For console scripting, I'd like to make a quick convenience tool to help me work with ID-s of objects and would like to know what are the variables to the function so I could package it.


Is there a way to do it so I wouldn't have to re-make the entire command?

Dannu, the safest method I thought of when I wanted to do the exact same thing was make a tool duplicating the Print Gun's datablocks and change OnHit(); and have your convenience store code in it.

Is there a way to do it so I wouldn't have to re-make the entire command?
Probably not, but I can't say I've ever tried. It's not a hard thing to remake though. I'll post some basic code later when I'm not using a phone if nobody else has.

You'll need to fired a containerRaycast to get the objects ID.
The args for it are Point3F start, Point3F end, bitset mask, SceneObject exempt=NULL .
You'd start at somewhere such as the players eyepoint, and end in the direction the player is looking at by scaling the players eye vector then adding it to the start.
The mask could be anything you want to look for, the global variables start with $TypeMasks::
Exempt removes the object from the search, you'd add your player object so you don't pick yourself up all the time.


Code: (Typemasks) [Select]
$TypeMasks::All = "-1";
$TypeMasks::CameraObjectType = "4096";
$TypeMasks::CorpseObjectType = "1048576";
$TypeMasks::DamagableItemObjectType = "268435456";
$TypeMasks::DebrisObjectType = "4194304";
$TypeMasks::EnvironmentObjectType = "2";
$TypeMasks::ExplosionObjectType = "524288";
$TypeMasks::FxBrickAlwaysObjectType = "67108864";
$TypeMasks::FxBrickObjectType = "33554432";
$TypeMasks::GameBaseObjectType = "1024";
$TypeMasks::ItemObjectType = "32768";
$TypeMasks::MarkerObjectType = "64";
$TypeMasks::PhysicalZoneObjectType = "8388608";
$TypeMasks::PlayerObjectType = "16384";
$TypeMasks::ProjectileObjectType = "262144";
$TypeMasks::ShapeBaseObjectType = "2048";
$TypeMasks::StaticObjectType = "1";
$TypeMasks::StaticRenderedObjectType = "134217728";
$TypeMasks::StaticShapeObjectType = "8192";
$TypeMasks::StaticTSObjectType = "16777216";
$TypeMasks::TerrainObjectType = "4";
$TypeMasks::TriggerObjectType = "32";
$TypeMasks::VehicleBlockerObjectType = "131072";
$TypeMasks::VehicleObjectType = "65536";
$TypeMasks::WaterObjectType = "16";

Code: (Example GetID) [Select]
function serverCmdGetInfo(%this)
{
if(!isObject(%this.player))
return;
%eye = vectorScale(%this.player.getEyeVector(), 100);
%pos = %this.player.getEyePoint();
%masks = $TypeMasks::All;
%rayCast = containerRaycast(%pos, vectorAdd(%pos, %eye), %masks, %this.player);
%hit = firstWord(%rayCast);
if(!isObject(%hit))
return;
%position = posFromRaycast(%rayCast);
messageClient(%this, '', "Object ID: " @ %hit.getID() @ " Distance: " @ vectorDist(%pos, %position) @ " Class: " @ %hit.getClassName());
}
This does pretty much the same thing as getID if I am correct.

This does pretty much the same thing as getID if I am correct.

Id recommend using %this.getControlObject() instead of %this.player so that it works when you're in admin orb, like /getID does.

I wrote this a while back, specifically for bricks. You'll need to change the mask type to include everything else.
Also, you might want to change player to %client.getControlObject(); for orb performance any point (like boodals said).
Code: [Select]
function serverCmdbrickInfo(%client)
{
if(%client.isSuperAdmin)
{
%player = %client.player;
%start = %player.getEyePoint();
%end = vectorAdd(%start, vectorScale(%player.getEyeVector(), 90));
%mask = $TypeMasks::fxBrickObjectType;

%result = ContainerRayCast(%start, %end, %mask, %player);
if(isObject(%obj = getWord(%result, 0)))
{
talk(%obj SPC "at [" @ %obj.getPosition() @ "], as " @ %obj.dataBlock @ ", color =" SPC %obj.getColorID());
}
}
else
%client.centerprint("You must be Super-Admin to use this command.", 3);
}