rafa23alzira 0 Posted April 17, 2015 Share Posted April 17, 2015 Hi, i create 2 functions for questlua_guild but no function. My c++ level is -1 First function: guild.get_gold() - For get the gold of guild, no return nothing. int guild_get_gold(lua_State* L) { luaL_checknumber(L, 1); CGuild * pkGuild = CGuildManager::instance().FindGuild((DWORD) lua_tonumber(L, 1)); if (pkGuild) lua_pushnumber(L, pkGuild->GetGuildMoney()); else lua_pushnumber(L, 0); return 1; } Second function: guild.change_money() For change the money of guild, crash server int guild_change_money(lua_State * L) { int gold = (int)lua_tonumber(L, -1); //LPCHARACTER ch = q.GetCurrentCharacterPtr(); CGuild * pkGuild = CGuildManager::instance().FindGuild((DWORD) lua_tonumber(L, 1)); if (gold + pkGuild->GetGuildMoney() < 0) sys_err("QUEST wrong ChangeGold %d (now %d)", gold, pkGuild->GetGuildMoney()); else{ DBManager::instance().Query("UPDATE guild%s SET gold=%d WHERE name = '%s'", get_table_postfix(), gold, pkGuild->GetName()); } return 0; } Game compile perfect. Thanks Link to comment Share on other sites More sharing options...
Active Member hachiwari 138 Posted April 17, 2015 Active Member Share Posted April 17, 2015 (1) How did you use guild.get_gold function? You will use: guild.get_gold(pc.get_guild()) (2) Show me syserr when server crash. (with auth, db and game) Link to comment Share on other sites More sharing options...
rafa23alzira 0 Posted April 17, 2015 Author Share Posted April 17, 2015 Thanks hachiwari, now 2 functions is correct, but in change_money when use the money change in database but no in game, if after use guild.get_gold return the old money. Link to comment Share on other sites More sharing options...
Solution Denis 1477 Posted April 17, 2015 Solution Share Posted April 17, 2015 int guild_get_gold(lua_State* L) { LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr(); if(ch && ch->GetGuild()) { CGuild * pkGuild = CGuildManager::instance().FindGuild(ch->GetGuild()->GetID()); if(pkGuild) lua_pushnumber(L, pkGuild ? pkGuild->GetGuildMoney() : 0); } return 1; } int guild_change_money(lua_State * L) { int gold = (int)lua_tonumber(L, 1); LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr(); if(ch && ch->GetGuild()) { CGuild * pkGuild = CGuildManager::instance().FindGuild(ch->GetGuild()->GetID()); if(pkGuild && gold > 0) pkGuild->RecvMoneyChange(gold); } return 1; } With these you don't need to pass any arguments so just call them like that: when 20091.click with pc.has_guild() begin local s = select("Get guild gold","Change guild gold","Exit") if s == 1 then say(string.format("Your guild gold: %s",guild.get_gold())) end else if s == 2 then say("Enter your amount") local gold = input("") if type(gold) == "number" then guild.change_gold(gold) say_reward(string.format("Your new guild gold ammount is: %s",guild.get_gold())) else say_reward("Only numbers are allowed") end end end I didn't really test these functions but I guess they should work. 1 Link to comment Share on other sites More sharing options...
rafa23alzira 0 Posted April 17, 2015 Author Share Posted April 17, 2015 (edited) int guild_get_gold(lua_State* L) { LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr(); if(ch && ch->GetGuild()) { CGuild * pkGuild = CGuildManager::instance().FindGuild(ch->GetGuild()->GetID()); if(pkGuild) lua_pushnumber(L, pkGuild ? pkGuild->GetGuildMoney() : 0); } return 1; } int guild_change_money(lua_State * L) { int gold = (int)lua_tonumber(L, 1); LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr(); if(ch && ch->GetGuild()) { CGuild * pkGuild = CGuildManager::instance().FindGuild(ch->GetGuild()->GetID()); if(pkGuild && gold > 0) pkGuild->RecvMoneyChange(gold); } return 1; } With these you don't need to pass any arguments so just call them like that: when 20091.click with pc.has_guild() begin local s = select("Get guild gold","Change guild gold","Exit") if s == 1 then say(string.format("Your guild gold: %s",guild.get_gold())) end else if s == 2 then say("Enter your amount") local gold = input("") if type(gold) == "number" then guild.change_gold(gold) say_reward(string.format("Your new guild gold ammount is: %s",guild.get_gold())) else say_reward("Only numbers are allowed") end end end I didn't really test these functions but I guess they should work. Thanks, after test edit this comment Edit: Thanks Denis, function perfect Edited April 18, 2015 by rafa23alzira Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now