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
  On 2/28/2015 at 5:40 AM, chisel said:

You mean like a trader in the mission.sqm?

I need to do it via SQF (randomization need). This will be an NPC not a trader. He won't trade, he won't need items/prices/stock level. He just needs to exist in the 3D world.

Link to comment
Share on other sites

  • 0
  On 3/2/2015 at 11:07 AM, KiloSwiss said:

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
  On 3/2/2015 at 4:07 PM, nedfox said:

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?

 

 

  On 3/2/2015 at 4:31 PM, nedfox said:

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
  On 3/2/2015 at 8:41 PM, KiloSwiss said:

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

 

 

  Reveal hidden contents

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Discord

×
×
  • Create New...