Jump to content
  • 0

Add item player Offline aCis


Question

Posted

Hello I put event monument in my acis however the player only wins the item if you have online if the player had ofline appears that mistake someone help me?

 

yITuFiw.png

 



    private static void addReward(int obj_id, boolean duple)
    {
        Player player = World.getInstance().getPlayer(obj_id);
        
        if(player != null && player.isOnline())
        {
            InventoryUpdate iu = new InventoryUpdate();
            final Item reward = ItemTable.getInstance().getTemplate(Config.EVENT_MONUMENT_STATUET_REWARD_ID);
            
            player.getInventory().addItem("top", Config.EVENT_MONUMENT_STATUET_REWARD_ID, duple ? Config.EVENT_MONUMENT_STATUET_REWARD_AMOUNT * 2 : Config.EVENT_MONUMENT_STATUET_REWARD_AMOUNT,player, null);
            player.sendMessage("Voce ganhou " + reward.getName() + ".");
            player.getInventory().updateDatabase();
            player.sendPacket(iu);
        }
        else
        {
            addOfflineItem(obj_id, Config.EVENT_MONUMENT_STATUET_REWARD_ID, duple ? Config.EVENT_MONUMENT_STATUET_REWARD_AMOUNT * 2 : Config.EVENT_MONUMENT_STATUET_REWARD_AMOUNT);
        }
    }
    
    private static void addOfflineItem(int owner_id, int item_id, int count)
    {
        try(Connection con = L2DatabaseFactory.getInstance().getConnection())
        {
            PreparedStatement st = con.prepareStatement("SELECT count FROM items WHERE item_id = ? and owner_id = ?");
            st.setInt(1,item_id);
            st.setInt(2,owner_id);
            ResultSet rs = st.executeQuery();
            int total = 0;
            
            while (rs.next())
            {
                total = rs.getInt("count");
            }
            
            st.close();
            rs.close();

            st = con.prepareStatement("SELECT MAX(object_id) as objid FROM items");
            st.executeQuery();
            rs = st.executeQuery();
            
            int obj_id = 0;
            
            while (rs.next())
            {
                obj_id = rs.getInt("objid") + 1000;
            }
            
            st.close();
            rs.close();
            
            if(total == 0)
            {
                st = con.prepareStatement("INSERT INTO items VALUES (?, ?, ?, ?, 0, 'INVENTORY', 0, 0, 0, NULL, 0, 0, -1)");
                st.setLong(1,owner_id);
                st.setLong(2,obj_id);
                st.setInt(3,item_id);
                st.setInt(4, count);
                st.execute();
                st.close();
            }
            else
            {
                st = con.prepareStatement("UPDATE items SET count = ? WHERE owner_id = ? and item_id = ? ");
                st.setInt(1, total + count);
                st.setLong(2, owner_id);
                st.setLong(3, item_id);
                st.execute();
                st.close();
            }
        }
        catch (SQLException e)
        {
            _log.severe("Could not update item char: " + e);
        }
    }
    

 

7 answers to this question

Recommended Posts

  • 0
Posted

Try this:

 

private static void addOfflineItem(int owner_id, int item_id, int count)
{
    try(Connection con = L2DatabaseFactory.getInstance().getConnection())
    {
        PreparedStatement st = con.prepareStatement("SELECT count FROM items WHERE item_id=? AND owner_id=?");
        st.setInt(1, item_id);
        st.setInt(2, owner_id);

        ResultSet rs = st.executeQuery();
        
        if(rs.next())
        {
            st = con.prepareStatement("UPDATE items SET count=? WHERE owner_id=? and item_id=?");
            st.setInt(1, rs.getInt("count") + count);
            st.setInt(2, owner_id);
            st.setInt(3, item_id);
        }
        else
        {
            st = con.prepareStatement("INSERT INTO items VALUES (?, ?, ?, ?, 0, 'INVENTORY', 0, 0, 0, NULL, 0, 0, -1)");
            st.setInt(1, owner_id);
            st.setInt(2, IdFactory.getInstance().getNextId())
            st.setInt(3, item_id);
            st.setInt(4, count);
        }

        st.execute();
        rs.close();
        st.close();
    }
    catch (SQLException e)
    {
        _log.severe("Could not update item char: " + e);
    }
}


I changed the Long for Int (because that's your input on the function), also your "objectId" generation method was wrong.
Remember to import net.sf.l2j.gameserver.idfactory.IdFactory;

 

 

  • 0
Posted

You don't rly need that. Part of my code, rewarding offline player. Using ItemInstance, create item and attach it to player. Example

item.setOwnerId(player.getObjectId());
item.setEnchantLevel(item.getEnchantLevel());
item.setLocation(ItemLocation.WAREHOUSE);
item.updateDatabase();

  • Like 1
  • 0
Posted
2 hours ago, Antartico™ said:

Try this:

 


private static void addOfflineItem(int owner_id, int item_id, int count)
{
    try(Connection con = L2DatabaseFactory.getInstance().getConnection())
    {
        PreparedStatement st = con.prepareStatement("SELECT count FROM items WHERE item_id=? AND owner_id=?");
        st.setInt(1, item_id);
        st.setInt(2, owner_id);

        ResultSet rs = st.executeQuery();
        
        if(rs.next())
        {
            st = con.prepareStatement("UPDATE items SET count=? WHERE owner_id=? and item_id=?");
            st.setInt(1, rs.getInt("count") + count);
            st.setInt(2, owner_id);
            st.setInt(3, item_id);
        }
        else
        {
            st = con.prepareStatement("INSERT INTO items VALUES (?, ?, ?, ?, 0, 'INVENTORY', 0, 0, 0, NULL, 0, 0, -1)");
            st.setInt(1, owner_id);
            st.setInt(2, IdFactory.getInstance().getNextId())
            st.setInt(3, item_id);
            st.setInt(4, count);
        }

        st.execute();
        rs.close();
        st.close();
    }
    catch (SQLException e)
    {
        _log.severe("Could not update item char: " + e);
    }
}


I changed the Long for Int (because that's your input on the function), also your "objectId" generation method was wrong.
Remember to import net.sf.l2j.gameserver.idfactory.IdFactory;

 

 

 

gave the same thing

  • 0
Posted

I have refacted the code but it does not add anything in the player's bag offilne

On 14/01/2018 at 8:28 PM, SweeTs said:

You don't rly need that. Part of my code, rewarding offline player. Using ItemInstance, create item and attach it to player. Example

 


item.setOwnerId(player.getObjectId());
item.setEnchantLevel(item.getEnchantLevel());
item.setLocation(ItemLocation.WAREHOUSE);
item.updateDatabase();

 

 

On 15/01/2018 at 4:15 AM, Tryskell said:

SweeTs said it all.

As a sidenote you can merge both queries using "ON DUPLICATE KEY UPDATE".  At least that's what I did for player skill acquisition cleanup.

private static void addOfflineItem(int owner_id, int item_id, int count)
    {
        ItemInstance item = new ItemInstance(IdFactory.getInstance().getNextId(), count);
        
        try(Connection con = L2DatabaseFactory.getInstance().getConnection())
        {
            PreparedStatement stm_items = con.prepareStatement("INSERT INTO items (owner_id,item_id,count,loc,loc_data,enchant_level,object_id,custom_type1,custom_type2,mana_left,time) VALUES (?,?,?,?,?,?,?,?,?,?,?)");
            
            stm_items.setInt(1, owner_id);
            stm_items.setInt(2, item.getItemId());
            stm_items.setInt(3, count);
            item.setLocation(ItemLocation.WAREHOUSE);
            stm_items.setInt(5, 0);
            stm_items.setInt(6, item.getEnchantLevel());
            stm_items.setInt(7, item.getObjectId());
            stm_items.setInt(8, 0);
            stm_items.setInt(9, 0);
            stm_items.setInt(10, -1);
            stm_items.setLong(11, System.currentTimeMillis());
            stm_items.executeUpdate();
            stm_items.close();
        }
        catch (SQLException e)
        {
            _log.severe("Could not update item char: " + e);
        }
    }

Guest
This topic is now closed to further replies.


  • Posts

    • If you're looking for high-performance residential proxies, try MoMoProxy—it's a reliable and top-tier solution in the proxy market. 📌 Need help or want to test? 💬 Live Support: https://t.me/momoproxy_com 📧 Email Us: support@momoproxy.com
    • interlude: l2acis uber alles
    • New Dragon-Network Server – Vote Now!   We’re launching a new Dragon-Network (Multiskill) server under a new domain, created by the original Classic-Interlude team. We no longer have access to the old domain, but this is the official continuation — not a scam, just a new home. The new domain will host: A main migrated server (nothing lost – all chars/items kept) Plus seasonal servers (voted by players) All seasonal progress will be merged into the main realm Help shape the new server – vote now: https://dragon-network.eu/   Let’s build the future of DN – together.
    • Hello there, Im beyond confused and dont know what path to take. I want to start working on a L2 server, changing some stuff here and there and finally in the future if  im happy with the results, to launch the server, but... L2j or L2off? After all this years, is there a Interlude L2j close to off?   Ive spent some time lookin over this forum, searching what would be better and what files to take but I ain't near to a clear answer.  Most of the time everyone is trowing stones at everyone, "your filles are trash, my filles are good" and viceversa. Therefore, Im reaching out to a knowledge guy, hopefully from a neutral position to all this drama, that can pin point me in a direction.    To explain what I want for a base start is an Interlude with a classic interface (features), low rate. Mostly what this guy TravorJ is describing in his post TravorJ post , and to do some reworks on it, ex: mobs drop, rethink the augment system/interface, rethink learning skills/enchant skills, create some custom potions/buff effects, siege mechanics... Is that possible on off files? or is better to go with L2j? I also want to mention that I have little to none L2 dev experince (13-15yrs ago I had an L2j server running  for a month where I made some basics changes), but I have coding background so Im used to that and more than willing to learn.   So in conclusion, I dont want to get some free shared files without any support, that I need to wrap my head around and fix stuff for long time to make them work, stuff thats already fixed buy someone else. Instead im looking to buy something thats more updated and start working from there. Question is what and from whom? Kinda sux when you go and buy something and u dont know what the hell are you buying (need some guidance here)   Is L2j Orion a good choice? I saw that is regularly updated. Lucera2 I dont think is something that I want cuz they dont sell soruce, prefer to have control and not to be dependent on someone to much...   Big thanks in advance!   
  • Topics

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock