View Single Post
  #1  
Old 08-09-2018, 03:20 AM
volek_the_fn_dwarf's Avatar
volek_the_fn_dwarf
Fire Beetle
 
Join Date: Aug 2018
Location: Charlotte NC
Posts: 2
Default PlayerInstance Helper

I ran into some trouble manipulating the database directly around instances zones and characters.


The mod will just let you know the latest instanced zone by shortname for the logged in character.


Code:
### quest/plugins/guild_instance.pl
#!/usr/bin/perl
use DBI;
### author: Volek
### Used to determine the current players instance id for given shortZone
### @param string zone.short_name
### @return int | null (instance not found)
sub GetPlayerInstance
{
  my $shortZone = $_[0];
  my $client = plugin::val('$client');
  my $charId = $client->CharacterID();

  $dbh = plugin::LoadMysql();
  my @row = $dbh->selectrow_array("
    SELECT il.id
    FROM
      instance_list il
      LEFT JOIN  instance_list_player ilp ON (il.id = ilp.id)
      JOIN zone z ON (il.zone = z.zoneidnumber)
    WHERE
      ilp.charid = '$charId'
      AND z.short_name = '$shortZone'
    ORDER BY
      il.id DESC
  ");
   if ( $dbh->errstr ) {
      plugin::Debug("DB Error attempting to lookup character instance: '$shortZone' : $sth->errstr");
   }

  if ($row[0]) {
    return $row[0];
  } else {
    return;
  }
}

## Get Guild Lobby the latest lobby Instance if custom instance or global instance id
## @return int | null Id of the characters instance or the global instance
sub GetGuildLobbyInstance
{
  my $shortZone = 'guildlobby';
  my $charInstance = GetPlayerInstance($shortZone);

  if($charInstance) {
    return $charInstance;
  }

  $dbh = plugin::LoadMysql();
  my @row = $dbh->selectrow_array("
    SELECT il.id
    FROM
      instance_list il
      JOIN zone z ON (il.zone = z.zoneidnumber)
    WHERE
      il.is_global = 1
      AND z.short_name = '$shortZone'
    ORDER BY
      il.id DESC
  ");

   if( $dbh->errstr ) {
        plugin::Debug("Failed to fetch Guild Lobby instance may not exist? "  . $dbh->errstr);
   }

  if ($row[0]) {
    return $row[0];
  } else {
    return;
  }
}
I also did update my guild lobby / poknowledge files. I am attaching them so you can see basic use of the plugin.

Code:
## /quests/poknowledge/player.pl
        if($doorid == 138) #guild lobby
        {
                if($client->CalculateDistance(1408, -377, -113) <= 30)
                {
                        if(($client->GetClientVersionBit() & 4294967264)!= 0)
                        {
                                # use instance id assigned to current player for guild hall or global id
                                my $lobbyId = plugin::GetGuildLobbyInstance();

                                quest::MovePCInstance(344,$lobbyId,18,-46,6,450);
                        }
                        else
                        {
                                quest::movepc(344,18,-46,6,492);
                        }
                }
        }
This updates the guild lobby from being hardcoded to single instance for RoF2 client. Will rollback to global instanced version is character is not assigned instance for lobby.

Last edited by volek_the_fn_dwarf; 08-09-2018 at 03:22 AM.. Reason: This bottom one needs some work as each person get's their own instance.
Reply With Quote