View Single Post
Old 03-05-2017, 03:05 PM   #43
Join Date: Feb 2017
Posts: 14
Originally Posted by IMfan
Can you please tell me how you hacked on your game? My game has cog strips too, but i do not know how to hack on them. Be awfully nice how to do that.

WARNING: this will be longer post

TL;DR: To give indy all available items put this code at the end of 00_cyn_opening.cog file just before return statement:
HTML Code:
for (bin= 0; bin < 200; bin = bin + 1) { SetInv(player, bin, GetInvMax(player, bin)); SetInvAvailable(player, bin, 1); }
Make sure to backup file first!

I'll try to make this post as short as possible
All information about cog scripts can be found here and here

I assume that you already know how to extract COG scripts from GOB files.
By the way, if you need a tool to do that I've made one: gobext.exe

Brief intro to COG scripts
From jkhub:
The COG Scripting Language is an event-driven imperative scripting language designed to help level designers write simple interactivity without requiring extensive programming experience. While COG was initially developed as an incremental improvement over the INF Scripting Language used in Dark Forces, COG quickly grew into a more complete language as the level designers continued to request more advanced features.
Cog scripts are logic behind the game. They are used to define game level opening animation, special effect when player enters some section within level,
they also define AI action on some special event eg. when hit by the bullet or what to do when the enemy is spotted etc...
Fundamentally COG scripts consist of two sections: symbols and code.
Each section begins with section name(symbols or code) and ends with word "end"
HTML Code:
symbols # Comments symbols [Symbol List] end code [Compound Statement] end

Symbols section is a list of variables described by their type followed by their name, optionally including a default value and a list of extensions.
Example of symbol section
HTML Code:
Symbols # Example outlines message startup # message type is a "function" within code section # that can be called from game engine when compiled. keyframe in_handsOnHips=0in_stand4.key local material topMat=pyr_jeep_top.mat local sound in_gotowork=Cn01j01.wav local thing player local # This is you, game player. thing indy linkid=0 # actor indy for cinematic movies. you will see a lot of this definitions in cog scripts which define game levels. end

Note that some variables such as things and keyframes are initialized by game engine when loading cnd file
and you don't have much control over it, for now I'm still working on it

Code section contains a C-style compound statements of code with messages indicated by C-style label statements. Note that every line of code that is not a comment (comments begins with '#') or a loop (for(){}) has to end with semicolon ';'

HTML Code:
code startup: # Note the name that we've declared in symbols section SetMasterCog(GetSelfCog()); Sleep(0.001); # Let engine get set up SetThingAlpha(fadeplate, 1.0); SetThingAlpha(fadeplate1, 1.0); SetThingAlpha(fadeplate2, 1.0); SetThingAlpha(maintitle, 0.0); SetThingAlpha(placetime, 0.0); SetCameraLookInterp(2, 0); SetCameraPosInterp(2, 0); SetCameraFocus(2, cam_1); SetCameraSecondaryFocus(2, ct_1); SetCurrentCamera(2); SetCameraFOV(25, 0, 0); return; end

I hope that this very brief crash course has made the cog scripts a little bit clearer.

Ok let's move on to real example
For the purpose of this short tutorial, I will be editing canyon lands opening script 00_cyn_opening.cog. Make sure to backup file before continue. To run this script you have to start IM from the beginning. All code in this tutorial will be written at the end of cog file just before the return statement:
HTML Code:
# RT: Give 'im a snake bite kit... SetInv(player, 46, 1); SetInvAvailable(player, 46, 1); ---> All code goes in here return; end

For start, let's make the gravity a little bit lighter. By the default the gravity is set to 2.0 let's make it 1.0. To do that just write this line: SetGravity(1.0);
In the game try to jump in the air and see what happens

Give Indy weapon:
Now let's give Indy a Simonov SKS rifle. Under the previous line write this two lines:
SetInv(player, 6, 500);
SetInvAvailable(player, 6, 1);

SetInv function gives indy inventory at the number 6 (Simonov rifle) and sets rifle's ammo to 500. The SetInvAvailable makes rifle available to indy (1- true, 0 - false). Note the 'player' object is type of thing. It was defined in symbols section of this cog script and initialized by the game engine. Instead of player thing you could use any other thing that is of type actor eg. you could also change inventory of an enemy with this two functions.

All Items:
Let's give Indy all available items (200). We'll use for loop to achieve this:
HTML Code:
for (bin= 0; bin < 200; bin = bin + 1) { SetInv(player, bin, GetInvMax(player, bin)); SetInvAvailable(player, bin, 1); }

You should now have all available items:

Make Indy Invulnerable:
SetActorFlags(player, 0x8);

Flags are thing's properties that can be set or unset. Flag Ref

Flying indy:
Now let's make something interesting. Let's make indy fly
First comment out or remove the line that sets gravity (SetGravity(1.0);).
Then put this two lines:
HTML Code:
ClearPhysicsFlags(player,0x1); # set player to have no gravity SetPhysicsFlags(player, 0x2000); # player can fly

In game use jump key to fly up and crouch key to move down.

I hope that this long post will help you mod IM. Note that with cog scripts you can modify everything including the shape of game level. But for now this is hard to do because you have to know symbol variables that are packed in cnd file. I'm working on conversion tool to convert cnd file to NDY file which is text based level definition file. If you are interested I've made tool to extract and replace materials in cnd files. You can find more info about this in my post here.

Happy modding
Marduk is offline   Reply With Quote