Jump to content
  • 0

Custom c++ for sd3


LordPsyan

Question

Finding any information on the changes to SD3 has been, well, let's just say I wont need a hair anytime soon. I have pulled all my hair out.

Everything looks about the same with SD3, but I cannot get any of my custom scripts to work. This is a small script, that has a couple of checks (IsInCombat, IsMoving)

This script summons an npc when you right click an item... or that is how it is supposed to work.

 

#include "precompiled.h"

struct summon : public CreatureScript
{
    summon() : CreatureScript("summon") {}

bool ItemUse_item_icerune(Player* pPlayer, Item* pItem, SpellCastTargets const& /*targets*/)
{
   uint32 sSpell = 18282; //Icerune Visual Spell when used
   if (pPlayer->IsInCombat())
   {
        pPlayer->GetSession()->SendNotification("You are in combat.");
   }
  
   else if (pPlayer->isMoving())
   {
        pPlayer->GetSession()->SendNotification("You can not do that while moving.");
   }
   else
   {
        float x, y, z, o = pPlayer->GetOrientation();
        o = o + 3.141592;
        Creature* pCreature = pPlayer->SummonCreature(100000,pPlayer->GetPositionX() ,pPlayer->GetPositionY(), pPlayer->GetPositionZ()+2, 0,TEMPSUMMON_TIMED_DESPAWN,120000);
        pCreature->CastSpell(pCreature, 40162, true);
        return false;
   }
  return false;
}
};
void AddSC_summon()
{
    Script* s;

    s = new summon();
    s->RegisterSelf();
}

 

I have added an entry into script_bindings. I do not get any errors in the scripdev3 logs (except something about ale... unrelated)

During compile I watch it check the cpp file, and there are no errors. Right clicking on the item does nothing. What am I missing?

 

EDIT: to test to see if the script was seen by the core, I removed the scipt_binding entry. I got: 2017-01-03 06:53:04 Script registering but ScriptName summon is not assigned in database. Script will not be used. so I know the core sees it. I just cant click on the item.

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

:) Your script has two major issues:

  1. If you want to script an item, then your handler has to be derived from ItemScript, not CreatureScript.
  2. In the handler, the method you have to override is called, simply, OnUse

 

So, the proper script can be written as:

struct summon : public ItemScript
{
    summon() : ItemScript("summon") {}

    bool OnUse(Player* pPlayer, Item* pItem, SpellCastTargets const& /*targets*/)
    {
        uint32 sSpell = 18282; //Icerune Visual Spell when used
        if (pPlayer->IsInCombat())
        {
          pPlayer->GetSession()->SendNotification("You are in combat.");
        }
        ...
    }
};

You may also look for sample item scripts here.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use