Tuesday, June 24, 2008

Valve's Source - Part 3

Authoring a Logical Entity

This post is related to the second modding tutorial you can find [here].

This is a very important tutorial as it's a real introduction to Mod programming in Valve's Source, and if you understand it you will be able to do more complex stuff.

Exploring this tutorial is not clear what is it purpose or how can you test it. That's the purpose of this post, make it clearer. Please note, there's not a single example of how can you use the entity or where it can be useful. I will help on that.

Go through the tutorial and, when you have completed the Build process, go back to this post. I will just mention a couple of things may help you with this process.

1. Although there's no mention about that, it's good if you start with the mod you just created in previous tutorial.

2. the sdk_logicalentity file name can be any other, what really matters is the following line:

LINK_ENTITY_TO_CLASS( my_logical_entity, CMyLogicalEntity );

Where you link the class you are creating to "my_logical_entity" label in the FGD file. This name is what you will see in Hammer

Once code is built, you can start the process of adding the logical entity to your map. Create the FGD as suggested in tutorial, and let's proceed with the map.

Now, open the Source SDK and double click the Hammer editor (Where you create the Levels). Before opening Hammer, make sure that under "Current Game", you have to select the Mod you have modified.

Now, you have to setup Hammer so you can use the logical entity by linking the FGD (with the entity description) to Hammer. Follow tutorial Instructions but, take a look at my screenshot. In Configuration, make sure you selected your Mod and, in Game Data Files, click on Add to add your FGD file. That's all. You are now ready to create your Level.

I won't give details on how to create a map, but it's prety straightforward if you have used a 3D package before. You can follow the Your First Map tutorial to create it. I just made a squared room where the action will take place.

As you can see in the screenshot, I added three rpg rounds (item_rpg_round) a crate (item_item_crate) and an npc grenade (npc_grenade_frag). Also, a player (Dr. Freeman) has been added so the game is ready. Now, run map to create the BSP file. I check "Don't run the game after compiling" so you don't have to start the Mod for every change you do. Instead, run your Mod from Steam and load map by typing "map [your map name]". If you make any change in your map, compile it and reload it in your Mod without restarting the application.

Note. Do not forget to name every object in your map (well, at least the most relevant) so you can link them later in events.

Now the logical entity starts to work. Let me think of a counter usage (no clues in tutorial) ... hmm it can be use for example to count flags you capture. Another usage ... as a trap; in our example we will use the counter to setup a trap for a player hungry for Ammo. If the user takes more than two Rpg rounds, the hidden grenade will blow punishing player. Got it?

Add my_logical_entity to the map and, place it anywhere (Mine is the red square on screen). Double click for properties. In threshold keyvalue enter 3. That is, the output is launched when count equals 3.

Go to outputs and add a new Output. Take a look at the following screenshot. Please note that, when the event "OnThreshold" is triggered, The entity "My Grenade" will call it's action "Ignite", that is ... blow!!

Now, there's only one thing left ... How to increment the counter? Take each Rpg Round and add an output: In the event that user touches the Round (OnPlayerTouch), tell the target (First Counter, this is the name of my logical Entity) to "Tick", that is, increment the counter. Do this for every round.

Now, when user picks up all three rounds, the logical entity counter will increment to 3 and the grenade will ignite.

This is how it looks when playing.

That's all. I hope you enjoy creating some other Logical Entities. Let me know what came to your mind.

Monday, June 23, 2008

Shaggy Vs. Cumbia Cienaguera

It's football time, UEFA cup is about to finish, and every time a game starts the official video is shown on TV. It's Shaggy's "Feel the rush". A nice song but ... hold on .... I can hear something familiar ... I've heard that accordion notes somewhere in my childhood ....

Please, check Shaggy's video below when a happy and friendly guy plays the accordion (Thanks Germany for this wonderful instrument), and listen carefully.

Oh I remember where I heard that. I was young ... long time ago ... and that song played everywhere in parties. It a song from the country, It's name "Cumbia Cienaguera" means Cumbia from the pond (cumbia is a music style from the Colombian Folklore), composed by Martinez and MontaƱo.

Follow this link to listen the original version [here] and click on the speaker link next to the song name "Cumbia Cienaguera".

Is Shaggy aware of anything I mention here? I hope so, otherwise, I think there's some kind of Copyright Infringement. Can anybody give some lights?

Thursday, June 19, 2008

Maya 2008 Plugin development - Part 2


Fortunately, you are not tied only to the development of plugins for Maya 3D using C++, which implies a good knowledge of programming, debugging, memory management, etc.

Using Python has some advantages over C++:

  • Multiplatform: Although C++ can run in multiple platforms, you have to fit the code to the machine and use different compilers and setting for each platform (although you use open source compilers). Anyway you have to recompile. There's no such in Python. It will work in every platform.
  • Faster coding: Coding in Python is a way easier than C++. Few setup steps are required to develop applications in Python, and obviously, results will be seen faster.

Nothing is perfect, so these are the disadvantages I can think of:

  • Speed: Being a scripted language, Python is a lot slower than C++ (Compiled)
  • Low Level Programming: If you need to make son low level operations, then C++ (and assembler calls) is the right option.
For in-house development it's ok, but if I really want to make a commercial product (to be sold as a commercial plugin) I think C++ is the best choice.

(Please correct me if I made any mistake)

Python Plugin

Ok, but the purpose of this post is to have a small guide to setup Maya to be able to create a python plugin ... let's start.

Python packages are located here:

{Base Maya Directory}\Python\lib\site-packages

The only step needed to setup the Maya is by creating an environment variable in the system:

Variable name: PYTHONPATH

Value: {Base Maya Directory}\Python\lib\site-packages

After this variable has been created, you should restart Maya in order to have it updated with the new variable pointing to the Python libraries.

Now, let's test if Python works. Try the following in the Maya Script Editor (Please make sure you are working in the Python Tab as shown in the following image

import maya.cmds as cmd

If you get the following error, then the Python variables were not set up properly. Please check your environment variable making sure that you have not included the "Maya" subfolder in the PYTHONPATH variable.

# Error: No module named maya.cmds

If no error is thrown, then you can start writing your Python scripts. Let's create a sphere with a radius of 3 units. The following command will create the new object named "Sphere1"

cmd.sphere(name='sphere1', radius=3)

Now you have a nice sphere, let's change some shape .... hmm something like an American Football ball (or whatever it's called ... pigskin?). To accomplish this, let's scale the sphere unevenly:

cmd.setAttr('sphere1.scale', 1, 1, 2, type='double3')

Note that the attribute is "scale" from the "sphere1" object. Also, we have a vector of 3 doubles with values 1, 1 and 2.

Finally, let's change our ball color. If you are thinking on something like setAttr sphere1.color, then you are wrong. Remember that color does not belong to the sphere itself but to the shader linked to it. By default, shader is lambert1, so let's change ball's color:

cmd.setAttr('lambert1.color', 0.63, 0.146, 0, type='double3')

Again, we modify "color" attribute from "lambert1" object, by updating color value using a 3-vector of doubles.

I hope this brief introduction will help you in your journey inside Maya scripting.

Thursday, June 05, 2008

Open Source Control Version System (Part 2)

Client Side

Now that we have setup the server side application and repository, clients (developers) should have access to repositories using a client tool.

A useful tool for this purpose is the TortoiseSVN. It's a subversion client for windows. (Please note that subversion is the core of the Version Control Server). It support several protocols including http (the one we will use for VisualSVN Server) and it's really easy to use.

After you have downloaded and installed the application you will be surprised that there's no applications to run (rather than the diff and merge applications) to manage files. Instead, under the windows explorer you will find new options when you right-click on a file or folder (that's what it's called a shell extension).

The first step to setup your environment is by creating a directory where your files will be stored where you take them from the repository. Of course this folder can be the location of the sources after you created a project, or the location of your local web application.

So, choose your target directory and right click, then select "SVN Checkout".

A window will ask you for some information like the location of the SVN server (in this particular case is the SimpleSample folder) and click OK. This action will take a copy of all files from the repository into the folder you selected.

Now, you can open any file inside that folder and start the edition process, and saving in your local machine. Then, when you feel comfortable with its functionality, you can send it back to the repository by selecting SVN Commit and of course, you can get the latest version of the file by clicking SVN Update.

Of course there's more than that, but at least you have your SVN working and you can try other great features like merging, file versions, etc.

Wednesday, June 04, 2008

Valve's Source - Part 2

My First Mod

This guide complements My First Mod basic tutorial from the Valve's developer web page, so please, have booth pages opened.

After you have downloaded and Installed the SDK, you should run the Game and .... just to make sure everything will run ok, restart the computer (Well, I had to do it because the Source SDK didn't start when I tried to run it)

This is how Source SDK looks when you double click on the application. In order to continue with the tutorial, double click on the Create a Mod link under Utilities.

It takes some time to create all Mod files (All source files required to rebuild the application). When finished, a folder src is created and, below it there's the Solution. Please open it according to the Visual Studio version you have. In my particular case, it's VS2005.

Following screen shot illustrates the solution location, as well as the Rocket file location and line to be changed:

You go through the steps in tutorial in order to compile changes. Now you have to restart Steam. By restarting, I mean right click on Steam tray Icon, select Exit, and open the application again. You will then be able to see something like this (FabianMod is now available):

Please follow me. Although tutorial is correct, it's confusing because it says "Run the game", but then ... hold on, there's nothing to view, please go back and do this... These are the instructions I propose:

1. After Building the application, you have to have a map to test the change you just did in the rocket speed. So, download GCFScape. This application will allow you to copy a map from the HL2 library into your Mod.

NOTE: You don't have to copy the map inside the folder where the solution is located. When you build the Mod, a folder is created in the following path (In this particular example):


So, copy the map into the maps folder just below FabianMod (or your Mod's name).

2. Start the Mod from the Steam console.

3. Enable the ~ key to be able to open the Console

4. load Map by typing "map [your map name]" and hit enter

5. Enable cheats to be able to select Rocket weapon: "sv_cheats 1"

6. load all weapons by typing: "impulse 101"

That's all, now you should be able to launch a really slow rocket . I can even take a screenshot!

The following is an in-game screenshot:

Tuesday, June 03, 2008

Open Source Control Version System (Part 1)

When Software Projects become larger and more people is involved, there's need to keep control of source code files.
Usually, several users have to make changes at the same time in a core file. Doing this the wrong way may lead to delete changes made by a developer, wasting a lot of time and raising errors in the coding.
Fortunately, there's Version Control software which keeps track of who is using a file, keep versions of that files, allows merging, branching and other cool stuff to keep your software project synchronized.
There are several vendors and open open source versions of this software, and a couple of models. Please check the List of Revision Control Software.

In this case we are going to setup a Control software using a Client-Server model with an open source application.

Server Side

VisualSVN is our choice, because it's Open Source, provides an easy installation package and a clean control panel. Just download it from VisualSVN. After downloading, run the setup and follow the wizard:

Next, set install location and repositories path. Repository is where the files will be physically located (Please do not modify anything inside repositories unless you know exactly what are you doing). Also, set the server port. VisualSVN Server runs on Apache server and it can be accessed through http protocol, that is, you can have some access using a web browser.

That's all. Now you can access the control panel using the Manager:

First of all you have to create the users who will have access to the repository by clicking on the "Create new user" link.

Final step in the server side is create the New Repository, that is, the particular space where the application files will be stored. I created a sample for this:

You can check if your system is running properly by logging to the VisualSVN server location using a web browser (As I am running local, I just entered localhost:8080/svn/SimpleSample):

Just remember you log in using the SVN user you created previously. You can create a user for each developer, so when you track changes you can view who modified the application by the means of this user.