Page 1 of 1

fuction searchs jail pe0ple problem

Posted: Mon Oct 26, 2009 9:29 pm
by darkzonenet
public boolean isLeaderInJail(int playerId)
{
boolean jailed = false;
for (L2PcInstance player : L2World.getAllPlayers())
{
if (player != null && player.getObjectId() == playerId)
{
jailed = player.isInJail();
}
}
return jailed;
}

Dear Member of l2j community,

this should check if a player is in jail. i am using it in siege.java like if (isLeaderInJail(getCastle().getOwnerId())) ... .but it doesn't work. all time fuctions send 0.

any ideas or suggestion for an other coding way or fix the current one?

Regards

Re: fuction searchs jail pe0ple problem

Posted: Mon Oct 26, 2009 9:42 pm
by Probe
castle.getOwnerId() returns the id of the owning clan, not its leader.
try using:

Code: Select all

L2Clan owningClan = ClanTable.getInstance().getClan(castle.getOwnerId());int leaderId = owningClan.getLeader().getObjectId();if (isLeaderInJail(leaderId)).....

Re: fuction searchs jail pe0ple problem

Posted: Mon Oct 26, 2009 9:49 pm
by janiii
if he has already the leader player instance, he doesnt need to get its object id and then loop all players in game again to search for the player instance. when having the ownerclan.getLeader() just check isInJail() on it.

Code: Select all

L2Clan owningClan = ClanTable.getInstance().getClan(castle.getOwnerId());boolean leaderIsInJail = false;if (owningClan != null && owningClan.getLeader() != null)    leaderIsInJail = owningClan.getLeader().isInJail();.....

Re: fuction searchs jail pe0ple problem

Posted: Mon Oct 26, 2009 9:53 pm
by Probe
didn't want to make him feel like he worked for nothing ;)

Re: fuction searchs jail pe0ple problem

Posted: Mon Oct 26, 2009 10:07 pm
by darkzonenet
i have problem with that with compiler :

L2Clan owningClan = ClanTable.getInstance().getClan(castle.getOwnerId());

i have it like that :

public void registerAttacker(L2PcInstance player, boolean force)
{
if (player.getClan() == null)
return;
int allyId = 0;
L2Clan owningClan = ClanTable.getInstance().getClan(castle.getOwnerId());
int leaderId = owningClan.getLeader().getObjectId();

if (getCastle().getOwnerId() != 0)
allyId = ClanTable.getInstance().getClan(getCastle().getOwnerId()).getAllyId();

if (isLeaderInJail(leaderId)
.............................
.............................
....................
}

Re: fuction searchs jail pe0ple problem

Posted: Mon Oct 26, 2009 10:41 pm
by Probe
did you import
net.sf.l2j.gameserver.DataTables.ClanTable;

its best if you drop the method you made and do what janiii suggested.

Code: Select all

 public void registerAttacker(L2PcInstance player, boolean force){       if (player.getClan() == null)            return;       L2Clan owningClan = ClanTable.getInstance().getClan(getCastle().getOwnerId());       int leaderId = owningClan.getLeader().getObjectId();        if (getCastle().getOwnerId() != 0) // not sure why you need this?              allyId = ClanTable.getInstance().getClan(getCastle().getOwnerId()).getAllyId();         if (owningClan.getLeader().getPlayerInstance().isInJail())            ....

Re: fuction searchs jail pe0ple problem

Posted: Mon Oct 26, 2009 10:50 pm
by darkzonenet
i found it it needs getCastle :)

btw your way is sending the castles owner id right?

Re: fuction searchs jail pe0ple problem

Posted: Mon Oct 26, 2009 10:58 pm
by Probe
oh yea you're right :D
player.getClan().getOwner().getPlayerInstance().isInJail()

for the player's clan leader

Re: fuction searchs jail pe0ple problem

Posted: Tue Oct 27, 2009 8:29 am
by darkzonenet
again fuction didn't work.


L2Clan owningClan = ClanTable.getInstance().getClan(castle.getOwnerId());
int leaderId = owningClan.getLeader().getObjectId();
if (isLeaderInJail(leaderId))


but the fuction again returned 0...

i want to check if the owner castle leader is in jail. shall i change something else

Re: fuction searchs jail pe0ple problem

Posted: Tue Oct 27, 2009 8:31 am
by janiii
you have to give us info. where are you running the code from? which class? how does your isLeaderInJail method looks like? but still you didnt understand that you dont need your method and you can make it more easily with Probe's code. check it what he and me wrote.

Code: Select all

if (owningClan.getLeader().getPlayerInstance().isInJail())

Re: fuction searchs jail pe0ple problem

Posted: Tue Oct 27, 2009 1:30 pm
by darkzonenet
i have it like this and it didn't work. i can not register but the leader is not in jail. if you have time check it too

Code: Select all

]public void registerAttacker(L2PcInstance player, boolean force)	{		if (player.getClan() == null)			return;		int allyId = 0;		if (getCastle().getOwnerId() != 0)			allyId = ClanTable.getInstance().getClan(getCastle().getOwnerId()).getAllyId(); 	     L2Clan owningClan = ClanTable.getInstance().getClan(getCastle().getOwnerId()); 		if(Config.IS_IN_JAIL)		{			if (owningClan.getLeader().getPlayerInstance().isInJail())			{					player.sendMessage("You can not register as an attacker because castle owner is in jail.");					return;			}		} 		if (allyId != 0)		{			if (player.getClan().getAllyId() == allyId && !force)			{				player.sendMessage("You can not register as an attacker because your alliance owns the castle.");				return;			}		}		if (force || checkIfCanRegister(player, ATTACKER))			saveSiegeClan(player.getClan(), ATTACKER, false); // Save to database	} 
in siege java

Re: fuction searchs jail pe0ple problem

Posted: Tue Oct 27, 2009 3:39 pm
by Probe
instead of

Code: Select all

if (getCastle().getOwnerId() != 0)         allyId = ClanTable.getInstance().getClan(getCastle().getOwnerId()).getAllyId();
do

Code: Select all

 allyId = owningClan.getAllyId();

Re: fuction searchs jail pe0ple problem

Posted: Tue Oct 27, 2009 4:04 pm
by darkzonenet
this do not touch the code inside the if(config.is_in_jail). why to change it?

none can register again