Magic

Magic

190k Downloads

Api integration bug

7-75 opened this issue · 13 comments

commented

was trying to have a plugin give a player spells via the API but it seems lthat even if I remove from a player let's say spell missile|3 they will still be able to use it trough skill items

commented

I see, the matter is that I was expecting the plug-in to remove skill items the player is not supposed to have..
Is there any way Magic can tell me what spells the player is supposed to have? Is there a way to create skillitems trough the API?

commented

The spells a player can do are generally determined by the wands they can use. If you want to cancel a spell nonetheless you could listen to the pre-cast event.

commented

Mmh if you consider this solved please do not restrain from closing the ticket but HM.. I'd appreciate any more help you would like to provide

commented

Yes, getMage().getSpells() (or getMageClass().getSpells() if using classes).

Or I think you can make skill items require that the player has the spell- honestly I can't remember how skill items work offhand since it's kind of a rarely-used feature. There's probably some way to block use of them, though, which would be best since players can always find some way to stash them or keep them somehow.

commented

My problem is mainly due to removing spells from players when they die.

Finding a way to block the cast of spells players shouldn't have would be just fine.. but I should also give them the skillitem they are supposed to have instead (example being removing "missile|2" when the player still has the "missile" spell).

I'll look into the API for anything related to skillitems but.. Hm.. I'm kind of a novice xD

Thanks for the help everyone, have a nice day.

commented

Nevemind, I can't find any mention of skillitems in the API..

commented

Well I think you have two separate problems

The API can identify skill items (MageController.isSkill(ItemStack) - which you could then use to remove the skill items. But none of that really helps, assuming they're losing the items on death anyway.

I think your best bet would be to have the skill items associated with a class, so you can add/remove spells to that class. I think if you do that they have to have "learned" the spells in order to use the skill items.

Normally players would have a spell book or something similar they use to get their skill items.

If you're building against the full plugin and not just the API, you could try using InventoryUtils.configureSkillItem to assign it to a class. Then you'd have to use getMage().getMageClass(...).addSpell to give the spell to the player, you can then use removeSpell() to take it away so they can no longer use the skill item if they've kept it somehow.

commented
commented

They wont lose skill-items on death, that's how skill-items work, right?

commented

It depends on the "keep" setting, if you have "keep: false" on it then they will disappear on death.

commented

I'd want the skill-items for the spells they have (that aren't removed trough the API) as a mage to remain.

It's not about them dying, that's just when I happened to decide to remove the spell from the mage.

I'm using the api to remove the spell on death from the mage but even though I do that they are still capable of casting the spell by the skillitem

commented

So I looked over the code and it doesn't look like there was anything preventing a player from using a skill item when they don't know the spell.

I've added a check for this now, only if the skill is assigned to a class. I think this makes good sense and hopefully won't break anyone- I didn't want to do it for classless spells since I think that'd break all Heroes users and possibly lots of other people.

This will be in the next dev build if you can give it a try.

commented