#(Netpex) Running multiple npcs from one plugin.

43 messages · Page 1 of 1 (latest)

manic quartz
#

Hello, Sorry if this has been asked before. Im currently making a shop plugin that utilizes citizen npcs overtime a shop is registered they set the npc, the npc id is stored in the shops yml. How would I go abouts listening for interaction from all the npcs attached to shops? (Sorry if this is to much to ask help of)

steep jasperBOT
#

(Netpex) Running multiple npcs from one plugin.

steep jasperBOT
#

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.
You can block this bot if you don't want to see these messages, I won't mind.
<@&525394568410038282>

wary sparrow
#

Are you using the citizens shop trait? Or making your own

manic quartz
#

I have not gotten to traits yet, atm this is all hypothetical.

#

I handn't looked at traits yet but i think this is what I need.

manic quartz
quaint talon
#

it might be better to explain what you want or what you're trying to do instead of hypothetical 'how do i do x' when it could be something totally different

#

a good writeup on why that's important:

#

!xy

idle currentBOT
# quaint talon !xy
Info: xy

Your question seems to be an XY Problem - you're asking about your attempted solution rather than your original problem.
Read in detail about the XY Problem here: http://xyproblem.info/

For an example of an XY Problem we've seen in Denizen, the question "how do I make an event for when a flag expires" has no answer, but the same question asked with full background detail will be something more like "I have this script: [LINK HERE], which sets a 3 minute cooldown flag on a player for when they use an ability. I want the player to be notified when the cooldown completes - how do I do this?" which we can then answer quite effectively (in this example, all that was needed was a simple wait command, no events or flag-listening or anything).

quaint talon
#

but here's information on traits: https://wiki.citizensnpcs.co/API#Creating_a_Trait

API

Citizens has an extensive API for working with NPCs. Make sure you always are using an up-to-date build of the CitizensAPI to ensure that your plugin works with the latest release of Citizens.

manic quartz
wary sparrow
#

But you haven’t started coding it yet right

#

So what kind of advice do you need from us

manic quartz
#

Have*

wary sparrow
#

What kind of advice do you want from me

manic quartz
#

I need help passing a varriable to the trait

wary sparrow
#

Which trait and which variable

manic quartz
#

Custom trait, and Id like to pass a string

#

This is my trait so far.

package info.netpex.marketplace.npcs;

import info.netpex.marketplace.Marketplace;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.TraitName;
import net.citizensnpcs.api.util.DataKey;
import org.bukkit.Server;
import org.bukkit.event.EventHandler;
import org.bukkit.plugin.java.JavaPlugin;

@TraitName("Rentable")
public class Rentable extends Trait {
    public Rentable() {
        super("Rentable");
        plugin = JavaPlugin.getPlugin(Marketplace.class);
    }

    Marketplace plugin = null;

    String shop = "";

    public String getShop() {
        return shop;
    }

    public void setShop(String shop) {
        this.shop = shop;
    }

    // An example event handler. All traits will be registered automatically as Spigot event Listeners
    @EventHandler
    public void click(net.citizensnpcs.api.event.NPCRightClickEvent event){
        //Handle a click on a NPC. The event has a getNPC() method.
        //Be sure to check event.getNPC() == this.getNPC() so you only handle clicks on this NPC!
        System.out.println(shop);
    }

    // Called every tick
    @Override
    public void run() {
    }

    //Run code when your trait is attached to a NPC.
    //This is called BEFORE onSpawn, so npc.getEntity() will return null
    //This would be a good place to load configurable defaults for new NPCs.
    @Override
    public void onAttach() {
        plugin.getServer().getLogger().info(npc.getName() + "has been assigned MyTrait!");
    }

    // Run code when the NPC is despawned. This is called before the entity actually despawns so npc.getEntity() is still valid.
    @Override
    public void onDespawn() {
    }

    //Run code when the NPC is spawned. Note that npc.getEntity() will be null until this method is called.
    //This is called AFTER onAttach and AFTER Load when the server is started.
    @Override
    public void onSpawn() {

    }

    //run code when the NPC is removed. Use this to tear down any repeating tasks.
    @Override
    public void onRemove() {
    }
}
#

Command class

 NPC npc = CitizensAPI.getNPCRegistry().createNPC(EntityType.PLAYER, args[2]);
 npc.spawn(player.getLocation());
 npc.getOrAddTrait(Rentable.class);
wary sparrow
#

So what do you want to pass

manic quartz
wary sparrow
#

that sounds like a general java question

#

maybe suited for the spigot discord

manic quartz
#

Sorry, I have really bad communication skills lol. I think I've found a solution. Id like to believe in good ad coding but I'm not so good at terms and vocabulary.

steep jasperBOT
#
Thread Archived

Thread moving into archive on request of @manic quartz.

random wyvernBOT
#
Thread Close Blocked

Thread was closed, but still has a Needs Helper tag. If closing was intentional, please use </resolved:1028673926114594866> or </invalid:1028673926898909185>.

#
Resolved

Thread closed as resolved.

manic quartz
#

I wasnt able to find anyone who could help, so i'll try to rephrase sorry.

#

idk if Im able to get this opened again

#

or if I should just make a new one but

#

I've created a trait and I assign it my npc. How do I pass a string to the trait when its assigned so I can use it in its trait functions. (I wasnt able to correctly say what I needed help with. Hope I have here)