| Blockland Forums > Modification Help |
| Help with discerning a brick's position |
| (1/1) |
| Treynolds416:
Basically, look at a brick, type a server command, and have the coordinates of a brick presented to you. Lilboarder's attempt (modified by me) worked perfectly, but only for basepates. Otherwise, the function did not seem able to find the object. --- Code: ---function servercmdobjtest(%client) { ClientCmdCenterPrint("You activated the function", 3); %obj = %client.player; %scale = vectorScale(%obj.getEyeVector(),100); %ray = containerRaycast(%obj.getEyePoint(),%scale,$Typemasks::fxBrickObjectType); %brick = firstWord(%ray); messageClient(%client,'',%brick.getPosition()); ClientCmdCenterPrint("It probably didn't work", 3); } --- End code --- Iban's attempt was a lot more cleaned up and user friendly, although it didn't work at all. Everytime I called the function, I would always get "Look at a brick, dummy". After some testing, I determined that the function never actually found the object, for whatever reason. --- Code: ---function serverCmdObjTest(%client) { %obj = %client.player; if(!isObject(%obj)) { %client.centerPrint("\c5Spawn first, dummy.", 2); return; } %fvec = %obj.getForwardVector(); %fX = getWord(%fvec, 0); %fY = getWord(%fvec, 1); %evec = %obj.getEyeVector(); %eX = getWord(%evec, 0); %eY = getWord(%evec, 1); %eZ = getWord(%evec, 2); %eXY = mSqrt((%eX * %eX) + (%eY * %eY)); %aimVec = (%fX * %eXY) SPC (%fY * %eXY) SPC %eZ; %range = 100; %end = vectorAdd(%start, vectorScale(%aimVec, %range)); %masks = $TypeMasks::FxBrickAlwaysObjectType; %col = firstWord(containerRayCast(%start, %end, %masks, %obj)); if(!isObject(%col)) { %client.centerPrint("\c5Look at a brick, dummy.", 2); return; } messageClient(%client, '', "\c5BRICK POSITION\c6:" SPC %col.getPosition()); echo("BRICK POSITION:" SPC %col.getPosition()); } --- End code --- Any help would be appreciated greatly. |
| Red_Guy:
something like this should do the trick: --- Code: ---function servercmdobjtest(%client) { %start = %client.getEyePoint(); %end = vectorAdd(%start, vectorScale(%client.getEyeVector(), 5)); %ray = containerRayCast(%start, %end, $Typemasks::PlayerObjectType | $Typemasks::FXbrickObjectType | $Typemasks::TerrainObjectType | $Typemasks::InteriorObjectType, %client); %hit = getWord(%ray, 0); if (isObject(%hit) ) { %client.centerPrint("\c5Look at a brick, dummy.", 2); return; } messageClient(%client, '', "\c5BRICK POSITION\c6:" SPC %hit.getPosition()); echo("BRICK POSITION:" SPC %hit.getPosition()); } --- End code --- |
| Treynolds416:
Doesn't work |
| Brian_Smith3:
--- Code: ---function serverCmdObjectTest(%client) { %player = %client.player; %start = %player.getEyePoint(); %end = vectorAdd(%start, vectorScale(%player.getEyeVector(), 5)); %ray = containerRayCast(%start, %end, $Typemasks::PlayerObjectType | $Typemasks::FXbrickObjectType | $Typemasks::TerrainObjectType | $Typemasks::InteriorObjectType, %player); if(isObject(%hit = getWord(%ray, 0))) { if(%hit.getClassName() $= "fxDTSBrick") { messageClient(%client,'',"Position: " @ %hit.getPosition()); } messageClient(%client,'',"That is not a brick."); } } --- End code --- Has not been tested, will most likely work |
| Treynolds416:
So close: At least it's an improvement. Edit: Oh, nevermind, all you did wrong was forget the 'else'. Works correctly now, thanks! Working script: --- Code: ---function ServerCmdObjTest(%client) { %player = %client.player; %start = %player.getEyePoint(); %end = vectorAdd(%start, vectorScale(%player.getEyeVector(), 5)); %ray = containerRayCast(%start, %end, $Typemasks::PlayerObjectType | $Typemasks::FXbrickObjectType | $Typemasks::TerrainObjectType | $Typemasks::InteriorObjectType, %player); if(isObject(%hit = getWord(%ray, 0))) { if(%hit.getClassName() $= "fxDTSBrick") { messageClient(%client,'',"Position:" @ %hit.getPosition()); } else { messageClient(%client,'',"That is not a brick!"); } } } --- End code --- |
| Navigation |
| Message Index |