Jump to content

  • Log In with Google      Sign In   
  • Create Account

Farcry modding


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
46 replies to this topic

#21 Lacutis   Members   -  Reputation: 301

Like
Likes
Like

Posted 06 August 2004 - 08:54 AM

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.


Sponsor:

#22 fagiano   Members   -  Reputation: 307

Like
Likes
Like

Posted 09 August 2004 - 03:21 AM

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 time
function 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 server
RotatingBox.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 sctipt
RotatingBox.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

#23 fagiano   Members   -  Reputation: 307

Like
Likes
Like

Posted 09 August 2004 - 04:49 AM

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

#24 Suli   Members   -  Reputation: 122

Like
Likes
Like

Posted 13 August 2004 - 09:13 AM

Thank you,
Suli

#25 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 13 August 2004 - 09:34 AM

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?

#26 DirectXXX   Members   -  Reputation: 151

Like
Likes
Like

Posted 13 August 2004 - 10:47 AM

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.

#27 fagiano   Members   -  Reputation: 307

Like
Likes
Like

Posted 14 August 2004 - 03:26 AM

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

#28 fagiano   Members   -  Reputation: 307

Like
Likes
Like

Posted 14 August 2004 - 03:54 AM

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.

[/quote]

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

#29 Quak   Members   -  Reputation: 206

Like
Likes
Like

Posted 14 August 2004 - 04:21 AM

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 :)

#30 Anarkist   Members   -  Reputation: 122

Like
Likes
Like

Posted 14 August 2004 - 04:06 PM

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.


#31 JD   Members   -  Reputation: 208

Like
Likes
Like

Posted 15 August 2004 - 06:38 PM

Guys, don't forget the far cry modding manual they put up on their website. Anyways, very informative background info on lua and far cry. I also thought that the GC is going to be a culprit for real time apps. Thanks a bunch for the info fagiano.

#32 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 24 August 2004 - 07:23 PM

Hi fagiano!

Can you answer some new questions on design FarCry entity sytem ?

Some entitys do not have client or server functions , like baseentity.lua ( functions not included into client or server table). In this case, what will be doing on server , and what on client ?

What data are transfered across network from server to clients ?
Physic are server side ? As i seen , entitys do not have functions to send messages across network. Entitys do not have any network functions. How entity knows what data needs to be transfered across network from server to client ?
As i understand all entitys working(handling messages/collisions) on server side ?

Thanks!Thanks!Thanks!Thanks!Thanks!Thanks!

P.S.
Sorry for my bad english.

#33 fagiano   Members   -  Reputation: 307

Like
Likes
Like

Posted 25 August 2004 - 05:34 AM

Hi,

Quote:
Original post by Anonymous Poster
Some entitys do not have client or server functions , like baseentity.lua ( functions not included into client or server table). In this case, what will be doing on server , and what on client ?

That's because those entities are ment to be single player only, btw if no Client and Server are specified, the entity behaves in the same way on client and server(the same stuff is called/spawned).

Quote:

What data are transfered across network from server to clients ?
Physic are server side ? As i seen , entitys do not have functions to send messages across network. Entitys do not have any network functions. How entity knows what data needs to be transfered across network from server to client ?
As i understand all entitys working(handling messages/collisions) on server side ?


physics is simulated on both sides but the server one is authoritative(if they get too different the client get whipped and adjust according to the server).

if the entity is "update enabled", that means self:EnableUpdate(1) is called at initialization; physical snapshot(Position, orientation, velocity etc..) and state are sinchronized automagically. If is not only the state is synchronized. That's all. However 90% of the time you can just rely on state change, for instance if the entity doesn't move(doors/elevators).
players and vehicles have extra synchronized stuff like firing/crouching/running flags etc...

there is a way to send commands from Cli to server and vice versa Client:SendCommand() or something like that..and you catch it in gamerules.lua OnClientCommand() (not sure about the function names but is something very similar). from server to client serverslot:SendCommand() and you catch it on the clientstuff.lua OnServerCommand(). However this funcz are used mostly for changing GUI or mod related satates.

is as simple as that.


ciao
Alberto
-----------------------------The programming language Squirrelhttp://www.squirrel-lang.org

#34 cwright   Members   -  Reputation: 122

Like
Likes
Like

Posted 31 August 2004 - 07:35 AM



Alberto,
I'm interested in making aircraft in Far Cry that can taxi, take off and land - oh, yes, and fly! There have been a number of threads about this but I don't think they're getting very far. Sadly Crytek don't seem to be helping people on the forums, despite their initial promises. So I wonder if you'd mind if I asked a few related questions?

1. To achiev a vehicle that can taxi as well as fly, could you recommend the best approach to achieve this? Did Crytek do any work on this?

2. I would favour modding the 4wd vehicle, as it can already taxi. One idea was to modify its gravity setting. I found that gravityx works as well as gravityz - but I didn't find a way of changing the gravity dynamically (when the game is running).

Can gravity be modified in real time as a function of some other variables such as speed? For example, could Update() be used to do this (I understand it's called on every frame).

3. Can the vehicle script read key presses in real time? This would give a means of controlling the vehicle, for example gear up and down.

4. Can scripts call Windows API functions? This would allow, for example, reading the joystick.

Many thanks.

Best regards,
Chris


#35 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 02 September 2004 - 08:53 PM

Quote:
Original post by cwright
1. To achiev a vehicle that can taxi as well as fly, could you recommend the best approach to achieve this? Did Crytek do any work on this?

For the taxi I guess you'll have to ack a bit with SetPos()(I'll post a better solution if anything comes to mind) while for flying you can take a look a the Glider script, it flies so I guess is the closest thing to what you want to archieve.

Quote:

2. I would favour modding the 4wd vehicle, as it can already taxi. One idea was to modify its gravity setting. I found that gravityx works as well as gravityz - but I didn't find a way of changing the gravity dynamically (when the game is running).

I do not think you can change such thing in a physics based entity it without respawning it.

Quote:

Can gravity be modified in real time as a function of some other variables such as speed? For example, could Update() be used to do this (I understand it's called on every frame).

You can do it on players, ladder.lua works this way.(disable the gravity so the player can move up and down).

Quote:

3. Can the vehicle script read key presses in real time? This would give a means of controlling the vehicle, for example gear up and down.

Yes I think there is Input:GetXKeyPressedName(), but
I suggest to remap the current key events, take a look at the player config file(.cfg) it shows how to create an action map. YOu can switch action maps dinamically from script.

Quote:

4. Can scripts call Windows API functions? This would allow, for example, reading the joystick.

nop. But the engine had joystic support, if they didn't explicitly removed it you can probably map it to standard commands.(the question is I have no clue what's the name of the bindings fo the joystic).

ciao
Alberto

#36 cwright   Members   -  Reputation: 122

Like
Likes
Like

Posted 02 September 2004 - 10:33 PM

Many thanks for the info.

I suspect it would be easier to mod the jeep - it would probably be easier to make it fly than to make the glider taxi!

ladders.lua sounds interesting - I'll take a look straight away.

It will be ironic if Far Cry does support joysticks - I'm just about to release a utility that gives proportional joystick support!

Best regards,
Chris

#37 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 03 September 2004 - 03:42 PM

Lots of great info in this thread, thanks Alberto:) Could you spare a couple more minutes to go over the use of OnTimer() for multiple timers in a script? I need some 'pauses' in my entity script similar to the Delay Trigger, but 2 or 3 in sequence.

#38 fagiano   Members   -  Reputation: 307

Like
Likes
Like

Posted 04 September 2004 - 04:04 AM

Quote:
Original post by Anonymous Poster
Lots of great info in this thread, thanks Alberto:) Could you spare a couple more minutes to go over the use of OnTimer() for multiple timers in a script? I need some 'pauses' in my entity script similar to the Delay Trigger, but 2 or 3 in sequence.


This is how things work, OnTimer only supports one timer at the time. However there is: Game:SetTimer()

this function generates an OnEvent(id,param) with ScriptEvent_Timer , you can set a 'infinite' number of this timers on the same entity.

Game:SetTimer(entity,msecs,table)

entity
is the entity that will receive the event
msecs
duration of the timer
table
a table that will be passed back as parameter of the event(can be obmitted)

the function returns a timerid that you can use to kill the timer before it expires. Game:KillTimer(timerid);

ciao
Alberto
-----------------------------The programming language Squirrelhttp://www.squirrel-lang.org

#39 TX_101   Members   -  Reputation: 112

Like
Likes
Like

Posted 04 September 2004 - 11:58 PM

<official mode on>

I'm currently working on a farcry mod ... I put a post about it in the Help Wanted forum here -
http://www.gamedev.net/community/forums/topic.asp?topic_id=268330

FarCry Isn't a game that I've modded before, there's quite a lot of talent on the team at the moment though. If anyone wants to join feel free to e-mail me at tx101.sk33j@gmail.com

<official mode off>


Actually I am surprised that you seem to think that there isn't many mods for FarCry, there are not many mods for FarCry that have been completed but many are in development, which isn't bad when you consider that the game is actually quite new.

#40 tstrait72   Members   -  Reputation: 122

Like
Likes
Like

Posted 05 September 2004 - 10:25 AM

Thanks fagiano for the help with the timer stuff:)

I decided to register this time, hehe...




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS