Advertisement

Farcry modding

Started by June 08, 2004 03:02 AM
45 comments, last by fagiano 19 years, 12 months ago
I don't have a copy of Farcry to try this, but if it's using Lua and there is a way to print to the console just do something like:

for k,v in pairs(_G)
print(k .. " : " .. v)
end

And watch as everything in the global namespace magically scrolls over your console.
Quote: Original post by DirectXXX
fagiano if you have time, can you explain the over all architecture of scripting interface to game engine. Also the event system please.



Far cry scripting architecture is relatively simple, is based on lua 4.1 alpha (hybrid version between 4 and 5)
everything is handled with a single lua_State.
I modified the VM in order to overcome several performance/memory problem created by the GC and
lua reference system.

the scripting handles most of the game code entities behaviour, game behaviour(aka gamerules),
materials (sound, decals and particles), AI, Weapons, hud & GUI.

the most interesting scripts are probably entity and gamerules scripts.

ENTITIES
Each entity class(type) has specific lua table that is used as prototype, the table gets cloned for each instance of the entity;
it defines the behaviour of the entity, plus informations for the editor to be able to enumerate parameters.
Each entity script is splitted into server and client table and can have one or more states.
States are synchronized through server and client. Each state can optionally implement as set of event handlers :

OnBeginState () when the entity enters in a certain state
OnContact(collider) collision with another entity
OnDamage() when it get shoot
OnTimer() a timer expires
OnUpdate() called every frame, if present
OnEndState() exit from a state
etc..(i forgot ;)

the entity 'self' is also filled with a certain amount of C++ functions to manipulate position,state,
orientation, load models, physicalize the geometry etc...

an entity looks like this(semi-pseudo code)

RotatingBox = {	--all the fields contained in the subtable Properties spawn in the	--editor properties window and can be configured	Properties = {		fileModel = "models/default_box.cgf" 	}	--	angle = {x =0, y =0 , z =0}}--called at spawn timefunction RotatingBox:OnInit()	--load the model	self:LoadModel(self.Properties.fileModel);	--registers the states	self:RegisterState("Stopped")	self:RegisterState("Rotating")end--server side script(runs only on the serverRotatingBox.Server = {	--stopped state	Stopped = {		--if a player comes in contact with the entity		--the entity goes in Rotating state		--beacause the state is sychronized through the net		--the entity works also online with no additional code		OnContact = function (collider)			--when a			if(collider.type == "Player") then				self:SetTimer(1000);				self:GotoState("Rotating");			end		end	}	--rotating state	Rotating = {		--until the player is on contact the box will reset the timer		--otherwise the timer expires and the box goes back in Stopped state		OnContact = function (collider)			self:SetTimer(1000);		end,		--stops the rotation		OnTimer = function()			self:GotoState("Stopped")		end	}}-- client side sctiptRotatingBox.Server = {	--stopped state	Stopped = {		//does nothing	}	--rotating state	Rotating = {		--each frame		OnUpdate = function(delta)			local angles = self:GetAngles() --rotates on the Z axis			angles.z = angles.z + delta;			self:SetAngles(angles);		end	}}


with this system far cry handles 90% of the entity logic.

a very important aspect of the system, is the fact of beeing able of call functions
from one entity to another. the editor wires them together filling some table at spawn time.
This allows stuff like changing state of an entity when a trigger entity is activated.
For instance a trigger could call rotatingboxinstance:GotoState("Rotating") when the player hits the trigger.
To do so we got functions like System:GetEntityByName() or System:GetEntity(id).

GAMERULES
Another important script is the 'game rules' script.
The game rules handle all games global events

OnClientConnect -- spawns the player entity, something like Server:SpawnEntity("Player")
OnClientDisconnect --guess
OnDamage --here we check if some damage has to be applied before we call the entity OnDamage()
etc...


HUD
well, we call Hud:Update() in the script System:DrawRectangle(),System:LoadTexture() ...etc

MATERIALS
is just a bounce of tables declaring particles,decals, sounds for a specific material.

AI
I'm never really got into AI scripts but are not very far from entity scripts, bounch of event handlers and
states(aka behaviours), stuff like OnEnemySeen() etc...

C++ BINDINGS
all the C++ binding are hand-coded through a C++ template, that has been a choice. I do not believe automatic
bindings , mapping the C++ 1:1 on scripts is against the pourpose of scripting.
the script interface must be higher level, is boring, but pays back.

Conclusion

Pros
-the system is very nice to work with and we got special C++ code just for actors(players and AI) and vehicles.
-writing entities is fun
-speed wise is more than enough(except for the GC problems)
-easy to integrate with tools
-modding the game takes 1/100000 than with C++(I wrote CTF in about day)

Cons
-lua worked well in prototyping stage, then when we got 6Mb+ of data in it the GC was killing the framerate
once a second, I had to put my hands in the VM and we had to set a bounch of scripting policies.
I can't immagine how could run on a console.
-the lua4-style reference system is very fragile, do not use it, after 30min of editing was dying.It uses
an integer to keep the reference number, if you got thousand of objects is going to overflow soon and bang!
I had to write a custom one... pretty much what squirrel uses.
-lua doesn't work with unicode, we had to use some XML files for localization
-we didn't have a debugger from the beginning...if you plan massive scripting a debugger is a must from day one.

I hope this is what you were asking for

ciao
Alberto


-----------------------------The programming language Squirrelhttp://www.squirrel-lang.org
Advertisement
Quote: Original post by Suli
Hello I was wondering which Lua libraries where included?


just the standard lua libs: string, base and math.

ciao
Alberto
-----------------------------The programming language Squirrelhttp://www.squirrel-lang.org
Thank you,
Suli
Hi, I'm currently working on a mod for farcry with a friend of mine. We are both new to modding but we have a little help and decided to give it a shot. Anyways, I'm running into confusion when it comes to weapon animations. I dont have the first clue how to use the sandbox editor and I'm assuming I have to animate my weapons in there. Is this true? And if so can anyone point me in the right direction. Otherwise, is there any way to animate the weapons in 3DS max instead? Also, any related info about character animation/bone systems would be appreciated. Anyone?
Thanx for your time fagiano, it helped me lot. Im starting to understand things now. I hope i'll learn more by modding farcry.

Just some small questions.

You may used lua4 not 5 because farcry developent started very early? Do you think that latest version of lua would make better system for farcry.

Offtopic; Im not experienced enough to ask this but as a maker of Squirrel what you have done to make it better than lua (for advance use in game, as in farcry). The feature list on the site doest add contrast with other scripting languages. Anyway im interested to try it because of your work.
3D Side-Scroller game demo Project-X2 "playable"Lashkar: A 3D Game & Simulation Project demo @ lashkar.berlios.de
Advertisement
Quote: Original post by Anonymous Poster
Hi, I'm currently working on a mod for farcry with a friend of mine. We are both new to modding but we have a little help and decided to give it a shot. Anyways, I'm running into confusion when it comes to weapon animations. I dont have the first clue how to use the sandbox editor and I'm assuming I have to animate my weapons in there. Is this true? And if so can anyone point me in the right direction. Otherwise, is there any way to animate the weapons in 3DS max instead? Also, any related info about character animation/bone systems would be appreciated. Anyone?


You need 3DMax and the Far Cry SDK (the exporter). You have to animate the weapons in max.
I'm not very sure about the details, I never exported animations by myself the artists did.
-----------------------------The programming language Squirrelhttp://www.squirrel-lang.org
Quote:
You may used lua4 not 5 because farcry developent started very early? Do you think that latest version of lua would make better system for farcry.


Yes is because the system was built during 2001/2002. No, lua 5 doesn't solve any of the problem we had with lua.

Quote:
Offtopic; Im not experienced enough to ask this but as a maker of Squirrel what you have done to make it better than lua (for advance use in game, as in farcry). The feature list on the site doest add contrast with other scripting languages. Anyway im interested to try it because of your work.



I started developing squirrel because of the problems I was having with lua, in fact initially I was not planning to release it at all, a collegue at crytek convinced me to open it.
Saying that squirrel is better than lua would be definitively wrong, lua is a wonderful language and I really like how its authors work. However I could say that squirrel is better for my pourposes.
For instance:

-First of all, squirrel is reference counted, so no GC problems at all. Also, the RC behaviour fits much better with C++ classes lifetime(to solve cycles, if any, squirrel has a GC as well that I can call explicitly).
-Squirrel has a very efficient C-side referencing, is also uses much less memory compared to was lua4.1 was offering(in lua 5 you have to code your own system basically).
-global variables. lua spawns table fields and global variable just by assigning a value. That's created a lot of problem because when a veriable is mistyped no error is thrown and you end up debugging for hours. Squirrel has on my advice a better policy.
-scoping squirrel has a very nice scoping system, by default you always reference the local scope and not the global. So no self in front of everything but :: in front of globals.
-squirrel has both float and integers, with only floats I freaked out because I couldn't really store flags, plus you got bitwise operators.
-squirrel can use unicode strings so no localization problems.
-Syntax. lua has is own pascalish but not really pascalish syntax, so creates a lot of confusion .I had constantly people asking me how to caode a for loop or accidentaly using != instead of ~= etc...
and most of the designer knew JScript so they were kinda familiar with C-like syntax.(I guess for the same reason Java and C# adopted C-like syntax).
-Squirrel has arrays. Is cool that lua only have 1 datatype but I prefer my language to be practical.
+ a bounch of other small fetures no I can't think of(generators etc...)

personally I'm using squirrel in my current project and is behaving wonderfully, but of course I've designed it to fit my vision of game scripting that is not necessarly the best.

ciao
Alberto
-----------------------------The programming language Squirrelhttp://www.squirrel-lang.org
Quote: Original post by Anonymous Poster
Hi, I'm currently working on a mod for farcry with a friend of mine. We are both new to modding but we have a little help and decided to give it a shot. Anyways, I'm running into confusion when it comes to weapon animations. I dont have the first clue how to use the sandbox editor and I'm assuming I have to animate my weapons in there. Is this true? And if so can anyone point me in the right direction. Otherwise, is there any way to animate the weapons in 3DS max instead? Also, any related info about character animation/bone systems would be appreciated. Anyone?


I don´t think you can animate weapons in the Sanbox ED. You will need an animation program like MAX for that. Also you will have to wait for an exporter which comes along with the SDK(correct me if i ´m mistaken). Check out www.3dtotal.com for informations about bone sytems.

Edit: Sorry I overlooked the second page so fagiano was first :)
Hey fagiano,
I really appreciate that you've posted in this thread and answering our questions, especially that regarding the structure of the interface between the engine and the scripting language. I hope you don't mind, but I took the liberty of reposting your answer in the various Farcry modding forums so this thread will probably get more traffic soon. The coders in the forum found the answer very helpful and informative.

I am working with Aarbro and he has struck one obstacle in coding for the mod and that is our wish to implement a text system in the maps which we would use to develop a branching conversation tree that would allow interactive conversations with NPCs and could possibly give the player the choice between several different mission objectives that would show up on the mission hud depending on which conversation branch he selected. We would appreciate any assistance in overcoming this problem. Earlier in the thread he had an enquiry regarding the development of a powered hanglider and possibly an aircraft for use in Farcry. Heres his original post for easy reference.

No problem. I've been rather late in replies myself here.

Actually what I'm looking for is a way to create a powered hangglider, like an ordinary aircraft. There was a q about this by NOVA_Maimer at the UBI forum but no solution was found. The idea is to use this combination:

Mouse --roll and pitch
Forward/w --power up
Backward/s --power down
Left/right/a/d --yaw left and right

For instance take the w/s keys, in the hangglider those keys are used for pitch there. I want to make them control the power instead, like engine rpm. But it's not really important what keys are used. Just how to make a variable change when a key is held down. When the key is held down the rpm should increase constantly.

In another project I've been polling GetXKeyPressedName for a trigger entity with success. It's a variant of the ProximityTrigger that can trap any key, not just the USE key. The idea is to make it possible for the player to enter a numerical code on the num keys for instance. It's using polling but only when the player is inside a small area so I don't think it'll be too costly. Still it's crude, if there is a way to get a system event for keys, the better. However, this method is not usable for the aircraft as only a single key pressed is recognized. When held down GetXKeyPressedName replies with nil.

Thanks again for taking the time to helping out and good luck at your new location.


This is what Aarbro has managed to accomplish so far.

ElectricDamage: it's an electric fence. In his map it's made with the builtin events. But this gave me the idea of making it into the first appliance. That's what I'm doing now. It reacts when touching the mesh and giving a spark sound, a flash particle and damage the player. All depending on the voltage and other parameters. This appliance can be used with any mesh. So loose unisolated wires can be simulated for instance, or anything were the player conduct electricity. You just connect any shape of an area to it and it'll electrify the player when entered. The visual and audio effects looks very realistic with random sparks occuring.

BlurEffect: He found a way to blur the vision for the player. It's the same as used by the smoke grenade when going into the cloud. He now have almost full control of that. Together with a slowed speed, and bad aim, It is a way to simulate the effects of the character being drugged.

Randomize: This gives a false or true when called depending on a specified percentage. I guess it's useful needing a random decisions on a map. It also contains a timer that fires randomly between certain time limits. Say anywhere between 10 and 30 seconds for instance. It could be repeating too for effects such as particles or similar.

ViewTrigger: This fires when looking at a certain entity or group of entities. It can for instance be used to further the plot when the player lay eyes on an object. I imagine more uses can be found.

This topic is closed to new replies.

Advertisement