Jump to content
Rosso777

AI Chat via Triggers

Recommended Posts

Spawned an AI that I want to say things in Chat when the player is within 5 meters.

I've done a TON of research on AI Chat Addons/Scripts, etc. None of them have instructions, so I couldn't quite figure out how to make AI give info to players (Dedicated Server, Exile). In the editor, everything works FLAWLESSLY. But when I add it to the server, the only thing that won't happen is the actual CHAT. The Ai waits a certain amount of time and then walks away, which is also based on a player-activated trigger. Can anyone see why this cat won't speak?
 

Spoiler

// Export of 'messenger1.chernarusredux' by Roscoe on v0.9

///////////////////////////////////////////////////////////////////////////////////////////
// Init
params [["_layerWhiteList",[],[[]]],["_layerBlacklist",[],[[]]],["_posCenter",[0,0,0],[[]]],["_dir",0,[0]],["_idBlacklist",[],[[]]]];
private _allWhitelisted = _layerWhiteList isEqualTo [];
private _layerRoot = (_allWhitelisted || {true in _layerWhiteList}) && {!(true in _layerBlackList)};


///////////////////////////////////////////////////////////////////////////////////////////
// Markers
private _markers = [];
private _markerIDs = [];


///////////////////////////////////////////////////////////////////////////////////////////
// Groups
private _groups = [];
private _groupIDs = [];

private _item0 = grpNull;
if (_layerRoot) then {
    _item0 = createGroup civilian;
    _this = _item0;
    _groups pushback _this;
    _groupIDs pushback 0;
};


///////////////////////////////////////////////////////////////////////////////////////////
// Objects
private _objects = [];
private _objectIDs = [];

private _item5 = objNull;
if (_layerRoot) then {
    _item5 = _item0 createUnit ["CUP_C_TK_Man_04",[4010.99,5228.43,0],[],0,"CAN_COLLIDE"];
    _item0 selectLeader _item5;
    _this = _item5;
    _objects pushback _this;
    _objectIDs pushback 5;
    _this setPosWorld [4010.99,5228.48,265.093];
    _this setVectorDirAndUp [[-0.192267,-0.968325,-0.159312],[-0.0349693,-0.155478,0.98722]];
    _this setUnitLoadout [["srifle_LeeEnfield","","","",["10x_303_M",10],[],""],[],["CHR_FlashLight","","","",[],[],""],["CUP_U_I_GUE_Anorak_01",[["10x_303_M",3,10]]],["CUP_V_OI_TKI_Jacket6_06",[]],["B_RadioBag_01_black_F",[]],"","",["Binocular","","","",[],[],""],["","","ItemRadio","ItemCompass","ItemWatch",""]];
    Man1 = _this;
    _this setVehicleVarName "Man1";
    _this setSkill 1;
    _this setUnitPos "DOWN";
    _this allowFleeing 0;
    _this allowdamage false;;
    _this setname "Luqman Jalali";;
    _this setface "PersianHead_A3_03";;
    _this setspeaker "CUP_D_Male01_TK";;
    _this setpitch 0.99;;
    _this setSkill ['aimingShake',1];
    _this setSkill ['aimingSpeed',1];
    _this setSkill ['aimingAccuracy',1];
    _this setSkill ['commanding',1];
    _this setSkill ['courage',1];
    _this setSkill ['general',1];
    _this setSkill ['reloadSpeed',1];
    _this setSkill ['spotDistance',1];
    _this setSkill ['spotTime',1];
    _this setUnitTrait ['Medic',false];
    _this setUnitTrait ['Engineer',false];
    _this setUnitTrait ['ExplosiveSpecialist',false];
    _this setUnitTrait ['UAVHacker',false];
};


///////////////////////////////////////////////////////////////////////////////////////////
// Triggers
private _triggers = [];
private _triggerIDs = [];

private _item2 = objNull;
if (_layerRoot) then {
    _item2 = createTrigger ["EmptyDetector",[4011.75,5228.66,0.071991],true];
    _this = _item2;
    _triggers pushback _this;
    _triggerIDs pushback 2;
    _item2 setPosATL [4011.75,5228.66,0.071991];
    _this setTriggerArea [5,5,0,false,-1];
    _this setTriggerActivation ["ANYPLAYER","PRESENT",false];
    _this setTriggerStatements ["call{this}","call{hint ""Hello."";}","call{this}"];
    _this setSoundEffect ["$NONE$","cough1","",""];
    say1 = _this;
    _this setTriggerTimeout [2,2,2,false];
};

private _item7 = objNull;
if (_layerRoot) then {
    _item7 = createTrigger ["EmptyDetector",[4011.59,5228.86,0.154999],true];
    _this = _item7;
    _triggers pushback _this;
    _triggerIDs pushback 7;
    _item7 setPosATL [4011.59,5228.86,0.154999];
    _this setTriggerArea [4,4,0,false,-1];
    _this setTriggerActivation ["ANYPLAYER","PRESENT",false];
    _this setTriggerStatements ["call{this}","call{hintSilent """";
Hint ""Is your group the ones who were fighting on Green Mountain recently?"";}","call{this}"];
    say2 = _this;
    _this setTriggerTimeout [10,10,10,false];
};

private _item8 = objNull;
if (_layerRoot) then {
    _item8 = createTrigger ["EmptyDetector",[4011.06,5229.02,0],true];
    _this = _item8;
    _triggers pushback _this;
    _triggerIDs pushback 8;
    _item8 setPosATL [4011.06,5229.02,0];
    _this setTriggerArea [4,4,0,false,-1];
    _this setTriggerActivation ["ANYPLAYER","PRESENT",false];
    _this setTriggerStatements ["call{this}","call{hintSilent """";
Hint ""Please... seek out the G.O.T.I. Group in the North; they can help you greatly..."";}","call{this}"];
    _this setSoundEffect ["$NONE$","cough6","",""];
    say3 = _this;
    _this setTriggerTimeout [20,20,20,false];
};

private _item9 = objNull;
if (_layerRoot) then {
    _item9 = createTrigger ["EmptyDetector",[4011.17,5228.94,0.411987],true];
    _this = _item9;
    _triggers pushback _this;
    _triggerIDs pushback 9;
    _item9 setPosATL [4011.17,5228.94,0.411987];
    _this setTriggerArea [4,4,0,false,-1];
    _this setTriggerActivation ["ANYPLAYER","PRESENT",false];
    _this setTriggerStatements ["call{this}","call{Man1 sideChat ""Last I heard, they had an outpost in Chezniki, but now I am not so sure."";}","call{this}"];
    say4 = _this;
    _this setTriggerTimeout [30,30,30,false];
};

private _item10 = objNull;
if (_layerRoot) then {
    _item10 = createTrigger ["EmptyDetector",[4011.34,5228.85,0.231995],true];
    _this = _item10;
    _triggers pushback _this;
    _triggerIDs pushback 10;
    _item10 setPosATL [4011.34,5228.85,0.231995];
    _this setTriggerArea [4,4,0,false,-1];
    _this setTriggerActivation ["ANYPLAYER","PRESENT",false];
    _this setTriggerStatements ["call{this}","call{Man1 globalChat ""Please be safe out here."";}","call{this}"];
    say5 = _this;
    _this setTriggerTimeout [40,40,40,false];
};

private _item29 = objNull;
if (_layerRoot) then {
    _item29 = createTrigger ["EmptyDetector",[4011.37,5228.97,0.476013],true];
    _this = _item29;
    _triggers pushback _this;
    _triggerIDs pushback 29;
    _item29 setPosATL [4011.37,5228.97,0.476013];
    _this setTriggerArea [4,4,0,false,-1];
    _this setTriggerActivation ["ANYPLAYER","PRESENT",false];
    _this setTriggerStatements ["call{this}","","call{this}"];
    say6LEAVE = _this;
    _this setTriggerTimeout [40,40,40,false];
};


///////////////////////////////////////////////////////////////////////////////////////////
// Group attributes (applied only once group units exist)
_this = _item0;
if !(units _this isEqualTo []) then {
    [_this,0] setWaypointPosition [position leader _this,0];
    [_this, "Alpha 1-1"] call CBA_fnc_setCallsign;
    _this setBehaviour "SAFE";
    _this setSpeedMode "LIMITED";
    _this enableDynamicSimulation true;
                if (!is3DEN && {!(["","ColorCIV","Alpha 1-1",true] isEqualTo ['','','',true])}) then            {                [_this,["","ColorCIV","Alpha 1-1",true]] spawn                {                    params ['_group','["","ColorCIV","Alpha 1-1",true]'];                    ["","ColorCIV","Alpha 1-1",true] params ['_type','_color','_text','_showGroupSize'];                    private _leader = leader _group;                    private _marker = createMarker                    [                        format ['ENH_GroupMarker_["","ColorCIV","Alpha 1-1",true]',str floor random 10e5],                        _leader                    ];                    _marker setMarkerType _type;                    _marker setMarkerColor _color;                    _marker setMarkerText _text;                    while {true} do                    {                        sleep 1;                        if (units _group isEqualTo []) exitWith {deleteMarker _marker};                        if (_group getVariable ['ENH_GroupMarker_Update',true]) then                        {                            _marker setMarkerPos _leader;                            if (_showGroupSize) then                            {                                _marker setMarkerText format ['["","ColorCIV","Alpha 1-1",true] ()',groupId _group, count units _group];                            };                        };                    };                };            };;
};


///////////////////////////////////////////////////////////////////////////////////////////
// Waypoints
private _waypoints = [];
private _waypointIDs = [];

private _item13 = [];
if (_layerRoot) then {
    _item13 = _item0 addWaypoint [[4010.85,5228.57,0.121582],0];
    _this = _item13;
    _waypoints pushback _this;
    _waypointIDs pushback 13;
    _this setWaypointType "MOVE";
    _this setWaypointCombatMode "WHITE";
    _this setWaypointBehaviour "CARELESS";
    _this setWaypointSpeed "LIMITED";
};

private _item14 = [];
if (_layerRoot) then {
    _item14 = _item0 addWaypoint [[4320.68,5014.3,0],0];
    _this = _item14;
    _waypoints pushback _this;
    _waypointIDs pushback 14;
    _this setWaypointType "MOVE";
};

private _item20 = [];
if (_layerRoot) then {
    _item20 = _item0 addWaypoint [[4772.14,4896.85,3.05176e-005],0];
    _this = _item20;
    _waypoints pushback _this;
    _waypointIDs pushback 20;
    _this setWaypointType "MOVE";
};

private _item23 = [];
if (_layerRoot) then {
    _item23 = _item0 addWaypoint [[5820.37,4776.62,3.05176e-005],0];
    _this = _item23;
    _waypoints pushback _this;
    _waypointIDs pushback 23;
    _this setWaypointType "MOVE";
};

private _item26 = [];
if (_layerRoot) then {
    _item26 = _item0 addWaypoint [[5859.85,4822.22,0],0];
    _this = _item26;
    _waypoints pushback _this;
    _waypointIDs pushback 26;
    _this setWaypointType "MOVE";
};

private _item27 = [];
if (_layerRoot) then {
    _item27 = _item0 addWaypoint [[5895.55,4847.48,-1.52588e-005],0];
    _this = _item27;
    _waypoints pushback _this;
    _waypointIDs pushback 27;
    _this setWaypointType "MOVE";
};

private _item28 = [];
if (_layerRoot) then {
    _item28 = _item0 addWaypoint [[5905.84,4846.84,0.0735779],0];
    _this = _item28;
    _waypoints pushback _this;
    _waypointIDs pushback 28;
    _this setWaypointType "SCRIPTED";
    _this setWaypointScript "\x\cba\addons\ai\fnc_waypointGarrison.sqf";
};


///////////////////////////////////////////////////////////////////////////////////////////
// Logics
private _logics = [];
private _logicIDs = [];


///////////////////////////////////////////////////////////////////////////////////////////
// Layers


///////////////////////////////////////////////////////////////////////////////////////////
// Crews


///////////////////////////////////////////////////////////////////////////////////////////
// Vehicle cargo


///////////////////////////////////////////////////////////////////////////////////////////
// Connections
if (!isNull _item5 && !isNull _item2) then {_item5 synchronizeObjectsAdd [_item2]; _item2 synchronizeObjectsAdd [_item5];};
if (!isNull _item29 && !(_item13 isEqualTo [])) then {_item29 synchronizeWaypoint [_item13];};


///////////////////////////////////////////////////////////////////////////////////////////
// Inits (executed only once all entities exist; isNil used to ensure non-scheduled environment)
isNil {
    if !(isnull _item5) then {
        this = _item5;
        call{this setunitpos "UP";};
    };
};


///////////////////////////////////////////////////////////////////////////////////////////
// Module activations (only once everything is spawned and connected)


///////////////////////////////////////////////////////////////////////////////////////////
[[_objects,_groups,_triggers,_waypoints,_logics,_markers],[_objectIDs,_groupIDs,_triggerIDs,_waypointIDs,_logicIDs,_markerIDs]]
 

 

Share this post


Link to post
Share on other sites

For the sake of anyone else who may encounter a similar issue in the future,  I will continue to update as I progress (or otherwise). I have discussed through very thorough testing that my triggers are NOT firing on the dedicated server. They run local with zero issues, but will not figure at all on the server. I was wrong to say that things were working a bit and it was only the chat that was flawed. I have tried every variable I could think of to activate the trigger, to no avail:

 

For this line essentially, 

    _this setTriggerActivation ["ANYPLAYER","PRESENT",false];
    _this setTriggerStatements ["call{this}","call{hint ""Hello."";}","call{this}"];

 

I have tried replacing ANYPLAYER with ANYBODY, BLUFOR, OPFOR, GUER, and even so far as trying to name specific players by their in-game name ("Roscoe"). No luck so far. 

I have been scouring these and other forums like a madman, and have learned a TON, but no success just yet. I read somewhere that if things are working in the editor on the local machine, they should also be working on the dedi, and I even went so far as to start adding the isServer()  stuff in the beginning of each trigger Condition or Activation. Nada.

 

I will continue to update as I go. Hopefully success will be found and it will help someone else someday. SO MANY TIMES am I seeing where someone had the SAME problem, said they solved it, and never said how. Ouch.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×