Jump to content

Recommended Posts

Posted (edited)

I found this code with problem on Target the npc ,so i decide to reshare this code FIXED

 

Spoiler

/*
* 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 com.l2jfrozen.gameserver.model.actor.instance;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.Collection;
import java.util.StringTokenizer;

import com.l2jfrozen.gameserver.model.L2World;
import com.l2jfrozen.gameserver.network.serverpackets.NpcHtmlMessage;
import com.l2jfrozen.gameserver.templates.L2NpcTemplate;

import javolution.text.TextBuilder;

/**
* @author Autos! 1-0
*
*/
public class L2PscDonateInstance extends L2FolkInstance
{


public L2PscDonateInstance(int objectId, L2NpcTemplate template)
{
	super(objectId, template);

}

@Override
public void onBypassFeedback(final L2PcInstance player, String command)
  {
	      if(player == null)
	      {
	         return;
	      }
	      
	      if(command.startsWith("dlist"))
	      {
	    	  info(player);
	      }
	      if(command.startsWith("donate"))
	      {
	    	  StringTokenizer st = new StringTokenizer(command);
	    	  st.nextToken();
	    	  String amount = null;
	    	  int pin1 = 0;
	    	  int pin2 = 0;
	    	  int pin3 = 0;
	    	  int pin4 = 0;
	    	  String message = "";
	    	  
	    	  try
	    	  {
	    		 amount = st.nextToken();
	    		 pin1 = Integer.parseInt(st.nextToken());
	    		 pin2 = Integer.parseInt(st.nextToken());
	    		 pin3 = Integer.parseInt(st.nextToken());
	    		 pin4 = Integer.parseInt(st.nextToken());
	    		 while(st.hasMoreTokens())
	    			 message = message + st.nextToken() + " ";
	    		 
	    		 String fname = "data/donates/"+player.getName()+".txt";
	    		 File file = new File(fname);
	    		 boolean exist = file.createNewFile();
	    		 if(!exist)
	    		 {
	    		     player.sendMessage("You have already sent a donation , GMs must check it first");
	    		     return;
	    		 }
	    		 FileWriter fstream = new FileWriter(fname);
	    		 BufferedWriter out = new BufferedWriter(fstream);
	    		 out.write("Character Info: [Character: "+ player.getName() +"["+ player.getObjectId()+"] - Account: "+ player.getAccountName()+" - IP: "+player.getClient().getConnection().getInetAddress().getHostAddress()+"]\nMessage : donate "+ amount +" "+ message + " "+ pin1+ " "+ pin2+ " "+ pin3+ " "+ pin4);
	    		 out.close();
	    		 player.sendMessage("Donation sent. GMs will check it soon. Thanks...");
	    		 
	    		 Collection<L2PcInstance> pls = L2World.getInstance().getAllPlayers();
	    			 for (L2PcInstance gms : pls)
	    				{
	    				 	if(gms.isGM())
	    				 	gms.sendMessage(player.getName() +" sent a donation.");
	    				}
	    	  }
	    	  catch(Exception e)
	    	  {
	    		  e.printStackTrace();
	    	  }
	      }
	      
  }

  @Override
public void onAction(L2PcInstance player)
  {
    if (!canTarget(player)) {
      return;
    }
      showHtmlWindow(player);
  }

  private void showHtmlWindow(L2PcInstance activeChar)
  {
		TextBuilder tb = new TextBuilder();
		NpcHtmlMessage html = new NpcHtmlMessage(1);
		        
		tb.append("<html><head><title>Donation Manager</title></head><body><center><table width=\"250\" bgcolor=\"000000\"><tr><td align=center><font color=\"6fd3d1\">Easy Donation With Paysafe Card</font></td></tr></table>_______________________________________<br><br><table width=\"250\"><tr><td><font color=\"ddc16d\">Select Donation Amount:</font></td><td><combobox width=80 height=17 var=amount list=10-Euro;25-Euro;50-Euro;100-Euro;></td></tr></table><br><br><font color=\"ddc16d\">Paysafe Card Pin:</font><table width=\"250\"><tr><td><edit var=\"pin1\" width=50 height=12 type=number></td><td><edit var=\"pin2\" width=50 height=12 type=number></td><td><edit var=\"pin3\" width=50 height=12 type=number></td><td><edit var=\"pin4\" width=50 height=12 type=number></td></table><br><br><multiedit var=\"message\" width=240 height=40><br><br><button value=\"Donate!\" action=\"bypass -h npc_"+getObjectId()+"_donate $amount $pin1 $pin2 $pin3 $pin4 $message\" width=95 height=21 back=\"bigbutton_over\" fore=\"bigbutton\"><br><button value=\"Donation List\" action=\"bypass -h npc_"+getObjectId()+"_dlist\" width=95 height=21 back=\"bigbutton_over\" fore=\"bigbutton\"><br><font color=\"a1df64\">Created by KnipeX (if he says so, huh)</font></center></body></html>");
		        
		html.setHtml(tb.toString());
		activeChar.sendPacket(html);
  }
  
  private void info(L2PcInstance activeChar)
  {
		TextBuilder tb = new TextBuilder();
		NpcHtmlMessage html = new NpcHtmlMessage(1);
		        
		tb.append("<html><head><title>Donation Manager</title></head><body><center>Info goes here</center></body></html>");
		html.setHtml(tb.toString());
		activeChar.sendPacket(html);
  }

}

 

new class with name L2PscDonateInstance  into com.l2jfrozen.gameserver.model.actor.instance.

We find an npc or we add one to our db and we use this type L2PscDonate.

Then we go to our serverfiles and create an new folder with name Donates into gameserver/data

 

HERE IS THE FIXED CODE:

Spoiler

/*
 * 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 com.l2jfrozen.gameserver.model.actor.instance;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.Collection;
import java.util.StringTokenizer;

import com.l2jfrozen.gameserver.model.L2World;
import com.l2jfrozen.gameserver.network.serverpackets.ActionFailed;
import com.l2jfrozen.gameserver.ai.CtrlIntention;
import com.l2jfrozen.gameserver.network.serverpackets.MyTargetSelected;
import com.l2jfrozen.gameserver.network.serverpackets.ValidateLocation;
import com.l2jfrozen.gameserver.network.serverpackets.NpcHtmlMessage;
import com.l2jfrozen.gameserver.templates.L2NpcTemplate;

import javolution.text.TextBuilder;

/**
 * @author user
 *
 */
public class L2PscDonateInstance extends L2FolkInstance
{


public L2PscDonateInstance(int objectId, L2NpcTemplate template)
{
    super(objectId, template);

}

@Override
public void onBypassFeedback(final L2PcInstance player, String command)
  {
          if(player == null)
          {
             return;
          }
          
          if(command.startsWith("dlist"))
          {
              info(player);
          }
          if(command.startsWith("donate"))
          {
              StringTokenizer st = new StringTokenizer(command);
              st.nextToken();
              String amount = null;
              int pin1 = 0;
              int pin2 = 0;
              int pin3 = 0;
              int pin4 = 0;
              String message = "";
              
              try
              {
                 amount = st.nextToken();
                 pin1 = Integer.parseInt(st.nextToken());
                 pin2 = Integer.parseInt(st.nextToken());
                 pin3 = Integer.parseInt(st.nextToken());
                 pin4 = Integer.parseInt(st.nextToken());
                 while(st.hasMoreTokens())
                     message = message + st.nextToken() + " ";
                 
                 String fname = "data/donates/"+player.getName()+".txt";
                 File file = new File(fname);
                 boolean exist = file.createNewFile();
                 if(!exist)
                 {
                     player.sendMessage("You have already sent a donation , GMs must check it first");
                     return;
                 }
                 FileWriter fstream = new FileWriter(fname);
                 BufferedWriter out = new BufferedWriter(fstream);
                 out.write("Character Info: [Character: "+ player.getName() +"["+ player.getObjectId()+"] - Account: "+ player.getAccountName()+" - IP: "+player.getClient().getConnection().getInetAddress().getHostAddress()+"]\nMessage : donate "+ amount +" "+ message + " "+ pin1+ " "+ pin2+ " "+ pin3+ " "+ pin4);
                 out.close();
                 player.sendMessage("Donation sent. Admin will check it soon. Thanks for support...");
                 
                 Collection<L2PcInstance> pls = L2World.getInstance().getAllPlayers();
                     for (L2PcInstance gms : pls)
                        {
                             if(gms.isGM())
                             gms.sendMessage(player.getName() +" sent a donation.");
                        }
              }
              catch(Exception e)
              {
                  e.printStackTrace();
              }
          }
          
  }

  @Override
public void onAction(L2PcInstance player)
  {
    if (!canTarget(player)) 
        player.setLastFolkNPC(this);
    
 // Check if the L2PcInstance already target the L2NpcInstance
             if (this != player.getTarget())
             {
                 // Set the target of the L2PcInstance player
                 player.setTarget(this);
                 
                 // Send a Server->Client packet MyTargetSelected to the L2PcInstance player
                 MyTargetSelected my = new MyTargetSelected(getObjectId(), 0);
                 player.sendPacket(my);
                 my = null;
                 
                 // Send a Server->Client packet ValidateLocation to correct the L2NpcInstance position and heading on the client
                 player.sendPacket(new ValidateLocation(this));
                 
                 
             }
             else
             {
                 // Calculate the distance between the L2PcInstance and the L2NpcInstance
                 if (!canInteract(player))
                 {
                     // Notify the L2PcInstance AI with AI_INTENTION_INTERACT
                     player.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, this);
                       showHtmlWindow(player);

                 }
    
      showHtmlWindow(player);
  }
         // Send a Server->Client ActionFailed to the L2PcInstance in order to avoid that the client wait another packet
                     player.sendPacket(ActionFailed.STATIC_PACKET);
  }

  private void showHtmlWindow(L2PcInstance activeChar)
  {
        TextBuilder tb = new TextBuilder();
        NpcHtmlMessage html = new NpcHtmlMessage(1);
                
        tb.append("<html><head><title>PaySafeCard</title></head><body><center><table width=\"250\" bgcolor=\"000000\"><tr><td align=center><font color=\"6fd3d1\">Easy Donation With Paysafe Card</font></td></tr></table>_______________________________________<br><br><table width=\"250\"><tr><td><font color=\"ddc16d\">Select Donation Amount:</font></td><td><combobox width=80 height=17 var=amount list=10-Euro;25-Euro;50-Euro;100-Euro;></td></tr></table><br><br><font color=\"ddc16d\">Paysafe Card Pin:</font><table width=\"250\"><tr><td><edit var=\"pin1\" width=50 height=12 type=number></td><td><edit var=\"pin2\" width=50 height=12 type=number></td><td><edit var=\"pin3\" width=50 height=12 type=number></td><td><edit var=\"pin4\" width=50 height=12 type=number></td></table><br><br><multiedit var=\"message\" width=240 height=40><br><br><button value=\"Donate!\" action=\"bypass -h npc_"+getObjectId()+"_donate $amount $pin1 $pin2 $pin3 $pin4 $message\" width=95 height=21 back=\"bigbutton_over\" fore=\"bigbutton\"><br><button value=\"INFO\" action=\"bypass -h npc_"+getObjectId()+"_dlist\" width=95 height=21 back=\"bigbutton_over\" fore=\"bigbutton\"><br><font color=\"a1df64\">LII Memories Team</font></center></body></html>

 

Credits : I dont know 

Edited by scraw

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Posts

    • We are taking new orders. DM us on Telegram! We are taking new orders. DM us on Telegram!
    • Hello guys.Im looking for a simple autoclicker that works for servers with anticheat
    • Thank you for the reply. I know that this issue is due to L2 being so old. I was just wondering if there was an external way to fix the UI scaling. Like a patch or some settings.
    • Bro the game is so old it doesn't have a native option to scale the UI like in modern MMOs
    • Dear players, From April 19 to April 27 inc., the Bonus Start event will be active. It’s designed to help new and low-level characters get started more easily.   All characters that meet one of the following conditions: — created less than 3 days ago (regardless of level), — currently level 20 or below, — created during the event period, will receive upon login: — 10 sets of buff scrolls (phys or mage, depending on class), — 10 packs of +50% Drop/Spoil runes (2 hours each), — 10 packs of +50% Exp runes (2 hours each). Characters between level 21 and 30 will receive upon login: — 6 sets of buff scrolls, — 6 packs of +50% Drop/Spoil runes (2h each), — 6 packs of +50% Exp runes (2h each).   Event items will be removed approx. 09.05.2025 Server rates will be increased to x2.25. Take this chance to start your journey with ease or bring an old hero back into the fight — it’s the perfect time to test your strength! Open Beta Test is started!  Helper cats are waiting in towns — talk to them to receive the necessary equipment and level up your character. Siege Schedule:  - April 13 at 16:00 (GMT+2) – Innadrile Castle - April 14 at 20:00 (GMT+2) – Bandit Stronghold - April 15 at 20:00 (GMT+2) – Devastated Castle 📌 During the OBT, players who report bugs will receive CoL:   - 1 CoL for each reported staticmeshes bug (e.g., walking through textures, stairs, etc.) - 2 CoL or more for server-related issues (depending on severity) You can report bugs on the forum. The Open Beta Test will run approximately until April 15 at 23:00 (GMT+2). Your activity and feedback will help us improve the game.   Download links: Download client | Download updater 
  • Topics

×
×
  • Create New...