give item to specify player

    Share
    avatar
    jamaica

    Posts : 135
    Join date : 2013-02-24
    Age : 28
    Location : Romania

    give item to specify player

    Post  jamaica on 20th August 2013, 13:10

    Code:
    Index: C:/Documents and Settings/Matt/workspace/L2_GameServer_c4_new/java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminAdmin.java
    ===================================================================
    --- C:/Documents and Settings/Matt/workspace/L2_GameServer_c4_new/java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminAdmin.java   (revision 1692)
    +++ C:/Documents and Settings/Matt/workspace/L2_GameServer_c4_new/java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminAdmin.java   (working copy)
    @@ -30,9 +30,11 @@
     import net.sf.l2j.gameserver.cache.HtmCache;
     import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
     import net.sf.l2j.gameserver.instancemanager.ZoneManager;
    +import net.sf.l2j.gameserver.model.GMAudit;
     import net.sf.l2j.gameserver.model.L2Multisell;
     import net.sf.l2j.gameserver.model.L2World;
     import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
    +import net.sf.l2j.gameserver.serverpackets.ItemList;
     import net.sf.l2j.gameserver.serverpackets.NpcHtmlMessage;
     import net.sf.l2j.gameserver.serverpackets.PlaySound;
     import net.sf.l2j.gameserver.serverpackets.ServerBasePacket;
    @@ -40,6 +42,7 @@
     import net.sf.l2j.gameserver.serverpackets.SunRise;
     import net.sf.l2j.gameserver.serverpackets.SunSet;
     import net.sf.l2j.gameserver.serverpackets.SystemMessage;
    +import net.sf.l2j.gameserver.model.L2Object;
     
     /**
      * This class handles following admin commands:
    @@ -52,7 +55,7 @@
      private static String[] _adminCommands = {"admin_admin","admin_play_sounds","admin_play_sound",
                                                "admin_gmliston","admin_gmlistoff","admin_silence",
                                                "admin_atmosphere","admin_diet","admin_tradeoff",
    -                                          "admin_reload", "admin_set"};
    +                                          "admin_reload", "admin_set", "admin_giveitem"};
        private static final int REQUIRED_LEVEL = Config.GM_MENU;
     
        public boolean useAdminCommand(String command, L2PcInstance activeChar) {
    @@ -59,7 +62,7 @@
           
            if (!Config.ALT_PRIVILEGES_ADMIN)
                if (!(checkLevel(activeChar.getAccessLevel()) && activeChar.isGM())) return false;
    -       
    +   
           if (command.equals("admin_admin")) showMainPage(activeChar);
     
           if (command.equals("admin_play_sounds"))
    @@ -254,6 +257,52 @@
                    activeChar.sendMessage("Usage:  //set parameter=value");
                }
            }
    +      //GIVEMADD command by morrow and OMGLOTS OF HELP from Snausages-iGO, //giveitem id# #ofitems
    +        else if(command.startsWith("admin_giveitem"))
    +        {
    +         try
    +         {
    +            String params = command.substring(14);
    +            StringTokenizer st = new StringTokenizer(params);
    +            if (st.countTokens() == 3)
    +            {
    +               L2PcInstance player = L2World.getInstance().getPlayer(st.nextToken());
    +               L2Object target = activeChar.getTarget();
    +               if(target instanceof L2PcInstance) {
    +                  player = (L2PcInstance)target;
    +               }
    +               int itemId = Integer.parseInt(st.nextToken());
    +               int itemAmount = Integer.parseInt(st.nextToken());
    +               giveItem(player,itemId,itemAmount);
    +               SystemMessage sm = new SystemMessage(614);
    +               sm.addString("Spawned " + itemAmount + "items number " + itemId + " in " + player + "'s inventory.");
    +               activeChar.sendPacket(sm);
    +            }
    +            else if (st.countTokens()== 2)
    +            {
    +               L2PcInstance player = L2World.getInstance().getPlayer(st.nextToken());
    +               L2Object target = activeChar.getTarget();
    +               if(target instanceof L2PcInstance) {
    +                  player = (L2PcInstance)target;
    +               }
    +                 int itemId = Integer.parseInt(st.nextToken());
    +               giveItem(player,itemId,1);
    +               SystemMessage sm = new SystemMessage(614);
    +               sm.addString("Spawned item number " + itemId + " in " + player + "'s inventory.");
    +               activeChar.sendPacket(sm);
    +            }
    +            
    +         }
    +          catch (StringIndexOutOfBoundsException e)
    +          {
    +          SystemMessage sm = new SystemMessage(614);
    +          sm.addString("Error while creating item.");
    +         activeChar.sendPacket(sm);
    +            }
    +        }
    +      //----------------------
    +      String target = (activeChar.getTarget() != null?activeChar.getTarget().getName():"no-target");
    +        GMAudit.auditGMAction(activeChar.getName(), command, target, "");
           return true;
        }
     
    @@ -272,6 +321,21 @@
          * @param type - atmosphere type (signssky,sky)
          * @param state - atmosphere state(night,day)
          */
    +   //---------for //giveitem
    +   private void giveItem(L2PcInstance selectedplayer, int itemId, int itemAmount)
    +   {
    +      selectedplayer.getInventory().addItem("Admin", itemId, itemAmount, selectedplayer, null);
    +      
    +        ItemList il = new ItemList(selectedplayer, true);
    +        selectedplayer.sendPacket(il);
    +      
    +      SystemMessage sm = new SystemMessage(614);
    +      sm.addString("An Admin has spawned " + itemAmount + " item(s) number " + itemId + " in your inventory.");
    +      selectedplayer.sendPacket(sm);
    +      
    +      
    +   }
    +   //-------------
        public void adminAtmosphere(String type, String state, L2PcInstance activeChar)
        {
            ServerBasePacket packet = null;

    DnR
    Admin
    Admin

    Posts : 985
    Join date : 2012-12-03

    Re: give item to specify player

    Post  DnR on 22nd August 2013, 15:04

    //giveitem command has been implemented. It's based on your command.
    Thanks a lot. Smile

      Current date/time is 28th July 2017, 18:03