L2JMobius

C6 Custom Zone Flag

Pirsys · 5 · 4046

Offline Pirsys

  • Knight
  • ***
    • Posts: 67
hello good morning everyone, I wanted to see if you can help me finish and thus be able to test if the pvp zone is activated, it is throwing me that the zone added to the console does not exist. If you are so kind to guide me where I have to point because in theory it should work but no....!!

package org.l2jmobius.gameserver.model.zone.type;
Code: [Select]
* This file is part of the L2J Mobius project.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.l2jmobius.gameserver.model.zone.type;

import java.util.concurrent.Future;
import java.util.logging.Logger;

import org.l2jmobius.commons.threads.ThreadPool;
import org.l2jmobius.commons.util.Rnd;
import org.l2jmobius.gameserver.data.SkillTable;
import org.l2jmobius.gameserver.model.Skill;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Playable;
import org.l2jmobius.gameserver.model.actor.instance.MonsterInstance;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.zone.ZoneType;

public class CustomZone extends ZoneType
{
protected final Logger LOGGER = Logger.getLogger(CustomZone.class.getName());
protected int _skillId;
int _chance;
private int _initialDelay;
protected int _skillLevel;
private int _reuse;
boolean _enabled;
String _target;
private Future<?> _task;

public CustomZone(int id)
{
super(id);
_skillId = 1323;
_skillLevel = 1;
_chance = 100;
_initialDelay = 0;
_reuse = 30000;
_enabled = true;
_target = "pc";
}

@Override
public void setParameter(String name, String value)
{
switch (name)
{
case "skillId":
{
_skillId = Integer.parseInt(value);
break;
}
case "skillLevel":
{
_skillLevel = Integer.parseInt(value);
break;
}
case "chance":
{
_chance = Integer.parseInt(value);
break;
}
case "initialDelay":
{
_initialDelay = Integer.parseInt(value);
break;
}
case "default_enabled":
{
_enabled = Boolean.parseBoolean(value);
break;
}
case "target":
{
_target = value;
break;
}
case "reuse":
{
_reuse = Integer.parseInt(value);
break;
}
default:
{
super.setParameter(name, value);
break;
}
}
}

@Override
protected void onEnter(Creature creature)
{
if ((((creature instanceof Playable) && _target.equalsIgnoreCase("pc")) || ((creature instanceof PlayerInstance) && _target.equalsIgnoreCase("pc_only")) || ((creature instanceof MonsterInstance) && _target.equalsIgnoreCase("npc"))) && (_task == null))
{
((PlayerInstance) creature).setPvpFlag(1);
((PlayerInstance) creature).sendMessage("You entered a Pvp Flag zone.");
((PlayerInstance) creature).broadcastUserInfo();

_task = ThreadPool.scheduleAtFixedRate(new ApplySkill(/* this */), _initialDelay, _reuse);
}
}

@Override
protected void onExit(Creature creature)
{
if (getCharactersInside().isEmpty() && (_task != null))
{
((PlayerInstance) creature).setPvpFlag(0);
((PlayerInstance) creature).sendMessage("You left the Pvp Flag zone.");
((PlayerInstance) creature).broadcastUserInfo();

_task.cancel(true);
_task = null;
}
}

public Skill getSkill()
{
return SkillTable.getInstance().getSkill(_skillId, _skillLevel);
}

public String getTargetType()
{
return _target;
}

public boolean isEnabled()
{
return _enabled;
}

public int getChance()
{
return _chance;
}

public void setZoneEnabled(boolean value)
{
_enabled = value;
}

class ApplySkill implements Runnable
{
@Override
public void run()
{
if (_enabled)
{
for (Creature temp : getCharactersInside())
{
if ((temp != null) && !temp.isDead() && (((temp instanceof Playable) && _target.equalsIgnoreCase("pc")) || ((temp instanceof PlayerInstance) && _target.equalsIgnoreCase("pc_only")) || ((temp instanceof MonsterInstance) && _target.equalsIgnoreCase("npc"))) && (Rnd.get(100) < _chance))
{
final Skill skill = getSkill();
if (skill == null)
{
LOGGER.warning("ATTENTION: error on zone with id " + getId());
LOGGER.warning("Skill " + _skillId + "," + _skillLevel + " not present between skills");
}
else
{
skill.applyEffects(temp, temp, false, false, false);
}
}
}
}
}
}

@Override
public void onDieInside(Creature creature)
{
}

@Override
public void onReviveInside(Creature creature)
{
onEnter(creature);
}
}

package org.l2jmobius.gameserver.model.zone;
Code: [Select]
* This file is part of the L2J Mobius project.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.l2jmobius.gameserver.model.zone;

/**
 * Zone Ids.
 * @author Mobius
 */
public enum ZoneId
{
BOSS,
CASTLE,
CLAN_HALL,
DANGER_AREA,
FLAGZONE,
HQ,
JAIL,
MONSTER_TRACK,
MOTHERTREE,
NO_LANDING,
NO_RESTART,
NO_STORE,
NO_SUMMON_FRIEND,
OLYMPIAD,
PEACE,
        CUSTOM,
PVP,
SCRIPT,
SIEGE,
TOWN,
SWAMP,
WATER;

public static int getZoneCount()
{
return values().length;
}
}

L2J_Mobius_C6_Interlude\game\data\zones
Code: [Select]
<?xml version="1.0" encoding="utf-8"?>
<list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../xsd/zones.xsd">
<zone name="Primeval Isle" type="CustomZone" shape="NPoly" minZ="-4290" maxZ="-1290"> <!-- Primeval Isle (Town Zone) -->
<node X="10408" Y="-27395" />
<node X="12065" Y="-25334" />
<node X="12223" Y="-23159" />
<node X="10424" Y="-22340" />
<node X="9566" Y="-23131" />
<node X="9290" Y="-24261" />
<spawn X="10468" Y="-24569" Z="-3645" />
</zone>
</list>

Thank you very much to the people who collaborate, and clearly once the code works I will share it in the contributions section.


Online Mobius

  • Distinguished King
  • *****
    • Posts: 16050
No need to use taks.
Just use onEnter onExit.



Online Mobius

  • Distinguished King
  • *****
    • Posts: 16050
Try this.
Code: [Select]
Index: java/org/l2jmobius/gameserver/data/xml/ZoneData.java
===================================================================
--- java/org/l2jmobius/gameserver/data/xml/ZoneData.java (revision 9990)
+++ java/org/l2jmobius/gameserver/data/xml/ZoneData.java (working copy)
@@ -338,6 +338,11 @@
  temp = new SwampZone(zoneId);
  break;
  }
+ case "CustomZone":
+ {
+ temp = new CustomZone(zoneId);
+ break;
+ }
  }
 
  // Check for unknown type


Offline Pirsys

  • Knight
  • ***
    • Posts: 67
Perfect Mr. Mobius, now it only remains to correct some details regarding which zone each one wants to put as the flag zone. Now I share the code. Thank you very much for collaborating with me.