Skip to content

Commit 2e3fb15

Browse files
committed
Added DecisionMaker example project
1 parent 24c513d commit 2e3fb15

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

examples/DecisionMaker/Main.cpp

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#include <plugin.h> // Plugin-SDK version 1002 from 2025-12-09 23:18:09
2+
#include <CDecisionMakerTypes.h>
3+
#include <CCivilianPed.h>
4+
#include <CStreaming.h>
5+
#include <CWorld.h>
6+
7+
using namespace plugin;
8+
9+
struct Main
10+
{
11+
eDecisionMakerType decisionMakerHandle = eDecisionMakerType::UNKNOWN;
12+
CPed* ped = nullptr;
13+
14+
Main()
15+
{
16+
// register event callbacks
17+
Events::restartGameEvent += []{ gInstance.OnGameRestart(); };
18+
Events::gameProcessEvent += []{ gInstance.OnGameProcess(); };
19+
}
20+
21+
void OnGameRestart()
22+
{
23+
decisionMakerHandle = eDecisionMakerType::UNKNOWN; // game deletes the DM itself, just clear our reference
24+
ped = nullptr; // game deletes the ped itself, just clear our reference
25+
}
26+
27+
void OnGameProcess()
28+
{
29+
// create our decision maker if not exists yet
30+
if (decisionMakerHandle == eDecisionMakerType::UNKNOWN)
31+
{
32+
// create decision maker
33+
auto dmManager = CDecisionMakerTypes::GetInstance();
34+
if (!dmManager) return; // try again later
35+
36+
CDecisionMaker templateDm; // empty
37+
decisionMakerHandle = dmManager->AddDecisionMaker(&templateDm); // take note the game only has 10 slots for custom DMs
38+
39+
if (decisionMakerHandle == eDecisionMakerType::UNKNOWN) return; // failed to create DM, try again later
40+
41+
dmManager->AddEventResponse(decisionMakerHandle, eEventType::EVENT_GUN_AIMED_AT,
42+
eTaskType::TASK_SIMPLE_HANDS_UP,
43+
DecisionChances(4, 4, 4, 4), // 4/5 chance
44+
DecisionContext(true, false)
45+
);
46+
47+
dmManager->AddEventResponse(decisionMakerHandle, eEventType::EVENT_GUN_AIMED_AT,
48+
eTaskType::TASK_SIMPLE_DUCK,
49+
DecisionChances(1, 1, 1, 1), // 1/5 chance
50+
DecisionContext(true, false)
51+
);
52+
}
53+
54+
// create ped
55+
if (ped == nullptr)
56+
{
57+
constexpr auto MODEL = 70; // scientist
58+
CStreaming::RequestModel(MODEL, eStreamingFlags::PRIORITY_REQUEST);
59+
CStreaming::LoadAllRequestedModels(true);
60+
ped = new CCivilianPed(PED_TYPE_CIVMALE, MODEL);
61+
62+
if (!ped) return; // failed to create ped, try again later
63+
64+
ped->SetPosn(FindPlayerPed()->TransformFromObjectSpace(CVector(0.0f, 3.0f, 0.0f))); // in front of the player
65+
ped->SetOrientation(0.0f, 0.0f, 0.0f);
66+
CWorld::Add(ped);
67+
ped->PositionAnyPedOutOfCollision();
68+
69+
ped->m_fMaxHealth = ped->m_fHealth = 1000.0f; // stronger for tests
70+
71+
if (ped->m_pIntelligence)
72+
{
73+
ped->m_pIntelligence->SetPedDecisionMakerType(decisionMakerHandle);
74+
}
75+
}
76+
}
77+
} gInstance;

examples/DecisionMaker/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
## Decision Maker
2+
Shows how to create custom DecisionMaker and assign it to ped.

examples/examples.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
PROJECT, TYPE, GTA2, GTA3, GTA-VC, GTA-SA, GTA4, DE-3, DE-VC, DE-SA, D3D
22
ColouredObjects, ASI, ---, ---, ---, YES, ---, ---, ---, ---, ---
33
CreateCar, ASI, ---, ---, ---, YES, ---, ---, ---, ---, ---
4+
DecisionMaker, ASI, ---, ---, ---, YES, ---, ---, ---, ---, ---
45
DXFont, ASI, ---, YES, YES, YES, ---, ---, ---, ---, YES
56
FullNitrousControl, ASI, ---, ---, ---, YES, ---, ---, ---, ---, ---
67
GPS, ASI, ---, ---, ---, YES, ---, ---, ---, ---, YES

0 commit comments

Comments
 (0)