#(malenkaya) API and Behavoirs

12 messages · Page 1 of 1 (latest)

pliant garnet
#

Hiya, I am attempting to use Citizens and our own Vehicle-System (Cars, Helicopters) to create NPCs that can find a car and drive it around. I've created two behavoirs, one for finding a car and a second one for entering and starting the car. I'm spawning the NPC using a simple command and add the goals right afterwards. After spawning, the NPC literally does nothing for some reason. Any help is welcome and appreciated!
Command:

private void spawn(Player p) {
        NPC npc = NpcHook.getRegistry().createNPC(EntityType.PLAYER, "Driver");
        npc.spawn(p.getLocation());
        npc.getDefaultGoalController().addBehavior(Sequence.createSequence(new NpcVehicleFindBehavoir(npc), new NpcVehicleStartBehavoir(npc, NpcVehicleFindBehavoir.getClosestNpcVehicle(npc))),0);
        ChatUtils.sendMessage(p, ChatUtils.MessageType.SUCCESS, "Done");
    }
late grottoBOT
#

(malenkaya) API and Behavoirs

late grottoBOT
#

Hi I'm AutoThreadBot! Don't mind me, I'll just be adding the helper team to this thread so they can see it. A human will get to you soon.

dark scroll
#

@pliant garnet need the behavior code as well

pliant garnet
#

FindBehavoir:

public class NpcVehicleFindBehavoir extends BehaviorGoalAdapter {

    private final NPC npc;

    public NpcVehicleFindBehavoir(NPC npc) {
        this.npc = npc;
    }

    @Override
    public void reset() {
        //vibing...
    }

    @Override
    public BehaviorStatus run() {
        if (isNearNpcVehicle())
            return BehaviorStatus.SUCCESS;
        if (!npc.getNavigator().isNavigating())
            npc.getNavigator().setTarget(getClosestNpcVehicle(npc).getLocation());
        return BehaviorStatus.RUNNING;
    }

    @Override
    public boolean shouldExecute() {
        return true;
    }
//some helper methods here...
}

StartCarBehavoir:

public class NpcVehicleStartBehavoir extends BehaviorGoalAdapter {

    private final NPC npc;
    private final Vehicle vehicle;
    public NpcVehicleStartBehavoir(NPC npc, Vehicle vehicle) {
        this.npc = npc;
        this.vehicle = vehicle;
    }


    @Override
    public void reset() {

    }

    @Override
    public BehaviorStatus run() {
        npc.addTrait(Equipment.class);
  // enter car
  // start engine
  // shift into first gear
        return BehaviorStatus.SUCCESS;
    }

    @Override
    public boolean shouldExecute() {
        return true;
    }
}
dark scroll
#

@pliant garnet hmm, are you sure a path is being found?

pliant garnet
#

I actually don't know, I don't get any errors in console. There shouldn't be any errors on a flat plane with 10 blocks distance tho lol

next jacinth
#

You may need to write some debug logging message to show what is actually happening, it is a good habit.

dark scroll
#

Yes need a bit more debugging to show what's actually happening

sullen shuttleBOT
#
Thread Closing Reminder

Has your issue been resolved, or your question been answered?
If so, please use the </resolved:1028673926114594866> command to close your thread.
Or </invalid:1028673926898909185> if it's not possible to resolve.

If not yet resolved, please reply below to tell us what you still need.

(Note that if there is no reply for a few days, this thread will eventually close itself.)

#

@pliant garnet