fuction searchs jail pe0ple problem

Support for the latest build of L2J Server, get help here with installations, upgrades, problems.
Do not post bugs reports here, use viewforum.php?f=77 instead.
There is no support for other server builds than the official provided by l2jserver.com
Forum rules
READ NOW: L2j Forums Rules of Conduct
Post Reply
darkzonenet
Posts: 42
Joined: Mon Oct 26, 2009 9:22 pm

fuction searchs jail pe0ple problem

Post 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
Probe
Posts: 915
Joined: Thu Sep 03, 2009 6:36 pm
Location: Israel
Contact:

Re: fuction searchs jail pe0ple problem

Post 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)).....
User avatar
janiii
L2j Veteran
L2j Veteran
Posts: 4269
Joined: Wed May 28, 2008 3:15 pm
Location: Slovakia

Re: fuction searchs jail pe0ple problem

Post 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();.....
DO NOT EVEN TRY TO MESS WITH ME!
forum flOOder dancing dEVILoper
I don't give private support - PM will be ignored!
Probe
Posts: 915
Joined: Thu Sep 03, 2009 6:36 pm
Location: Israel
Contact:

Re: fuction searchs jail pe0ple problem

Post by Probe »

didn't want to make him feel like he worked for nothing ;)
darkzonenet
Posts: 42
Joined: Mon Oct 26, 2009 9:22 pm

Re: fuction searchs jail pe0ple problem

Post 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)
.............................
.............................
....................
}
Probe
Posts: 915
Joined: Thu Sep 03, 2009 6:36 pm
Location: Israel
Contact:

Re: fuction searchs jail pe0ple problem

Post 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())            ....
darkzonenet
Posts: 42
Joined: Mon Oct 26, 2009 9:22 pm

Re: fuction searchs jail pe0ple problem

Post by darkzonenet »

i found it it needs getCastle :)

btw your way is sending the castles owner id right?
Probe
Posts: 915
Joined: Thu Sep 03, 2009 6:36 pm
Location: Israel
Contact:

Re: fuction searchs jail pe0ple problem

Post by Probe »

oh yea you're right :D
player.getClan().getOwner().getPlayerInstance().isInJail()

for the player's clan leader
darkzonenet
Posts: 42
Joined: Mon Oct 26, 2009 9:22 pm

Re: fuction searchs jail pe0ple problem

Post 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
User avatar
janiii
L2j Veteran
L2j Veteran
Posts: 4269
Joined: Wed May 28, 2008 3:15 pm
Location: Slovakia

Re: fuction searchs jail pe0ple problem

Post 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())
DO NOT EVEN TRY TO MESS WITH ME!
forum flOOder dancing dEVILoper
I don't give private support - PM will be ignored!
darkzonenet
Posts: 42
Joined: Mon Oct 26, 2009 9:22 pm

Re: fuction searchs jail pe0ple problem

Post 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
Probe
Posts: 915
Joined: Thu Sep 03, 2009 6:36 pm
Location: Israel
Contact:

Re: fuction searchs jail pe0ple problem

Post 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();
darkzonenet
Posts: 42
Joined: Mon Oct 26, 2009 9:22 pm

Re: fuction searchs jail pe0ple problem

Post by darkzonenet »

this do not touch the code inside the if(config.is_in_jail). why to change it?

none can register again
Post Reply