Jump to content
×
×
  • Create New...
  • 0

[C++] Error with 2 functions


rafa23alzira

Question

Hi, i create 2 functions for questlua_guild but no function.

 

My c++ level is -1  :blink:

 

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  :huh:

	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

4 answers to this question

Recommended Posts

  • 0
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.

  • Love 1
Link to comment
Share on other sites

  • 0
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 by rafa23alzira
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.