Page 1 of 1

PvP Region To ID

PostPosted: Thu Sep 08, 2011 3:24 am
by Sensi
Atm, i'm working on a Queue/Mapchanger script to releaes but ran into a small problem i'm stuck on :?
Code: Select all
public override bool Interact(GamePlayer player)
{
if (!base.Interact(player)) return false;

player.Out.SendMessage("Greetings!" + player.Name + "\n Where would you like to teleport?\n\n - [PvP] -\n ["+ PvPHandler.currentPvPPort() +"] - (" + PvPHandler.currentPvPPort(GameNPC.CurrentZone.ID) +"/" + MaxPlayers + ") ", eChatType.CT_Say, eChatLoc.CL_PopupWindow);
Utils.ClearChat(player);
return true;
}

What i'm trying to do is get the ID off the region of the Current PvP Zone, but if the Voting System is constantly rotating maps. How do I get it to check for the ID whenever the Map Changes?
Code: Select all
(" + WorldMgr.GetClientsOfRegionCount() + "/" + MaxPlayers + ")
Is there a way I can Convert the PvPHandler.currentPvPPort to a ID? For Example: WorldMgr.GetClientsofRegionCount(currentPvPPortID)? Basically what I want to do is make currentPvPPort(which is a string) convert to something like CurrentPvPPortID(which would make the current PvP map a ID)..


and just so you can review.
Code: Select all
public static GameNPC currentPvPPort()
{
GameNPC[] npcs = WorldMgr.GetNPCsByName(m_PvPZone, eRealm.None);
if (npcs.Length > 0 && npcs != null)
{
GameNPC theNPC = npcs[0];
if (theNPC != null)
{
if (theNPC.GuildName == "PvP Setup")
{
return theNPC;

}
}
}
return null;
}
}
Honestly i'm not sure how to do it.
Would be great if you can help.
Regards

-Sensi

Re: PvP Region To ID

PostPosted: Thu Sep 08, 2011 7:12 am
by Graveen
Hum,

1) GetClientsofRegionCount(int regionId) -> you *must* provide the current region id to have it working
2) replace the following block
Code: Select all
if (npcs.Length > 0 && npcs != null)
{
...
}
with
Code: Select all
if (npcs.Length > 0 && npcs != null)
{
foreach (var npc in npcs)
if (npc.GuildName == "PvP Setup") return npc;
}

Re: PvP Region To ID

PostPosted: Thu Sep 08, 2011 8:07 am
by Sensi
Now what does this exactly do if you don't mind explaining?

Edit:
this gave me an error that all paths do not return a value.
Code: Select all
public static GameNPC currentPvPPort()
{
GameNPC[] npcs = WorldMgr.GetNPCsByName(m_PvPZone, eRealm.None);
if (npcs.Length > 0 && npcs != null)
{
foreach (var npc in npcs)
if (npc.GuildName == "PvP Setup") return npc;
}
}

Re: PvP Region To ID

PostPosted: Thu Sep 08, 2011 8:12 am
by Graveen
what you are asking for :mrgreen:

it returns the first npc with "PvP Setup" as guild name. This mainly means you must only have one pvp setup in the current zone.

Re: PvP Region To ID

PostPosted: Thu Sep 08, 2011 8:14 am
by Sensi
:)
sorry about the communication issue.

what i'm trying to accomplish is getting

WorldMgr.GetClientsofRegionCount() working to where the Map Changer will not just give me the name of the zone, but give me the ID.
if you understand?

Re: PvP Region To ID

PostPosted: Thu Sep 08, 2011 8:23 am
by Dunnerholl
if you understand?
i dont understand a thing

Re: PvP Region To ID

PostPosted: Thu Sep 08, 2011 8:32 am
by Sensi
*Sad Face*..

Ok i'll try one more time..


Code: Select all
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;

using DOL.AI;
using DOL.AI.Brain;
using DOL.Events;
using DOL.Database;
using DOL.GS.PacketHandler;

using log4net;
namespace DOL.GS.Scripts
{
public class PvPHandler
{
private static string m_PvPZone = "";

Queue<GamePlayer> queuespot = new Queue<GamePlayer>(1000);

private static ushort lastRegionID = 51;
private static Dictionary<string, string> m_IPsVotedAndVote = new Dictionary<string, string>();

private static Dictionary<string, int> m_MapsAndVotes = new Dictionary<string, int>();



public static void setPvPZone(string set)
{
GameNPC last = null;
GameNPC[] search = WorldMgr.GetNPCsByName(m_PvPZone, eRealm.None);
foreach (GameNPC searching in search)
{
if (searching.GuildName == "PvP Marker")
{
last = searching;
}
}
if (last != null)
{
lastRegionID = last.CurrentRegionID;
}
m_PvPZone = set;
foreach (GameClient client in WorldMgr.GetAllPlayingClients())
{

if (client.Player.CurrentRegionID == lastRegionID)
{
PortToPvPZone(client.Player);
}
client.Player.Out.SendMessage("The PvP Zone has changed to " + m_PvPZone + "!", eChatType.CT_Important, eChatLoc.CL_ChatWindow);
}
}
public static string getPvPZone()
{
return m_PvPZone;
}
public static string ZoneWithHighestAmountOfVotes()
{
int highest = 0;
string strHighest = "";
foreach (KeyValuePair<string, int> kvp in m_MapsAndVotes)
{
if (kvp.Value > highest)
{
highest = kvp.Value;
strHighest = kvp.Key;
}
}
m_MapsAndVotes = new Dictionary<string, int>();
m_IPsVotedAndVote = new Dictionary<string, string>();
return strHighest;
}
public static int NumberOfVotes(string str)
{
int number = 0;
if (m_MapsAndVotes.ContainsKey(str))
{
number = m_MapsAndVotes[str];
}
return number;
}
public static bool playerHasVoted(GamePlayer player)
{
if (m_IPsVotedAndVote.ContainsKey(player.Client.TcpEndpointAddress))
{
return true;
}
return false;
}
public static void AddVote(string Choice, GamePlayer Player)
{
if (m_IPsVotedAndVote.ContainsKey(Player.Client.TcpEndpointAddress))
{
//
string oldVote = m_IPsVotedAndVote[Player.Client.TcpEndpointAddress];
// int oldCount = m_MapsAndVotes[oldVote];
int oldCount = 0;
if (m_MapsAndVotes.ContainsKey(oldVote))
{
oldCount = m_MapsAndVotes[oldVote] - 1;
m_MapsAndVotes.Remove(oldVote);
}
m_MapsAndVotes.Add(oldVote, oldCount);


m_IPsVotedAndVote.Remove(Player.Client.TcpEndpointAddress);
m_IPsVotedAndVote.Add(Player.Client.TcpEndpointAddress, Choice);

//int newCount = m_MapsAndVotes[Choice];
int newCount = 1;
if (m_MapsAndVotes.ContainsKey(Choice))
{
newCount = m_MapsAndVotes[Choice] + 1;
m_MapsAndVotes.Remove(Choice);
}
m_MapsAndVotes.Add(Choice, newCount);
}
else
{
m_IPsVotedAndVote.Add(Player.Client.TcpEndpointAddress, Choice);

//int newCount = m_MapsAndVotes[Choice];
int newCount = 1;
if (m_MapsAndVotes.ContainsKey(Choice))
{
newCount = m_MapsAndVotes[Choice] + 1;
m_MapsAndVotes.Remove(Choice);
}
m_MapsAndVotes.Add(Choice, newCount);
}


const string VotePvP = "VotePvP";
long PvPVote = Player.TempProperties.getProperty<long>(VotePvP);
long changeTime = Player.CurrentRegion.Time - PvPVote;
if (NumberOfVotes(Choice) > 2 && changeTime < 30000)
{
PvPHandler.setPvPZone(Choice);
Player.TempProperties.setProperty(VotePvP, Player.CurrentRegion.Time);
}
else if (NumberOfVotes(Choice) > 2)
{
Player.Out.SendMessage("You must wait " + ((30000 - changeTime) / 1000).ToString() + " more second to attempt to use this command!", eChatType.CT_System, eChatLoc.CL_ChatWindow);
return;
}
}
public static void PortToPvPZone(GamePlayer player)
{
GameNPC npc = currentPvPPort();

int num = 0;
num = WorldMgr.GetClientsOfRegionCount(npc.CurrentRegionID);
if (npc == null)
{
player.Out.SendMessage("Error : 0 Vote", eChatType.CT_Important, eChatLoc.CL_ChatWindow);
return;
}
if (player.Client.Account.PrivLevel == 1)
{
if (WorldMgr.GetClientsOfRegionCount(51) > QueueTeleporter.MaxPlayers)
{
player.Out.SendMessage("Sorry, but at this time the zone" + getPvPZone() + " is full. Would you like to [Join] the Queue?", eChatType.CT_Say, eChatLoc.CL_PopupWindow);
return;
}
else
{
player.Out.SendMessage("You are now teleporting to" + getPvPZone() + "!", eChatType.CT_Say, eChatLoc.CL_PopupWindow);
player.MoveTo(npc.CurrentRegionID, npc.X, npc.Y, npc.Z, npc.Heading);
player.Bind(true);
}
}
else if (player.Client.Account.PrivLevel == 3 || player.Client.Account.PrivLevel == 2)
{
if (WorldMgr.GetClientsOfRegionCount(51) > QueueTeleporter.MaxPlayers)
{
player.Out.SendMessage("Sorry, but at this time the zone" + getPvPZone() + " is full. Would you like to [Join] the Queue?", eChatType.CT_Important, eChatLoc.CL_ChatWindow);
return;
}
else
{
player.Out.SendMessage("You are now teleporting to" + getPvPZone() + "!", eChatType.CT_Say, eChatLoc.CL_PopupWindow);
player.MoveTo(npc.CurrentRegionID, npc.X, npc.Y, npc.Z, npc.Heading);
player.Bind(true);
}
}
}

public static GameNPC currentPvPPort()
{
GameNPC[] npcs = WorldMgr.GetNPCsByName(m_PvPZone, eRealm.None);
if (npcs.Length > 0 && npcs != null)
{
foreach (var npc in npcs)
if (npc.GuildName == "PvP Setup") return npc;
}
return npcs[0];
}
public class QueueTeleporter : GameNPC
{
// the list that players will be stored in
public static Queue<GamePlayer> QueueList = new Queue<GamePlayer>();
// Max players allowed in PvP
public static ushort MaxPlayers = 1;
// Add To World
public override bool AddToWorld()
{
Name = "Master Teleporter";
Level = 80;
return base.AddToWorld();
}
// Interaction with NPC
public override bool Interact(GamePlayer player)
{
if (!base.Interact(player)) return false;
TurnTo(player.X, player.Y);
string message = "Greetings " + player.Name + "!";
message += "\n\nWhere would you like to teleport?\n\n - [PvP] - [" + PvPHandler.getPvPZone() + "] - (" + WorldMgr.GetClientsOfRegionCount(51) + "/" + MaxPlayers + ") ";
Utils.ClearChat(player);
SendReply(player, message);
return true;
}
// WhisperRecieve
public override bool WhisperReceive(GameLiving source, string text)
{
if (base.WhisperReceive(source, text))
{
GamePlayer player = source as GamePlayer;
if (player == null)
return false;
{

if (text == "PvP")
{
if (WorldMgr.GetClientsOfRegionCount(51) > MaxPlayers)
{
player.Out.SendMessage("Sorry, but at this time the zone" + PvPHandler.currentPvPPort() + " is full. Would you like to [Join] the Queue?", eChatType.CT_Say, eChatLoc.CL_PopupWindow);
return true;
}
else
{
PvPHandler.PortToPvPZone(player);
player.Bind(true);
return true;
}
}
if (text == "Join")
{
QueueList.Enqueue(player);
player.Out.SendMessage("Congradulations, you have just entered the Queue! There are " + QueueList.Count + " listings in the queue! ", eChatType.CT_Staff, eChatLoc.CL_ChatWindow);
player.Out.SendMessage("Waiting List Total: " + QueueList.Count + "\n " + QueueList.Peek() + " is at the front of the Queue", eChatType.CT_Say, eChatLoc.CL_PopupWindow);
return true;
}

}
}
return true;
}
// SendReply
public void SendReply(GamePlayer player, string msg)
{
player.Out.SendMessage(msg, eChatType.CT_System, eChatLoc.CL_PopupWindow);
}
}
}
}




This is the WHOLE Script.


This is what i'm trying to figure out...
Code: Select all
(" + WorldMgr.GetClientsOfRegionCount() + "/" + MaxPlayers + ") ";
1. "WorldMgr.GetClientsOfRegionCount()" What i'm trying to do here is retrieve the ID even if the map changes.
But my question is, "How Can I Get The Region ID from this part of the code public static GameNPC currentPvPPort()"...
Code: Select all
public static GameNPC currentPvPPort()
{
GameNPC[] npcs = WorldMgr.GetNPCsByName(m_PvPZone, eRealm.None);
if (npcs.Length > 0 && npcs != null)
{
foreach (var npc in npcs)
if (npc.GuildName == "PvP Setup") return npc;
}
return npcs[0];
}
2. Getting it so ^ this part of the code will show the current Zones name as a string right here without it saying a bunch of weird text in game...
message += "\n\nWhere would you like to teleport?\n\n - [PvP] - [" + PvPHandler.currentPvPPort() + "]

Re: PvP Region To ID

PostPosted: Thu Sep 08, 2011 12:59 pm
by geshi
Code: Select all
message += "\n\nWhere would you like to teleport?\n\n - [PvP] - [" + PvPHandler.getPvPZone() + "]
I should upload the latest version, I fixed a few things to do with this I think.
Code: Select all
To get the region just use PvPHandler.currentPvPPort().CurrentRegionID.

*begs for geshi*

Re: PvP Region To ID

PostPosted: Thu Sep 08, 2011 1:13 pm
by Dunnerholl
yeah, as geshi said, you get the id from the npc that u get back from this function call :)

Re: PvP Region To ID

PostPosted: Thu Sep 08, 2011 7:30 pm
by Graveen
Now what does this exactly do if you don't mind explaining?

Edit:
this gave me an error that all paths do not return a value.
Code: Select all
public static GameNPC currentPvPPort()
{
GameNPC[] npcs = WorldMgr.GetNPCsByName(m_PvPZone, eRealm.None);
if (npcs.Length > 0 && npcs != null)
{
foreach (var npc in npcs)
if (npc.GuildName == "PvP Setup") return npc;
}
}
replace ONLY the block i have quoted.

Re: PvP Region To ID

PostPosted: Thu Sep 08, 2011 9:03 pm
by Dunnerholl
Now what does this exactly do if you don't mind explaining?

Edit:
this gave me an error that all paths do not return a value.
Code: Select all
public static GameNPC currentPvPPort()
{
GameNPC[] npcs = WorldMgr.GetNPCsByName(m_PvPZone, eRealm.None);
if (npcs.Length > 0 && npcs != null)
{
foreach (var npc in npcs)
if (npc.GuildName == "PvP Setup") return npc;
}
}
replace ONLY the block i have quoted.
but this doesnt return null if nothing is found

Re: PvP Region To ID

PostPosted: Thu Sep 08, 2011 9:27 pm
by Graveen
if he follows my first post of the thread, yes it is ;)