Author Topic: Problems porting weapons to FOnline  (Read 10361 times)

Problems porting weapons to FOnline
« on: May 19, 2013, 08:56:44 am »
I'm using Revison 404.
I can't figure this out. I found this M16 off the internet and can't figure out how to make it show up in my FOnline Setup.

I opened the item.lst and added the following:
Code: [Select]
873  PID_COLT_M16
Copied ID #23 [Assault Rifle] in weapon.fopro and changed the ProtoID to 873.
It shows up in the inventory when I use the console.
Then followed this tutorial:
http://fodev.net/forum/index.php/topic,26833.0.html?PHPSESSID=29qlpetphm1resckcen20nnbg3
Got to the part where you edit _FOHuman.fo3d.
The thing that throws me off is, there is no _FOHuman.fo3d in my client folder, just _VBHuman.fo3d. Am I supposed to edit that?
What else am I doing wrong?
« Last Edit: May 19, 2013, 09:21:36 am by E3245 »

Offline Luther Blissett

  • Moderator
Re: Problems porting weapons to FOnline
« Reply #1 on: May 19, 2013, 11:26:16 am »
The main thing is simply that the 3D stuff being done on here is not part of the main Fonline repo - so revision 404 from http://xp-dev.com/svn/fonline_sdk/ will not contain any of our 3D models or setup files (including FOHuman.fo3d etc. The 3D bits included in the main Fonline repo are the Van Buren models etc.

The main 3D repo for our stuff (the "Karpov model", following the shape of original Fallout sprites) is at http://svn3.xp-dev.com/svn/FOnline3d/.

You may find also that our 3D stuff currently won't work well with the newer SDK revisions (see Need help getting Karpov era 3D models to work with newer SDK revisions and Porting to the latest SDK; big trouble - though it will do eventually.

I wrote this #1 - Setting up 3D SDK a little while back, which though probably a bit out of date, should help you get started. May be worth having a read through the other tutorials and a few other threads in this forum to fill in any more recent changes.

Hope that helps - please ask again if you're still having problems :)

Re: Problems porting weapons to FOnline
« Reply #2 on: May 20, 2013, 12:48:41 am »
1) How do I load multiple textures to the model in the Client?

2) How do I get the game to load the model when I equip the weapon? So far, only ~param command loads it.

Offline Luther Blissett

  • Moderator
Re: Problems porting weapons to FOnline
« Reply #3 on: May 20, 2013, 01:25:30 am »
1) I don't think there's a client command to simply change texture. You'd need to add an extra value into _FOHuman.fo3d for each texture, for example :
Code: [Select]
# Head --------------------------
Layer 4
[...]
Value 27 Root Attach Armor_%anim%_dusterhat.x Texture 0 Armor_male_cowboyhat_brown.png
Value 28 Root Attach Armor_%anim%_dusterhat.x Texture 0 Armor_male_cowboyhat_black.png

That would mean param 0 154 27 gave you a hat with brown texture, 0 154 28 with black texture. It should be possible to change the colours by script, but I think they'd still rely upon separate values in the fo3d.

2) You need to change some stuff in \scripts\client_main.fos. Should be described somewhere near here -
http://fodev.net/forum/index.php/topic,26833.msg232944.html#msg232944
The file upload mentioned in that link has expired. I have reuploaded to http://depositfiles.com/files/uf48gu96u. You can probably just drop that file "as is" into your own \scripts\ folder, and it will magically work.

Re: Problems porting weapons to FOnline
« Reply #4 on: May 21, 2013, 01:28:06 pm »
The script you gave me relies on start_server_client.fos (I think that's the name), which is no longer provided in the repository.

I also noticed that the game cannot load multiple textures to one object, the game can only load one texture for one object, Texture 0. Texture 1,2,3... won't load. Any way to fix this?

Offline Luther Blissett

  • Moderator
Re: Problems porting weapons to FOnline
« Reply #5 on: May 21, 2013, 04:01:14 pm »
Sorry I've not tested much in the newest revisions - I have no idea about the start_server_client.fos to be honest. If client_main.fos is also no longer used, then I assume this info must be put somewhere else instead. Basically it's these bits below you're looking for - in mine they're pretty much at the end of the client_main.fos file, but if that file doesn't exist, perhaps the same code has been put in a different file?

If so, you can find the bits which look like this :
Code: [Select]
#ifdef PLAYERS_3D
int GetHandleValue(uint16 pid)
{
if(pid == 0 || (pid >= 1000 && pid <=1100)) return 0;

int handle = 0;
switch(pid)
{
case PID_ZIP_GUN:                        handle = ATTRIBUTE_Handle_Weapon_22Autoloader;               break;
case PID_9MM_MAUSER:                     handle = ATTRIBUTE_Handle_Weapon_9mmAutoloader;              break;
case PID_10MM_PISTOL:                    handle = ATTRIBUTE_Handle_Weapon_22Autoloader;               break;
case PID_14MM_PISTOL:                    handle = ATTRIBUTE_Handle_Weapon_22Autoloader;               break;
case PID_DESERT_EAGLE:                   handle = ATTRIBUTE_Handle_Weapon_45Autoloader;               break;
[...]
case PID_BROWN_BAG:
case PID_BACKPACK:                       handle = 0;                                                  break;
// Generic item
default:                                 handle = 0;                                                  break;
}

return handle;
}
#endif

Then replace them with bits which look like this instead :

Code: [Select]
#ifdef PLAYERS_3D
int GetHandleValue(uint16 pid)
{
if(pid == 0 || (pid >= 1000 && pid <=1100)) return 0;

int handle = 0;
switch(pid)
{
case 1 : handle = 1 ;                break;
case 2 : handle = 2 ;                break;
case 3 : handle = 3 ;                break;
case 4 : handle = 4 ;                break;
case 5 : handle = 5 ;                break;
case 6 : handle = 6 ;                break;
case 7 : handle = 7 ;                break;
case 8 : handle = 8 ;                break;
case 9 : handle = 9 ;                break;
[...]
case 498 : handle = 498 ;                break;
case 499 : handle = 499 ;                break;
case 500 : handle = 500 ;                break;

// Generic item
default:                                 handle = 0;                                                  break;
}

return handle;
}
#endif

Hopefully that would get the weapons working (because it's done by number instead of specific name, it should work regardless of what the files are called).

You can have multiple textures on a single object - you just need the object to have several different materials, which can be altered by subsets. Have a quick look through the thing I wrote up here : #2 - Testing custom body textures. That should help to explain most of it I think.

In short, the different texture numbers (Texture 0, 1, 2) are for diffuse, normal and specular. They're not for multiple textures on the same model. Like this :
Code: [Select]
Value 10 Root Texture 0 diffuse.png Texture 1 normalmap.png Texture 2 specularmap.png
Note that I never managed to get normal maps to work. Specular and diffuse did work.

If you looked at the tutorial link, you should roughly understand the subsets on the main body. You can of course add subsets to any other model. There's a little annotated code here from when I was testing hair subsets :
Code: [Select]
# testing the subsets
 Value 90  Root Attach longhairtestsubsets.x Texture 0 hair_brown.png
# character shows in game with fully brown hair, covering all materials
 Value 91  Root Attach longhairtestsubsets.x
             Subset 0 Texture 0 hair_purple.png
             Subset 1 Texture 0 hair_grey.png
             Subset 2 Texture 0 hair_red.png
             Subset 3 Texture 0 hair_white.png
# character shows in game with
# purple side of head (subset 0 therefore material 1)
# grey top of head (subset 1 therefore material 2)
# red long part of hair (subset 2, therefore material 3)
# white non existent.

The hair model was split into three areas with different materials (material 1, 2 and 3). The material at the top of the materials list (irrespective of its name) seemed to be treated as subset 0. The others followed in sequence.

Hope that all makes sense.

Re: Problems porting weapons to FOnline
« Reply #6 on: May 24, 2013, 04:20:40 am »
So that would mean that Subset 0 = Material ID 0, Subset 1 = Material ID 1, etc?

Offline Luther Blissett

  • Moderator
Re: Problems porting weapons to FOnline
« Reply #7 on: May 24, 2013, 07:43:03 pm »
Different 3D programs may call the materials something different (like 1,2,3 instead of 0,1,2 or not give them a number at all) but basically, yes. It should do as you described.

Re: Problems porting weapons to FOnline
« Reply #8 on: May 25, 2013, 08:55:45 am »
Okay, I finally got the textures to load, but I tried to replace the code in the client_main.fos, but it messes up the models. Like the assault rifle model is now the baseball bat instead of the sawed-off shotgun. Is this supposed to happen?

Plus I still can't figure out how to link the weapon to the model. Would Case 1 be ProtoID #1 and handle would be the attribute of the weapon? I need a clear understanding of this because I am confused.

Offline Luther Blissett

  • Moderator
Re: Problems porting weapons to FOnline
« Reply #9 on: May 25, 2013, 10:37:19 pm »
You're unfortunately getting to the point where I start having to say "I don't know" - but it definitely shouldn't be showing the wrong models. I THINK the problem is with an older version of the _FOHuman.fo3d. The layer you want to be looking at is "# Right Handle Layer 1" (this corresponds to param 151 by in game code).

In different versions I have, one starts with :
(I've spoilered the three chunks of code here)

The former has objects listed at every number, the middle has only objects listed at the correct number for their object ID and the latter is grouped in sections.

I've uploaded the last one here > FOHuman.fo3d.

If you're lucky, you can maybe drop that in and it will just work. What you ask about linking weapon/model... that's what it's meant to do, but might not do yet :(

The layer IDs SHOULD correspond to the object IDs, and the code in CLIENT_main.fos :
Code: [Select]
case 1 : handle = 1 ;                break;should be pretty much saying "When it's ID#1, look at value#1 in the Fo3d" (I think). This should mean that some of the numbers don't exist any more, so there is no line for wearing armour ID#4 (layer 3 value 4), because ID#4 is a knife, so will only be in Layer 1 (active hand) and possible Layer 2 (inactive hand). The general skin and hair layers aren't drawing numbers from the object IDs, so should currently be simply in sequence (i.e. 1, 2, 3, 4 etc).

Basically, the main problem is that loads of this stuff is half done, and various bits are uploaded in different places, with different bits working. I've tested lots of things myself, but it means my own in-progress "FOHuman" is completely incompatible with Karpov's in-progress "FOHuman". It also means I have 5 or 6 different versions of FOHuman in different folders. They can be combined later with things like "Winmerge" or manually correcting them though.

For the general question about how the bits link together, it's again a little beyond my knowledge, but I'd assume anyone who's successfully added extra objects to the game (like the 2238 devs) should know how this all works properly.

The bits I am aware of are roughly as follows :
server\data\ItemNames.lst < this lists all objects in game, and ID numbers. I'm not sure if it's just for reference, or whether it affects anything

server\proto\weapon.fopro < this gives all the info for each of the weapons. "Pid" is the ID and the "Weapon.Anim1=" line specifies which animation set to use. You can see these animation sets listed at the bottom of _FOHuman.fo3d, though it shows as ABCD instead of 1234 (i.e. knife uses Weapon.Anim1=4, which corresponds to animation set "Anim D". Armour is in "armor.fopro".

server\text\engl\foobj.msg < These are the in-game names for the objects. Seems to follow ID00 = short name, ID01 = description, i.e. assault rifle is ID 23, so 2300 = "Assault Rifle" etc. I don't know if these are hardcoded from ID, or whether they're specified in a file somewhere.

server\scripts\CLIENT_main.fos < has loads of other stuff in I don't understand, but also contains the object/animation links at the bottom. The older one said :
Code: [Select]
case PID_10MM_PISTOL:                    handle = ATTRIBUTE_Handle_Weapon_22Autoloader;               break;Which meant "when you equip the object with "10MM_PISTOL" ID, load the model "Weapon_22Autoloader".

The newer one should say :
Code: [Select]
case 1 : handle = 1 ;                break;"When you equip the object with ID 1, load the model listed under value 1 in the relevant layer of the fo3d file".

I hope that makes some sense to you - I only just understand what I'm trying to say myself ???

Re: Problems porting weapons to FOnline
« Reply #10 on: May 26, 2013, 08:19:33 am »
How does ATTRIBUTE_Handle_Weapon_22Autoloader work? I've seen that in the _animations.fos script. I tried to add ATTRIBUTE_Handle_Weapon_M16 then add case PID_M16A1 ;handle = ATTRIBUTE_Handle_Weapon_M16 in the client_main.fos, but nothing happens.

Just so I'm clear, I am going to try to add this the old way instead of the other way.

Offline Luther Blissett

  • Moderator
Re: Problems porting weapons to FOnline
« Reply #11 on: May 26, 2013, 09:05:54 pm »
I've never really messed with that stuff myself, sorry. Looks like you're trying two things, which are :
1) General modding to add a new item
2) Linking a 3D model to an item

I pretty much know nothing about the first, but one of the 2238 devs or any other general modder must know this. I've only got a vague idea about the 2nd bit too. I guess you can either wait, or try various things yourself.

I'd look at the following files :
server\scripts\_itempid.fos < I missed mentioning this before, so perhaps this is a key file to change?
server\data\ItemNames.lst
server\scripts\_client_main.fos
server\proto\items\weapon.fopro
server\text\engl\foobj.msg
server\scripts\_animation.fos
server\scripts\pids_groups.fos < not sure about this, but it does include "PID_10MM_PISTOL" in it, so perhaps should include equivalent for what you're adding?

A lot of the threads which explained this stuff were on the old fonline.ru, and seem now to be lost. I did copy and paste this bit which may be necessary (though it might only apply to changing the character registration screen) :

Quote
Some changes in the .fos need to update the fosb and fosp files
- Run client
- Press Enter
- Restart client
- Registration (This called "update client scripts")
This is necessary for changes to client registration. It makes new .fosb .fosp

If you do find the answer yourself, make sure to report how to do so here. It will save a lot of trouble in future.

Re: Problems porting weapons to FOnline
« Reply #12 on: May 27, 2013, 08:32:04 am »
Finally, I've got the weapons working and linked, which means Karpov's weapons will work once they get implemented, but only through the _VBHuman.fo3d, because the _FOHuman.fo3d file doesn't load in FOnline.

Anyways, here are the steps to add a new weapon and then link the 3d model into the latest update, Revision 404:[/size]

1. Make a weapon model in you favorite 3d modeling program (i.e 3dsmax, Maya, Fragmotion, Blender, etc.) and export it to the .x file. Name your weapon: WP_Weaponname.x (Replace Weaponname with the name you choose). The textures don't really need to be name ITEM_Texturename, because the engine loads them anyways, so there is no point. Probably the same case with the WP_Weaponname.x file.
Following this tutorial will help: http://fodev.net/forum/index.php/topic,26833.0.html

2. Put the textures in /.../Client/data/textures and the .x file in /.../Client/data/art/critters/

3. Open Notepad or a text editor and save the file as WP_Weaponname.fo3d in the same directory with the model (i.e /.../Client/data/art/critters/) as Like this: WP_WeaponName.fo3d

4. Now for the text part.
The first line should be:
Code: [Select]
Model WP_Weaponname.xIf your weapon has multiple textures, you'll need to write this: Root
Code: [Select]
Subset 1 Texture 0 Texture1.tga
Subset 2 Texture 0 Texture2.tga
Subset = the material that the weapon is assigned in the 3d modeling program.
I'm not sure what this line means but the other WP_x.fo3d files has this loaded, so I added it in anyways:
Code: [Select]
Include _VBWeapon.fo3d name WP_WeaponNameSo, it should look like this:
Code: [Select]
Model WP_Weaponname.x
Subset 1 Texture 0 Texture1.tga
Subset 2 Texture 0 Texture2.tga
Include _VBWeapon.fo3d name WP_WeaponName
5. Open the _VBHuman.fo3d and go down to Layer 1 or # Right Handle. Go to the end of the Layer 1 and add this:
Code: [Select]
Value 57 Attach WP_Weaponname.fo3d Link R_Handle_1 RotX x  RotY y RotZ z MoveX xx Move yy MoveZ zz Scale s
Replace the symbols x,y,z,xx,yy,zz,s with the desired numbers. You may need to tinker a bit before it will look right.

6. Now we added the weapon thru the _VBHuman.fo3d, we need to actually add the weapon so the FOnline Server will add the weapon. Open the file ItemNames.lst in Server/data/ folder and go down to the last line, which should be 872. Write 873 PID_WEAPONNAME on the next line. (873 is the ProtoID that will be referenced, PID_WEAPONNAME being the weapon. It is case sensitive so be sure to copy the PID name.)

7. You will need to use Object Editor in the Tools folder to understand what each parameters does in the .fopro file later in the tutorial. Open Object Editor and go to File>Load List, and go to Server/proto/item/weapon.fopro. Then choose a weapon (I chose Assault Rifle) and go to Object>Clone Selected Object (CTRL+SHIFT+C), and type in the right PID, in this case 872. Rename the weapon and description and change the parameters in the Main and Ext Info. Once you are done, then File>Save List and overwrite weapon.fopro.

8. We are not done yet. Go to Server/Scripts and open _itempid.fos. Go find the weapons section and add this line anywhere:
Code: [Select]
#define PID_WEAPONNAME ( 872 )
9. Open Client_main and go down until you see this line
Code: [Select]
if( pid == 0 || ( pid >= 1000 && pid <= 1100 ) )
        return 0;
Insert this line:
Code: [Select]
case PID_WEAPONNAME:
        handle = 57;
        break;
This could also work, I haven't test this yet:
Code: [Select]
case 872: handle = 57; break;
10. Test and Enjoy! Post any errors that you encounter below.

The _VBHuman.fo3d loads but not the _FOHuman.fo3d. I think it is defined what loads somewhere in the server/scripts folder.

Also, can someone tell me how to add muzzle effects to these weapons?
« Last Edit: May 27, 2013, 11:52:53 am by E3245 »

Offline Luther Blissett

  • Moderator
Re: Problems porting weapons to FOnline
« Reply #13 on: May 27, 2013, 01:50:00 pm »
Nicely done!

Re: Problems porting weapons to FOnline
« Reply #14 on: May 28, 2013, 01:24:37 pm »
New problem, How do I change animations to weapons. I noticed that the Rocket Launcher is two handed but there is no .fo3d or script that tells how the weapon's animation is handled.