View unanswered posts | View active topics It is currently Thu Dec 26, 2024 7:20 am



Reply to topic  [ 4 posts ] 
 May I make a suggestion? 
Author Message
User avatar

Joined: Sat Feb 04, 2012 7:45 pm
Posts: 4
Reply with quote
Post May I make a suggestion?
The AI should have a random chance of switching weapons when reloading so you don't spend money for grenades they don't use!


Sat Oct 06, 2012 2:51 am
Profile
User avatar

Joined: Sat May 19, 2012 9:27 pm
Posts: 364
Reply with quote
Post Re: May I make a suggestion?
16-Bit wrote:
The AI should have a random chance of switching weapons when reloading so you don't spend money for grenades they don't use!


Hmm, interesting point it would be nice if the AI could tactically see "Hmm, so the guy just dove behind that rock, and I have a frag grenade..."

currently it seems they only use grenades when they have no other options.


Sat Oct 06, 2012 6:31 am
Profile

Joined: Fri Oct 05, 2012 9:32 pm
Posts: 7
Reply with quote
Post Re: May I make a suggestion?
I had a quick look at base.rte/Actors/AI/...

There is a file called HumanAI.lua which, after looking inside, seems to handle when to reload.

For example at row 145:
Code:
   function self:CreateSuppressBehavior()
      if self:EquipFirearm(true) then
         self.NextBehavior = coroutine.create(HumanBehaviors.ShootArea)
         self.NextBehaviorName = "ShootArea"
      else
         if self.FirearmIsEmpty then
            self:ReloadFirearm()
         end
         
         return
      end


one could add before or after "self:ReloadFirearm()" something like this and see what happens:
Code:
local z = math.random();
if z > 0.70 then
<whatever is called to switch weapons>


I guess you'd have to add it everywhere where you find the ReloadFirearm()-call.

But I never modded CC or even programmed in lua. This is just guesswork based on some programming knowledge...

Edit:
Now I somehow want to try it...
What is called to let the AI switch weapons?


Sat Oct 06, 2012 7:04 pm
Profile
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post Re: May I make a suggestion?
Both Lua and CC is both easy and rewarding to get started with if you have some programming experience, much thanks to the Programming in Lua html-book and the CC-API documention.

As you can see the CreateAttackBehavior-function always try to use a firearm first, so the easiest way to do this is probably to create a new factory-function that initializes the HumanBehaviors.ThrowTarget behavior and then call that from HumanBehaviors.ShootTarget and return.

Here are a few other things that may help:
Set up a test scene (e.g. by modifying the Zombie Cave activity script) so you can spawn units with the press of a button and reload their scripts so you don't have to restart the game every time you make a change.
Code:
      if UInputMan:KeyPressed(6) then   --  f-key
         local Act = CreateAHuman("Silver Man", "Techion.rte")
         if Act then
            Act.Pos = self.AreaThrow:GetCenterPoint()
            Act.Team = Activity.TEAM_1
            Act.AIMode = Actor.AIMODE_SENTRY
            Act:AddInventoryItem(CreateHDFirearm("Pistol", "Base.rte"))
            MovableMan:AddActor(Act)
            
            print(Act.PresetName .. " reload = " .. Act:ReloadScripts()) -- -1 if reload failed
            self:SetViewState(Activity.ACTORSELECT, Activity.PLAYER_1)
            self:SetActorSelectCursor(Act.Pos, Activity.PLAYER_1)
         end
      end


Replace all 'require' with 'dofile' so external files also are reloaded.
Code:
dofile("Base.rte/Actors/AI/HumanBehaviors.lua")
-- instead of
require("Actors/AI/HumanBehaviors")


Sun Oct 07, 2012 7:59 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.392s | 13 Queries | GZIP : Off ]