[Coding] Server-side modding

Making or wanting help making your own asset? Check in here
Post Reply
rPoXoTauJIo
PR:BF2 Developer
Posts: 1979
Joined: 2011-07-20 10:02

[Coding] Server-side modding

Post by rPoXoTauJIo »

So far bfeditor 404 rip, and realitymod is being one of largest dumps of tutorials left.

For the memory i just write down what i have collected so far\tested could be done by server-side without client downloads. Could be useful for map-tests\hotfixes, or something like this...

NOTE!:
This is FORBIDDEN to use on public non-passworded PR servers. Server-side modding is only is only allowed on local\private\passworded servers.

Editing assets to spawn server-side.
With restricted access to server side modding in comparison to bf1942, we can not do so much tricks...

I. Some theory
The spawner system for assets in bf2 consisting from 2 parts - ObjectSpawnerTemplate's and ObjectSpawners itself.
  • ObjectSpawnerTemplate is non-existant object in memory and it's a telling us what to spawn and when to spawn, aswell as some other params.
  • ObjectSpawners in gpo files is usually invisible non-collision static objects existing in game world, they're calling ObjectSpawnerTemplate to be activated on their position.
Tbh there's quite lot other possibilities with this file, but it's depend on map, so let's proceed further.

II. Some practice.
Lets make a example of server-side training mod for muttrah.
Objectives:
  • Move assets.
  • Make more assets.
  • Make all assets spawn faster.
  • Deleting assets.
First of all, lets move some assets, like for example lets swap cobra and attack huey.
What we need is to change coordinates in ObjectSpawners(which is calling ObjectSpawnerTemplates). The task is simplified by the fact that we have only one cobra and one huey.

1. Lets move cobra on huey position first. We're starting from finding huey coordinates.

Open mods/pr/levels/muttrah_city_2/server.zip\gamemodes\gpm_cq\64\gameplayobjects.con
Find huey ObjectSpawnerTemplate by finding object template assigned to it, us_ahe_uh1nrockets in our case:
rem [ObjectSpawnerTemplate: cpname_muttrah_city_2_aas64_carrier_TransHeli2]
ObjectTemplate.create ObjectSpawner cpname_muttrah_city_2_aas64_carrier_TransHeli2
...some stuff...
ObjectTemplate.setObjectTemplate 2 us_ahe_uh1nrockets
...some stuff...
Now we need to find ObjectSpawner object that referring to our ObjectSpawnerTemplate.
rem [ObjectSpawner: cpname_muttrah_city_2_aas64_carrier_TransHeli2]
Object.create cpname_muttrah_city_2_aas64_carrier_TransHeli2
Object.absolutePosition 763.740/46.992/894.459
Object.rotation -154.341/0.000/0.000
Object.setControlPointId 1
Object.layer 3
That's position and rotation of our ObjectSpawner. Bf2 uses x/y/z;yaw/pitch/roll position/rotation system relative from 0, center of map.
Write down those coords somewhere.

Now lets find cobra ObjectSpawnerTemplate:
ObjectSpawnerTemplate - us_ahe_ah1z
ObjectSpawner - cpname_muttrah_city_2_aas64_carrier_AttakHeli
rem [ObjectSpawner: cpname_muttrah_city_2_aas64_carrier_AttakHeli]
Object.create cpname_muttrah_city_2_aas64_carrier_AttakHeli
Object.absolutePosition 839.930/46.992/776.396
Object.rotation -97.848/0.000/0.000
Object.setControlPointId 1
Object.layer 3
Write those coordinates too, and replace with huey ones.
Now go into huey ObjectSpawner and replace it's coordinates with cobra ones.

Now we have cobra and huey spawn replaced.

EDIT: thanks to Ason for finding another way to replace vehicles.
When you want to switch position of cobra and huey you can also just change the 'ObjectTemplate.setObjectTemplate 2 us_ahe_uh1nrockets'
to 'ObjectTemplate.setObjectTemplate 2 us_ahe_ah1z'.
The coordinates just means it will spawn an object of for example "cpname_muttrah_city_2_aas64_carrier_TransHeli2" on X,Z,Y. Most of the time you don't need to change the coordinates when you just want to switch two assets position.
This is possible only if we have both object templates and spawner templates loaded into client game memory.

2. Now we wanna have more and more mtlbs. There's 2 ways to do it.
First is to multiply ObjectSpawners - then we gonna have multiple spawn positions. So instead of:
...some stuff...

rem [ObjectSpawner: cpname_muttrah_city_2_aas64_southcity_apc_0]
Object.create cpname_muttrah_city_2_aas64_southcity_apc_0
Object.absolutePosition 92.706/39.368/-910.191
Object.rotation -20.951/0.000/0.000
Object.setControlPointId 205
Object.layer 3

...some stuff...
We gonna have multiple instances of ObjectSpawners:
rem [ObjectSpawner: cpname_muttrah_city_2_aas64_southcity_apc_0]
Object.create cpname_muttrah_city_2_aas64_southcity_apc_0
Object.absolutePosition 92.706/39.368/-910.191
Object.rotation -20.951/0.000/0.000
Object.setControlPointId 205
Object.layer 3

rem [ObjectSpawner: cpname_muttrah_city_2_aas64_southcity_apc_0]
Object.create cpname_muttrah_city_2_aas64_southcity_apc_0
Object.absolutePosition 92.706/49.368/-910.191
Object.rotation -20.951/0.000/0.000
Object.setControlPointId 205
Object.layer 3

rem [ObjectSpawner: cpname_muttrah_city_2_aas64_southcity_apc_0]
Object.create cpname_muttrah_city_2_aas64_southcity_apc_0
Object.absolutePosition 92.706/59.368/-910.191
Object.rotation -20.951/0.000/0.000
Object.setControlPointId 205
Object.layer 3

rem [ObjectSpawner: cpname_muttrah_city_2_aas64_southcity_apc_0]
Object.create cpname_muttrah_city_2_aas64_southcity_apc_0
Object.absolutePosition 92.706/69.368/-910.191
Object.rotation -20.951/0.000/0.000
Object.setControlPointId 205
Object.layer 3
Notice the difference in Y - height coordinates, mtlb's gonna spawn 10, 20, 30 meters high that our stock mtlb. This is just for educational purposes, for actual coordinates you either need good imagination for calculating coordinates in your brain, or need to load up in editor, place some gpo's and find their coordinates. Or use python+PIL.

Second way to spawn more objects in one position is to add multiply parameter into ObjectSpawnerTemplate:
ObjectTemplate.maxNrOfObjectSpawned 5
Where 5 is number of objects that will be spawned.
Keep in mind that if this number is greater than 1(or line non-exist like in 98% of spawners in pr), then spawn time is starting ticking right after object has moved from it's spawn position.
So of we gonna have 5 cobras, you will have to move one from spawn place, and wait another 15 minutes.
For example on std muttrah check boats, they have 120 seconds spawntime and 5 objects to spawn.

3. Making assets spawn faster.
In this case we just modifying parameters in ObjectSpawnerTemplate:
ObjectTemplate.minSpawnDelay 300
ObjectTemplate.maxSpawnDelay 300
When number is representing spawntime in seconds.

4. Deleting assets.
Lets say we wanna delete cobra.
No need to delete ObjectSpawnerTemplate as it's loaded into memory of both clients and server.
Instead, we're deleting ObjectSpawner, so cobra could be spawned - but we're not telling clients to spawn it.
rem [ObjectSpawner: cpname_muttrah_city_2_aas64_carrier_AttakHeli]
Object.create cpname_muttrah_city_2_aas64_carrier_AttakHeli
Object.absolutePosition 839.930/46.992/776.396
Object.rotation -97.848/0.000/0.000
Object.setControlPointId 1
Object.layer 3
In gameplayobjects.con file just delete those lines, and meet new gameplay without cas whores.
Image

assetruler69: I've seen things you smurfs wouldn't believe. Apaches on the Kashan. I watched burned down tank hulls after the launch of the single TOW. All those moments will be lost in time, like tears in rain.

Time to give up and respawn.
rPoXoTauJIo
PR:BF2 Developer
Posts: 1979
Joined: 2011-07-20 10:02

Re: [Coding] Server-side modding

Post by rPoXoTauJIo »

In addition for mappers, if only GPO changes are planned, then it is possible to prepare for them by including ObjectSpawnerTemplate's of all assets of both factions in GPO file, so they can be used later for balance.
Ofc, the drawback of this method is bit of overuse of resources, as we're loading assets without actual use.
Image

assetruler69: I've seen things you smurfs wouldn't believe. Apaches on the Kashan. I watched burned down tank hulls after the launch of the single TOW. All those moments will be lost in time, like tears in rain.

Time to give up and respawn.
rPoXoTauJIo
PR:BF2 Developer
Posts: 1979
Joined: 2011-07-20 10:02

Re: [Coding] Server-side modding

Post by rPoXoTauJIo »

HOW TO - Testing server-side changes.
One of the interesting thins in bf2 is it's client-server architecture, allowing us to do some kind of server-side modding. But ofc, to get something working, we need to properly test it.
As we all know, git do not like the way bf2 maps are packed, so numerous commits increasing repo size by a lot pretty fast. That's why mappers at best should test their stuff well before commits.
Instead of pushing semi-working bugged versions to server just to test small things that isn't working it would be better to test stuff locally as much as possible.
Here's a guide how to:

Server files are now included with PR client as of 1.7, you can and advised to host local server.
1. Copy PR install.
2. Run prbf2_w32ded.exe +modPath mods/pr. Same options, configs, maplist as for vbf2 server applies.

If you want to test server-side changes you have made(i always wanted get kashan with infinite chinooks), what you would need to do:
1. Backup stuff on prbf2 client.
2. Develop changes.
3. Track what have you done inside files(like gpo changes, what have changed, etc...), and write\remember them.
4. Test then LOCALLY from ingame menu.
5. If you like the stuff you have done - get stuff to it's original state from backups.
6. Now modify files in server(not server.zip's in client files, but in server files we're installed) archives manually.
7. Launch LOCAL DEDICATED server, and try to connect to it with your prbf2 client.
8. Usually if you have done something wrong it will crash ~15%\End of load\Spawnscreen. In this case you have test things one by one, step by step.
9. If you got everything working - time to commit&push.(this is for prta where we have server update git hook)
10. Test on the INTERNET DEDICATED server.

Note how to save some space on HDD:
After coping 'pr' folder to bf2 server/mods/, just search files with 'client' in their names, and delete.
Last edited by rPoXoTauJIo on 2023-11-24 20:19, edited 1 time in total.
Reason: server files are now included with pr 1.7
Image

assetruler69: I've seen things you smurfs wouldn't believe. Apaches on the Kashan. I watched burned down tank hulls after the launch of the single TOW. All those moments will be lost in time, like tears in rain.

Time to give up and respawn.
UTurista
PR:BF2 Developer
Posts: 985
Joined: 2011-06-14 14:13

Re: [Coding] Server-side modding

Post by UTurista »

To start a local-dedicated server you don't need to install the server stuff or move the folders to "server/...", you can create a shortcut to:
"...\Battlefield 2 Complete Collection\bf2_w32ded.exe" +modPath mods/pr"
with the above parameters "+modPath" and the actual path to the mod "mods/pr".

Once this shortcut is set you just need to double click it and a server-console will pop up, then run your modded game and join a local server normally (Although for something different then COOP you might need to enter the IP manually).
Image


Dont question the wikipedia! Just because it reports different things on different languages does not make it unreliable source!
rPoXoTauJIo
PR:BF2 Developer
Posts: 1979
Joined: 2011-07-20 10:02

Re: [Coding] Server-side modding

Post by rPoXoTauJIo »

The whole point of this is to test server-side changes.
How you would modify server files if they're being client files too in your case? :)
Image

assetruler69: I've seen things you smurfs wouldn't believe. Apaches on the Kashan. I watched burned down tank hulls after the launch of the single TOW. All those moments will be lost in time, like tears in rain.

Time to give up and respawn.
SANGUE-RUIM
Posts: 1390
Joined: 2009-04-26 12:37

Re: [Coding] Server-side modding

Post by SANGUE-RUIM »

thank you for the tutorial and all the effort

keep them coming :)
Amok@ndy
Retired PR Developer
Posts: 5144
Joined: 2008-11-27 22:13

Re: [Coding] Server-side modding

Post by Amok@ndy »

rPoXoTauJIo wrote:The whole point of this is to test server-side changes.
How you would modify server files if they're being client files too in your case? :)
server doesnt read client files. it doesnt matter if they are there as they wont get touched.
Image
rPoXoTauJIo
PR:BF2 Developer
Posts: 1979
Joined: 2011-07-20 10:02

Re: [Coding] Server-side modding

Post by rPoXoTauJIo »

[R-DEV]Amok@ndy wrote:server doesnt read client files. it doesnt matter if they are there as they wont get touched.
That's the point. Files are getting touched.

As a server, you have your server.zip\gamemodes\<mode>\<size>\gpo.con changed from it's original state.
If you would dramatically change it(i.e. add new vehicles, new templates), the clients will CTD. But, if you're just change things i've described in 1st post, clients will load all good, and vehicles spawns will be changed(i.e. removed cobra on muttrah, even through clients not required to download files to match).

Ofc, this is one way to do a server modding, and it's bad infact, as:
  • Maps might get changed with patch - you'll have to re-do your changes again incase patch removed\added\changed spawner templates.
  • Not allowed on public servers.
  • Limited possibilities.
That's why python is superior :)
Image

assetruler69: I've seen things you smurfs wouldn't believe. Apaches on the Kashan. I watched burned down tank hulls after the launch of the single TOW. All those moments will be lost in time, like tears in rain.

Time to give up and respawn.
rPoXoTauJIo
PR:BF2 Developer
Posts: 1979
Joined: 2011-07-20 10:02

Re: [Coding] Server-side modding

Post by rPoXoTauJIo »

Apparently server-side modding with activeSafe possible aswell, inspired by 'SoundDistances.con'(removed in 1.4.12 :p ) and 'LockDistances.con'.

1. Create 'Mats.con' in mapfolder.
2. Paste sample code.

Code: Select all

ObjectTemplate.activeSafe GenericProjectile 1200_buck
ObjectTemplate.damage 1005000
What we're doing here, is selecting 1200_buck projectile from global bf2 mod scope, and then changing it's damage value to 1005000. Same should apply for materials, explosion radius, explosion damage - anything non-visible.
3. Add this line to game section in bfeditor condition check in init.con.

Code: Select all

run Mats.con
Image
4. Pack both .con files into server.zip.
5. Run server, connect with unmodified clients to test changes.

WARNING. Doing such modifications on live public server will get your server license revoked.
Last edited by rPoXoTauJIo on 2017-07-11 15:19, edited 2 times in total.
Image

assetruler69: I've seen things you smurfs wouldn't believe. Apaches on the Kashan. I watched burned down tank hulls after the launch of the single TOW. All those moments will be lost in time, like tears in rain.

Time to give up and respawn.
Post Reply

Return to “PR:BF2 Community Modding”