Modified gainItem(), accomodates pets.

Status
Not open for further replies.
Joined
Nov 30, 2007
Messages
511
Reaction score
0
Using Leifde's pet patch requires that you modify certain things, the gainItem() function included, when pets are involved. If you don't use this fix, your client will crash if you ever use the gainItem() function for pets due to the whole database shabang not being applied to that pet. Here we go:

In AbstractPlayerInteraction.java, replace the gainItem() function with this:
PHP:
public void gainItem(int id, short quantity) {
            MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
                        if (id >= 5000000 && id <= 5000045) {
            try {
                Connection con = (Connection) DatabaseConnection.getConnection();
                PreparedStatement ps = (PreparedStatement) con.prepareStatement("INSERT INTO pets (name, level, closeness, fullness) VALUES (?, ?, ?, ?)");
                ps.setString(1, ii.getName(id));
                ps.setInt(2, 1);
                ps.setInt(3, 0);
                ps.setInt(4, 100);
                ps.executeUpdate();
                ResultSet rs = ps.getGeneratedKeys();
                rs.next();
                //c.getPlayer().equipChanged();
                MapleInventoryManipulator.addById(c, id, (short) quantity, c.getPlayer().getName() + " receieved pet, ID " + id + ", from a scripted PlayerInteraction. (Quantity: " + quantity + ")", null, rs.getInt(1));
                rs.close();
                ps.close();
            } catch (SQLException ex) {
                java.util.logging.Logger.getLogger(AbstractPlayerInteraction.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
        if (quantity >= 0) {
            StringBuilder logInfo = new StringBuilder(c.getPlayer().getName());
            logInfo.append(" received ");
            logInfo.append(quantity);
            logInfo.append(" from a scripted PlayerInteraction (");
            logInfo.append(this.toString());
            logInfo.append(")");
            MapleInventoryManipulator.addById(c, id, quantity, logInfo.toString());
                
        } else {
            MapleInventoryManipulator.removeById(c, MapleItemInformationProvider.getInstance().getInventoryType(id), id, -quantity, true, false);
                    }
                }
        c.getSession().write(MaplePacketCreator.getShowItemGain(id, quantity, true));
    }

That's about it. You'll need a bunch of imports, but if you're using Netbeans and haven't noticed by now that it gives you the option of adding in all missing imports then you should shoot yourself, sorry.
 
Last edited:
Re: [Release] Modified gainItem(), accomodates pets.

what does this do exactly? can't you just use gainitem, and equip it to your pet.
 
Re: [Release] Modified gainItem(), accomodates pets.

YESHH!!! Pet Evolver Will Work Great Now! Thanks ill release my script soon =)
 
Re: [Release] Modified gainItem(), accomodates pets.

So... This will stop your server from crashing by the gainItem function... Right?
Yes, it fixes client crashes when the gainItem() function is used.


YESHH!!! Pet Evolver Will Work Great Now! Thanks ill release my script soon =)
Yeah, I saw your post in the pets topic and I knew why you had that problems so I here this is. ;o
 
Re: [Release] Modified gainItem(), accomodates pets.

in case some noobies out their don't know what to replace just replace this.

PHP:
public void gainItem(int id, short quantity) {
		if (quantity >= 0) {
			StringBuilder logInfo = new StringBuilder(c.getPlayer().getName());
			logInfo.append(" received ");
			logInfo.append(quantity);
			logInfo.append(" from a scripted PlayerInteraction (");
			logInfo.append(this.toString());
			logInfo.append(")");
			MapleInventoryManipulator.addById(c, id, quantity, logInfo.toString());
		} else {
			MapleInventoryManipulator.removeById(c, MapleItemInformationProvider.getInstance().getInventoryType(id), id, -quantity, true, false);
		}
		c.getSession().write(MaplePacketCreator.getShowItemGain(id,quantity, true));
	}
 
Re: [Release] Modified gainItem(), accomodates pets.

[...]That's about it. You'll need a bunch of imports, but if you're using Netbeans and haven't noticed by now that it gives you the option of adding in all missing imports then you should shoot yourself, sorry.
*Shoots shelf* Ah well, manually doing it FTW.
 
Re: [Release] Modified gainItem(), accomodates pets.

Code:
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import java.rmi.RemoteException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import net.sf.odinms.client.MapleCharacter;
import net.sf.odinms.client.MapleClient;
import net.sf.odinms.client.MapleInventory;
import net.sf.odinms.client.MapleInventoryType;
import net.sf.odinms.client.MapleQuestStatus;
import net.sf.odinms.database.DatabaseConnection;
import net.sf.odinms.net.channel.ChannelServer;
import net.sf.odinms.net.world.MapleParty;
import net.sf.odinms.net.world.MaplePartyCharacter;
import net.sf.odinms.net.world.guild.MapleGuild;
import net.sf.odinms.server.MapleInventoryManipulator;
import net.sf.odinms.server.MapleItemInformationProvider;
import net.sf.odinms.server.MaplePortal;
import net.sf.odinms.server.maps.MapleMap;
import net.sf.odinms.server.quest.MapleQuest;
import net.sf.odinms.tools.MaplePacketCreator;

those are all the imports, those aren't all that i added but yeah for people that dont know how to use netbeans to get imports.
 
Re: [Release] Modified gainItem(), accomodates pets.

Code:
init:
deps-jar:
Compiling 1 source file to C:\Documents and Settings\Compaq_Owner\Desktop\StarLightMS Pack\odinms\build\classes
C:\Documents and Settings\Compaq_Owner\Desktop\StarLightMS Pack\StarLightMS RePack\StarLightMS RePack\src\net\sf\odinms\scripting\AbstractPlayerInteraction.java:127: cannot find symbol
symbol  : method addById(net.sf.odinms.client.MapleClient,int,short,java.lang.String,<nulltype>,int)
location: class net.sf.odinms.server.MapleInventoryManipulator
                MapleInventoryManipulator.addById(c, id, (short) quantity, "Cash Item was purchased.", null, rs.getInt(1));
1 error
BUILD FAILED (total time: 0 seconds)

Anyone can help me with this error please?
 
Re: [Release] Modified gainItem(), accomodates pets.

Updated, changed the addById() function to fit the situation:
PHP:
MapleInventoryManipulator.addById(c, id, (short) quantity, c.getPlayer().getName() + " receieved pet, ID " + id + ", from a scripted PlayerInteraction. (Quantity: " + quantity, null, rs.getInt(1));
 
Re: [Release] Modified gainItem(), accomodates pets.

could be the fix for why players just sometimse cc with pets (equiped) and then get bugged and cant ever log back on their chars? :S xD
 
Re: [Release] Modified gainItem(), accomodates pets.

PHP:
MapleInventoryManipulator.addById(c, id, (short) quantity, c.getPlayer().getName() + " receieved pet, ID " + id + ", from a scripted PlayerInteraction. (Quantity: " + quantity + ")", null, rs.getInt(1));
 
Re: [Release] Modified gainItem(), accomodates pets.

could be the fix for why players just sometimse cc with pets (equiped) and then get bugged and cant ever log back on their chars? :S xD

You need to add this in ChangeChannelHandler.java..

Code:
import net.sf.odinms.net.channel.handler.SpawnPetHandler;

at the imports.

Then find

Code:
		if (c.getPlayer().getTrade() != null) {
			MapleTrade.cancelTrade(c.getPlayer());
		}

And add under it.
Code:
		if (c.getPlayer().getPet() != null) {
			SpawnPetHandler pethandler = new SpawnPetHandler();
			pethandler.unequipPet(c);
		}
 
Status
Not open for further replies.
Back