Forts
The Forts Foundry
Player made maps and mods for the physics-based RTS Forts!
Learn More
Thonio 81 30 Jun, 2020 @ 2:30pm
A few questions on forts scripting API
I'm currently working on a mod and i'm trying to do some dynamic scripting to implement a new effect for a weapon.

I would like to find all the nodes in a radius around the impact point of the projectile. I could not find a function for this purpose in the forts scripting API. Is this function or a similar one not in the game ? I doubt it considering applying splash damadge to structures around an impact point is a very similar problem.

I also want to manipulate the state of a material (current and max hit point, absorption, reflection). Is this possible to do it ?

The idea is to create a weapon changing the property of materials in a radius around the impact point.

I also tried to use the SpawCircles function but i could not get it to work. Here is an example of the code i used :

function Load(gameStart)
SpawnCircle( {0,0,0} , 1000, {0,0,10,255}, 15)
end

Logs shows the code is executed but i don't see any circle, is there a synthax error ?
< >
Showing 1-8 of 8 comments
[DEV] BeeMan  [developer] 39 30 Jun, 2020 @ 7:31pm 
To find nodes within a radius you can iterate all nodes and check their distance to the point in question. This would require the use of the NodeCount, GetNodeId and NodePosition functions.

Alternatively you could use EnumerateLinks, providing a callback to receive the node ids of each strut, then check their distance. It sounds like this would be more suitable given you want to affect struts rather than joints.

It's not possible to change the properties of each individual strut, since it is associated with a material type. You could perhaps include new materials in your mod, and then use the CreateLink function to change the material of the affected struts.

To use SpawnCircle you must pass it correct parameter types:
SpawnCircle(Vec3(0,0,0), 1000, Colour(0,0,10,255), 15)

I'd recommend joining our Discord server to get help from other modders:
https://discord.gg/TP4CpnF
Thonio 81 1 Jul, 2020 @ 5:43am 
Thank you, that helps me a lot.
Thonio 81 1 Jul, 2020 @ 2:28pm 
I tried to use the EnumerateLinks function and that did not work out as expected. Here is the code i used :

EnumerateLinks(2, "displayLinks", 100, 100, "", true)

function displayLinks(nodeA, nodeB, saveName, relativeHealth, stress, segmentsOnFire, deviceId)
Log(tostring(nodeA))
Log(tostring(nodeB))
Log(tostring(saveName))
end

I tied the execution to the impact of a sniper's bullet and it literally erased team 2 base. I think this is a bug.

I used another trigger and it solved the explosion problem but it only ever gives me the same two nodes with one callback and i don't really understant why. These two nodes are alway the same regardless of other parameters.
[DEV] BeeMan  [developer] 39 1 Jul, 2020 @ 5:47pm 
You have to return true or false from your callback. A return value of true means continue the search. This is why you are only getting one result. Also the health values are in the range [0-1]. I'll add this detail to the documentation.
Thonio 81 2 Jul, 2020 @ 2:27pm 
Thanks, i managed to get the effect to work. it's properly converting the material to their weakened version in a radius on impact.
Thonio 81 4 Jul, 2020 @ 2:14pm 
I still have two small problems i don't know how to fix :

-I hide the materials with ShowOnHud = False but if I hoover the mouse on the right of the material list the description for one of them is still showing despite them not being present. Is there a way to hide it ? If i remove the descriptions a blank bubble is displayed instead.

- I use sparks to create an effect on impact, is there a way to place the sparks in front of structures ?

Besides i found out EnumerateLinks is unable to scan team 3 (team id -2). It's not a big problem considering there is only one good map using it but it's weird this function does not work properly for all teams.
[DEV] BeeMan  [developer] 39 4 Jul, 2020 @ 7:59pm 
Try setting Enabled = false, instead of using ShowOnHUD.

You can adjust the y component of the spark LocalPosition value to move the spawn point of the particles.

The background team (team 3) is intended to be for static structures, impervious to damage and change, for the purpose of special mission elements.
Thonio 81 5 Jul, 2020 @ 2:26pm 
Thanks, now the particles are in front of structures and it looks much better.

I tried setting Enabled = False. It properly hides the material on the HUD but it breaks the effect. The reason is CreateDevice and CreateLink don't spawn material or device if they are not enabled. It's weird because i looked at shockernaught's codes and it uses the exact same function to spawn the barrel. The barrel is not enabled but it works fine. Is there a way to solve the problem ?

If not i'm just going to let the materials visible on the HUD, give them an abnormal building cost to make players undestand they are not supposed to use them and use their description to give usefull informations on them.
< >
Showing 1-8 of 8 comments
Per page: 1530 50