Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

More Lua Issue Help

Elite Diviner
Joined
Sep 12, 2020
Messages
442
Reaction score
224
Rune Analyzer Item 243520
Code:
function LuaS_243520_USE()
    local player = OwnerID();
    local npc = TargetID();
    local QuestID = 427683;
    local Item1 = 243520;    -- delete items
    local Flag = 549525;    -- request
    local requiredX, requiredY = -965.2, 167.4;    -- Replace with the desired X and Y coordinates
    local radius = 10;      -- Set the desired radius
    local GetPlayerX = requiredX
    local GetPlayerY = requiredY
 
    -- Calculate the distance between the player's location and the target location
    local distance = math.sqrt((GetPlayerX(player) - requiredX)^2 + (GetPlayerY(player) - requiredY)^2);

    -- Check if the player is within the specified radius of the target location
    if TargetID > radius then
        return false; -- Player is outside the radius, exit the function
   end

    if CheckAcceptQuest(player, QuestID) == true then
        SetFlag(player, Flag, 1);
        DelBodyItem(player, Item1, 1);

        if CountBodyItem(player, Item1) == 1 then
            SetFlag(player, Flag, 1);
            DelBodyItem(player, Item1, 1);
        end
    end

    return true;
end

ok my lua code is not the best but i can do most of the quest myself except the boss fight, anyone understand why this does not work inside the locations it gives ? help would be nice ? but it works with out the check and it should not because you can finish the quest with out going to that location .
 
Newbie Spellweaver
Joined
Aug 23, 2022
Messages
6
Reaction score
7
Hello Jane,
i sadly can directly see 4 lua problems in your function; first let me show them to you:

1) local GetPlayerX = requiredX
>> u copy the requiredX coord into the local GetPlayerX variable you will never get the right result with that.

2,3) if TargetID > radius then
>> you cannot use TargetID cause its not a variable; you can use TargetID() or your variable npc
>> what you want from the Target?? > >you only have to check "playerCoords VS requiredCoords" i think


4) GetPlayerX(player)
>> getPlayerX is only a local variable not a function; this is not how to get the player coords

Here a correct version of your function including a debug output:
Code:
function LuaS_243520_USE()
    local player = OwnerID();
    local playerX = ReadRoleValue(player,EM_RoleValue_X)
    local playerY = ReadRoleValue(player,EM_RoleValue_Y)
    local QuestID = 427683;
    local Item1 = 243520;    -- delete items
    local Flag = 549525;    -- request
    local requiredX, requiredY = -965.2, 167.4;    -- X and Y coord we need
    local radius = 10;

    local distance = math.sqrt((playerX - requiredX)^2 + (playerY - requiredY)^2); -- distance between player and required coords

    if distance > radius then
        ScriptMessage( OwnerID(),OwnerID(),1,"Not close enough, distance is " .. distance,0) --DEBUG OUTPUT   
        return false; -- Player is outside the radius, exit the function
   end

    if CheckAcceptQuest(player, QuestID) == true then
        SetFlag(player, Flag, 1);
        DelBodyItem(player, Item1, 1);

        if CountBodyItem(player, Item1) == 1 then
            SetFlag(player, Flag, 1);
            DelBodyItem(player, Item1, 1);
        end
    end

    return true;
end
 
Upvote 0
Back
Top