Author Topic: Getting a list of vehicles on the server  (Read 1721 times)

no that is storing vehicle objects, goth77 is looking for vehicle datablocks
OH. My bad.

For the life of me I cannot figure out why this won't work.

Code: [Select]
function serverCMDcheckVehicle(%client,%vehicle)
{
echo("" @ %vehicle @ "");

%size = datablockGroup.getCount();

for(%i=0;%i<%size;%i++)
{
%d = getDataBlock(%i);

if(%d.rideable $= true && %d.className $= "FlyingVehicleData" || %d.className $= "WheeledVehicleData")
{
if(%d.uiName $= %vehicle)
{
echo("TEST");
break;
}
}
}
}

When I echo %vehicle, it returns my input as it should, but TEST only echos when %vehicle is left blank. WTF? Why does if(%d.uiName $= %vehicle) always return false even if they match?

Maybe because the UI name is blank, so when you compare a blank string (uiname) to a blank string (%vehicle), the if statement returns true. I feel like you could of found this out by using echos though...

Edit: also in that if statement, you'd probably want to change %d.rideable $= true to:

%d.rideable

or

%d.rideable == 1



Edit #2: Ok so Uiname was either blank on some datablocks or it was correct, but had white spaces after it which is
what is causing your if statement check to fail ("Apples  " is not the same as "Apples"  for example).

This should work now, remember to use echos they can solve 90% of your problems.


function serverCMDcheckVehicle(%client,%vehicle)
{
   echo("" @ %vehicle @ "");
   
   %size = datablockGroup.getCount();   

   for(%i=0;%i<%size;%i++)
   {
      %d = getDataBlock(%i);
      
      if(%d.rideable && (%d.className $= "FlyingVehicleData" || %d.className $= "WheeledVehicleData"))
      {
         %uiName = stripTrailingSpaces(%d.uiName);
         if(%uiName !$= "" && %uiName $= %vehicle)
         {
            echo("TEST");
            break;
         }
      }
   }
}
« Last Edit: January 25, 2016, 08:17:38 PM by elm »

It works!!
------------
Thanks a billion Elm and Swollow!
You guys helped make this possible
« Last Edit: January 26, 2016, 12:57:25 AM by Goth77 »

Could someone please explain to me a little more how vehicles work in minigames?
Code: [Select]
      %v = new WheeledVehicle()
{
datablock = %data;
position = %pos;
sourceObject = getObjectFromMiniGame(%mini);
client = %client;
minigame = %mini;
};
  MissionCleanup.add(%v);
? i know thats all wrong...
Specifically, players should own/be able to use this specific vehicle in and out of any minigame

Why don't you start a minigame, spawn a vehicle, and then dump it?

Maybe because the UI name is blank, so when you compare a blank string (uiname) to a blank string (%vehicle), the if statement returns true. I feel like you could of found this out by using echos though...

Edit: also in that if statement, you'd probably want to change %d.rideable $= true to:

%d.rideable

or

%d.rideable == 1



Edit #2: Ok so Uiname was either blank on some datablocks or it was correct, but had white spaces after it which is
what is causing your if statement check to fail ("Apples  " is not the same as "Apples"  for example).

This should work now, remember to use echos they can solve 90% of your problems.


function serverCMDcheckVehicle(%client,%vehicle)
{
   echo("" @ %vehicle @ "");
   
   %size = datablockGroup.getCount();   

   for(%i=0;%i<%size;%i++)
   {
      %d = getDataBlock(%i);
      
      if(%d.rideable && (%d.className $= "FlyingVehicleData" || %d.className $= "WheeledVehicleData"))
      {
         %uiName = stripTrailingSpaces(%d.uiName);
         if(%uiName !$= "" && %uiName $= %vehicle)
         {
            echo("TEST");
            break;
         }
      }
   }
}


$UINameTable_Vehicles[%name] is a thing