Author Topic: Vehicle Spawning  (Read 1696 times)

I am working on a piece of my Colony RP where you need to pay resources to spawn vehicles. It spams the console with unable to find function getdatablock()

Code: [Select]
function fxDTSBrick::setVehicle(%brick, %vehicle)
{

if(isObject(%brick.getGroup().client) && isObject(%vehicle))
{
%CostWood = %vehicle.getdatablock().CostWood;
%CostSteel = %vehicle.getdatablock().CostSteel;
if(%Costwood >= 1 || %Coststeel >= 1)
{
%client = %brick.getGroup().client;
if(%client.Colonies["Wood"] >= %Costwood && %client.Colonies["Steelbar"] >= %CostSteel)
{
%client.Colonies["Wood"] -= %costwood;
%client.Colonies["Steelbar"] -= %costSteel;
parent::setVehicle(%brick, %vehicle);
}
else
{
%vehicle = 0;
return;
messageClient(%brick.getGroup().client, '', "\c6You need at least \c3" SPC %Costwood @ "\c6Wood and \c3" SPC %CostSteel @ "\C6Steel.");
}


}
else
{
%vehicle = 0;
return;
}

}



}
I want it to make you lose the amount of resources specified in the vehicle's datablock as well as return and not force you to pay when the vehicle has an error when spawning, such as stuck in terrain.

It's packaged by the way, just didn't feel like pasting the whole mega package.

Never used setVehicle myself so I can't say for sure, but maybe %vehicle is supposed to be the datablock?


That worked, but what about checking for spawning errors or setting the vehicle back to none. When I try to set it back to none, it returns.

I changed it up a bit:
Code: [Select]
function fxDTSBrick::spawnVehicle(%brick, %vehicle)
{

if(isObject(%brick.getGroup().client))
{
%CostWood = %vehicle.CostWood;
%CostSteel = %vehicle.CostSteel;
if(%Costwood >= 1 || %Coststeel >= 1)
{
%client = %brick.getGroup().client;
if(%client.Colonies["Wood"] >= %Costwood && %client.Colonies["Steelbar"] >= %CostSteel)
{
%client.Colonies["Wood"] -= %costwood;
%client.Colonies["Steelbar"] -= %costSteel;
parent::spawnVehicle(%brick, %vehicle);
}
else
{
%vehicle = 0;
return;
messageClient(%brick.getGroup().client, '', "\c6You need at least \c3" SPC %Costwood @ "\c6Wood and \c3" SPC %CostSteel @ "\C6Steel.");
}


}
else
{
%vehicle = 0;
return;
}

}



}
But now when I try spawning it, nothing happens. No console errors either.

From what I see the following have issues.


%vehicle.CostWood/Steel isn't defined.
You have a return; before messageclient.
Try using the echo("Stuf"); function to figure out where the scripts stops.

From what I see the following have issues.


%vehicle.CostWood/Steel isn't defined.
You have a return; before messageclient.
Try using the echo("Stuf"); function to figure out where the scripts stops.

It's defined in the vehicle's datablock.

I fixed that

I used it to figure out that the problem is here:

               %CostWood = %vehicle.CostWood;
               %CostSteel = %vehicle.CostSteel;
               if(%Costwood >= 1 || %Coststeel >= 1

The defining doesn't want to work for some reason bow that I switched functions. I don't know if %vehicle is now a datablock, and object, a name, or what.

what about determining the cost of the vehicle from it's size/if it can fly or not?

It's defined in the vehicle's datablock.

I fixed that

I used it to figure out that the problem is here:

               %CostWood = %vehicle.CostWood;
               %CostSteel = %vehicle.CostSteel;
               if(%Costwood >= 1 || %Coststeel >= 1

The defining doesn't want to work for some reason bow that I switched functions. I don't know if %vehicle is now a datablock, and object, a name, or what.

Try using %vehicle.dump(); to search for the %vehicle.CostWood/Steel values. Although I usually use global variables to define costs for items.

This would only apply if %vehicle was indeed a datablock.
Code: [Select]
//Put this somewhere other then inside the function.
$Heed::VehicleCost["VehicleDatablockName"] = "5 10"; //First is Wood, Second is Steel


//In the BuyVehicle function.
%a = getWord($Heed::VehicleCost[%vehicle],0);
%b = getWord($Heed::VehicleCost[%vehicle],1);
if(%a !$= "")
{
if(%client.VariableStuff1 >= %a && %client.VariableStuff2 >= %b)
{
//DoStuff
}
else
{
echo("DERP NOT ENOUGH STUFZ");
}
}

That may be useful later on. The problem is I just don't know exactly what works with that function at all. There's spawnvehicle, setvehicle, respawnvehicle, and tons of other stuff that I have no idea which does which.

Making it set the vehicle back to none if it doesn't work right.

Making it check for errors in vehicle spawning.

Making it so when the vehicle dies it gets set to "none"

There isn't a lot of references because vehicles seem to be a neglected subject for scripting. The only resource I found was the vehicle events which only gave me the args.

That may be useful later on. The problem is I just don't know exactly what works with that function at all. There's spawnvehicle, setvehicle, respawnvehicle, and tons of other stuff that I have no idea which does which.

Making it set the vehicle back to none if it doesn't work right.

Making it check for errors in vehicle spawning.

Making it so when the vehicle dies it gets set to "none"

There isn't a lot of references because vehicles seem to be a neglected subject for scripting. The only resource I found was the vehicle events which only gave me the args.
You can get all of that information using the dump(); function.

You can get all of that information using the dump(); function.
SO I just do a %vehicle.dump and I figure out how to set the vehicle to none in the script and check if it is none, as well as check for errors when spawning it?

SO I just do a %vehicle.dump and I figure out how to set the vehicle to none in the script and check if it is none, as well as check for errors when spawning it?
It's not that simple. You need to actually experiment and look through the functions that can be ran on it. If you don't know how to do a simple if(isObject()) then I suggest you learn the basics of scripting before moving on to something like this. :/

%spawnbrick.vehicle, I believe.

I have this code in my LogWriter:
Code: [Select]
    %banCount = BanManagerSO.numBans;
    parent::servercmdunban(%unbanner, %positionInList);
    if(%banCount == BanManagerSO.numBans)
        return;
You'll want to implement something similar to actually assure that the vehicle actually spawned, or changed. The code above checks that the ban actually went through.

%spawnbrick.vehicle, I believe.

I have this code in my LogWriter:
Code: [Select]
    %banCount = BanManagerSO.numBans;
    parent::servercmdunban(%unbanner, %positionInList);
    if(%banCount == BanManagerSO.numBans)
        return;
You'll want to implement something similar to actually assure that the vehicle actually spawned, or changed. The code above checks that the ban actually went through.
%spawnbrick wait what the doesn't even exist. I am so confused right now. I've read, understood, and wrote much more difficult scripts than this but I just cannot figure this out. I am going to try the dump thing now I guess.