PDA

View Full Version : Save pvp state on zone in.


Figback65
06-14-2013, 02:45 PM
Hello everyone. I am having an issue trying to save the clients pvp state upon zone in so when they leave the zone it will revert them back to their pre-zone in pvp state.

So lets say. your pvp state is 0 or off. You zone into a pvp only zone, lets say ecommons. I need it to save their state of pvp 0, change them to pvp 1, then when they zone out reload the pvp 0. I figured I needed to use qglobals to store the intial pvp state but I cannot get it right. It either doesn't work other times crashes the zone.

Here is what I have so far.
sub EVENT_ENTERZONE {

if($client->GetPVP() == $client->GetPVP(1){
quest::setglobal("PvPState", $PvP, 2, "F");
}

$client->SetPVP(1);
$client->Message(15, "It's time for some Mischief, kill or be killed!");
}


sub EVENT_ZONE {

if $PvP == $client->GetPVP(0) {
$client->SetPVP(0);
}

}


Thanks guys!

Fig

Dunge0nMastr
06-14-2013, 03:29 PM
if($client->GetPVP() == $client->GetPVP(1)

think you need an extra )
if($client->GetPVP() == $client->GetPVP(1)) {

Figback65
06-14-2013, 05:56 PM
Thank you for noticing that. changed it but its still not working. here is a newer try and even more a mess. I am sure im over complicating things but still learning lol.


sub EVENT_ENTERZONE {
my $on = $client->GetPVP(1);
my $off = $client->GetPVP(0);

if($client->GetPVP() == $client->GetPVP(1)){
quest::setglobal("PvPState", $PvP, 2, "F");
}
if($client->GetPVP() == $client->GetPVP(0)){
quest::setglobal("PvPState2", $PvP2, 2, "F");

$client->SetPVP(1);
$client->Message(15, "It's time for some Mischief, kill or be killed!");
}


sub EVENT_ZONE {

if ($PvP == $on) {
$client->SetPVP(1);
}

if ($PvP2 == $off) {
$client->SetPVP(0);
}


}

Kingly_Krab
06-14-2013, 06:48 PM
Sir, from your code it doesn't look like you're assigning $PvP or $PvP2 to a value, also I don't believe it's necessary to do this 'if($client->GetPVP() == $client->GetPVP(0))' I believe you can do 'if($client->GetPVP() == 0)', you must pre-define $PvP and $PvP2 before you're capable of using them. you were Ymissing a curly to close sub EVENT_ENTERZONE, also, you must re-define each variable for a different event unless you define it globally outside of the sub event.

Figback65
06-14-2013, 06:52 PM
I had found the curly. Thank you. I agree with you, im not assigning the values right or something. K ill move the variables. That makes sense..
Will update.

NatedogEZ
06-15-2013, 12:52 AM
Fixed heh

sub EVENT_ENTERZONE {
quest::setglobal("PvPState",$client->GetPVP(),5,"F"); #Adds their PVPstate to gloabl
$client->SetPVP(1);
}

sub EVENT_ZONE {
if(defined $qglobals{"PvPState"} && $qglobals{"PvPState"}==1)
{
$client->SetPVP(1); #Player was already PVP before entering zone will remain PVP on zone out
}
else
{
$client->SetPVP(0); #This player was not PVP flagged when zoning in
}

}




Here is the code I use for a PVP zone...

Limits the zone to a single character in the zone per IP

Requires that the zone is STATIC though


sub EVENT_ENTERZONE {
my $playerip = $client->GetIP();
@pvplist;
if ( grep { $_ eq $playerip } @pvplist )
{

$client->Message(315,"YOU MAY ONLY HAVE ONE CHARACTER IN THIS ZONE!");
push(@pvplist, "$playerip");
$client->MovePC(348, 1.8, 1.6, -22.8, 187);
return;
}
push(@pvplist, "$playerip");
$client->SetPVP(1);
}

sub EVENT_ZONE {
my $playerip = $client->GetIP();
my $count = 0;
foreach $pvp_player (@pvplist)
{
next unless $pvp_player = $playerip;
$count++;
}

if ($count >= 2)
{
@pvplist = grep {$_ ne $playerip} @pvplist;
push(@pvplist, "$playerip"); #Add the IP back to list since there are 2 of the same IP
}
else
{
@pvplist = grep {$_ ne $playerip} @pvplist;
}
$client->SetPVP(0);
}

sub EVENT_DISCONNECT {
my $playerip = $client->GetIP();
my $count = 0;
foreach $pvp_player (@pvplist)
{
next unless $pvp_player = $playerip;
$count++;
}

if ($count >= 2)
{
@pvplist = grep {$_ ne $playerip} @pvplist;
push(@pvplist, "$playerip"); #Add the IP back to list since there are 2 of the same IP
}
else
{
@pvplist = grep {$_ ne $playerip} @pvplist;
}
}

Figback65
06-15-2013, 01:09 AM
Thank you for the input. I'm needing the player to return to the pvp state (derp just saw YOUR edit after my extensive editing lol) they were before they entered the contested zone. To paint the picture. I am having mischief be a pvp zone. upon entering you are forced pvp. now when you leave the zone I need it to return the player to their previous pvpstate, so if they were 0 then make them 0 but if they were state 1, leave them pvp. I was trying todo it in the player.pl in folder mischiefplane but due to not being able to share the global from EVENT ENTERZONE to EVENT ZONE, I believe it needs to be handled in global_player.

this is the current run after a few hours. it still doesn't initialize lol.
Oh c0ncrete I came across a post about perl -c filename.pl love it!

sub EVENT_ENTERZONE {

if(!defined $qglobals{PvPState}) {

if($client->GetPVP() == 1) {
quest::setglobal("PvPState", $PvP, 4, "F");
$client->Message(15, "pvp saved!");

if($zonesn =~ /^mischiefplane$/) {
$client->SetPVP(1);
$client->Message(15, "It's time for some Mischief, kill or be killed");
}

elsif ($PvP == $client->GetPVP(1)) {
$client->SetPVP(1);
$client->Message(15, "pvp on!");
}
else {
$client->SetPVP(0);
$client->Message(15, "pvp off!");
}

}

}

}

Figback65
06-15-2013, 01:18 AM
damn you can pull qglobals between different events

hmm im still crashing, gonna mess with it a few minutes!

Thanks a ton!

Figback65
06-15-2013, 01:31 AM
Its mostly working besides when you zone out, its just turning pvp off, I turned pvp on, zoned into a pvp zone, then zoned out and went blue.
we almost got it though



sub EVENT_ENTERZONE {
quest::setglobal("PvPState",$client->GetPVP(),5,"F"); #Adds their PVPstate to gloabl

if($zonesn =~ /^mischiefplane$/) {
$client->SetPVP(1);
$client->Message(15, "It's time for some Mischief, kill or be killed");
}



}

sub EVENT_ZONE {
if(defined $qglobals{"PvPState"} && $qglobals{"PvPState"}==1)
{
$client->SetPVP(1); #Player was already PVP before entering zone will remain PVP on zone out
}
else
{
$client->SetPVP(0); #This player was not PVP flagged when zoning in
}

}

Figback65
06-15-2013, 01:51 AM
[06.15. - 01:47:06] Argument "" isn't numeric in numeric eq (==) at quests/templates/global_player.pl line 29.

if(defined $qglobals{"PvPState"} && $qglobals{"PvPState"}==1)

Ill work on it some more tomorrow.
Thanks again for the help!

NatedogEZ
06-15-2013, 02:49 AM
sub EVENT_ENTERZONE {
quest::setglobal("PvPState",$client->GetPVP(),5,"F");
$client->SetPVP(1);
}

sub EVENT_ZONE {
if(defined $qglobals{"PvPState"} && $qglobals{"PvPState"}==1)
{
$client->SetPVP(1);
}
else
{
$client->SetPVP(0);
}
}





This works just fine for me .. hmmm

lerxst2112
06-15-2013, 06:04 AM
If I had to guess I'd say the qglobal may have been set weird from previous attempts to get this working. You might try deleting it and see if it works better after that.

Figback65
06-15-2013, 12:11 PM
roger, on it. Will update after testing
Thanks Lerxst

Figback65
06-15-2013, 12:47 PM
Hmm I dunno what I am doing wrong then. These are my steps.

I deleted the qglobals for the quest in the table
#reloadpl
#pvp off
#zone ecommons
(PVP Turns on)
#zone nro
(PVP Stays On when intial was #pvp off)
#zone sro
(PVP Still on)
NateDogs Version
sub EVENT_ENTERZONE {
quest::setglobal("PvPState",$client->GetPVP(),5,"F");
$client->SetPVP(1);
}

sub EVENT_ZONE {
if(defined $qglobals{"PvPState"} && $qglobals{"PvPState"}==1)
{
$client->SetPVP(1);
}
else
{
$client->SetPVP(0);
}
}


Steps with my Version
I again clear Qglobals.
#reloadpl
#pvp off
#zone ecommons
(PVP Still off)
#zone nro
(pvp still off)
#zone mischiefplane
(PVP Turns on)
#zone ecommons
(PVP Turns Off) Seems to work but false)

Again Clear qglobals
#reloadpl
#pvp on
#zone ecommons
(PVP Turns off)

My Version
sub EVENT_ENTERZONE {
quest::setglobal("PvPState",$client->GetPVP(),5,"F"); #Adds their PVPstate to gloabl

if($zonesn =~ /^mischiefplane$/) {
$client->SetPVP(1);
$client->Message(15, "It's time for some Mischief, kill or be killed");
}



}

sub EVENT_ZONE {
if(defined $qglobals{"PvPState"} && $qglobals{"PvPState"}==1)
{
$client->SetPVP(1); #Player was already PVP before entering zone will remain PVP on zone out
}
else
{
$client->SetPVP(0); #This player was not PVP flagged when zoning in
}

}


In Conclusion: My version is always pvpoff on zoneout, Nates is always pvpon with zonein.

If this makes sense lol

Uleat
06-15-2013, 01:25 PM
On yours..

If you clear globals ("PvPState" = 0) and use #pvp on, when will EVENT_ZONE ever catch $qglobals("PvPState") == 1?

Shouldn't you check $client to set $qglobals on the way out, instead of vica-versa?

Figback65
06-15-2013, 01:57 PM
Thanks Uleat!

I was wondering about that, after I clear it has no value. I did try zoning to a normal zone to make the global then did my test as well, got the same result.

On the way out will probably work better. or maybe change sub EVENT ENTERZONE to CONNECT?
Going to work on that now. Will update!!!

Figback65
06-15-2013, 02:24 PM
Another update, by watching the globals table on the "PvPState row,
Value on the right was remaining empty. Still isnt pulling 1 or 0
quest::setglobal("PvPState",$client->GetPVP(),5,"F");

128 0 0 PvPState

NatedogEZ
06-15-2013, 02:35 PM
|| *charid* || *npcid* || *zoneid* || *name* || *value* || *expdate* ||
|| 224 || 0 || 0 || PvPState || 1 || _NULL_ ||



Working for me... thats my character zoning in PVP flagged so "Value" is set to 1



When i zone in while not flagged it gets set to nothing ... so thats why I was checking for PvPState==1

Figback65
06-15-2013, 02:51 PM
Could it be a perl version difference? I copied your script directly from the post, deleted everything else but your version in global player. zoned to like 10 different zones in a row and value never gained 1 or 0. All it does is always make me pvp no matter what state I start with or zone I go to. is there something in your player.pl for the zones?
perl 5.10.1 build 1007


er wait, checking something
I tried zoning with and without pvp flag turned on initially. still stores no value for me. :/

NatedogEZ
06-15-2013, 03:01 PM
Without PVP it stores NO VALUE :p

with PVP it stores it as a 1

So when they zone back out if its 1 .. they are set back to PVP when zoning out... else it turns off PVP when they zone out... meaning that it had no value

Figback65
06-15-2013, 03:15 PM
Thank you for clarifying that. I was noticing that the more I zoned back and forth. Its still not working properly for me but im widdling away. will post an update later. I think im getting close tho lol *hopes*

Thank you for all the help guys!

edit: As Uleat stated if you change pvp states and you zone. The qglobal doesn't get saved that you changed to a new state and then it will call the previous state from the last zone. That's my issue atm. So if your pvpoff and talk to npc and say pvpon, then zone, it just loads the global from the zone and your not pvp anymore.

Can you set a global in ENTERZONE and ZONE with the same name and it just auto overwrites? Like so when you ENTERZONE and sets value 1 pvpstate then you ZONE and make another global named pvpstate and just overwrites the previous to record a state change between ENTERZONE and ZONE? Or does it need to be deleted and refreshed per sub?

Figback65
06-15-2013, 03:43 PM
This works almost. It saves the state change between zoning and applies it. I watch the state change to empty from 1 when zoning after changing from pvpon to pvpoff but then about 2 seconds pass and your name still turns read.
It even says the chat msg of "You no longer follow the ways of discord" but still turns back on after the couple seconds.
Possible hard coding conflict?
Edit : I don't think its hard coding, still blindly missing the correct order I guess. Because it does change the globals from 1 to Nothing to save the change after talking to NPC but when the name turns red after the couple seconds the pvpstatus value changes back to 1. So, its somewhere in the script always applying the change maybe. lol I envy you smart guys who know this stuff. I am learning through trial, error and eqemu forums :)

notice the del qglobals are # for testing purposes.

sub EVENT_ENTERZONE {
quest::setglobal("PvPState",$client->GetPVP(),5,"F");
if(defined $qglobals{"PvPState"} && $qglobals{"PvPState"}==1)
{
$client->SetPVP(1);
#quest::delglobal([PvPState]);
}
elsif($zonesn =~ /^mischiefplane$/) {
$client->SetPVP(1);
$client->Message(15, "It's time for some Mischief, kill or be killed");

}
else
{
$client->SetPVP(0);
#quest::delglobal([PvPState]);
}
}

sub EVENT_ZONE {
quest::setglobal("PvPState",$client->GetPVP(),5,"F");
if(defined $qglobals{"PvPState"} && $qglobals{"PvPState"}==1)
{
$client->SetPVP(1);
#quest::delglobal([PvPState]);

}
else
{
$client->SetPVP(0);
#quest::delglobal([PvPState]);

}
}

NatedogEZ
06-15-2013, 04:07 PM
wait are you doing this in the global_player.pl ??

(since you are checking the zone shortname)


If so then my script would have to be changed I could help ya more when I get back =p

Figback65
06-15-2013, 04:19 PM
Ya lol the global_player. I think I got the closed loop working to save state changes between zone in and out. but it doesn't clear mischiefplanes direct set of pvpon. worken on that now.

NatedogEZ
06-15-2013, 11:15 PM
Why not just use the player.pl for the zone that is a PVP zone? Or do you have multiple pvp zones?

lerxst2112
06-15-2013, 11:39 PM
If you need to use it as a gloab file you might look at the code or add some logging. It's possible when more than one zone is involved that the events overlap and aren't processed in the order you might expect.

Figback65
06-15-2013, 11:57 PM
I do plan on having multiple zones that are considered "contested" plane of mischief is one of them. So the point being able to turn u pvp when u zone in and turn you back on or off depending what u were before u zoned in.

I butted heads with this for hours today, I got it to save the pvp state for the most part bbut when you hit a contested zone it screws it up. I tried making a global for the contested zones but that's where I stopped at, needed a break lol.

lerxst2112
06-16-2013, 12:42 AM
Well, if you have it global it would seem you only need to handle the enter zone event and do the right thing there. If it's a zone where they should be pvp then save the current state and set pvp on. If it isn't one of those zones then restore the old state.

Figback65
06-16-2013, 05:05 PM
Well, if you have it global it would seem you only need to handle the enter zone event and do the right thing there. If it's a zone where they should be pvp then save the current state and set pvp on. If it isn't one of those zones then restore the old state.

that covers everything except the optional pvp change between zones.

Parts of everything we have tried work but not as a whole in the script meaning sometimes it will save the change but not load it or forcing pvp from zones messes up the global rotation. Still working on it. I am getting closer though.

Just gotta have the recall of globals at the right time. And I gotta figure out how to call the global after exiting a specific zone. Like with code listed above, when you zone into mischief, I call short name and force pvp, but when you zone out, its not calling the preset global. I think I may have to copy the shortname call to EVENT_ZONE as well, if that will work. going to play with that today. Orignally I was just trying to recall the global at ALL zone ins but I cant get that to work. In theory when you read the script, it should work but its not lol. Sometimes it looks like its working and changes the correct pvp state but then it will change a few seconds later lol. This math of words is crazy!!! lol

lerxst2112
06-16-2013, 06:38 PM
Like I said before, if the events happen in a different order than you think they do the logic of the script will be broken.

I haven't looked at the code, but consider if you got EVENT_ZONE for the old zone after you got ENTER_ZONE for the new zone.

I don't see anything in your existing script that can't be handled by the single ENTER_ZONE event. There is nothing optional in your script, just force pvp on in mischief and set it to the old state for everything else.

NatedogEZ
06-17-2013, 03:30 AM
sub EVENT_ENTERZONE {
#this is all the contested zones
my @zonelist = qw(
commons
mischiefplane
);

if ( grep { $_ eq $zonesn } @zonelist ) #Save PVP state if you zone into a contested zone
{
quest::setglobal("PvPState",$client->GetPVP(),5,"F"); #Adds their PVPstate to global
$client->SetPVP(1);
}
}



This will make it so it only flags you when zoning into your contested zones

Figback65
06-18-2013, 09:11 PM
Didn't work :( After you zoned into the contested and zoned out it still kept you the forced pvp state.


BUT, thanks to all of you, its now working.

sub EVENT_ENTERZONE {
#this is all the contested zones
my @zonelist = qw(
mischiefplane
);
if ( grep { $_ eq $zonesn } @zonelist ) { #Save PVP state if you zone into a contested zone
quest::setglobal("PvPState",$client->GetPVP(),5,"F"); #Adds their PVPstate to global
$client->SetPVP(1);
}

}

sub EVENT_ZONE {
my @zonelist = qw(
mischiefplane
);
if ( grep { $_ eq $zonesn } @zonelist ) { #If you zone out a contested zone
if(defined $qglobals{"PvPState"} && $qglobals{"PvPState"}==0) { #Checks global PVPState & Check if PvPState = 0
$client->SetPVP(0) #Then turn pvp off
}
}
}


Now for the next part lol.
I am working on a bonus to players who play as pvp for the risk vs reward. I could not get the bonus to kick in without a sub event being called. Which means if even you turn pvp, the bonus wont kick in until you zone, item, or whichever. So the only solution I could come up with was to use a timer on each logged in character at all times. Will that be a memory hog? Would there be a better way?

1 major problem is the bonus will not turn on when you zone into a contested zone and the pvp is forced. I Will continue to work on it!