Jump to content

Question

Posted (edited)

Hello! The only problem that i am facing is the bold line i cant find the SetVar! Need to adapt it for Acis 398.If anyone can help! Thanks

 

 

private void rewardPlayers()
    {
        // First Add Fixed Reward
        for (Player player : players)
        {
            
            PlayerMemo.setVar(player, "dungeon_atleast1time", "true", -1);
            for (Entry<Integer, Integer> itemId : template.getRewards().entrySet())
            {
                player.addItem("dungeon reward", itemId.getKey(), itemId.getValue(), null, true);
            }
        }
        
        if (!template.getRewardHtm().equals("NULL"))
        {
            NpcHtmlMessage htm = new NpcHtmlMessage(0);
            htm.setFile(template.getRewardHtm());
            for (Player player : players)
                player.sendPacket(htm);
        }
        else
        {
            for (Player player : players)
            {
                player.setInstance(InstanceManager.getInstance().getInstance(0), true);
                player.teleportTo(82635, 148798, -3464, 25);
            }
        }
    }

 

===================================================================================================================================

 

Here is PlayerMemo

 

package net.sf.l2j.gameserver.model.memo;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import net.sf.l2j.commons.data.MemoSet;
import net.sf.l2j.commons.logging.CLogger;
import net.sf.l2j.commons.pool.ConnectionPool;

/**
 * An implementation of {@link MemoSet} used for Player. There is a restore/save system.
 */
public class PlayerMemo extends MemoSet
{
    private static final long serialVersionUID = 1L;
    
    private static final CLogger LOGGER = new CLogger(PlayerMemo.class.getName());
    
    private static final String SELECT_MEMOS = "SELECT * FROM character_memo WHERE charId = ?";
    private static final String DELETE_MEMO = "DELETE FROM character_memo WHERE charId = ? AND var = ?";
    private static final String INSERT_OR_UPDATE_MEMO = "INSERT INTO character_memo (charId, var, val) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE val = VALUES(val)";
    
    private final int _objectId;
    
    public PlayerMemo(int objectId)
    {
        _objectId = objectId;
        
        // Restore memos.
        try (Connection con = ConnectionPool.getConnection();
            PreparedStatement ps = con.prepareStatement(SELECT_MEMOS))
        {
            ps.setInt(1, _objectId);
            
            try (ResultSet rs = ps.executeQuery())
            {
                while (rs.next())
                    put(rs.getString("var"), rs.getString("val"));
            }
        }
        catch (Exception e)
        {
            LOGGER.error("Couldn't restore memos for player id {}.", e, _objectId);
        }
    }
    
    @Override
    protected void onSet(String key, String value)
    {
        // Insert memo, on duplicate update it.
        try (Connection con = ConnectionPool.getConnection();
            PreparedStatement ps = con.prepareStatement(INSERT_OR_UPDATE_MEMO))
        {
            ps.setInt(1, _objectId);
            ps.setString(2, key);
            ps.setString(3, value);
            ps.execute();
        }
        catch (Exception e)
        {
            LOGGER.error("Couldn't set {} memo for player id {}.", e, key, _objectId);
        }
    }
    
    @Override
    protected void onUnset(String key)
    {
        // Clear memo.
        try (Connection con = ConnectionPool.getConnection();
            PreparedStatement ps = con.prepareStatement(DELETE_MEMO))
        {
            ps.setInt(1, _objectId);
            ps.setString(2, key);
            ps.execute();
        }
        catch (Exception e)
        {
            LOGGER.error("Couldn't unset {} memo for player id {}.", e, key, _objectId);
        }
    }
}

Edited by addx20

3 answers to this question

Recommended Posts

  • 0
Posted
37 minutes ago, addx20 said:

Hello! The only problem that i am facing is the bold line i cant find the SetVar! Need to adapt it for Acis 398.If anyone can help! Thanks

 

 

private void rewardPlayers()
    {
        // First Add Fixed Reward
        for (Player player : players)
        {
            
            PlayerMemo.setVar(player, "dungeon_atleast1time", "true", -1);
            for (Entry<Integer, Integer> itemId : template.getRewards().entrySet())
            {
                player.addItem("dungeon reward", itemId.getKey(), itemId.getValue(), null, true);
            }
        }
        
        if (!template.getRewardHtm().equals("NULL"))
        {
            NpcHtmlMessage htm = new NpcHtmlMessage(0);
            htm.setFile(template.getRewardHtm());
            for (Player player : players)
                player.sendPacket(htm);
        }
        else
        {
            for (Player player : players)
            {
                player.setInstance(InstanceManager.getInstance().getInstance(0), true);
                player.teleportTo(82635, 148798, -3464, 25);

            }
        }
    }

 

===================================================================================================================================

 

Here is PlayerMemo

 

package net.sf.l2j.gameserver.model.memo;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import net.sf.l2j.commons.data.MemoSet;
import net.sf.l2j.commons.logging.CLogger;
import net.sf.l2j.commons.pool.ConnectionPool;

/**
 * An implementation of {@link MemoSet} used for Player. There is a restore/save system.
 */
public class PlayerMemo extends MemoSet
{
    private static final long serialVersionUID = 1L;
    
    private static final CLogger LOGGER = new CLogger(PlayerMemo.class.getName());
    
    private static final String SELECT_MEMOS = "SELECT * FROM character_memo WHERE charId = ?";
    private static final String DELETE_MEMO = "DELETE FROM character_memo WHERE charId = ? AND var = ?";
    private static final String INSERT_OR_UPDATE_MEMO = "INSERT INTO character_memo (charId, var, val) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE val = VALUES(val)";
    
    private final int _objectId;
    
    public PlayerMemo(int objectId)
    {
        _objectId = objectId;
        
        // Restore memos.
        try (Connection con = ConnectionPool.getConnection();
            PreparedStatement ps = con.prepareStatement(SELECT_MEMOS))
        {
            ps.setInt(1, _objectId);
            
            try (ResultSet rs = ps.executeQuery())
            {
                while (rs.next())
                    put(rs.getString("var"), rs.getString("val"));
            }
        }
        catch (Exception e)
        {
            LOGGER.error("Couldn't restore memos for player id {}.", e, _objectId);
        }
    }
    
    @Override
    protected void onSet(String key, String value)
    {
        // Insert memo, on duplicate update it.
        try (Connection con = ConnectionPool.getConnection();
            PreparedStatement ps = con.prepareStatement(INSERT_OR_UPDATE_MEMO))
        {
            ps.setInt(1, _objectId);
            ps.setString(2, key);
            ps.setString(3, value);
            ps.execute();
        }
        catch (Exception e)
        {
            LOGGER.error("Couldn't set {} memo for player id {}.", e, key, _objectId);
        }
    }
    
    @Override
    protected void onUnset(String key)
    {
        // Clear memo.
        try (Connection con = ConnectionPool.getConnection();
            PreparedStatement ps = con.prepareStatement(DELETE_MEMO))
        {
            ps.setInt(1, _objectId);
            ps.setString(2, key);
            ps.execute();
        }
        catch (Exception e)
        {
            LOGGER.error("Couldn't unset {} memo for player id {}.", e, key, _objectId);

        }
    }
}

PlayerMemo.setVar(player, "dungeon_atleast1time", "true", -1);

 

use

 

player.getMemos().set("dungeon_atleast1time", -1);

Guest
This topic is now closed to further replies.


×
×
  • Create New...