Game Development Community

Runtime updating from the player.cs file

by Jared Schnelle · in Torque Game Engine · 10/11/2002 (6:37 pm) · 5 replies

Hello all, I'm new to the GG crowd, so I say, Hello.

I have a question. I'm trying to adjust the 3rd person view some. I have added two functions, (zoomIn and zoomOut) that are bound to Home and End, respectivly.

These functions increment or decrement the value of $pref::Player::zoomValue that is in the prefs.cs file.

Press home a few times, and the value decreases, press end a few times and the value increases.

The end result should be that it zooms in or out on the character, in 3rd person mode; however, I'm not getting that.

What's happening actually is as follows: The functions work fine, and the zoomValue is updated perfectly(if I restart, it will take on the new value), but I run into a problem right here:

//------------------
// File: Player.cs
//------------------
datablock PlayerData(LightMaleHumanArmor)
{
   renderFirstPerson = false;
   emap = true;
   
   className = Armor;
   shapeFile = "~/data/shapes/player/player.dts";
   cameraMaxDist = $pref::Player::zoomValue;

It seems this script is loaded on game startup, and the cameraMaxDist is only loaded on startup as well. How can I get the script to reload the:

cameraMaxDist = $pref::Player::zoomValue;

When I change the value of zoomValue?

Is there a getUpdate() function? Any ideas or suggestions will be greatly appreciated!

Thanks,
Jared

#1
10/12/2002 (9:04 am)
Jared,

I think what you want to do is expose a console method that will allow you to set the parameter cameraMaxDist in the datablock from the script. Then you can just declare a $gCameraMaxDist global somewhere and use the key binding to cycle through some default presets and set $gCameraMaxDistance such as 3 (default), 30, 300, etc. and call the console function to set the parameter.

I think I'm on the right track. This seems like a cool idea for games where it makes sense to use it. I think it opens up the possibility for someone to cheat though because they could have their own script that changes the number to some very big number which would allow them to see the entire map for example, so in the console function make sure you check the value that is being passed in to make sure it is within acceptable limits or else use an enumeration and a switch statement so that only the distances defined by the server that can be used.

Also, this value is not a zoom value. It is the distance from the EYE node in the model. So, with the default value of 3 which is in the script the camera in 3rd person view is 3 meters from the player models eye node.
#2
10/12/2002 (11:17 am)
Mhm, it should work this way:
put this in "client/scripts/default.bind.cs":
function increaseCamOffset(%val)
{
   if(%val)
   {
      commandToServer('IncreaseCamOffset');
   }
}
function decreaseCamOffset(%val)
{
   if(%val)
   {
      commandToServer('DecreaseCamOffset');
   }
}
and this in "server/scripts/commands.cs":
function serverCmdIncreaseCamOffset(%client)
{
   %client.getDatablock().getName().cameraOffset+=0.5;
}
function serverCmdDecreaseCamOffset(%client)
{
   %client.getDatablock().getName().cameraOffset-=0.5;
}
and put some binds for that in default.bind.cs and client/config.cs
MoveMap.bind(keyboard, ".", increaseCamOffset);
MoveMap.bind(keyboard, ",", decreaseCamOffset);
#3
10/12/2002 (12:55 pm)
I'm not sure but that code doesn't seem to work. I can see this in the console log...

fps/server/scripts/commands.cs (116): Unknown command getDataBlock.
Object LocalClientConnection(1371) GameConnection -> NetConnection -> SimGroup -> SimSet -> SimObject
fps/server/scripts/commands.cs (116): Unable to find object: '' attempting to call function 'getName'

must be happening in this code...

function serverCmdIncreaseCamOffset(%client)
{
%client.getDatablock().getName().cameraOffset+=0.5;
}
function serverCmdDecreaseCamOffset(%client)
{
%client.getDatablock().getName().cameraOffset-=0.5;
}
#4
10/12/2002 (1:56 pm)
Sorry, that code was for setting the values in a mounted vehicle datablock...
player datablock values can be retrieved with:
%val = %client.player.getDatablock().getName().maxFreelookAngle;
for example...
#5
10/13/2002 (12:17 pm)
I can get it to update the field of view just fine, when I press home / end using a method like you posted, because it seems that it's already programmed in the engine to accept changes to the FOV values; however, I dont want it to change the FOV value, because that makes everything look skewed.

Changing the FOV values to anything other than 90 make it look like you're looking through a convex/concave lens, or rather, you're looking through something in a funny house in the circus :)

The value that I need to update is cameraMaxDist, which has one instance in the script, and several in the engine. I just dont understand(yet) how to make the engine look for updates to this. From what I can tell, it's already looking for updates, as part of the code which contains cameraMaxDist in the engine, looks for the value in the bstream coming in. I dont know if there's a bit that needs to go from 0 to 1 when I actually change the value for cameraMaxDist it in the script.

I'm assuming that's what I need to do, find that list of bits that is sent back to the engine to tell it when something is changed, and add cameraMaxDist to the list.

Maybe it's already there, I dont know.

Any help would be appreciated.
Jared