Force Powers & Master Cog
To set force powers in single player levels, a little bit of cog knowledge is required. The most important concept is understanding the uses of the level's master cog. Immediately below you will find the complete cog, with comentary and explanations following.
# Jedi Knight Cog Script # Master Cog # [...] # This cog is NOT supported by LucasArts Entertainment Company. symbols message startup message timer end # ----------------------------------------------------------------------- code startup: // Master Cog/Player Setup SetMasterCOG(GetSelfCOG()); // Cog sets self as the master cog player = GetLocalPlayerThing(); // The local player is identified // Goal Flags SetInv(player, 99, 1000); SetGoalFlags(player, 0, 1); // Goal 0 visible, all others hidden SetGoalFlags(player, 1, 0); // Weapons & Ammo SetInv(player, 1, 1.0); // Fists SetInv(player, 2, 1.0); // Briar SetInv(player, 10, 1.0); // Lightsaber SetInv(player, 11, 100); // Energy cells // Weapon Setup SetFireWait(player, -1); SetMountWait(player, 0); SetCurInvWeapon(player, 0); SelectWeapon(player, AutoSelectWeapon(player, 1)); SetTimer(15); # ....................................................................... timer: // Force Ranking SetInv(player, 20, 5.0); SetInv(player, 14, 5*50); // Force Speed SetInv(player, 22, 2.0); SetInvAvailable(player, 22, 1); // Force Seeing SetInv(player, 23, 2.0); SetInvAvailable(player, 23, 1); // Force Healing SetInv(player, 25, 2.0); SetInvAvailable(player, 25, 1); // Force Persuasion SetInv(player, 26, 2.0); SetInvAvailable(player, 26, 1); jkSyncForcePowers(); Return; end # -----------------------------------------------------------------------Goal flags are simple - there are only 3 settings: 0, 1 and 2. If the flag is 0, this means that the text for this goal is hidden in the JK objectives screen. If the goal flag is 1, this means that the text for this goal is visible in JK objectives screen. Along similar lines, the goal flag 2 means that the text for this goal is visible and shown as completed in JK objectives screen.
For example, take a look at the first line:
SetGoalFlags(player, 0, 1);The first argument to the SeatGoalFlags() function is 'player', meaning that these flags are for the player which was defined earlier by the line "player = jkGetLocalPlayer()". The second argument, '0', tells the function that this flag is being set for Goal0, your first level objective. The last argument is the flag value to set -- in this case, '1' makes this objective visible in the game.
The following section sets the number of weapons/ammunition for the player. This is done by setting the inventory of each particular bin. For a list of bin numbers and what they correspond to, extract items.dat from your Jedi Knight CD and look at it using any text editor. For example:
SetInv(player, 1, 1.0); // FistsLet's break down one line for easy understanding:
SetInv(player, 11, 100); // Energy cellsLike with the goal flags, the first argument tells the SetInv() function that we want to set the inventory of the player. The second argument, '11', lets the function know what we want to modify bin 11, or the number of energy cells. The final argument is the number of energy cells we want the player to have -- 100 units.
These lines automatically select the weapon you start with from the ones in inventory (similar to when you run out of ammo and it switches in the game).
SetFireWait(player, -1);The following code sets a refresh timer for the force powers so when a game is saved and reloaded you still retain your powers.
SetTimer(15);In general, all of your code goes between the 'code' and 'end' tags. The stuff in the 'startup:' section runs when you begin the level; other sections (like 'timer:') activate at different times.
Now, we will set the player's Jedi rank:
SetInv(player, 20, 5.0);Bin 20 sets the ranking. Depending on the second number, you give a certain Force ranking, such as learner, apprentice, journeyman, Jedi master, and so on. (5.0 corresponds to the "Charge" rank). Bin 14 contains Force energy/total manna. This number seems to be 50 x the rank in all LEC levels.
For each force power, you set the number of stars and make them available to the player:
SetInv(player, 22, 2.0);For example, take the lines:
SetInv(player, 26, 2.0);Like before, the first argument tells SetInv() that we are changing the player. Next, the value '26' tells the function we are updating the bin 26 -- the location where the number of Force stars for persuasion are stored. Lastly, the actual number of stars for persuasion is specified to be 2. The second line makes the contents of bin 26 (persuasion) available for use.
I hope this article is helpful for everyone trying to write a master cog or incorporate Force powers into a level. If you have any further questions, post them on the message board or email me.