How do you get an NPC to drop an item?

Post topics regarding Level Building/Design and Entity Usage with Reality Factory
Post Reply
realityfactoryusr
Posts: 73
Joined: Fri Dec 19, 2008 7:20 pm

How do you get an NPC to drop an item?

Post by realityfactoryusr » Mon Nov 04, 2013 7:03 pm

Ive been through the manuals several times and cannot find it anywhere. Say I have a boss that after its defeated, it drops a key that lets you leave the level. Is this possible? I think it has something to do with attributes but...

While were here... is there any way to get smoother shadows on objects? When I put a light underneath a pipe, the individual faces are visible, it looks odd, even for one of my levels. Is there anyway to make the shadow smoother?

Thanks in advanced!

User avatar
QuestOfDreams
Site Admin
Posts: 1520
Joined: Sun Jul 03, 2005 11:12 pm
Location: Austria
Contact:

Re: How do you get an NPC to drop an item?

Post by QuestOfDreams » Tue Nov 05, 2013 6:21 pm

realityfactoryusr wrote:Ive been through the manuals several times and cannot find it anywhere. Say I have a boss that after its defeated, it drops a key that lets you leave the level. Is this possible? I think it has something to do with attributes but...
Place an Attribute entity in your level, fill in the TriggerName and activate that trigger from the Pawn's script when he dies (SetEventState). If you need to move the Attribute entity to the exact location of the Pawn you may use SetEntityPosition.
realityfactoryusr wrote:While were here... is there any way to get smoother shadows on objects? When I put a light underneath a pipe, the individual faces are visible, it looks odd, even for one of my levels. Is there anyway to make the shadow smoother?
In contrast to actors, level geometry is always flat shaded (i.e. based on the face normal).

realityfactoryusr
Posts: 73
Joined: Fri Dec 19, 2008 7:20 pm

Re: How do you get an NPC to drop an item?

Post by realityfactoryusr » Sat Nov 09, 2013 8:54 pm

QuestofDreams:

Thank you for the reply, I KNEW it had something to do with the Attribute entity!
However, I added the attribute entity, named the trigger "dropkey". I used the cratea2.act model for the key model.
In the enemy script -> SetEventState (dropkey, true);

Upon defeat, the crate doesnt show up even with positioning.

Heres the script:

Death[()
{
DelTimerOrder(1);
AddPainOrder("PainToAlert", 0);
FindTargetOrder(0, "FoundTarget", DAMAGEATTRIBUTE);
DelTriggerOrder("IdleToAlert");

SetEventState (dropkey, true); --> Wherever I put this line, the script doesnt read past it. At this point, the NPC collision is still on, its animation keeps going, it doesnt fade out and is not removed.

SetNoCollision();
AnimateStop(DIE, DIEHOLD, "");
FadeOut(DIEFADE, 0);
Remove(true);


When the NPC "dies", the cratea2 model should appear shouldnt it?
Forgive me Im still learning how to understand the scripting and all.
Am I missing a step or something?

realityfactoryusr
Posts: 73
Joined: Fri Dec 19, 2008 7:20 pm

Re: How do you get an NPC to drop an item?

Post by realityfactoryusr » Sat Nov 09, 2013 9:10 pm

While I still have the chance.....

Is there anyway to make a level end AFTER completing a task? Say clearing a room down to the last enemy?
Or even better, after boss is defeated, the level simply ends, bypassing the whole "collect a key" problem.
Making a health bar appear over an enemies head?
Doors that ONLY open when player has the key for them?

Allanon
Posts: 493
Joined: Mon Aug 29, 2005 8:23 am

Re: How do you get an NPC to drop an item?

Post by Allanon » Sun Nov 10, 2013 11:38 am

realityfactoryusr wrote:SetEventState (dropkey, true); --> Wherever I put this line, the script doesnt read past it. At this point, the NPC collision is still on, its animation keeps going, it doesnt fade out and is not removed.
You need quotes around dropkey and DIE. If the command requires a string value then use quotes:

Code: Select all

SetEventState ("dropkey", true);
SetNoCollision();
AnimateStop("DIE", DIEHOLD, "");
FadeOut(DIEFADE, 0);
Remove(true);
realityfactoryusr wrote:Is there anyway to make a level end AFTER completing a task? Say clearing a room down to the last enemy?
Or even better, after boss is defeated, the level simply ends, bypassing the whole "collect a key" problem.
Create a trigger entity that when activated will change the level. For this example I will call it LevelChangeTrigger. Add that trigger to the TriggerChange field of the ChangeLevel entity.

Then create a player attribute that keeps track of the number of enemies. For this example I'm going to use the attribute EnemyNumber. Set EnemyNumber to 0 in the player.ini.

Code: Select all

[EnemyNumber]
initial = 0
low = 0
high = 99999
In each enemy spawn order add 1 to EnemyNumber:

Code: Select all

Spawn[()
{
    ModifyAttribute("EnemyNumber", 1, "Player");
In each enemy death order subtract 1 from EnemyNumber and check if EnemyNumber is 0, if it is then set ChangeLevel state to true:

Code: Select all

Death[()
{
    ModifyAttribute("EnemyNumber", -1, "Player");
    if (GetAttribute("EnemyNumber","Player") = 0)
    {
        SetEventState("ChangeLevel", true);
    }
For a boss enemy you can leave out the EnemyNumber attribute code and just call the SetEventState("ChangeLevel", true) code in the death order of a boss.

realityfactoryusr wrote:Making a health bar appear over an enemies head?
I guess you can use the CheckArea() command to see if the enemy is visible on the screen and use a combination of the GetDistanceTo(), GetEntityScreenX(), GetEntityScreenY() commands to determine where to draw the health bar.

You can make a flipbook with 100 images which represent each percentage of health. Then use the DrawFlipBookImage() command to display the flipbook image. Or maybe use the FillScreenArea() command and calculate the correct size of rectangle to draw.
realityfactoryusr wrote:Doors that ONLY open when player has the key for them?
Place a trigger on the door and when you get the key set the trigger to true. If the door's bNoCollide field is false then the door won't open until you collide with it. You won't be able to open the door unless the trigger is true.

Note: I never tried any of this but it should work.

Post Reply