How do you make npc attack the player?

magicmetal02
21 Feb 2016, 21:37
I want to make the npc attack player.Also,how can the player pick up edible objiects?I tried to pick up food,and it says you can't take it.

XanMag
21 Feb 2016, 23:06
NPC attacking the player will probably be done with a turn script. My guess is you'll need to run an 'If' script to check and see if the NPC is in the room with the player, and if so, THEN print a message indicating the player is attacked followed by some decrease health script. The Pixie can certainly give you a better answer for more complex attack systems, but that's how I would do it to start off with (fyi, I have not had an attacking NPC in any of my games, so the above is sort of a guess).

Picking up edible objects - it sounds like you just didn't tick the 'can be taken' box in the inventory tab.

HegemonKhan
21 Feb 2016, 23:36
Do you want actual damage (aka: using life/health), or just a prompt/msg and/or etc stuff to occur?

Do you want the npc to initiate the attack, or do you initiate the attack/fight?

-------------

to "attack" with "damage" taking away "life/health", in skeleton form:

run as script -> add new script -> variables -> 'set a variable or attribute' Script -> [expression] -> (see below)

set variable attacked_Object's_name_here.life/health_Attribute's_name_here = [expression] attacked_Object's_name_here.life/health_Attribute's_name_here - attacker_object's_name_here.damage_Attribute's_name_here

-----------

you can also take a look at my combat code here:

viewtopic.php?f=10&t=3348&start=120#p22483
(scroll down to my next post too, as it has the key/legend for all of my annoying abrevs, lol)

The Pixie
22 Feb 2016, 08:49
magicmetal02 wrote:I want to make the npc attack player.

It depends. What triggers the attack? If the NPC attacks as soon as the player enters the room, you should do that in a script on the room, in the "After entering the room for the first time" section. If the NPC attacks when the player picks something up, you need a script on the item. If the NPC attacks after you attack him, you need to add something to the attack command (or verb) script. If you can give more details, we can walk you through it.

Forgewright
23 Feb 2016, 04:32
Pixie's CombatLib2 is the best.
viewtopic.php?f=18&t=5976&p=41308&hilit=CombatLib#p41308
This has the file and instructions on installation.

xordevoreaux
11 Mar 2016, 17:00
I also plan to have NPCs attack autonomously, but I've two development goals right now: pathing as well as attacking.

Pathing:
For pathing, I'm going to create nested spaces, which you could think of as zones, and certain NPCs (rats, for example) can scamper within any room and to any room within that zone (collection of spaces). This is based on a timer that calls functions to update all objects of the type needing their locations updating.

Attacking:
Similar to pathing, attacking is tied, in part, to the overall timer. Different NPC properties work at different numbers of clicks of the timer. For example, rats have just a few clicks, which means in their object definitions, once their cooldown occurs, they can attack again. They don't do much damage, but they attack more frequently than a wild bear. Using a timer with combat gives me a nice way also to attenuate the cool down, giving me the ability, for example, for the player to cast a spell that increases the tick count property on a given instance of an NCP (slows their attacks) or resets the tick count to 0 (interrupts their attacks).

Side note about other timers:
I currently have a similar timing system for fire, and it works beautifully. You can strike a match, and without typing anything at all, hands completely off the keyboard, watch the match burn out after so long because there's a timer running in the background all the time, calling functions, and when an object's IsBurningYN boolean attribute is currently true and the object's property BurnTicksCount < MaxBurnTicks, it continues to burn, but when BurnTicksCount = MaxBurnTicks, the match (candle, whatever), also burns out. If you snuff a candle, for example, and there are burnticks left, you can re-light it again and then watch it burn out once it reaches its maximum number of burn ticks.

Important: I do not have a separate "match" object or "candle" or "torch" object. All manipulable objects are assigned my MCobject property list, which accounts for such things as fragility (can it and will it either break or shatter when dropped or thrown), burn-ability as mentioned, and other properties. Two challenges that I have not addressed yet include pouring liquids to spread part of one object around into smaller-volume copies of itself, etc. Their are script properties within the MCObject property list such as OnIgnite, OnDrop, OnThrow, etc., that initialize, increment, or reset other properties in the list (IsBrokenYN, IsBurningYN, etc.) and are called from verbs.

So NPCs, which is my next development piece to work on, it's timer + function calls + object type + object type properties. Lots of work in the background, but man it is cool to watch stuff happen when you're not even touching the keyboard. It feels more real-life.

I've no idea when I'll release the game, it's not high on my list of TO-DO's, but wanted to share my overall approach.