Jump to content
  • 0

[RESOLVED] Need working code to add an NPC


mgm

Question

 

 

 

 

 

 

ORIGINAL POST BELOW

 

 

Hi guys,

 

I have some addAction items working on a container object - I want to remove the container and add an NPC in its place (keeping the same addAction items).

 

I tried to re-use the code I had for A2 OA but it didn't work NPC did not appear in 3D game world.
Here is a guide I found here which has the same code I use:

 

If you have working NPCs for Arma3 Epoch, please can you share?

 

Thanks!

Link to comment
Share on other sites

13 answers to this question

Recommended Posts

  • 0

I would rather spawn a single unit via a serverside script.

Do You have the position coordinates, model direction and the actual ClassName of the playerModel (maybe also the gear and uniform he should wear)?

Greez KiloSwiss

 

What I am looking for is a working code in any shape or form. I will then play with it to customize with the gear/features I wish.

Do you have a working code please?

 

The reason I need this is, it is taking too much time to change stuff in config & restart & test & repeat over.

It would save me literally hours if somebody just copy a few lines of "WORKING"code.

 

Thanks

Link to comment
Share on other sites

  • 0

I'll post the snippets in a few hours; it's not too hard with a server-side pbo (which I posted elsewhere but will post here too).. What do you want the NPC to do ? stand around doing nothing?

 

 

Drop this in @EpochHive\Addons

 

You might want to remark out the createcrate script in fn_init.sqf , and edit the spawn_AI script to your needs.

 

You don't have to activate anything after dropping the PBO in that folder.

 

Thanks I will try this when I get back home.  

 

In response to your question about why and what for: basically I am writing a taxi script and I have decided to hire taxi dispatchers so yes I need this AI dude and a few of his buddies just to spawn in and stand there all day long with no trade items / no other dialogs etc.

 

I will assign addAction menu option(s) to him if I can.

 

Currently this "role" is on metal containers and from a practical perspective "it is working fine" but it appears taxi customers are now talking to a big metal container which then magically dispatches a driver.

This breaks immersion for me. An aiDude would fit in better than a metal container. I understand Epoch3 AntiHack module is forbidding use of addAction on player (self) object however I am hoing I can do this with an aiDude - we'll see soon anyway...

Link to comment
Share on other sites

  • 0

I'm sorry for sounding retarded, but:

If You work witb addActions then go with a unit created within the mission.sqm

The reason is: addActions are local.

If You create the unit on the server, all clients need to know about that unit and attach the addActions to it.

If You have the code inside the mission.sqm every client has the addAction code and automatically executes it.

Greez KiloSwiss

Link to comment
Share on other sites

  • 0

I'm sorry for sounding retarded, but:

If You work witb addActions then go with a unit created within the mission.sqm

The reason is: addActions are local.

If You create the unit on the server, all clients need to know about that unit and attach the addActions to it.

If You have the code inside the mission.sqm every client has the addAction code and automatically executes it.

Greez KiloSwiss

I need players to be able to use addAction but I don't want the menu option to be there 24/7... I might add/remove constraints in the future, rather than mission.SQM I'd like to keep it in script SQF for the time being.

 

My client-side script creates the addAction on the object (as I said currently it creates it on metal containers -- soon, hopefully, it will create it on NPC chars) only when certain criteria is met and this system is working fine, no reason to change now unless it stops working or somehow I become convinced that it is bad for any reason (performance, security etc.).

 

I haven't had a chance to test this yet as I would like to finish developing the core functionality first, then I will revisit this which is immersion/cosmetics improvement really.

Link to comment
Share on other sites

  • 0

After spending a beautiful night on this, with a zillion server restart/tests, and biki/biforums 'surfing', I have the solution I needed and my final working code below for the next guy.

The code at the bottom of this post, will give you the dude you see in the picture.

 

I still have one more TODO:

Epochmod NPC trader characters turn towards the player and face him head on when there's a player nearby.

I think it's a good feature, making it look more realistic and I also think it's not resource heavy at all.

I think I will revisit this and add that feature at some point. Definitely not soon :P

If you know how to do that please do share.

 

 

How to Use This

You can add this code to a script.sqf file and then call script.sqf from init.sqf like this below [change file path & name]:

if (isServer) then {
    [] execVM "\x\addons\custom\serverside\mgmTfA\script.sqf";
};

How NOT to Use This

You can add this code to a script.sqf file and then call script.sqf from initServer.sqf and then it will not work properly as uiSleep (sleep) cannot sleep in that file due to scheduled/non-scheduled magic (note to the curious: magic explained here).

 

 

What I learned somewhere about my restarts 27 and 44 while working on this:

It appears due to security issue setVehicleInit is no longer supported in Arma 3. If you add that directive, it will result in a script which throws an error and then exits [i.e.: no agent created] (note to the curious: explained here tl;dr; security issue).  On other forums they say instead of setVehicleInit just use BIS_fnc_MP but if I recall correctly LordAWOL disabled it due to this new functions major security flaws (see a pattern here?).

 

DuWEPvE.jpg

 

 

// Spawn an AI character to act as a TaxiCorp dispatcher at a Call-a-Taxi Point
if (mgmTfA_configgv_serverVerbosityLevel>=5) then {diag_log format ["[mgmTfA] [mgmTfA_scr_server_initCreateObjectCATP01b.sqf]  [V5]          Spawning an AI character as the TaxiCorp dispatcher at this Call-a-Taxi Point"];};

private ["_mgmTfA_anotherUnit1", "_mgmTfA_anotherUnit1sGroup"];

_mgmTfA_anotherUnit1				= objNull;
_mgmTfA_anotherUnit1sGroup			= objNull;

if (true) then {
	_mgmTfA_anotherUnit1sGroup = createGroup RESISTANCE;
	uiSleep 0.05;
	mgmTfA_configgv_catpObject	createUnit		[[13227.2,14525.1,0], _mgmTfA_anotherUnit1sGroup, "_mgmTfA_anotherUnit1=this; this setDir 0; this allowDammage false; this enableSimulation true; this enableSimulationGlobal true; this disableAI 'FSM'; this disableAI 'MOVE'; this disableAI 'ANIM'; this disableAI 'AUTOTARGET'; this disableAI 'TARGET'; this forceSpeed 0;",0.6,"Private"];
	uiSleep 0.05;
	_mgmTfA_anotherUnit1	setVariable ["BIS_fnc_animalBehaviour_disable", true];
	uiSleep 0.05;
	_mgmTfA_anotherUnit1	setDir mgmTfA_configgv_catp01DirectionDegreesNumber;
	uiSleep 0.05;
	_mgmTfA_anotherUnit1	forceSpeed 0;
	uiSleep 0.05;
	// NOTE: setVehicleInit has been completely removed from Arma 3 and if this line is not commented out it will prevent the unit from spawning

	//TODO: add all the below to unit's setVehicleInit section
	//set AI unit's AI parameters
	_mgmTfA_anotherUnit1	disableAI			"TARGET";
	uiSleep 0.05;
	_mgmTfA_anotherUnit1	disableAI			"AUTOTARGET";
	uiSleep 0.05;
	_mgmTfA_anotherUnit1	allowDammage		false;
	uiSleep 0.05;
	removeAllWeapons		_mgmTfA_anotherUnit1;
	uiSleep 0.05;
	// any extras for this AI unit?
	// posture work
	if (mgmTfA_configgv_serverVerbosityLevel>=5) then {diag_log format ["[mgmTfA] [mgmTfA_scr_server_initCreateObjectCATP01b.sqf]  [V5]          uiSleep'ing 0.05 seconds before executing SetPosturePhase2"];};
	uiSleep 0.05;
	_mgmTfA_anotherUnit1	enableSimulationGlobal	true;
	uiSleep 0.05;
	_mgmTfA_anotherUnit1	enableSimulation		true;
	uiSleep 0.05;
	_mgmTfA_anotherUnit1	enableAI				"ANIM";
	uiSleep 0.05;
	_mgmTfA_anotherUnit1	enableAI				"FSM";
	uiSleep 0.05;
	_mgmTfA_anotherUnit1	disableAI				"ANIM";
	uiSleep 0.05;
	_mgmTfA_anotherUnit1	setPosATL				[13227.2,14525.1,0];
	uiSleep 0.05;
	_mgmTfA_anotherUnit1	switchMove			"AidlPercSnonWnonDnon_talk1";
	uiSleep 0.05;
};
// EOF

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Discord

×
×
  • Create New...