[Guide] Pimp My Rifle Display

DiFFtYDiFFtY Join Date: 2010-03-07 Member: 70867Members
edited April 2010 in Modding
<div class="IPBDescription">Some tips to make your own display.</div>Hi guys !
In the last past days, I worked on customize the little screen which displays the amount of remaining ammo of your favorite toy. Now that I managed to make my own little screen, I think it could interest some people here to know how it works.

I made this post because there are some stuffs to know about those animations. I’ll not learn you here how to build your custom display from A to Z, just give you the keys to link your script to the game and get it working.


First, you have to know that game’s SWF library only supports files compatible with version 6 of the Flash format. That’s why you’ll have to forget about ActionScript 3, pay attention to which function and classes you’ll use. (compatibility information is noticed on each function/class page in Adobe’s doc)


To begin, create a new project. Set the animation dimensions to 256x417px. I think that you’re not forced to use precisely those dimensions, but it will be easier to handle the game restrictions by using those default values. Indeed, the game cut the animation in two parts : the first 256x256 being used for the screen, and the rest for an obscure smaller clip counter. This second part is not used in the Engine Test, so you don’t have to care about it.
Notice that if you miss with those dimensions, and set and fill, for example, your workspace as a 256x256 drawing space, you’ll get a partially displayed and stretched animation on the final in-game render. You’ve been warned! ;)


Next, let’s see how the link is made between the game and Actionscript.
In one hand, you have a Lua script called “PlayerUI.lua” (in “Natural Selection 2/ns2/lua”). It contains some functions you’ll need in order to retrieve information from the player to your Flash script. Here some examples, took from the actual PlayerUI.lua, the one modded by ns2lua team :

PlayerUI_GetHealth
PlayerUI_GetGameTime
PlayerUI_GetWeaponClip
PlayerUI_GetWeaponAmmo

Those functions are used to get, respectively, player’s health, current game playtime, weapon’s remaining ammo in the current clip and in the whole clips. They are just programmed to return one attribute.
In the other hand, you have your Flash animation which needs this data to display the good informations on the little screen. To call the Lua function from your Actionscript code, you’ll have to use the lua() function, with the name of the function you want to get the information.
For example, to get the current weapon’s ammo remaining, you’ll type, in your AS2 code :

<div class='codetop'>CODE</div><div class='codemain' style='height:200px;white-space:pre;overflow:auto'>ammo = lua(“PlayerUI_GetWeaponClip”);</div>

It’s that simple.


You have to know, too, that the game loops the animation to infinite. But it will execute only one time the code you put in your first frame (naturally.). That’s why you’ll have to define an event in this frame, which will be executed each time the frame is changing, in which you’ll add everything that needs to be refreshed constantly (like reading and drawing).
This event looks like that :

<div class='codetop'>CODE</div><div class='codemain' style='height:200px;white-space:pre;overflow:auto'>onEnterFrame = function ()
{
/* stuff you want to refresh */
}</div>


Now I’ll give you a little tip, used in the original code to test the animation without needing to be in game.
The idea is to make an Actionscript function to retrieve the information and return it, but return a defaut value in the case where the lua code couldn’t be called. (When you test the animation outside of the game, for example…)
To make this, we will test the existence of an object named “lua”, and then set an arbitrary value to the return of the function in the case where it doesn’t exists. For example, for an ammo counter, you can descrease a global variable which will show you, in loop, every step of your animation. Example :

<div class='codetop'>CODE</div><div class='codemain' style='height:200px;white-space:pre;overflow:auto'>var MAXAMMO = 30
var ammo = MAXAMMO

function getAmmo()
{
if(lua == undefined)
{
ammo--;
if( ammo < 0 )
{
ammo = MAXAMMO;
}
return ammo;
}
return lua("PlayerUI_GetWeaponClip");
}</div>


Finally, to install your mod, export it to rifleDisplay.swf and copy/erase it (AFTER BACKING UP THE ORIGINAL) to Natural Selection 2/ns2/ui/.


I think I said everything. Maybe this little guide will evoluate, with more visuals, examples, tips, etc. Maybe it won’t ; it depends on your feedback. I’m making a video of my work, it’s actually looking pretty cool !
To analyze the original SWF, I used Flash Decompiler Trillix. I don’t want to make any advertisement for them, I just took the first software of this kind in Google and it worked pretty well, and its demo mode is enough complete to see in details the mechanics of the scripts. ;)
Being novice in Flash development, certain points may be obvious for more skilled people. Please excuse me for that. Excuse me too if I made English mistakes, I’m French. ;)
And feel free posting comments and questions. :)

<a href="http://uppix.net/1/4/3/654998a3fd6a2c9c6aa3f96250810.html" target="_blank"><img src="http://uppix.net/1/4/3/654998a3fd6a2c9c6aa3f96250810t.jpg" border="0" class="linked-image" /></a><a href="http://uppix.net/a/a/e/288d1dd8d1947edc3640da1d299d2.html" target="_blank"><img src="http://uppix.net/a/a/e/288d1dd8d1947edc3640da1d299d2t.jpg" border="0" class="linked-image" /></a><a href="http://uppix.net/f/e/b/94faa633dd227e978a3640036badb.html" target="_blank"><img src="http://uppix.net/f/e/b/94faa633dd227e978a3640036badbt.jpg" border="0" class="linked-image" /></a>

Good luck and happy Flashing ;)

Comments

  • GDWhiteGDWhite Join Date: 2009-07-17 Member: 68170Members
    Oh wow, that's sexy.
    What's the display in the middle? A dancing guy in a polo and Marine helmet? :D
  • DiFFtYDiFFtY Join Date: 2010-03-07 Member: 70867Members
    Haha, <a href="http://www.geek-gaming.fr/divers/Flyflo/f/Schro_Trouble_Boy.swf" target="_blank">that's right</a> ;)
  • johhny djohhny d Join Date: 2010-04-08 Member: 71215Members
    <!--quoteo(post=1766992:date=Apr 14 2010, 11:19 PM:name=DiFFtY)--><div class='quotetop'>QUOTE (DiFFtY @ Apr 14 2010, 11:19 PM) <a href="index.php?act=findpost&pid=1766992"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->Haha, <a href="http://www.geek-gaming.fr/divers/Flyflo/f/Schro_Trouble_Boy.swf" target="_blank">that's right</a> ;)<!--QuoteEnd--></div><!--QuoteEEnd-->

    hehe i love it

    <img src="http://img52.imageshack.us/img52/3568/99779406.gif" border="0" class="linked-image" />
  • DiFFtYDiFFtY Join Date: 2010-03-07 Member: 70867Members
    That's better than the original isn't it ?
    I think we could even make something useful with it. x)
  • FocusedWolfFocusedWolf Join Date: 2005-01-09 Member: 34258Members
    <!--quoteo(post=1766992:date=Apr 14 2010, 07:19 PM:name=DiFFtY)--><div class='quotetop'>QUOTE (DiFFtY @ Apr 14 2010, 07:19 PM) <a href="index.php?act=findpost&pid=1766992"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->Haha, <a href="http://www.geek-gaming.fr/divers/Flyflo/f/Schro_Trouble_Boy.swf" target="_blank">that's right</a> ;)<!--QuoteEnd--></div><!--QuoteEEnd-->

    LMAO!!!!!!!!!!!!!! Junior Warrant Officer Schrödinger!!!! xD
  • WatchMakerWatchMaker Join Date: 2003-09-26 Member: 21233Members, Constellation
    It just hit me that I can put any .swf I want into NS2. I'm giddy with excitement all over again.
  • Mr. EpicMr. Epic Join Date: 2003-08-01 Member: 18660Members, Constellation
    <!--quoteo(post=1767015:date=Apr 14 2010, 09:32 PM:name=WatchMaker)--><div class='quotetop'>QUOTE (WatchMaker @ Apr 14 2010, 09:32 PM) <a href="index.php?act=findpost&pid=1767015"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->It just hit me that I can put any .swf I want into NS2. I'm giddy with excitement all over again.<!--QuoteEnd--></div><!--QuoteEEnd-->
    I'm not, you just KNOW someone will embed a hidden rickroll in all of the flash screens...
  • rsdrsd Join Date: 2003-02-11 Member: 13405Members
    This tutorial is brilliant, thanks for taking the time to write it!
  • BacillusBacillus Join Date: 2006-11-02 Member: 58241Members
    Awesome. Great job on the guide and great job by UWE on the modifiability.
  • DiFFtYDiFFtY Join Date: 2010-03-07 Member: 70867Members
    Thank you ! =)

    I'm thinking about making a little simple example, step-by-step, to make the guide more beginner friendly. I plan to write it this evening or tomorrow, so stay tuned if you're interested ;)
  • CoolCookieCooksCoolCookieCooks Pretty Girl Join Date: 2003-05-18 Member: 16446Members, NS1 Playtester, Contributor, Constellation
    Shame its in AS2 :( old language is old.
  • rsdrsd Join Date: 2003-02-11 Member: 13405Members
    For the record, using Macromedia Flash 8, I had to do this (note the ".text"):

    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->onEnterFrame = function ()
    {
        txtTotalAmmo.text = lua("PlayerUI_GetWeaponAmmo");
    }<!--c2--></div><!--ec2-->
  • RobBRobB TUBES OF THE INTERWEB Join Date: 2003-08-11 Member: 19423Members, Constellation, Reinforced - Shadow
    I just hope that i can stop servers from putting crap on my displays.
    i certainly do not want to have carameldansen or any other crappy erogee loops on, in, over or under my ammo counters.
  • DiFFtYDiFFtY Join Date: 2010-03-07 Member: 70867Members
    HUD files are local content, you don't have to fear about this.

    rsd : okay, that's pretty strange... I'm using Flash CS4, but I was thinking that the both AS versions were exactly the same...
Sign In or Register to comment.