Jump to content

Same guild function


Go to solution Solved by VegaS™,

Recommended Posts

  • Gold

Hey guys,

have someone function is same guild? What I need? I need to check if target player have the same guild as me.

I tried something like this:

local x, y, targetGuild = pc.get_x() * 100, pc.get_y() * 100, pc.get_guild()

But it didn't work when I tried to use this:

if targetGuild != pc.get_guild() then

Thanks for answers!


Sincerely,

ReFresh

I'll be always helpful! 👊 

Link to comment
Share on other sites

  • Premium

You need to compare the guild of 2 players and see if they're the same guild?

1. Declare an empty variable that will store the guild of the target player. (e.s. local target_player_guild;)

2. Declare a variable that stores your own vid. (e.s. local player_vid = pc.get_vid();)

3. Get Target player's vid. (e.s. local target_vid = npc.get_vid();) #When to trigger it is up to you :shrugs:

4. Select his vid (pc.select(target_vid);)

5. set target_player_guild = pc.get_guild();

6. Go back to your vid. (pc.select(player_vid);)

7. 

if (target_player_guild == pc.get_guild()) then
	-- do things.
end -- if

 

  • Love 1

 

"Nothing's free in this life.

Ignorant people have an obligation to make up for their ignorance by paying those who help them.

Either you got the brains or cash, if you lack both you're useless."

Syreldar

Link to comment
Share on other sites

  • Forum Moderator
  • Solution

If you want to compare the guild of 2 players and see if they're in the same guild you should do a global function for LUA, which can be used everywhere.

  • Src/Server/game/src/questlua_global.cpp
Spoiler

// Search for:
	ALUA(_get_locale)
	{
		lua_pushstring(L, g_stLocale.c_str());
		return 1;
	}
// Add after:
	ALUA(_is_same_guild)
	{
		if (!lua_isstring(L, 1) || !lua_isstring(L, 2))
		{
			sys_err("invalid argument");
			lua_pushboolean(L, 0);
			return 1;
		}

		// Get name of players (arg1, arg2).
		const std::string c_rstrName = lua_tostring(L, 1);
		const std::string c_rstrTargetName = lua_tostring(L, 2);
		
		// Get character pointer by name.
		const LPCHARACTER pkChr = CHARACTER_MANAGER::instance().FindPC(c_rstrName.c_str());
		const LPCHARACTER pkChrTarget = CHARACTER_MANAGER::instance().FindPC(c_rstrTargetName.c_str());

		// Check if players are in a guild and if they're same.
		if ((pkChr && pkChrTarget) && (pkChr->GetGuild() && pkChrTarget->GetGuild()))
		{
			lua_pushboolean(L, pkChr->GetGuild() == pkChrTarget->GetGuild());
		}
		else
		{
			lua_pushboolean(L, 0);
		}

		return 1;
	}

// Search for:
			{	"get_locale",				_get_locale				},
// Add after:
			{	"is_same_guild",			_is_same_guild			},

 

  • share/locale/germany/quest_function
Spoiler

is_same_guild

 

  • quest_example.lua
Spoiler

local name = pc.get_name()
local target_name = "UnknownName"

if (is_same_guild(name, target_name)) then
  -- They're in the same guild.
else
  -- They aren't in the same guild.
end

 

 

  • Love 2
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

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.