[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: Kiffy • Posted: 2023-06-17T17:24:39.694000+00:00
Original source
yea Im just unsure of how it goes in terms of attatching and fetching a script
Archived author: Nix • Posted: 2023-06-17T17:27:04.195000+00:00
Original source
Well, there is only one way to learn
Archived author: Nix • Posted: 2023-06-17T17:29:10.866000+00:00
Original source
There are examples by GPT4, so don't assume they'll just work out of the box.
Spellscript
```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 portal's AI
if (portal->AI())
portal->AI()->SetData(0, Position(x, y, z));
}
}
void Register() override
{
AfterCast += SpellCastFn(spell_portal_creation_SpellScript::HandleAfterCast);
}
};
```
Archived author: Nix • Posted: 2023-06-17T17:29:43.639000+00:00
Original source
Gameobject Script
```cpp
class go_portal : public GameObjectScript
{
public:
go_portal() : GameObjectScript("go_portal") { }
bool OnGossipHello(Player* player, GameObject* go) override
{
// Fetch the coordinates associated with this portal
Position pos;
if (go->AI())
pos = go->AI()->GetData(0);
// 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
Position pos;
if (go->AI())
pos = go->AI()->GetData(0);
player->TeleportTo(player->GetMapId(), pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), player->GetOrientation());
}
return true;
}
};
```
Archived author: Nix • Posted: 2023-06-17T17:30:19.398000+00:00
Original source
inside of gameobject_template, you'd set the scriptname to go_portal
Archived author: Kiffy • Posted: 2023-06-17T17:30:19.992000+00:00
Original source
yeah it forgets the spellscript loader class by default but the methods are defo useful
Archived author: Nix • Posted: 2023-06-17T17:30:37.985000+00:00
Original source
Yeah, it isn't that great at the big picture stuff
Archived author: Nix • Posted: 2023-06-17T17:30:54.697000+00:00
Original source
but this should kind of give you an idea, the spellscript loader stuff should be "easy" enough to figure out, there are literally hundreds of examples in the code.
Archived author: Nix • Posted: 2023-06-17T17:31:29.278000+00:00
Original source
I'm sure you can fetch the go_portal script somehow, but it seems to want to use the AI() function, I'm unsure if that is the proper solution or not as I don't work with the emulator
Archived author: Nix • Posted: 2023-06-17T17:31:40.055000+00:00
Original source
But this would be a step in the "right" direction if you will