PDA

View Full Version : Variable Question


Mindtwistah
07-15-2009, 05:20 PM
Hay.

I would like to know if it's possible to make variables that you can change the value on at any time, and use them as conditionals.

For example:

You have a ship. This ship has a certain fuel level. For every time you travel, the variable will decrease one value.

So, the starting fuel value is:

global.fuel = 6

I decide to take the ship for a ride to Onderon. The fuel value decreases.

global.fuel = global.fuel - 1

When the fuel value reaches 0

if global.fuel == 0;
return True

you won't be able to fly the ship any further (A [Failure] dialog node will show up, conditional to access this node is the "script" above)

I know these "scripts" won't work. I'm no coder, I just wanted to show you what I meant.
Well, is it possible to create and use these sort of global variables, and if yes, how? What would the script be like to do what I described it would do?

gsusfrk
07-15-2009, 08:24 PM
It would actually be pretty simple. Make a global variable in globalcat.2da. Have it be a string and name it something like "lastModuleVisited". Make another variable of type int and have it named "fuelLevel" or whatever. Make another variable of type boolean and name it "canFly". Then add this code to the end of each module's "OnEnter" script EXCEPT the ship's module (otherwise, your fuel level will drop regardless of whether you've traveled or not):

if(GetGlobalString("lastModuleVisited") != GetModuleFileName())//Checks if you've flown to a planet or not.
{
SetGlobalNumber("fuelLevel", GetGlobalNumber("fuelLevel") - 1);//Decrements fuel level
SetGlobalString("lastModuleVisited", GetModuleFileName());//Sets the last module you visited to the current one.
}
if(GetGlobalNumber("fuelLevel") == 0)
{
SetGlobalBoolean("canFly", FALSE);//Should be checked by a conditional script
}
If you want to, you can check how "far" the player has flown (check which new module they flew to) and deduct different amounts of fuel based on the distance between "planets".

Now just attach a conditional script that should check if you can fly or not, and if so, should grant access to the ship. It should look something like this:

int StartingConditional()
{
return GetGlobalBoolean("canFly");
}

Just remember to script a way to refuel the ship, or you'll be stuck! That can be a simple script attached to a dialogue, for example, if you talk to a dock worker, he will refuel your ship (for a price, of course):

void main()//This script will remove credits from the player and refuel the ship
{
TakeGoldFromCreature(nAmount, GetFirstPC(), TRUE);//Replace nAmount with the amount of credits to take from player
SetGlobalNumber("fuelLevel", 6)//Replace 6 with your ideal fuel level you have in mind. Can also be replaced by a global variable.
}

If you really want to get fancy, you could check the fuel level of the ship and charge different amounts based on how much fuel is actually needed. This is scripted to charge a flat rate, no matter how much fuel needs to be replaced.
Here's a conditional script to make sure the conniving dock worker doesn't keep charging you for a ship that's fueled! (That would be the player's fault, but let's not make that possible)

int StartingConditional()
{
if(GetGlobalNumber("fuelLevel") < 6)//Replace with max fuel level or its global variable
{
return TRUE;//tank can be refueled.
}
return FALSE;//tank is full.
}

Attach that conditional to a node that asks the player if he'd like to refuel that ship. Place a node under it that tells the player their ship is refueled. That way, they know their ship is refueled and they don't have the option to pay to refuel a fully fueled ship.

Well, I hope this works for what you had in mind. Feel free to ask questions if you don't understand something or something doesn't work as intended. If you have other ideas, I'd be glad to try to script those too. You can modify the above scripts as well in order to do different things. Enjoy!