Five Elite Mercenaries are send to an Island in middle of the 1980'. The Task: Find and Eliminate a local Drug Baron. Features: new Physic, real Sunmovement, Day/Night Change, Hunger/Food system, realistic (!) Weather system, Light/Dark viewing system for AI, 5 different Fractions on the Island. Complete Realistic simulation of nearly all things, including Sleep. New weapons, new Vehicles. Vehicles driving system is now exact (!) like GTA IV , FireSystem,... this mod is Heavily inspired by GTA, IGI, FarCry.

Forum Thread
  Posts  
scripting help needed (Games : Far Cry : Mods : FarCry Operation Clearing : Forum : Technical Discussion for OP CL Devkit : scripting help needed) Locked
Thread Options
pvcf
pvcf Germany
Apr 9 2016 Anchor

in game there is a little "bug": if you drop a weapon, the pickup cgf will loaded on the fly: if this is the first time for the weapon, and the mesh is very complex, it can need up to 1 second which results in a one second engine freeze during gameplay. the same happens if you pick up a weaponpickup: activating a new weapon where

the mesh is loaded the first time in engine, can result in a engine stuttering at this point.

actually i preload on levelstart some critical models "by hand" (some preselected cgf's in a script).

but the nice way would be, to step on mapstart trough all pickups and all equipement packages: for each pickup preload the weapon first person model and for each weapon in all equipement packs preload the pickup model, which will be spawned if this wpn is dropped by player or AI.

first i started with pickups and try to get the weapon object phad, but i fail, this is, what i have:

------------------------------------

function ClearingWorldDirector:PrecatchWpnModels()
  
  if not completeEntityTable then
   completeEntityTable=System:GetEntities();
  end 
  for idx,ent in completeEntityTable do
   if ent and ent.weapon then       
    --for example PickupM4.lua 
      --ent.weapon is then "M4" , (a string)
      
      --now i need from M4.lua (which is automaticly loaded on engine start
      --M4.object as cgf-phad
      
      --theoretically its now ent.weapon.object , practically ofcourse not, because its
      --then like "M4-string".object , which the engine does not understand.
      
       --PreloadCGF(phad) --will then load the model, routine done
   end 
  end 
end
------------------------------------


this is the PickupM4.lua
------------------------------------
local params={
 weapon="M4",
 ammotype="Assault",
 model="Objects/Weapons/M4/M4_bind.cgf",
 default_amount=0,
 sound="Sounds/Weapons/M4/m4weapact.wav", 
}
PickupM4=CreateWeaponPickup(params);
PickupM4.Properties.sndDrop="Sounds/objectimpact/wpndrop3.wav";

------------------------------------


and this is the M4.lua weaponscript with the object phad i need:

------------------------------------

M4 = {
 name  = "M4",
 object = "Objects/Weapons/M4/M4_bind.cgf",
 character = "Objects/Weapons/M4/M4.cgf",

------------------------------------

is there any way to combine the "M4" string from pickup with the M4.object to get the phad ?

Edited by: pvcf

Apr 9 2016 Anchor

PreloadModel can be LoadObject for sake of simplicity. Freeze can't be eliminated within script this can be done only in CryGame C++, this of all you need learn what are Thread & how to use it, don't there are many tutorials & sample code there around a net.


There solution:
*Write c++ method that are accessible from scripts, see any CScriptObjectXXX classes.
*Create 'RequestModel' Method that takes object path, in C++ that string will be copied and stored, I suggest use linked list or std::deque, and it will return nothing.
*Somewhere in CryGame you need write function that is called by background Thread.
*That function will iterate thru storage that calls LoadObject, when it done storage will be emptied.

pvcf
pvcf Germany
Apr 10 2016 Anchor

many thanx for your input, Arn ! unfortunately my c++ coding knowledge is still to bad to do such things, so i have to fight with lua because i know it :)

the idea for precatching a cgf is for levelstart, not eleminating the enginefreeze in realtime, i have the enginefreeze on levelstart in a row, instead by collected and activating a weapons each.

it was a long way, my first idea, after realizing i dont can create the correct table name, was, to parse trough WeaponParams.lua, compare there the weapon name string with wpn name from pickup and get there the from fireparams merged table entries, like object and char cgf.

but after i have coded that, i found out that the merge procedure is done by a c++ routine for playerentities by activating this weapon (choosing as active weapon). so, this is now the cleanest way i found:

function PrecatchWpnModels()
	
		if not completeEntityTable then
			completeEntityTable=System:GetEntities();
		end	
		for idx,ent in completeEntityTable do
			if ent and ent.weapon then	--this means its a weapon pickup and we have the name from the weapon to pickup as string
						if not wpnAI then             --spawn a player entity which can call MakeWeaponAvailable
							wpnAI = Server:SpawnEntity("Player");								
							wpnAI:SetPos(v000);
						end
						local classid = GetWeaponIDByName(ent.weapon);
						wpnAI.cnt:MakeWeaponAvailable(classid);   --merge weaponparams and fireparams tables
						wpnAI.cnt:SetCurrWeapon(classid);       --load the character cgf from weapon model 
						clog("precatch weapon "..wpnAI.cnt.weapon.name);  --log this event to log.txt
--						PreloadCGF(name); --not needed,  SetCurrWeapon will do this job too
			end	
		end
		
end

however, this is the solution for weaponpickups, i will investigate now for the other case: precatch weapon drops from weapons which player drops from inventory and where engine create a pickup for.

Edited by: pvcf

Reply to thread
click to sign in and post

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.