• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua Function getPlayerParty(cid) and getPartyMembers(leaderCid)

slaw

Software Developer
Joined
Aug 27, 2007
Messages
3,665
Solutions
125
Reaction score
1,111
Location
Germany
GitHub
slawkens
These functions I made for TFS, but it should also work for any NOT outdated source ; o

getPlayerParty(cid)
+
getPartyMembers(partyId (leaderCid))

luascript.cpp After: (it really not important where, but somewhere we must place this code :mellow:)
PHP:
	//getMonsterTargetList(cid)
	lua_register(m_luaState, "getMonsterTargetList", LuaScriptInterface::luaGetMonsterTargetList);

Add:
PHP:
	//getPlayerParty(cid)
	lua_register(m_luaState, "getPlayerParty", LuaScriptInterface::luaGetPlayerParty);

	//getPartyMembers(partyId (leaderCid))
	lua_register(m_luaState, "getPartyMembers", LuaScriptInterface::luaGetPartyMembers);

After:
PHP:
int32_t LuaScriptInterface::luaGetMonsterFriendList(lua_State* L)
Add:
PHP:
int32_t LuaScriptInterface::luaGetPlayerParty(lua_State* L)
{
	//getPlayerParty(cid)
	uint32_t cid = popNumber(L);

	ScriptEnviroment* env = getScriptEnv();

	Player* player = env->getPlayerByUID(cid);
	if(player)
	{
		Party* party = player->getParty();
		if(party)
		{
			uint32_t cid = env->addThing(party->getLeader());
			lua_pushnumber(L, cid);
		}
		else
			lua_pushnumber(L, LUA_FALSE);
	}
	else
	{
		reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND));
		lua_pushboolean(L, false);
	}

	return true;
}

int32_t LuaScriptInterface::luaGetPartyMembers(lua_State* L)
{
	//getPartyMembers(leaderId) // leaderId = partyId
	uint32_t leaderCid = popNumber(L);

	ScriptEnviroment* env = getScriptEnv();

	Player* player = env->getPlayerByUID(leaderCid);

	if(player)
	{
		Party* party = player->getParty();
		if(party)
		{
 			PlayerVector memberList = party->getMembers();
			if(!memberList.empty())
			{
				lua_newtable(L);
				for(uint16_t i = 0; i < memberList.size(); ++i)
				{
					uint32_t cid = env->addThing(memberList[i]);

					lua_pushnumber(L, ++i);
					lua_pushnumber(L, cid);
					lua_settable(L, -3);
				}
			}
			else
	    		lua_pushnumber(L, LUA_FALSE);
		}
		else
	    	lua_pushnumber(L, LUA_FALSE);
	}
	else
		lua_pushnumber(L, LUA_FALSE);

	return 1;
}

luascript.h
After:
PHP:
static int32_t luaGetMonsterFriendList(lua_State* L);
Add:
PHP:
static int32_t luaGetPlayerParty(lua_State* L);
static int32_t luaGetPartyMembers(lua_State* L);

party.h
After:
PHP:
bool isPlayerInvited(const Player* player) const;
Add:
PHP:
PlayerVector getMembers() {return memberList;}

Also i made next function to check if player A is in party with player B.
functions.lua:
PHP:
function isPlayerInParty(cid, leaderCid)
	if getPlayerParty(cid) ~= FALSE then
		if getPlayerParty(cid) == getPlayerParty(leaderCid) then
			return TRUE
		end
	end
	return FALSE
end

Example 1: (getPlayerParty usage)
PHP:
	cidTwo = getPlayerByName("Knightos")
	if getPlayerParty(cid) == getPlayerParty(cidTwo) then
		doPlayerSendCancel(cid, "Yes, these player are in one party :)")
	elseif getPlayerParty(cid) ~= FALSE then
		doPlayerSendCancel(cid, "No, player one is without party.")
	elseif getPlayerParty(cidTwo) ~= FALSE then
		doPlayerSendCancel(cid, "No, player two is without party.")
	end]]--

Example 2: (getPartyMembers)
PHP:
	membersList = getPartyMembers(cid)
	if membersList ~= FALSE then
		for i, _cid in pairs(membersList) do
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, getCreatureName(_cid))
		end
	else
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "There is no PARTY!")
	end

Im not sure how with TAGS, but on TRUNK it will work. :)
 
Last edited:
Can I use this function for (example) healing only party members? Something like area spell, which check, and heal only those players who are in area? I think it can be done in talkactions? can anybody show me a tips,examples? xD
 
No, it are just functions for party system. You can get player Id party, and members from this party. Tomorrow i'll try make somethink usefull from this ;o
 
Can I use this function for (example) healing only party members? Something like area spell, which check, and heal only those players who are in area? I think it can be done in talkactions? can anybody show me a tips,examples? xD

yes this is what i was going to use this function for, it is perfect for the spell i needed. I will try to script it today.

EDIT: im not sure yet but i think it may need more functions than just get.
 
Last edited:
Hmm, you can make command like this for healing party members: :)

!healteammembers
Code:
--config
HEALTH_ADD = 300 -- how much HP will gain every player from party


function healPartyMember(cid)
	doCreatureAddHealth(cid, HEALTH_ADD)
	doSendMagicEffect(getCreaturePos(cid), 12) 
end

function onSay(cid, words, param)
	membersList = getPartyMembers(cid)
	if membersList ~= FALSE then
		for i, _cid in pairs(membersList) do
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, getCreatureName(_cid))
			healPartyMember(_cid)
		end
	else
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Your party doesnt exist.")
	end
end
 
sorry for double post, but @slawkens :
in this way, all party memebrs will be healed, even they are very far from caster ;( can anybody make a distanse check(if it's possible... cuz I don't know ways to make this)
 
Try this:
Code:
--config
HEALTH_ADD = 300 -- how much HP will gain every player from party


function healPartyMember(cid)
	doCreatureAddHealth(cid, HEALTH_ADD)
	doSendMagicEffect(getCreaturePos(cid), 12) 
end

function onSay(cid, words, param)
	membersList = getPartyMembers(cid)
	if membersList ~= FALSE then
		for i, _cid in pairs(membersList) do
			if getDistanceBetween(getPlayerPos(cid), getPlayerPos(_cid)) < 7 then
				healPartyMember(_cid)
			end
		end
	else
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Your party doesnt exist.")
	end
end
 
Hey slawkens, where I can find this functions.lua? didn't found this file at TFS repositories..
 
Functions.lua is a file in 0.3, which isn't even in Alpha stage.
 
Is there any way to return the leader cid also?
Function getPartyMembers returns only the actual members, not the leader :(
 
Back
Top