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();

  • 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

    • Never buy from gx gustavo orellano, he's a scammer.  
    • Good evening everyone! I wouldn't normally ask for help with something like this, but I'm honestly stuck and can't figure it out anymore. I have a C3 pack (I'll also include the link below since it took me a while to find a good one with everything needed to run it): (https://www.mediafire.com/file/glhnscql6hkd6ra/l2jnvc3_rev178_Greenhope_l2j_%2Bjava_%2Bsql.zip/file) The problem is that I'm completely stuck on one thing. No matter what I do, I can't log in. I keep getting a "wrong protocol" error. I've tried changing the protocol from 550–700 all the way to 1–999. I've tested many different C3 versions and every main system I could find, but I still haven't managed to log in successfully. I'm not sure if I'm doing something wrong when saving the .ini file after changing it to my server's IP address. If anyone could help me, I would really appreciate it. I'll keep the server online so that if someone is willing to assist, they can try logging in and help me figure out what's wrong. Server IP: 194.219.108.63 Thank you very much in advance to anyone who decides to take the time to help me. I'd really love to get this pack running properly and preserve it for the future.
    • Anosim Update   - New updated design is live - Free Numbers added on the mainpage - Use free numbers for activation - Receive SMS for free   ⸻   New Blog added Future news, updates and platform changes will be posted there   ⸻   Partner Section added New space for partners and integrations   ⸻   New Websites for Activation added   🇩🇪 Germany wg-gesucht.de dikidi.net 🇨🇭 Switzerland Tutti.ch Ricardo.ch 🇦🇺 Australia Gumtree.com.au 🇬🇧 UK Askable.com   ⸻   New Countries added for Activation   🇦🇷 Argentina 🇧🇬 Bulgaria 🇨🇲 Cameroon 🇭🇷 Croatia 🇬🇷 Greece 🇰🇿 Kazakhstan 🇲🇦 Morocco   ⸻   New Full Rent 🇬🇪 Georgia +995 Numbers Full Rent now available Real SIM Cards No VoIP   ⸻   Available now on https://anosim.net
    • Shadowsocks Released   World’s first Dedicated Mobile Proxy with Shadowsocks support. Dedicated 4G/5G mobile proxies can now be used with Shadowsocks.   New dedicated mobile proxy locations added: 🇩🇪 Germany (Leipzig) 🇳🇬 Nigeria (Lagos) 🇺🇸 USA (South Haven)   Also available: 🌐 Residential Proxies from $1/GB   ⚡️ Datacenter Proxies from $0.50/GB   Available now on Proxied.   https://proxied.com For Free Trials, write us a DM with your registered E-mail.
  • Topics

×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..