• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

Custom Flightpath Problem

Status
Not open for further replies.

Teryaki

Exalted Member
Hey there everyone,

I have just started using Eluna for TrinityCore, because I recently switched from ArcEmu so I wanted to switch into scripting as smoothly as possible. I have to say Eluna is quite good, and I dont quite know C++ as well as LUA. Anyway, on to my question. I am having a problem with a script I had on my ArcEmu server. I think I have it mostly converted to Eluna I think, I am still quite new to Eluna itself.

I am getting an error in my worldserver stating "attempt to index local 'pUnit' (a number value)" I looked at the custom scripts as well, and the setup is a little different than what I have in this script. So I don't know if I will have to go through and edit some more of the code to make it match the gossip script for the teleporter or what. And if that is the case, then is it possible to register the flight path and having it require an item? Here is the code of the script I have so far, if there is any help that I could get or something to point me in the right direction that would be wonderful! Thank you!

Code:
local GetDisplay = 17699
local NPCID = 99993
local item1id = 49623

local MyFlightPath = {
    {1, 16218.30, 16277.84, 25},
    {1, 16206.73, 16251.14, 32},
    {1, 16228.76, 16230.82, 42},
    {1, 16266.93, 16246.27, 63},
    {1, 16275.62, 16281.19, 66},
    {1, 16250.80, 16298.93, 51},
    {1, 16224.79, 16301.91, 49},
    {1, 16206.46, 16313.54, 39},
    {1, 16189.04, 16307.65, 34},
    {1, 16214.10, 16285.48, 26},
    {1, 16218.45, 16281.15, 21}
}


local GMIslandTest = {
    {1, 16218.30, 16277.84, 25},
    {1, 16206.73, 16251.14, 32},
    {1, 16228.76, 16230.82, 42},
    {1, 16266.93, 16246.27, 63},
    {1, 16275.62, 16281.19, 66},
    {1, 16250.80, 16298.93, 51},
    {1, 16224.79, 16301.91, 49},
    {1, 16206.46, 16313.54, 39},
    {1, 16189.04, 16307.65, 34},
    {1, 16214.10, 16285.48, 26},
    {1, 16218.45, 16281.15, 21}
}


function Flight_Master_OnGossipTalk(pUnit, event, player, pMisc)
	pUnit:GossipCreateMenu(50, player, 0)
	pUnit:GossipMenuAddItem(9, "Show Me Where I Can fly.", 1, 0)
	pUnit:GossipMenuAddItem(4, "Show Me What Else You Have To Offer.", 5, 0)
	pUnit:GossipMenuAddItem(9, "Never Mind", 2, 0)
	pUnit:GossipSendMenu(player)
end


function Flight_Master_OnGossipSelect(pUnit, event, player, id, intid, code, pMisc)
	if (intid == 1) then
		pUnit:GossipCreateMenu(50, player, 0)
		pUnit:GossipMenuAddItem(9, "Custom Location", 3, 0, "The Cost: 1 Shadowmourne")
		pUnit:GossipMenuAddItem(9, "GM Island Joy Ride", 4, 0, "The Cost: 1 Shadowmourne", 100)
		pUnit:GossipMenuAddItem(9, "Never Mind", 2, 0)
		pUnit:GossipSendMenu(player)
	end

	if (intid == 2) then
		player:GossipComplete()
	end

	if (intid == 3) then
		if (player:IsInCombat()==true) then
			player:SendAreaTriggerMessage("You are in combat!")
		elseif (player:GetItemCount(item1id)) > 0 then
			CustomFlightPath = LuaTaxi:CreateTaxi() 
			for i = 1, #MyFlightPath do
			     MYFP = MyFlightPath[i]
		             CustomFlightPath:AddPathNode(MYFP[1], MYFP[2], MYFP[3], MYFP[4])
			end 
			player:RemoveItem(item1id, 1)
			player:StartTaxi(CustomFlightPath, GetDisplay)
		else
			player:SendAreaTriggerMessage("You do not have the required item in your inventory!")
		end
			player:GossipComplete()
	end

	if (intid == 4) then
             GMIslandJoy = LuaTaxi:CreateTaxi() 
             for i = 1, #GMIslandTest do
	          local GMFP = GMIslandTest[i]
	          GMIslandJoy:AddPathNode(GMFP[1], GMFP[2], GMFP[3], GMFP[4])
             end 
             player:DealGoldCost(100)
             player:StartTaxi(GMIslandJoy, GetDisplay)
             player:GossipComplete()
	end

	if (intid == 5) then
		pUnit:GossipCreateMenu(50, player, 0)
		pUnit:GossipMenuAddItem(4, "Weather", 6, 0)
		pUnit:GossipMenuAddItem(5, "Queue Me For A Battleground!", 7, 0)
		pUnit:GossipMenuAddItem(5, "Show Me The Money!", 8, 0)
		pUnit:GossipMenuAddItem(5, "Screw the Battlegrounds, give me honor! (200 honor)", 9, 0, "The Cost:", 2000000)
		pUnit:GossipMenuAddItem(9, "Never Mind", 2, 0)
		pUnit:GossipSendMenu(player)
	end

	if (intid == 6) then
		pUnit:GossipCreateMenu(50, player, 0)
		pUnit:GossipMenuAddItem(6, "Sunny", 10, 0)
		pUnit:GossipMenuAddItem(6, "Foggy", 11, 0, "The Cost:", 20000)
		pUnit:GossipMenuAddItem(6, "Rainy", 12, 0, "The Cost:", 23000)
		pUnit:GossipMenuAddItem(6, "Monsoon", 13, 0, "The Cost:", 25000)
		pUnit:GossipMenuAddItem(6, "Snowy", 14, 0 , "The Cost:", 34000)
		pUnit:GossipMenuAddItem(6, "Sandstorm", 15, 0, "The Cost:", 22000)
		pUnit:GossipMenuAddItem(9, "Never Mind", 2, 0)
		pUnit:GossipSendMenu(player)
	end

	if (intid == 9) then
        player:DealGoldCost(2000000)
        player:GiveHonor(200)
        player:GossipComplete()
	end

	if (intid == 10) then
        player:SetPlayerWeather(0, 1)
        player:GossipComplete()
	end

	if (intid == 11) then
        player:DealGoldCost(20000)
        player:SetPlayerWeather(1, 1)
        player:GossipComplete()
	end

	if (intid == 12) then
        player:DealGoldCost(23000)
        player:SetPlayerWeather(2, 1)
        player:GossipComplete()
	end

	if (intid == 13) then
        player:DealGoldCost(25000)
        player:SetPlayerWeather(4, 1)
        player:GossipComplete()
	end

	if (intid == 14) then
        player:DealGoldCost(34000)
        player:SetPlayerWeather(8, 1)
        player:GossipComplete()
	end

	if (intid == 15) then
        player:DealGoldCost(22000)
        player:SetPlayerWeather(16, 1)
        player:GossipComplete()
	end

	if (intid == 8) then
        player:SendBankWindow(player)
        player:GossipComplete()
	end  
end

RegisterCreatureGossipEvent(NPCID, 1, Flight_Master_OnGossipTalk)
RegisterCreatureGossipEvent(NPCID, 2, Flight_Master_OnGossipSelect)
 

Lightning Blade

BETA Tester
What you are making a elseif statment like you did here

Code:
elseif (player:GetItemCount(item1id)) > 0 then

You have to put the whole code inside of (), basically it would look like this

Code:
elseif (player:GetItemCount(item1id) > 0) then

I can't promis you this is the only error, it was just one that caught my attention.
 

Foereaper

Founder
The above is irrelevant Lightning Blade, it has no technical impact on the code itself.

The issue is your function arguments, they are in the wrong order. Eluna uses a different argument list for its functions compared to arc . The correct arguments can be found on the wiki.
 

Rochet2

Moderator / Eluna Dev
You are using arcemu style code way too much.

Here is an example gossip script to help you understand how it all works:
https://github.com/ElunaLuaEngine/Scripts/blob/master/Example Scripts/example_gossip.lua

And here is what you did wrong:
1. The pUnit variable being a number:
See the right parameter order here for the hooks:
https://github.com/ElunaLuaEngine/Eluna/blob/master/HookMgr.h#L264
event ALWAYS comes first on eluna. So whatever hook you have, the event number will be passed first for the function hooked to the event.

2. Trinitycore and mangos, and thus also Eluna.. all use player to build the gossip menu.
This means that you use player:GossipMenuAddItem(...) and player:GossipSendMenu(...)
See more about the gossip methods here:
https://github.com/ElunaLuaEngine/Eluna/blob/master/LuaFunctions.cpp#L592

3. There is no pUnit:GossipCreateMenu(50, player, 0) method.
On TC and mangos and thus on Eluna, the text ID (50), will be passed with player:GossipSendMenu.
https://github.com/ElunaLuaEngine/Eluna/blob/master/LuaFunctions.cpp#L593

4. The arguments to GossipMenuAddItem are slightly different from arcemu.
Arcemu: :GossipMenuAddItem(Icon, "Name", intid, code[, messagebox, gold])
Eluna: :GossipMenuAddItem(icon, msg, sender, intid[, code, popup, money])
Notice the small difference that sender is right before intid. So there is one extra value there.
Both sender and intid work the same way. They are just passed onto the OnGossipSelect hook.

5. There is no GMIslandJoy = LuaTaxi:CreateTaxi()
The correct way of doing taxi is this (this is a small example of how to)
Notice how the path is added ONCE in the script and then in the code just the pathID is used to start the path for any player who comes by.
Code:
local waypoints = {
    {map, x, y, z}, -- this should be at / very near the spot where you use player:StartTaxi(pathid) on the player
    {map, x, y, z},
    {map, x, y, z},
    {map, x, y, z},
}
local pathid = AddTaxiPath(waypoints, 541, 541) -- these mountIDs are NPC entries

local function OnGossipHello(event, player, creature)
    player:StartTaxi(pathid)
end

RegisterCreatureGossipEvent(123123, 1, OnGossipHello)
functions:
https://github.com/ElunaLuaEngine/Eluna/blob/master/LuaFunctions.cpp#L100
https://github.com/ElunaLuaEngine/Eluna/blob/master/LuaFunctions.cpp#L677

6. DealGoldCost doesnt exist.
Use player:ModifyMoney(amount) with negative amount instead.
https://github.com/ElunaLuaEngine/Eluna/blob/master/LuaFunctions.cpp#L605

7. There is no SetPlayerWeather.
Currently there are functions only to change the weather for all players.
You will need to construct your own packets with CreatePacket(...) and packet methods.
Functions:
https://github.com/ElunaLuaEngine/Eluna/blob/master/LuaFunctions.cpp#L105

https://github.com/ElunaLuaEngine/Eluna/blob/master/LuaFunctions.cpp#L92
https://github.com/ElunaLuaEngine/Eluna/blob/master/LuaFunctions.cpp#L1086

8. There is no SendBankWindow.
It is player:SendShowBank(WorldObject)
WorldObject can be any world object (player,creature, gameobject etc)
Notice that with recent TC check changes you cant use player as sender without being GM or having some permissions I guess.
This was/is a vulnerability in all cores before the change. (arc, mangos, TC)
https://github.com/ElunaLuaEngine/Eluna/blob/master/LuaFunctions.cpp#L670

9. I would greatly suggest adding the keyword local before your functions like so:
local function MyFunc()
end
This will make them .. local.
I suggest you read this:
http://emudevs.com/showthread.php/2471-Lua-tips-and-tricks

Do report back if you dont understand something or need help with something etc.
:)
 
Last edited:

Teryaki

Exalted Member
Thank you for the quick responses! I will definitely take a second look at the code with the tips you all gave when I get home later this afternoon. If I run into any other problems I will let you know, I figured it was still too much of an ArcEmu-like script but I wasn't sure where to begin the process of converting it all the way so Eluna can register it. I had this code just laying around, I am not sure why I had the weather and send bank windows in the script, I believe it was just an NPC that I was tsting out to see how these functions worked on ArcEmu, but like you said there is no weather change for single players; so I will probably end up removing both the weather and the bank window all together to just get the flight path working, and probably test out those other features in another script. I am hoping that converting this script will help me with some of the other scripts I had on my ArcEmu server and get them converted to work on TrinityCore. I hope to start contributing to this community as well once I have learned how to use Eluna. Thanks again!
 
Status
Not open for further replies.
Top