Forums WoW Modding Support Archives WoWModding Threads [DiscordArchive] LF help with script which using item about tele...

[DiscordArchive] LF help with script which using item about tele...

[DiscordArchive] LF help with script which using item about tele...

rektbyfaith
Administrator
0
12-22-2024, 04:35 PM
#1
Archived author: Needle • Posted: 2024-12-22T16:35:25.121000+00:00
Original source

rektbyfaith
12-22-2024, 04:35 PM #1

Archived author: Needle • Posted: 2024-12-22T16:35:25.121000+00:00
Original source

rektbyfaith
Administrator
0
12-22-2024, 04:35 PM
#2
Archived author: Needle • Posted: 2024-12-22T16:35:26.768000+00:00
Original source

Thread automatically created by Funnye in <#415944535718494208>
rektbyfaith
12-22-2024, 04:35 PM #2

Archived author: Needle • Posted: 2024-12-22T16:35:26.768000+00:00
Original source

Thread automatically created by Funnye in <#415944535718494208>

rektbyfaith
Administrator
0
12-22-2024, 04:35 PM
#3
Archived author: Funnye • Posted: 2024-12-22T16:35:39.920000+00:00
Original source

thats the script which i am using
Custom_ITEM_Friend_Porter.lua
rektbyfaith
12-22-2024, 04:35 PM #3

Archived author: Funnye • Posted: 2024-12-22T16:35:39.920000+00:00
Original source

thats the script which i am using
Custom_ITEM_Friend_Porter.lua

rektbyfaith
Administrator
0
12-22-2024, 04:36 PM
#4
Archived author: Funnye • Posted: 2024-12-22T16:36:14.408000+00:00
Original source

working on 50% but when u click at the options got that error : scripts\Custom_ITEM_Friend_Porter.lua:42: attempt to call method 'GetMapId' (a nil value)
[Image: image.png?ex=690c25be&is=690ad43e&hm=439...e0fbb0f13&]
rektbyfaith
12-22-2024, 04:36 PM #4

Archived author: Funnye • Posted: 2024-12-22T16:36:14.408000+00:00
Original source

working on 50% but when u click at the options got that error : scripts\Custom_ITEM_Friend_Porter.lua:42: attempt to call method 'GetMapId' (a nil value)
[Image: image.png?ex=690c25be&is=690ad43e&hm=439...e0fbb0f13&]

rektbyfaith
Administrator
0
12-22-2024, 04:47 PM
#5
Archived author: Deleted User • Posted: 2024-12-22T16:47:51.324000+00:00
Original source

Running the code through ChatGPT returns potential fixes
rektbyfaith
12-22-2024, 04:47 PM #5

Archived author: Deleted User • Posted: 2024-12-22T16:47:51.324000+00:00
Original source

Running the code through ChatGPT returns potential fixes

rektbyfaith
Administrator
0
12-22-2024, 04:48 PM
#6
Archived author: Deleted User • Posted: 2024-12-22T16:48:28.224000+00:00
Original source

The error message indicates that the GetMapId method is being called on a nil value, which means it's trying to access an object or table that doesn't exist.
In your case, this issue arises when you're checking if targetPlayer has a valid map ID. The problem lies in these lines:
```


mapId = targetPlayer:GetMapId() -- Attempt to retrieve map ID again
if not mapId then
print("Error: Failed to retrieve map ID from target player. Defaulting to player's current map ID.")
mapId = player:GetMapId()
print("Using Player's Current Map ID:", mapId) -- Debug
end

mapId = targetPlayer:GetMapId() -- This line is unnecessary and causes the error.```

You're trying to call GetMapId on both targetPlayer (which doesn't exist in this context, as you've already retrieved it with player:GetClosestPlayer() or player:GetRandomPlayer(0)) and then again on targetPlayer. This is causing the error because targetPlayer is nil.
Here's how to fix your code:
rektbyfaith
12-22-2024, 04:48 PM #6

Archived author: Deleted User • Posted: 2024-12-22T16:48:28.224000+00:00
Original source

The error message indicates that the GetMapId method is being called on a nil value, which means it's trying to access an object or table that doesn't exist.
In your case, this issue arises when you're checking if targetPlayer has a valid map ID. The problem lies in these lines:
```


mapId = targetPlayer:GetMapId() -- Attempt to retrieve map ID again
if not mapId then
print("Error: Failed to retrieve map ID from target player. Defaulting to player's current map ID.")
mapId = player:GetMapId()
print("Using Player's Current Map ID:", mapId) -- Debug
end

mapId = targetPlayer:GetMapId() -- This line is unnecessary and causes the error.```

You're trying to call GetMapId on both targetPlayer (which doesn't exist in this context, as you've already retrieved it with player:GetClosestPlayer() or player:GetRandomPlayer(0)) and then again on targetPlayer. This is causing the error because targetPlayer is nil.
Here's how to fix your code:

rektbyfaith
Administrator
0
12-22-2024, 04:48 PM
#7
Archived author: Deleted User • Posted: 2024-12-22T16:48:43.864000+00:00
Original source

```


-- Function to handle menu selection
function Item_OnSelect(item, event, player, sender, intid, code)
print("Item_OnSelect called with intid:", intid) -- Debug
local targetPlayer, mapId, x, y, z, o

if intid == 1 then
print("Teleporting to closest player") -- Debug
targetPlayer = player:GetClosestPlayer()
elseif intid == 2 then
print("Teleporting to random nearby player") -- Debug
targetPlayer = player:GetRandomPlayer(0)
elseif intid == 3 then
print("Player canceled the menu") -- Debug
player:GossipComplete()
return
end

if not targetPlayer then
print("No players nearby") -- Debug
player:SendAreaTriggerMessage("No players nearby to teleport to.")
player:GossipComplete()
return
end

x, y, z = targetPlayer:GetX(), targetPlayer:GetY(), targetPlayer:GetZ()
o = targetPlayer:GetO()

mapId = targetPlayer:GetMapId() -- Get the map ID from the retrieved target player.

if not mapId then
print("Error: Failed to retrieve map ID. Defaulting to player's current map ID.")
mapId = player:GetMapId()
print("Using Player's Current Map ID:", mapId) -- Debug
end

if not x or not y or not z or not o then
print("Error: Invalid target player position data") -- Debug
player:SendAreaTriggerMessage("Failed to retrieve target player position data.")
player:GossipComplete()
return
end

if not player:HasItem(20857) then
print("Player does not have the required item") -- Debug
player:SendAreaTriggerMessage("You don't have the required item (20857) to teleport.")
player:GossipComplete()
return
end

player:RemoveItem(20857, 1)
player:Teleport(mapId, x, y, z, o)
player:SendAreaTriggerMessage("You have been teleported to the target. Item 20857 has been consumed.")
player:GossipComplete()
end```
rektbyfaith
12-22-2024, 04:48 PM #7

Archived author: Deleted User • Posted: 2024-12-22T16:48:43.864000+00:00
Original source

```


-- Function to handle menu selection
function Item_OnSelect(item, event, player, sender, intid, code)
print("Item_OnSelect called with intid:", intid) -- Debug
local targetPlayer, mapId, x, y, z, o

if intid == 1 then
print("Teleporting to closest player") -- Debug
targetPlayer = player:GetClosestPlayer()
elseif intid == 2 then
print("Teleporting to random nearby player") -- Debug
targetPlayer = player:GetRandomPlayer(0)
elseif intid == 3 then
print("Player canceled the menu") -- Debug
player:GossipComplete()
return
end

if not targetPlayer then
print("No players nearby") -- Debug
player:SendAreaTriggerMessage("No players nearby to teleport to.")
player:GossipComplete()
return
end

x, y, z = targetPlayer:GetX(), targetPlayer:GetY(), targetPlayer:GetZ()
o = targetPlayer:GetO()

mapId = targetPlayer:GetMapId() -- Get the map ID from the retrieved target player.

if not mapId then
print("Error: Failed to retrieve map ID. Defaulting to player's current map ID.")
mapId = player:GetMapId()
print("Using Player's Current Map ID:", mapId) -- Debug
end

if not x or not y or not z or not o then
print("Error: Invalid target player position data") -- Debug
player:SendAreaTriggerMessage("Failed to retrieve target player position data.")
player:GossipComplete()
return
end

if not player:HasItem(20857) then
print("Player does not have the required item") -- Debug
player:SendAreaTriggerMessage("You don't have the required item (20857) to teleport.")
player:GossipComplete()
return
end

player:RemoveItem(20857, 1)
player:Teleport(mapId, x, y, z, o)
player:SendAreaTriggerMessage("You have been teleported to the target. Item 20857 has been consumed.")
player:GossipComplete()
end```

rektbyfaith
Administrator
0
12-22-2024, 04:48 PM
#8
Archived author: Deleted User • Posted: 2024-12-22T16:48:45.442000+00:00
Original source

This revised code retrieves targetPlayer once and uses its properties as needed without trying to call methods on it again.
rektbyfaith
12-22-2024, 04:48 PM #8

Archived author: Deleted User • Posted: 2024-12-22T16:48:45.442000+00:00
Original source

This revised code retrieves targetPlayer once and uses its properties as needed without trying to call methods on it again.

rektbyfaith
Administrator
0
12-22-2024, 05:13 PM
#9
Archived author: Funnye • Posted: 2024-12-22T17:13:27.597000+00:00
Original source

still nothing hm
rektbyfaith
12-22-2024, 05:13 PM #9

Archived author: Funnye • Posted: 2024-12-22T17:13:27.597000+00:00
Original source

still nothing hm

rektbyfaith
Administrator
0
12-22-2024, 07:08 PM
#10
Archived author: Needle • Posted: 2024-12-22T19:08:55.163000+00:00
Original source

Thread was archived by Funnye. Anyone can send a message to unarchive it.
rektbyfaith
12-22-2024, 07:08 PM #10

Archived author: Needle • Posted: 2024-12-22T19:08:55.163000+00:00
Original source

Thread was archived by Funnye. Anyone can send a message to unarchive it.

Recently Browsing
 1 Guest(s)
Recently Browsing
 1 Guest(s)