How to recreate a res file like in Carnivores 2 for Godot?

Godot Version

Godot 4.5.1-stable

Question

I desire to make a open source game based in the Carnivores series, but i have a insertenty about this. The code bellow is a modified version of the Carnivores 2 _res.txt file, i want to know how i can port this to gdscript. Note that already have made some export variables to my res.gd file.

weapons {
{
name = ‘Tranq Rifle’
file = ‘tranq.car’
pic = ‘.tga’
shots = 6
power = 2.5
fall = 1
loud = 2
rate = 2
reload= 1
}

{
name = ‘M975 Pistol’
file = ‘pistol.car’
pic = ‘bullet1.tga’
power = 2
prec = 0.8
loud = 0.8
rate = 1.6
shots = 8
}

{
name = ‘KS-23 Shotgun’
file = ‘shotgun.car’
pic = ‘bullet2.tga’
power = 1
prec = 0.3
loud = 1.5
rate = 1.0
trace = 6
shots = 7
}

{
name = ‘DB Shotgun’
file = ‘dbsgun.car’
pic = ‘bullet2.tga’
fall = 1
power = 1
prec = 0.2
loud = 1.9
rate = 1.2
trace = 6
shots = 6
reload= 2
}

{
name = ‘CrossBow’
file = ‘cbow.car’
pic = ‘bullet4.tga’
shots = 6
power = 6
prec = 1.0
loud = 0.4
rate = 1.0
}

{
name = ‘SemiAuto Rifle’
file = ‘rifle.car’
pic = ‘bullet3.tga’
power = 4
prec = 1.8
loud = 1.5
rate = 1.6
shots = 15
}

} //==== end of weapons =========//

characters {

{
name = ‘Hunter’
file = ‘hunter1.car’
ai = 0
health = 1
}

{
name = ‘Moschops’
file = ‘mosh.car’
ai = 1
wlkspeed = 0.3
runspeed = 0.6
health = 2
mass = 0.15
}

{
name = ‘Halszkaraptor’
file = ‘.car’
wlkspeed = 0.32
runspeed = 0.9
ai = 2
health = 2
mass = 0.1
}

{
name = ‘Dimorphodon’
file = ‘dimor2.car’
wlkspeed = 1.3
runspeed = 1.5
ai = 3
health = 1
mass = 0.05
}

{
name = ‘Pteranodon’
file = ‘ptera.car’
wlkspeed = 1.3
runspeed = 1.5
ai = 4
health = 1
mass = 0.25
}

{
name = ‘Dimetrodon’
file = ‘dimet.car’
wlkspeed = 0.3f
runspeed = 0.6f
ai = 5
health = 3
mass = 0.22
}

{
name = ‘Mamenchisaurus’
file = ‘.car’
ai = 6
mass = 9
length = 12
wlkspeed = 0.2
radius = 400
health = 1024
basescore = 0
smell = 0.4
hear = 0.8
look = 0.6
shipdelta = 168
}

{
name = ‘Oryctodromeus’
file = ‘.car’
ai = 10
wlkspeed = 0.4
runspeed = 1.6
mass = 1.5
length = 3.9
radius = 320
health = 20
basescore = 5
smell = 0.8
hear = 1.0
look = 0.4
shipdelta = 48
}

{
name = ‘Falcaris’
file = ‘.car’
ai = 11
scale0 = 1200
scaleA = 600
wlkspeed = 0.28
runspeed = 0.75
mass = 0.8
length = 2.9
radius = 280
health = 25
basescore = 6
smell = 0.4
hear = 0.8
look = 0.6
shipdelta = 16
}

{
name = ‘Beipianosaurus’
file = ‘.car’
ai = 12
mass = 7
wlkspeed = 0.36
runspeed = 0.96
length = 5.8
radius = 480
health = 25
basescore = 7
smell = 0.4
hear = 0.8
look = 0.6
shipdelta = 128
}

{
name = ‘Pachyrhinosaurus’
file = ‘.car’
ai = 14
mass = 2.6
scale0 = 1200
scaleA = 100
runspeed = 1.2
wlkspeed = 0.30
length = 4.6
radius = 400
kradius = 300
aggress = 16
health = 25
basescore = 9
smell = 0.6
hear = 0.5
look = 0.4
shipdelta = 108
}

{
name = ‘Qianzhousaurus’
file = ‘.car’
ai = 13
mass = 0.5
length = 4.2
wlkspeed = 0.428
runspeed = 1.2
jumpspeed = 1.1
swimspeed = 0.4
radius = 256
kradius = 256
aggress = 130
health = 15
basescore = 10
scale0 = 1000
scaleA = 600
smell = 1.0
hear = 0.3
look = 0.5
shipdelta = 0
danger = TRUE
}

{
name = ‘Velociraptor’
file = ‘.car’
ai = 15
mass = 0.51
length = 4.0
wlkspeed = 0.428
runspeed = 1.5
jumpspeed = 1.3
swimspeed = 0.4
radius = 256
health = 15
kradius = 256
aggress = 160
basescore = 12
scaleA = 400
smell = 1.3
hearK = 0.7
lookK = 0.5
shipdelta = -32
danger = TRUE
}

{
name = ‘Becklespinax’
file = ‘.car’
ai = 16
mass = 1.6
length = 5.9
wlkspeed = 0.70
runspeed = 1.6
swimspeed = 0.5
jumpspeed = 1.4
radius = 256
kradius = 300
health = 20
aggress = 180
basescore = 25
scaleA = 400
smell = 1.1
hearK = 0.6
lookK = 0.6
shipdelta = 60
danger = TRUE
}

{
name = ‘Ceratosaurus’
file = ‘.car’
ai = 17
mass = 4.2
length = 7.8
radius = 256
health = 30
wlkspeed = 0.75
runspeed = 2.2
kradius = 350
basescore = 18
aggress = 210
scaleA = 400
smell = 1.2
hearK = 0.7
lookK = 0.6
shipdelta = 96
danger = TRUE
}

{
name = ‘Maip’
file = ‘.car’
ai = 17
mass = 4.2
length = 7.8
radius = 256
health = 30
wlkspeed = 0.75
runspeed = 2.2
kradius = 350
basescore = 18
aggress = 210
scaleA = 400
smell = 1.2
hearK = 0.7
lookK = 0.6
shipdelta = 96
danger = TRUE
}

{
name = ‘Tyrannosaurus’
file = ‘.car’
ai = 18
mass = 6
length = 10.5
radius = 400
wlkspeed = 0.76
runspeed = 2.49
swimspeed = 0.70
kradius = 380
health = 1024
basescore = 25
smell = 0.85
hear = 0.8
look = 0.8
shipdelta = 168
danger = TRUE
}

} //===== end of characters ==========//

prices {
start = 100
area = 20
area = 35
area = 50
area = 100
area = 200
area = 300
area = 500

dino = 10
dino = 15
dino = 20
dino = 30
dino = 50
dino = 100
dino = 250
dino = 300
dino = 500
dino = 1000

weapon = 20
weapon = 150
weapon = 200
weapon = 250
weapon = 300

acces = 0
acces = 5
acces = 10
acces = 15
}

You could use a resource for this.

1 Like

That looks like a JSON file. Try importing and parsing it as JSON.

1 Like

Nope. Its just a .txt file, used as a base in the source code for data. But still what about the data it self? It is possible to do something like this in gdscript? I have already turned this in floats for the numbers stuff, booleans for the true/false parts and the name and file into strings. Heres how i did it, honestly i know it would be better if i just shared a link to googlle drive but it displays a log in no matter what i do.

extends Resource
class_name _Resource

#---------------------- Exports ----------------------#

Strings

@export var name: String = “”
@export var weaponfile: String = “res://HUNTDAT/MODELS/WEAPONS/.fbx”
@export var hunterfile: String = “res://HUNTDAT/MODELS/FAUNA/.fbx”
@export var dinofile1: String = “res://HUNTDAT/MODELS/FAUNA/HUNTABLES/.fbx”
@export var dinofile2: String = “res://HUNTDAT/MODELS/FAUNA/AMBIENTALS/.fbx”

floaters

@export var shots: float
@export var loud: float
@export var rate: float
@export var reload: float

@export var mass: float
@export var hear: float
@export var look: float
@export var smell: float

@export var scale0: float
@export var scaleA: float

@export var health: float
@export var damage: float
@export var lenght: float

@export var radius: float
@export var kradius: float

@export var aggress: float

@export var scoremin: int = 10
@export var basescore: float = 25
@export var scoremax: int = 250

@export var walkspeed: float
@export var swimspeed: float
@export var runspeed: float
#@export var shipdelta: float

booleans

@export var dagger: bool = false # Makes the damage work as a long term debuf.
@export var damvar: bool = false # Weapon score perk(+25%).
@export var armor: bool = false
@export var dangercall: bool = false
#---------------------- End of Exports ---------------#
#---------------------- Calculs ----------------------#

var score = basescore * scoremin / scoremax

Res.txt stuff

#----------- Weapons -----------#
#----------- Fauna --------------#
#----------- Prices ------------# < Prices so i dont forget when i gonna start making the score system.

That exacly what i am trying to do. i did a _res.gd but it doesnt stays as local to scene

Let me clarify. It is formatted as a JSON file. Therefore, it is a JSON file. So you can load it as such.

You can post formatted code like so:

#Your code goes here.

And it wills how up like this:

#Your code goes here.

You must copy and paste from the Godot editor fresh, the code you already posted will not work because it has lost its indentation.

It can be loaded into a Dictionary. So if you loaded it into a variable named data you could do:

var tranq_rilfe = data.weapons["Tranq Rilfe"]
print(tranq_rilfe.shots)

And it would print “6”.

2 Likes

You must copy and paste from the Godot editor fresh, the code you already posted will not work because it has lost its indentation.

Thats because it was copid from the file it self. But why the print it is just a placeholder function, because i dont want to print anything? But still thanks for the advise, ill post again if i need anything else.

Well, i have copied the code into a fresh json file, i got this: “Expected ‘true’, ‘false’, or ‘null’, got ‘weapons’”

That note was for formatting your code here.

Gonna need more info that that.

To be a properly formatted JSON file it would need to start with [ to begin an array and end with ], commas are also missing from every field, and // comments are not valid JSON.

It is close to a JSON file, and a savvy text editor could fix it quickly, but it’s not valid JSON and not a simple fix.


Making your own resource is a good idea, you only need to punch in the data or write a custom importer

1 Like

Arrays can be openned with {}? That would explain why i got the error, since Carnivores 2 is coded in C++.

In JSON an array of values begins with [ and ends with ]. C++ is not relevant to JSON. JSON Dictionaries begin with { and end in } which is maybe where the JSON style is being assumed.

I didnt know i needed to format it properly to json, as i just copied it staight from the file.

That explain why the _res.txt file exists in the first place, after the Carnivores series, Action Forms stopped to make the script built-in the executable. Also the reason for the lack of indentation is because there are none of them, just space.

I’m not familiar with the series but I know older custom engines will often use custom formats for their own resources. You could convert the data or write your own inspired parser, Godot’s import plugin format can help with the latter.

I don’t think you can directly convert this data to JSON since it has repeated keys at the end here:

This isn’t something JSON can represent without a large restructure. May be best to write a importer/Resource in Godot, but again I’m not familiar with the game I don’t know what this data is for.

1 Like

My bad.

This isn’t something JSON can represent without a large restructure. May be best to write a importer/Resource in Godot, but again I’m not familiar with the game I don’t know what this data is for.

These prices are used for the ranking system which got dropped after the first game, so Carnivores 2 and C: Ice Age, uses only the score stuff, as you can see a fresh new save, starts by default, at 100 points. The area is how much each map costs to unlocked/To be played on. This is probably a custom format exept for the tga used for the menu and the txt/u/m, as Action Forms created the .car(character) file format which is a format used for the player, weapons and dinosaurs that somehow dont have bones/rig despite being capable to be animated, alongside the 3df, .rsc and .map files.

I’m not familiar with the series but I know older custom engines will often use custom formats for their own resources. You could convert the data or write your own inspired parser, Godot’s import plugin format can help with the latter.

I don’t think you can directly convert this data to JSON since it has repeated keys at the end here:

Yes, Action Forms had their own engine, AtmosFear it wa called, Action Forms used it in most of their games, also i acidentaly removed the } that closes the pricing array.

1 Like