[DiscordArchive] do you mean a version using ground targeting or using unit data instead of one time accessed positio
[DiscordArchive] do you mean a version using ground targeting or using unit data instead of one time accessed positio
Archived author: Nix • Posted: 2023-06-17T17:34:10.730000+00:00
Original source
Alright I got it to understand it can fetch the script
Archived author: Nix • Posted: 2023-06-17T17:34:22.466000+00:00
Original source
Whether it is accurate or not I don't know, but it might be useful to you
Archived author: Nix • Posted: 2023-06-17T17:34:26.089000+00:00
Original source
```cpp
class spell_portal_creation_SpellScript : public SpellScript
{
PrepareSpellScript(spell_portal_creation_SpellScript);
void HandleAfterCast()
{
if (Unit* target = GetHitUnit())
{
// Spawn the portal at the caster's location
float x, y, z;
GetCaster()->GetPosition(x, y, z);
GameObject* portal = GetCaster()->SummonGameObject(100001, x, y, z, 0, 0, 0, 0, 0, 0);
// Save the target's location
target->GetPosition(x, y, z);
// Store these coordinates in the go_portal class
if(auto script = dynamic_cast<go_portal*>(portal->GetScript()))
script->SetTargetPosition(Position(x, y, z));
}
}
void Register() override
{
AfterCast += SpellCastFn(spell_portal_creation_SpellScript::HandleAfterCast);
}
};
```
Archived author: Nix • Posted: 2023-06-17T17:34:35.651000+00:00
Original source
```cpp
class go_portal : public GameObjectScript
{
public:
go_portal() : GameObjectScript("go_portal") { }
bool OnGossipHello(Player* player, GameObject* go) override
{
// Add a gossip option that teleports to the stored location
player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Teleport", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 1);
player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, go->GetGUID());
return true;
}
bool OnGossipSelect(Player* player, GameObject* go, uint32 /*sender*/, uint32 action) override
{
player->PlayerTalkClass->ClearMenus();
if (action == GOSSIP_ACTION_INFO_DEF + 1)
{
// Teleport the player
player->TeleportTo(player->GetMapId(), _pos.GetPositionX(), _pos.GetPositionY(), _pos.GetPositionZ(), player->GetOrientation());
}
return true;
}
void SetTargetPosition(Position pos)
{
_pos = pos;
}
private:
Position _pos;
};
```
Archived author: Kiffy • Posted: 2023-06-17T17:34:52.788000+00:00
Original source
im drowning in code
Archived author: Kiffy • Posted: 2023-06-17T17:34:55.855000+00:00
Original source
xD
Archived author: Kiffy • Posted: 2023-06-17T17:34:59.763000+00:00
Original source
ill try some stuff
Archived author: Nix • Posted: 2023-06-17T17:35:42.419000+00:00
Original source
It only took 4 messages to convince it that go_portal in fact does exist, and isn't magically resolved at runtime <:kekw:728766271772033046>
It initially said GameObjectScript is static and there is no instance on any specific gameobject... silly gpt
Archived author: bulbous0617 • Posted: 2023-06-17T17:41:13.461000+00:00
Original source
the spell script should work, for the gameobject one you can use GameObjectAI instead of GameObjectScript and then register it with `RegisterGameObjectAI(go_portal)`, saves you from doing loader stuff
Archived author: Kiffy • Posted: 2023-06-17T17:44:36.989000+00:00
Original source
I do use gameobjectai currently, but why wouldnt a loader be needed for the spellscript? has been my experience that it doesnt register without it