Author Topic: How to pass variables to datablocks?  (Read 1492 times)

I have this code in a vehicle datablock:

Code: [Select]
engineTorque = $vtorque;
engineBrake = 2000;         
brakeTorque = 50000;     
maxWheelSpeed = $vspeed;

How do I get these to update when I change the values of the variables in later functions?

You don't. The entire point of a datablock is that it sets the VALUES, not VARIABLES, that the server, clients, and engine use. While it's fun to mess around with datablock values in realtime, you should NEVER do it in a script you plan to actually be using.

Plus I suspect that you're trying to do this so that different vehicles with this datablock have different values, which still won't work.

You don't. The entire point of a datablock is that it sets the VALUES, not VARIABLES, that the server, clients, and engine use. While it's fun to mess around with datablock values in realtime, you should NEVER do it in a script you plan to actually be using.

Plus I suspect that you're trying to do this so that different vehicles with this datablock have different values, which still won't work.
Ok...

And no, that's not why I need this at all. Is there any way to modify a vehicle's speed during gameplay?

Ok...

And no, that's not why I need this at all. Is there any way to modify a vehicle's speed during gameplay?
not without work arounds that require both a client and server side script (untested theory of mine) or forcing each player to reconnect (buggy and something baddy said not to do)

Ok then... well, I'll do this another way. Thanks anyway.

Alright, here's what I did for my vehicle upgrading system way back when (a few years ago).
It might apply but it's a bit of a weird fix and I'm not sure if it works now but it worked at the time....

The first bit of code generates datablocks for everyone who might enter your server. Note, this only generates 20 datablocks. If you plan on having more, make the for loop run more iterations. (You obviously wont need more than 99 unless you're messing with the player counts)
Code: [Select]
datablock WheeledVehicleData(RWVehicle0 : JeepVehicle)
{   
   //--SNIP-- Vehicle datablock members were here but I snipped cause it was huge
};

//Generates 20 datablocks that all have different DB names and UI names but everything else is the same
for(%i=1; %i<20; %i++)
{
eval("datablock WheeledVehicleData(RWVehicle" @ %i @ " : RWVehicle0) { uiName = \"RWVehicle" @ %i @ "\"; };");
}

The next part would assign a datablock to someone who joins your server. It takes the first available datablock.
You could then change their specific datablock using $RW::VehicleDatablocks[(%client.RWVehicleDatablock)] member to go in and edit values. For some reason, back when I did this, I never had to transmit datablocks to all the clients. I don't know why I didn't but it worked regardless.
Code: [Select]
function GameConnection::onClientEnterGame(%this)
{
Parent::onClientEnterGame(%this);
for(%i=0; %i<20; %i++)
{
if(!$RW::VehicleDatablocksAvailable[%i])
{
%this.RW_VehicleDatablock=%i;
$RW::VehicleDatablocks[%i]=true;
return;
}
}
messageClient(%this,"","\c0Error: No vehicle datablock has been assigned to your client as none were available.");
}

This part dumps their datablock back into the pool when they leave.
Code: [Select]
function gameConnection::onClientLeaveGame(%this)
{
$RW::VehicleDatablocks[(%this.RWVehicleDatablock)]=false;
Parent::onClientLeaveGame(%this);
}

Then, when they wrench a vehicle brick, I made it spawn a vehicle using their datablock and not allowing them to spawn other random vehicles
Code: [Select]
function wrenchImage::onHitObject(%this, %player, %a, %brick, %particle, %f)
{
%client=%player.client;
if(%brick.getClassName()$="fxDTSBrick" && %brick.dataBlock$="brickVehicleSpawnData")
{
if(%client==%brick.getGroup().client)
{
%vehicle="RWVehicle"@%client.RWVehicleDatablock;
%vehicle=%vehicle.getId();
%brick.setVehicle(%vehicle, %client);
%brick.spawnVehicle();
return;
}
else
{
messageClient(%client,"","Sorry, this isn't your brick");
return;
}
}
Parent::onHitObject(%this, %player, %a, %brick, %particle, %f);
}
« Last Edit: August 16, 2013, 04:56:03 PM by DYLANzzz »

Thanks for trying, not quite what I need, though. (It'd work, but this will be a public addon, and has certain limitations people wouldn't want). I'll just settle for a simplified version. I experimented all afternoon, and almost succeeded; just not quite. But eh, it's still gonna be a fun addon. ;)