Author Topic: Customizable Vehicles  (Read 634 times)

Hi BLF, I'm trying to make an upgradable vehicle thing. I just want to be able to change the speed of a car, on a per-car basis. I've been going through a few solutions, but my options are limited as apparently I can't create datablocks during runtime (idk). What the code below is doing is creating 20 (or however high the max playercount is) vehicle datablocks. Whenever someone joins the server, they are handed out a personal datablock from those 20. When they leave, the datablock is wiped clean and awaits a new player. There are a few problems with this. One, I can't get it to work (See: Syntax Error) and two it won't account for people having many different types of vehicles that they'd want to use. Basically, this script would only allow for upgradable jeeps but in what I'm doing you're allowed to change the type of your car and this script can't account for that. I'd have to make another 20 tank datablocks in that case. Can anyone find a better, working way of doing this? I'm basically trying to do .setMaxForwardSpeed for cars.

package Stunts
{
   function gameConnection::onClientEnterGame(%client) //When you joined you're given a unique datablock
   {
      parent::onClientEnterGame(%client);
      for(%i=0;%i<$Pref::Server::MaxPlayers;%i++)
      {
         if($StuntCars::Car[%i].reservee $= "")
         {
            %car = $StuntCars::Car[%i];
            break;
         }
      }

      %car.reservee = %client;
      %client.reservedDatablock = %car;
   }

   function gameConnection::onClientLeaveGame(%client)
   {
      %client.reservedDatablock.reservee = "";
      parent::onClientLeaveGame(%client);
   }
};
activatePackage(Stunts);

if($CarDatablocksInitialized != 1)
{
   $CarDatablocksInitialized = 1;
   for(%i=0;%i<$Pref::Server::MaxPlayers;%i++)
   {
      %name = "StuntCar" @ %i;
      $StuntCars::Car[%i] = datablock ##W##heeledVehicleData(%name : JeepVehicle)
      {
         num = %i;
      };
   }
}