EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   Quests::LUA (https://www.eqemulator.org/forums/forumdisplay.php?f=680)
-   -   TakeMoneyFromPP() not working for this script (https://www.eqemulator.org/forums/showthread.php?t=42178)

irongut_av 11-16-2018 12:50 PM

TakeMoneyFromPP() not working for this script
 
I've tried to use TakeMoneyFromPP() in Lua, in several different scripts and can't seem to get it working. I'm using an EQEMU version from October. Perhaps I'm just doing it wrong.

Example from global\global_player.lua (there is no global_player.pl):


Code:

function event_enter_zone(e)
  if(e.self:GetName() == "Raccoon") then
    if(e.self:TakeMoneyFromPP(1000, true)) then
      e.self:Message(14,"Thanks for the cash!")
    else
      e.self:Message(14,"You're broke, sucker!")
    end
  end
end


Kingly_Krab 11-16-2018 01:01 PM

Value is in copper. I.E the 1,000 you have is 1 Platunum, not 1,000 Platinum. For 1,000 you’d need to put 1,000,000 there.

irongut_av 11-16-2018 01:09 PM

Thanks for the reply... I understand about the value being copper.

The problem is that no money is being taken at all. The method is not returning a Boolean, and no message is shown to the entering client that has the proper name. I wanted to know if this script will fire on someone else's server, of course checking for a different client name, etc.


Edit: I've updated the script, to verify the event is firing correctly... and it does:
Code:

function event_enter_zone(e)
  if(e.self:GetName() == "Raccoon") then
    e.self:Message(14, "Hi Raccoon")
    if(e.self:TakeMoneyFromPP(1000, true)) then
      e.self:Message(14,"Thanks for the cash!")
    else
      e.self:Message(14,"You're broke, sucker!")
    end
  end
end


The only message I see with my test client is "Hi Raccoon". I don't see either of the 'if' statement branch messages, with no money taken.

irongut_av 11-16-2018 02:12 PM

Looks like I figured out the problem:

zone/lua_client.h
Code:

bool TakeMoneyFromPP(uint64 copper);
bool TakeMoneyFromPP(uint64 copper, bool update_client);

When I changed the param from uint64 to uint32, as well as the lua binding call from uint64 to uint32 , it worked.

The wrapped client function still uses uint64, so I just a cast inside of it:

Code:


bool Lua_Client::TakeMoneyFromPP(uint32 copper)
{
        Lua_Safe_Call_Bool();
        return self->TakeMoneyFromPP(static_cast<uint64>(copper));
}

bool Lua_Client::TakeMoneyFromPP(uint32 copper, bool update_client)
{
        Lua_Safe_Call_Bool();
        return self->TakeMoneyFromPP(static_cast<uint64>(copper), update_client);
}


.def("TakeMoneyFromPP", (bool(Lua_Client::*)(uint32))&Lua_Client::TakeMoneyFromPP)
.def("TakeMoneyFromPP", (bool(Lua_Client::*)(uint32, bool))&Lua_Client::TakeMoneyFromPP)
...


Uleat 11-16-2018 05:42 PM

I think your original problem was that you were trying to call a client function off of an entity/mob object.

You would either need to pull the client pointer from entity list or cast e to client - after an IsClient() check.

I could be wrong...

irongut_av 11-17-2018 09:14 PM

Quote:

Originally Posted by Uleat (Post 260758)
I think your original problem was that you were trying to call a client function off of an entity/mob object.

You would either need to pull the client pointer from entity list or cast e to client - after an IsClient() check.

I could be wrong...

I think if it was a pointer issue, changing the bound return type from a 64 bit to 32bit unsigned int wouldn't have fixed it. I think that Lua binding doesn't like uint64 functions for some reason, at least maybe on 32 bit builds (my server build is 32 bit).

Uleat 11-18-2018 12:12 AM

Disregard..I always forget semicolons are optional in lua...


All times are GMT -4. The time now is 02:26 PM.

Powered by vBulletin®, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.