#(Netpex) Running multiple npcs from one plugin.
43 messages · Page 1 of 1 (latest)
(Netpex) Running multiple npcs from one plugin.
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>
Are you using the citizens shop trait? Or making your own
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.
Looked at traits, how do I pass say a string to the trait?
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
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).
but here's information on traits: https://wiki.citizensnpcs.co/API#Creating_a_Trait
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.
Alr,
I create an npc with a command, I store its id in the yml of the shop its assigned. I want to create a trait that allows the shop to be rented; but I need to pass through the shop name when I assign the trait.
But you haven’t started coding it yet right
So what kind of advice do you need from us
And this point I had
Have*
What kind of advice do you want from me
I need help passing a varriable to the trait
Which trait and which variable
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);
So what do you want to pass
args[1]
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.
Thread moving into archive on request of @manic quartz.
Thread was closed, but still has a Needs Helper tag. If closing was intentional, please use </resolved:1028673926114594866> or </invalid:1028673926898909185>.
Thread closed as resolved.
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)