PDA

View Full Version : New Credit System Using Quest Globals


trevius
09-09-2008, 07:39 AM
This is a new system I made for a zone on my server. It isn't too complicated, but it took a little while to figure it all out and get it working. Anyone can use this and adjust it to do whatever they might like. Most of the stuff in it can be removed or changed where needed. There are 3 quest scripts for this system. The first one is the Mob script for the mobs that are killed. The second and is the quest NPC that gives rewards for the credits. And the 3rd is the NPC that gives out the initial globals to the character and explains a little about the zone.

All of the notes in GREEN are only comments and can be removed. I added them for this submission so people could easily see and understand exactly what is being done at each step of the scripts.

There are 3 main points to using this system. The first one is to add in a new type of currency that can be used to purchase items or as part of another quest. The second part is to make a new way for characters to level above level 50 at an accelerated rate without having the zone abused for insanely fast AA leveling. The level rate can be adjusted to any rate desired. The 3rd reason is to have a zone that AE groups cannot abuse by using an Anti-AE check.

The system can be used as-is or it can be modified however you see fit. I figured it might be useful to someone. And since it is fairly different from anything I have seen, I thought it would make a good quest submission.

Here they are:

################################################## #################
### NPC Quest for gaining credits when the NPC dies ###
################################################## #################
##The anti_ae global is set to expire after X amount of time
##Setting expire time for it will adjust how quickly credits can be earned.
##The exp_credits global is used to track how many kills the player has made.
##Using this system, you can define exactly how many kills/credits are required to gain each level.
##The point of exp_credits is to make a system separate from normal experience so that the zone
##cannot be abused by AE groups to gain AA points quickly, but it can still have accelerated leveling.
##The new_credits global is used to track how many kills the player has made also.
##These credits are the ones used for purchasing quest rewards.
##The $exp_req variable is what defines how many credits are required for each level or level range.
##The $exp_needed variable does not need to be adjusted. It is used for displaying the character's total credits
##The unique_spawn command is used to spawning an optional named mob.
################################################## #################

sub EVENT_KILLED_MERIT {

#Checking if the anti-AE global is defined to stop credits from being earned if it is
if (!defined($qglobals{anti_ae})) {

#Optional code to randomly spawn a named NPC when the target dies.
my $x = $npc->GetX();
my $y = $npc->GetY();
my $z = $npc->GetZ();
my $named = quest::ChooseRandom(1,2,3,4,5,6,7,8,9,10,11,12,13, 14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30 ,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,4 7,48,49,50);

if ($named == 50) {
quest::unique_spawn(quest::ChooseRandom(2700667,27 00670,2700673,2700676,2700683,2700685),0,0,$x,$y,$ z);
$named = undef;}

#Checking if the exp_credit global is defined for this character
if (defined($qglobals{exp_credits})) {
#Making sure the character is not already level 70+
if ($ulevel <= 69) {
#Adding 1 point/credit to the exp_credits global
quest::setglobal("exp_credits", $qglobals{exp_credits}+1, 1, "F");

#Checking the character's level range
if ($ulevel >= 50 && $ulevel <= 55) {
#Variable to define how many exp_credits are needed to level in this level range.
my $exp_req = 24;
if ($qglobals{exp_credits} >= $exp_req) {
quest::level($ulevel+1);
#subtract the actual exp_credits global points. Note that this has to be 1 more than the exp_req global is set to.
quest::setglobal("exp_credits", $qglobals{exp_credits}-25, 1, "F");
}
my $exp_needed = ($exp_req - $qglobals{exp_credits});
$client->Message(5, "You currently need $exp_needed experience credits for your next level.");
}
#same thing as above, but for the next higher level range
if ($ulevel >= 56 && $ulevel <= 60) {
my $exp_req = 29;
if ($qglobals{exp_credits} >= $exp_req) {
quest::level($ulevel+1);
quest::setglobal("exp_credits", $qglobals{exp_credits}-30, 1, "F");
}
my $exp_needed = ($exp_req - $qglobals{exp_credits});
$client->Message(5, "You currently need $exp_needed experience credits for your next level.");
}
if ($ulevel >= 61 && $ulevel <= 65) {
my $exp_req = 34;
if ($qglobals{exp_credits} >= $exp_req) {
quest::level($ulevel+1);
quest::setglobal("exp_credits", $qglobals{exp_credits}-35, 1, "F");
}
my $exp_needed = ($exp_req - $qglobals{exp_credits});
$client->Message(5, "You currently need $exp_needed experience credits for your next level.");
}
if ($ulevel >= 66 && $ulevel <= 69) {
my $exp_req = 39;
if ($qglobals{exp_credits} >= $exp_req) {
quest::level($ulevel+1);
quest::setglobal("exp_credits", $qglobals{exp_credits}-40, 1, "F");
}
my $exp_needed = ($exp_req - $qglobals{exp_credits});
$client->Message(5, "You currently need $exp_needed experience credits for your next level.");
}

}
#If the character is level 70+, delete the exp_credit global for them since it is no longer needed.
if ($ulevel >= 70) {
quest::delglobal("exp_credits");
}

}

#Checking if the new_credits global is defined for this character
if (defined($qglobals{new_credits})) {
#Adding 1 point/credit to the new_credits global
quest::setglobal("new_credits", $qglobals{new_credits}+1, 1, "F");
#Setting the anti_ae global after all credits are applied.
quest::setglobal("anti_ae", 1, 1, "S5");
my $total_credits = ($qglobals{new_credits} + 1);
$client->Message(5, "You currently have $total_credits Credits.");
}

}

}




################################################## ##################
### Quest for turning in items and spending credits for upgrades ###
################################################## ##################
##The new_credits global is used to track how many kills the player has made.
##These credits are the ones used for purchasing quest rewards.
################################################## ##################

sub EVENT_SAY {

if($text =~ /Hail/i) {
if (!defined($qglobals{new_credits})) {
#This tells the player to hail the NPC that sets the credit globals on their character if they haven't already
quest::say ("Nice to meet you, $name. You should speak with the Camp Leader before you do anything else here."); }

if (defined($qglobals{new_credits})) {
quest::say ("I can upgrade your Timeless [armor] if you have enough [credits] for it."); }
}

if($text =~ /credits/i && defined($qglobals{new_credits})) {
quest::say ("To upgrade your armor, you must turn in the Timeless piece that you wish to upgrade, and you must also have enough credits to afford the labor [costs]."); }

if($text =~ /costs/i && defined($qglobals{new_credits})) {
quest::say ("Upgrading Chest and Leg armor pieces costs 35 credits each. For bracers, boots, helms, sleeves, and gloves, they cost 25 credits each."); }

if($text =~ /armor/i && defined($qglobals{new_credits})) {
quest::say ("I can do upgrades for Chest, Legs, bracers, boots, helms, sleeves, and gloves. For all other accessories, you should speak with Seenfa Tungtrip."); }


}

sub EVENT_ITEM {

#This is the hash of item turn ins and upgrade rewards with comments as to what each is.

my %armor = (
2683 => 3482, #Chain_Boots
2672 => 3479, #Chain_Bracer
2668 => 3397, #Chain_Coif
2673 => 3480, #Chain_Gauntlets
2670 => 3442, #Chain_Vambraces
2826 => 3537, #Cloth_Boots
2810 => 3540, #Cloth_Bracer
2807 => 3582, #Cloth_Cap
2812 => 3539, #Cloth_Gloves
2809 => 3541, #Cloth_Sleeves
2730 => 3625, #Leather_Boots
2687 => 3486, #Leather_Bracer
2684 => 3483, #Leather_Cap
2717 => 3487, #Leather_Gloves
2686 => 3485, #Leather_Sleeves
2667 => 3233, #Plate_Boots
2664 => 3230, #Plate_Bracer
2665 => 3231, #Plate_Gauntlets
2661 => 3226, #Plate_Helm
2663 => 3229, #Plate_Vambraces
2437 => 3234, #Crown
2438 => 3235, #Bracer
);

#Separate hash item turn ins and rewards to allow for separate credit prices
my %chestlegs = (
2669 => 3404, #Chain_Breastplate
2675 => 3481, #Chain_Greaves
2808 => 3542, #Cloth_Robe
2820 => 3538, #Cloth_Leggings
2685 => 3484, #Leather_Breastplate
2718 => 3491, #Leather_Leggings
2662 => 3227, #Plate_Breastplate
2666 => 3232, #Plate_Greaves
);

#Verify that the character has enough credits for the turn in.
if ($qglobals{new_credits} >= 25) {
#Sort the hash
for my $armor (sort keys %armor) {
if(defined($armor)) {
#Check the item turn in is correct and in the hash
if (plugin::check_handin(\%itemcount, $armor => 1)) {
#Check to make sure that there is a reward defined for the turn in
if(defined($armor{$armor})) {
quest::emote("recognizes your efforts and fashions an upgrade for your armor piece" );
quest::say("Thank you, $name, here is your upgraded armor piece!");
quest::exp(45000);
#Subtract the amount of credits for the upgrade purchase
quest::setglobal("new_credits", $qglobals{new_credits}-25, 1, "F");
#Reward the player with the upgrade reward.
quest::summonitem($armor{$armor});
#Send a message with the character's new credit total after the purchase
my $total_credits = ($qglobals{new_credits} - 25);
$client->Message(5, "You have spent 25 Corathus Credits and now have $total_credits remaining credits.");
}
}
#This is supposed to return items if the wrong one is turned in, but it just eats incorrect items.
#This is the only part of all credit quests that doesn't work properly yet as it should.
# else {
# plugin::return_items(\%itemcount);
# quest::say ("I have no use for this item, $name.");
# }
}
}
}
#This repeats the process above accept for the items of a higher credit cost
if ($qglobals{new_credits} >= 30) {
for my $chestlegs (sort keys %chestlegs) {
if(defined($chestlegs)) {
if (plugin::check_handin(\%itemcount, $chestlegs => 1)) {

if(defined($chestlegs{$chestlegs})) {
quest::emote("recognizes your efforts and fashions an upgrade for your armor piece" );
quest::say("Thank you, $name, here is your upgraded armor piece!");
quest::exp(45000);
quest::setglobal("new_credits", $qglobals{new_credits}-30, 1, "F");
quest::summonitem($chestlegs{$chestlegs});
my $total_credits = ($qglobals{new_credits} - 30);
$client->Message(5, "You have spent 30 Corathus Credits and now have $total_credits remaining credits.");
}
}
# else {
# plugin::return_items(\%itemcount);
# quest::say ("I have no use for this item, $name.");
# }
}
}
}
#This returns the items if the character does not have enough credits to make the purchase
else {
plugin::return_items(\%itemcount);
# quest::say ("You don't have enough credits for that, sorry.");
}

}



################################################## ##################
### Introduction to the Credit System ###
################################################## ##################
##This NPC must be hailed in order to give the globals for both credit systems to the character
##It can also be used to help explain a little about the system and to check credit totals
################################################## ##################

sub EVENT_SAY {

if($text =~ /Hail/i) {

#If hailed, this checks if the player has the correct globals defined and if not, it adds the globals
#This hail is required before any credits can be earned with this system.
if ((!defined($qglobals{exp_credits}))&&(!defined($qglobals{new_credits}))) {
quest::say ("Hail, $name, welcome to Corathus! Would you like me to tell you about this little [camp] site.");
quest::setglobal("exp_credits", 0, 1, "F");
quest::setglobal("new_credits", 0, 1, "F");
$client->Message(15, "You are now flagged to earn credits from this zone!"); }

#This is a general response to a hail after the character has the proper flags and is level 70+
if ((!defined($qglobals{exp_credits}))&&(defined($qglobals{new_credits}))) {
quest::say ("Hello again, $name! Would you like me to tell you about this [camp] site again? I can also tell you what your Corathus Credit [Total] currently is. Or maybe you would like to [reset] your level credits so you can level here again?"); }

#This is the response for hail if the player has not yet reached level 70.
if ((defined($qglobals{exp_credits}))&&(defined($qglobals{new_credits}))) {
quest::say ("Hello again, $name! Would you like me to tell you about this [camp] site again? I can also tell you what your Corathus Credit [Total] currently is."); }
}

#This is just a response to explain the camp of NPCs where these quests are used
if($text =~ /camp/i) {
quest::say ("To get down from here or back up here, simply click the purple mushrooms nearby. You may also want to speak with the [others] here before you start adventuring. Or maybe you would like to hear what [else] I recommend while you are here."); }

#Another explaination of the camp of NPCs
if($text =~ /others/i) {
quest::say ("The other Frogloks in this camp are able to provide upgrades for Timeless items. Speak with them for the details, but make sure you turn your items into the correct one, as they will not return any incorrect items."); }

#This esplains to turn on AA, since the exp_credits will level characters faster than normal experience can in this case.
if($text =~ /else/i) {
quest::say ("You should turn on Alternate Abilities Experience since normal experience isn't very useful here."); }

#This reports the total credit for the character incase they have forgotten and want to check on their status.
if($text =~ /total/i) {
quest::say ("You currently have a total of $qglobals{new_credits} Corathus Credits."); }

#This will re-add the exp_credits global to the character in case they have lost it for any reason.
#This part mainly only pertains to my server due to special deleveling features I have.
if($text =~ /reset/i && (!defined($qglobals{exp_credits}))) {
quest::setglobal("exp_credits", 0, 1, "F");
$client->Message(15, "Your Level Credits have been reset!"); }


}

paaco
09-09-2008, 09:06 AM
Thanks for posting this Trev, amazing work on some of the stuff on your server. I may try to use this on mine if I can make it work. Keep up the great work and thanks for sharing so much with the rest of us.

paaco
09-12-2008, 01:39 PM
Can't seem to get this to work correctly on a global scale. I have it in eqemu/quests/default.pl

I have confirmed that my test char has the flags to get credits in my quest_globals table.

When I kill mobs, nothing happens at all, any ideas what I overlooked or did wrong? :(

sub EVENT_KILLED_MERIT {

#Checking if the anti-AE global is defined to stop credits from being earned if it is
if (!defined($qglobals{anti_ae})) {

#Optional code to randomly spawn a named NPC when the target dies.
my $x = $npc->GetX();
my $y = $npc->GetY();
my $z = $npc->GetZ();
my $named = quest::ChooseRandom(1,2,3,4,5,6,7,8,9,10,11,12,13, 14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30 ,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,4 7,48,49,50);

if ($named == 50) {
quest::unique_spawn(quest::ChooseRandom(2700667,27 00670,2700673,2700676,2700683,2700685),0,0,$x,$y,$ z);
$named = undef;}

#Checking if the exp_credit global is defined for this character
if (defined($qglobals{exp_credits})) {
#Making sure the character is not already level 70+
if ($ulevel <= 49) {
#Adding 1 point/credit to the exp_credits global
quest::setglobal("exp_credits", $qglobals{exp_credits}+1, 1, "F");

#Checking the character's level range
if ($ulevel >= 1 && $ulevel <= 50) {
#Variable to define how many exp_credits are needed to level in this level range.
my $exp_req = 4;
if ($qglobals{exp_credits} >= $exp_req) {
quest::level($ulevel+1);
#subtract the actual exp_credits global points. Note that this has to be 1 more than the exp_req global is set to.
quest::setglobal("exp_credits", $qglobals{exp_credits}-5, 1, "F");
}
my $exp_needed = ($exp_req - $qglobals{exp_credits});
$client->Message(5, "You currently need $exp_needed experience credits for your next level.");
}
#same thing as above, but for the next higher level range
if ($ulevel >= 10 && $ulevel <= 20) {
my $exp_req = 10;
if ($qglobals{exp_credits} >= $exp_req) {
quest::level($ulevel+1);
quest::setglobal("exp_credits", $qglobals{exp_credits}-11, 1, "F");
}
my $exp_needed = ($exp_req - $qglobals{exp_credits});
$client->Message(5, "You currently need $exp_needed experience credits for your next level.");
}
if ($ulevel >= 21 && $ulevel <= 35) {
my $exp_req = 15;
if ($qglobals{exp_credits} >= $exp_req) {
quest::level($ulevel+1);
quest::setglobal("exp_credits", $qglobals{exp_credits}-16, 1, "F");
}
my $exp_needed = ($exp_req - $qglobals{exp_credits});
$client->Message(5, "You currently need $exp_needed experience credits for your next level.");
}
if ($ulevel >= 36 && $ulevel <= 49) {
my $exp_req = 20;
if ($qglobals{exp_credits} >= $exp_req) {
quest::level($ulevel+1);
quest::setglobal("exp_credits", $qglobals{exp_credits}-21, 1, "F");
}
my $exp_needed = ($exp_req - $qglobals{exp_credits});
$client->Message(5, "You currently need $exp_needed experience credits for your next level.");
}

}
#If the character is level 70+, delete the exp_credit global for them since it is no longer needed.
if ($ulevel >= 50) {
quest::delglobal("exp_credits");
}

}

#Checking if the new_credits global is defined for this character
if (defined($qglobals{new_credits})) {
#Adding 1 point/credit to the new_credits global
quest::setglobal("new_credits", $qglobals{new_credits}+1, 1, "F");
#Setting the anti_ae global after all credits are applied.
quest::setglobal("anti_ae", 1, 1, "S5");
my $total_credits = ($qglobals{new_credits} + 1);
$client->Message(5, "You currently have $total_credits Credits.");
}

}

}

trevius
09-12-2008, 05:40 PM
First, in order for you to earn credits, you first have to be flagged by the quest NPC for earning credits. The actual kills themselves don't flag you for that, because I didn't want it to do more work for every kill and I also didn't want to risk any possible reset of credits.

So, you need to use one of the other quests I posted here first.

Also, for this to work on a global level, you have to edit the option in the globals to 5 instead of 1. So, note the following and see where I marked it in RED:
quest::setglobal("exp_credits", $qglobals{exp_credits}+1, 1, "F");

If you want this global to be seen by all NPCs in all Zones, you need to change every flag to use option 5 like this:
quest::setglobal("exp_credits", $qglobals{exp_credits}+1, 5, "F");

That should resolve both of your issues. Lemme know if you have any more questions.

Jibbatwinkers
09-12-2008, 08:19 PM
Awesome Trev. I was trying to work out something like this about 2 weeks ago on my server but couldn't figure out how to make a variable a counter. I kind of gave up on the idea but I might go back and plug this in in my own way. I appreciate the work.

paaco
09-13-2008, 12:49 AM
Still doesn't work for me. I changed what you posted. Hailed the NPC for the flags. It says I got them. Zoned to gukbottom and killed something. All I get is normal xp. Do you have to have aaxp on for the quest to work at all or will it work anyways? On my server all I have is old school eq enabled. No kunark or anything, even if I #lvl myself to 51 it doesn't let me turn aa on. Thats the only thing I can come up with that may be breaking it.

trevius
09-13-2008, 03:55 AM
I haven't really messed with default or player.pl files much yet. Maybe try putting the quest directly on a certain NPC and try it that way first.

paaco
09-13-2008, 11:27 AM
I still can't get it to work. I copy and pasted your quest to one zone and made no mods to it at all. I get the flag when I hail an NPC. Then kill the NPC that I have the kill script set too...I get normal xp...so now I'm totally at a loss. All other quests on the server work...it just seems to hate this one haha :(

paaco
09-14-2008, 02:55 AM
Man this is about to drive me frikken crazy, I copied your quest directly from this page into a file called a_gnoll.pl in the blackburrow folder. I also have the quest that gives the flags on an NPC. I hail, it says I have the flag. I kill a gnoll...I get normal xp....why does my server hate me :( Can anyone see anything wrong with this script?

sub EVENT_KILLED_MERIT {

#Checking if the anti-AE global is defined to stop credits from being earned if it is
if (!defined($qglobals{anti_ae})) {

#Optional code to randomly spawn a named NPC when the target dies.
my $x = $npc->GetX();
my $y = $npc->GetY();
my $z = $npc->GetZ();
my $named = quest::ChooseRandom(1,2,3,4,5,6,7,8,9,10,11,12,13, 14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30 ,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,4 7,48,49,50);

if ($named == 50) {
quest::unique_spawn(quest::ChooseRandom(2700667,27 00670,2700673,2700676,2700683,2700685),0,0,$x,$y,$ z);
$named = undef;}

#Checking if the exp_credit global is defined for this character
if (defined($qglobals{exp_credits})) {
#Making sure the character is not already level 70+
if ($ulevel <= 69) {
#Adding 1 point/credit to the exp_credits global
quest::setglobal("exp_credits", $qglobals{exp_credits}+1, 5, "F");

#Checking the character's level range
if ($ulevel >= 1 && $ulevel <= 55) {
#Variable to define how many exp_credits are needed to level in this level range.
my $exp_req = 24;
if ($qglobals{exp_credits} >= $exp_req) {
quest::level($ulevel+1);
#subtract the actual exp_credits global points. Note that this has to be 1 more than the exp_req global is set to.
quest::setglobal("exp_credits", $qglobals{exp_credits}-25, 5, "F");
}
my $exp_needed = ($exp_req - $qglobals{exp_credits});
$client->Message(5, "You currently need $exp_needed experience credits for your next level.");
}
#same thing as above, but for the next higher level range
if ($ulevel >= 56 && $ulevel <= 60) {
my $exp_req = 29;
if ($qglobals{exp_credits} >= $exp_req) {
quest::level($ulevel+1);
quest::setglobal("exp_credits", $qglobals{exp_credits}-30, 5, "F");
}
my $exp_needed = ($exp_req - $qglobals{exp_credits});
$client->Message(5, "You currently need $exp_needed experience credits for your next level.");
}
if ($ulevel >= 61 && $ulevel <= 65) {
my $exp_req = 34;
if ($qglobals{exp_credits} >= $exp_req) {
quest::level($ulevel+1);
quest::setglobal("exp_credits", $qglobals{exp_credits}-35, 5, "F");
}
my $exp_needed = ($exp_req - $qglobals{exp_credits});
$client->Message(5, "You currently need $exp_needed experience credits for your next level.");
}
if ($ulevel >= 66 && $ulevel <= 69) {
my $exp_req = 39;
if ($qglobals{exp_credits} >= $exp_req) {
quest::level($ulevel+1);
quest::setglobal("exp_credits", $qglobals{exp_credits}-40, 5, "F");
}
my $exp_needed = ($exp_req - $qglobals{exp_credits});
$client->Message(5, "You currently need $exp_needed experience credits for your next level.");
}

}
#If the character is level 70+, delete the exp_credit global for them since it is no longer needed.
if ($ulevel >= 70) {
quest::delglobal("exp_credits");
}

}

#Checking if the new_credits global is defined for this character
if (defined($qglobals{new_credits})) {
#Adding 1 point/credit to the new_credits global
quest::setglobal("new_credits", $qglobals{new_credits}+1, 5, "F");
#Setting the anti_ae global after all credits are applied.
quest::setglobal("anti_ae", 1, 7, "S5");
my $total_credits = ($qglobals{new_credits} + 1);
$client->Message(5, "You currently have $total_credits Credits.");
}

}

}

trevius
09-14-2008, 05:17 PM
Every NPC that uses qglobals in a script HAS to have the qglobal setting in the NPC_Types table set to 1 (default is 0 which ignores globals completely).

You can set these easily for an entire zone by using GeorgeS NPC Loot Editor and changing 1 of the NPCs to have qglobal set to 1 and then use the field tool menu to "propagate the field" or whatever it is called. That will set all NPCs in the zone to the same setting.

That should resolve your issue.

paaco
09-15-2008, 12:31 AM
I have never messed with global quests so didn't catch that at all. Many thanks Trev, you're the man. Works perfectly after this change.

paaco
09-15-2008, 12:33 AM
One more question, and I'm sorry to keep bugging you, but I really do appreciate you helping out. Is there any way to make mobs only within 7 levels give points? Since this is global, it would be way too easy to lvl on my server at like 40 killing in qeynos hills haha.

trevius
09-15-2008, 04:13 AM
You would just need to compare the mob level to the userlevel. So, something like this at the top of the script right below the EVENT_MERIT line should work:

if($mlevel + 7 >= $ulevel) {

or if you wanted to restrict it to 7 levels higher and lower, you could use this:

if(($mlevel + 7 >= $ulevel)&&($mlevel - 7 >= $ulevel)) {

Then, of course, you would need to add an extra bracket "}" at the end of the script to encompass the whole EVENT_MERIT section.

paaco
09-15-2008, 11:59 AM
Thanks again Trev, I'll try to leave ya alone for a while now ;p

Shunkthefunkunk
09-19-2008, 07:03 AM
Is there a way to make this work for player kills? I mean, killing players in PVP and having a script that gives them the points as a reward?

paaco
10-21-2008, 01:15 AM
Since people have been testing my server I have had a few reports of this quest taking points and not giving the item. Every time I test it I get the item though. Anyone see something wrong with this? :(

sub EVENT_SAY {

if($text =~ /Hail/i) {
if (!defined($qglobals{new_credits})) {
#This tells the player to hail the NPC that sets the credit globals on their character if they haven't already
quest::say ("Nice to meet you, $name. You should speak with the God of War"); }

if (defined($qglobals{new_credits})) {
quest::say ("I can enhance your Starter [armor] if you have enough [credits] for it."); }
}

if($text =~ /credits/i && defined($qglobals{new_credits})) {
quest::say ("To enhance your armor, you must turn in the Starter piece that you wish to enhance, and you must also have enough credits to afford the labor [costs]."); }

if($text =~ /costs/i && defined($qglobals{new_credits})) {
quest::say ("Enhancing Chest and Leg armor pieces costs 35 credits each. Other armor costs 25 credits each. Weapons are 50 each and I can currently do Pierceing, a shield, 1hb, 2hb, 1hs, and Bows"); }

if($text =~ /armor/i && defined($qglobals{new_credits})) {
quest::say ("I can Enhance your starter armor for you. Just hand me the old piece if you have enough credits."); }


}

sub EVENT_ITEM {

#This is the hash of item turn ins and upgrade rewards with comments as to what each is.

my %armor = (
2683 => 3482, #Chain_Boots
2672 => 3479, #Chain_Bracer
2668 => 3397, #Chain_Coif
2673 => 3480, #Chain_Gauntlets
2670 => 3442, #Chain_Vambraces
2826 => 3537, #Cloth_Boots
2810 => 3540, #Cloth_Bracer
2807 => 3582, #Cloth_Cap
2812 => 3539, #Cloth_Gloves
2809 => 3541, #Cloth_Sleeves
2730 => 3625, #Leather_Boots
2687 => 3486, #Leather_Bracer
4212 => 25439, #Starter_Boots
4210 => 25437, #Starter_Gauntlets
4209 => 25436, #Starter_Braces
4208 => 25435, #Starter_Vambraces
4207 => 71234, #Starter_Belt
4206 => 89803, #Starter_Cloak
4201 => 25433, #Starter_Helm
4202 => 89900, #Starter_Mask
4203 => 34132, #Starter_Neck
4205 => 83353, #Starter_Shoulder
);

#Separate hash item turn ins and rewards to allow for separate credit prices
my %chestlegs = (
4204 => 25434, #Starter_Breastplate
4211 => 25438, #Starter_Greaves
68232 => 34142, #Starter_Robe
2820 => 3538, #Cloth_Leggings
2685 => 3484, #Leather_Breastplate
2718 => 3491, #Leather_Leggings
42040 => 3616, #Plate_Breastplate
2666 => 3232, #Plate_Greaves
);

my %weapons = (
70646 => 62258, #Starter_1hb
6652 => 27054, #Starter_2hb
11940 => 11938, #Starter_1hs
2820 => 3538, #Starter_2hs
2595 => 2689, #Starter_Piercing
5758 => 45137, #Starter_Bow
6730 => 6806, #Starter_Shield
2666 => 3232, #Starter_caster
);

#Verify that the character has enough credits for the turn in.
if ($qglobals{new_credits} >= 25) {
#Sort the hash
for my $armor (sort keys %armor) {
if(defined($armor)) {
#Check the item turn in is correct and in the hash
if (plugin::check_handin(\%itemcount, $armor => 1)) {
#Check to make sure that there is a reward defined for the turn in
if(defined($armor{$armor})) {
quest::emote("recognizes your efforts and fashions an upgrade for your armor piece" );
quest::say("Thank you, $name, here is your enhanced armor piece!");
quest::exp(45000);
#Subtract the amount of credits for the upgrade purchase
quest::setglobal("new_credits", $qglobals{new_credits} - 25, 1, "F");
#Reward the player with the upgrade reward.
quest::summonitem($armor{$armor});
#Send a message with the character's new credit total after the purchase
my $total_credits = ($qglobals{new_credits} - 25);
$client->Message(5, "You have spent 25 Credits and now have $total_credits remaining credits.");
}
}
#This is supposed to return items if the wrong one is turned in, but it just eats incorrect items.
#This is the only part of all credit quests that doesn't work properly yet as it should.
# else {
# plugin::return_items(\%itemcount);
# quest::say ("I have no use for this item, $name.");
# }
}
}
}
#This repeats the process above accept for the items of a higher credit cost
if ($qglobals{new_credits} >= 35) {
for my $chestlegs (sort keys %chestlegs) {
if(defined($chestlegs)) {
if (plugin::check_handin(\%itemcount, $chestlegs => 1)) {

if(defined($chestlegs{$chestlegs})) {
quest::emote("recognizes your efforts and enhances your armor piece" );
quest::say("Thank you, $name, here is your upgraded armor piece!");
quest::setglobal("new_credits", $qglobals{new_credits} - 35, 1, "F");
quest::summonitem($chestlegs{$chestlegs});
my $total_credits = ($qglobals{new_credits} - 30);
$client->Message(5, "You have spent 35 Credits and now have $total_credits remaining credits.");
}
}
# else {
# plugin::return_items(\%itemcount);
# quest::say ("I have no use for this item, $name.");
# }
}
}
}
#This repeats the process above accept for the items of a higher credit cost
if ($qglobals{new_credits} >= 50) {
for my $weapons (sort keys %weapons) {
if(defined($weapons)) {
if (plugin::check_handin(\%itemcount, $weapons => 1)) {

if(defined($weapons{$weapons})) {
quest::emote("recognizes your efforts and enhances your weapon" );
quest::say("Thank you, $name, here is your enhanced weapon!");
quest::setglobal("new_credits", $qglobals{new_credits} - 50, 1, "F");
quest::summonitem($weapons{$weapons});
my $total_credits = ($qglobals{new_credits} - 50);
$client->Message(5, "You have spent 50 Credits and now have $total_credits remaining credits.");
}
}
# else {
# plugin::return_items(\%itemcount);
# quest::say ("I have no use for this item, $name.");
# }
}
}
}
#This returns the items if the character does not have enough credits to make the purchase
else {
plugin::return_items(\%itemcount);
# quest::say ("You don't have enough credits for that, sorry.");
}

}

paaco
11-15-2008, 04:46 PM
Just thought I would add on to your quest submission Trev just in case this is useful to someone. In this version the quest works on a global level and matches the con system. I'm sure there are better ways to do this, but meh it works.
sub EVENT_KILLED_MERIT {
if (($ulevel <= 8)&&($mlevel + 3 >= $ulevel)) {
if (($ulevel = 9)&&($mlevel + 4 >= $ulevel)) {
if (($ulevel = 10)&&($mlevel + 5 >= $ulevel)) {
if (($ulevel = 11)&&($mlevel + 5 >= $ulevel)) {
if (($ulevel = 12)&&($mlevel + 5 >= $ulevel)) {
if (($ulevel = 13)&&($mlevel + 6 >= $ulevel)) {
if (($ulevel = 14)&&($mlevel + 6 >= $ulevel)) {
if (($ulevel = 15)&&($mlevel + 6 >= $ulevel)) {
if (($ulevel = 16)&&($mlevel + 6 >= $ulevel)) {
if (($ulevel = 17)&&($mlevel + 7 >= $ulevel)) {
if (($ulevel = 18)&&($mlevel + 7 >= $ulevel)) {
if (($ulevel = 19)&&($mlevel + 7 >= $ulevel)) {
if (($ulevel = 20)&&($mlevel + 7 >= $ulevel)) {
if (($ulevel = 21)&&($mlevel + 8 >= $ulevel)) {
if (($ulevel = 22)&&($mlevel + 8 >= $ulevel)) {
if (($ulevel = 23)&&($mlevel + 8 >= $ulevel)) {
if (($ulevel = 24)&&($mlevel + 8 >= $ulevel)) {
if (($ulevel = 25)&&($mlevel + 9 >= $ulevel)) {
if (($ulevel = 26)&&($mlevel + 9 >= $ulevel)) {
if (($ulevel = 27)&&($mlevel + 9 >= $ulevel)) {
if (($ulevel = 28)&&($mlevel + 10 >= $ulevel)) {
if (($ulevel = 29)&&($mlevel + 10 >= $ulevel)) {
if (($ulevel = 30)&&($mlevel + 10 >= $ulevel)) {
if (($ulevel = 31)&&($mlevel + 11 >= $ulevel)) {
if (($ulevel = 32)&&($mlevel + 11 >= $ulevel)) {
if (($ulevel = 33)&&($mlevel + 12 >= $ulevel)) {
if (($ulevel = 34)&&($mlevel + 12 >= $ulevel)) {
if (($ulevel = 35)&&($mlevel + 12 >= $ulevel)) {
if (($ulevel = 36)&&($mlevel + 12 >= $ulevel)) {
if (($ulevel = 37)&&($mlevel + 13 >= $ulevel)) {
if (($ulevel = 38)&&($mlevel + 13 >= $ulevel)) {
if (($ulevel = 39)&&($mlevel + 13 >= $ulevel)) {
if (($ulevel = 40)&&($mlevel + 13 >= $ulevel)) {
if (($ulevel = 41)&&($mlevel + 14 >= $ulevel)) {
if (($ulevel = 42)&&($mlevel + 15 >= $ulevel)) {
if (($ulevel = 43)&&($mlevel + 15 >= $ulevel)) {
if (($ulevel = 44)&&($mlevel + 15 >= $ulevel)) {
if (($ulevel = 45)&&($mlevel + 16 >= $ulevel)) {
if (($ulevel = 46)&&($mlevel + 16 >= $ulevel)) {
if (($ulevel = 47)&&($mlevel + 16 >= $ulevel)) {
if (($ulevel = 48)&&($mlevel + 16 >= $ulevel)) {
if (($ulevel = 49)&&($mlevel + 17 >= $ulevel)) {
if (($ulevel = 50)&&($mlevel + 17 >= $ulevel)) {
}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}

#Checking if the anti-AE global is defined to stop credits from being earned if it is
if (!defined($qglobals{anti_ae})) {

#Optional code to randomly spawn a named NPC when the target dies.
my $x = $npc->GetX();
my $y = $npc->GetY();
my $z = $npc->GetZ();
my $named = quest::ChooseRandom(1,2,3,4,5,6,7,8,9,10,11,12,13, 14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30 ,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,4 7,48,49,50);

if ($named == 50) {
quest::unique_spawn(quest::ChooseRandom(2700667,27 00670,2700673,2700676,2700683,2700685),0,0,$x,$y,$ z);
$named = undef;}

#Checking if the exp_credit global is defined for this character
if (defined($qglobals{exp_credits})) {
#Making sure the character is not already level 50+
if ($ulevel <= 49) {
#Adding 1 point/credit to the exp_credits global
quest::setglobal("exp_credits", $qglobals{exp_credits}+1, 5, "F");

#Checking the character's level range
if ($ulevel >= 1 && $ulevel <= 5) {
#Variable to define how many exp_credits are needed to level in this level range.
my $exp_req = 3;
if ($qglobals{exp_credits} >= $exp_req) {
quest::level($ulevel+1);
#subtract the actual exp_credits global points. Note that this has to be 1 more than the exp_req global is set to.
quest::setglobal("exp_credits", $qglobals{exp_credits}-4, 5, "F");
}
my $exp_needed = ($exp_req - $qglobals{exp_credits});
$client->Message(5, "You currently need $exp_needed experience credits for your next level.");
}
#same thing as above, but for the next higher level range
if ($ulevel >= 6 && $ulevel <= 15) {
my $exp_req = 5;
if ($qglobals{exp_credits} >= $exp_req) {
quest::level($ulevel+1);
quest::setglobal("exp_credits", $qglobals{exp_credits}-6, 5, "F");
}
my $exp_needed = ($exp_req - $qglobals{exp_credits});
$client->Message(5, "You currently need $exp_needed experience credits for your next level.");
}
if ($ulevel >= 16 && $ulevel <= 30) {
my $exp_req = 12;
if ($qglobals{exp_credits} >= $exp_req) {
quest::level($ulevel+1);
quest::setglobal("exp_credits", $qglobals{exp_credits}-13, 5, "F");
}
my $exp_needed = ($exp_req - $qglobals{exp_credits});
$client->Message(5, "You currently need $exp_needed experience credits for your next level.");
}
if ($ulevel >= 31 && $ulevel <= 50) {
my $exp_req = 22;
if ($qglobals{exp_credits} >= $exp_req) {
quest::level($ulevel+1);
quest::setglobal("exp_credits", $qglobals{exp_credits}-23, 5, "F");
}
my $exp_needed = ($exp_req - $qglobals{exp_credits});
$client->Message(5, "You currently need $exp_needed experience credits for your next level.");
}

}
#If the character is level 70+, delete the exp_credit global for them since it is no longer needed.
if ($ulevel >= 50) {
quest::delglobal("exp_credits");
}

}

#Checking if the new_credits global is defined for this character
if (defined($qglobals{new_credits})) {
#Adding 1 point/credit to the new_credits global
quest::setglobal("new_credits", $qglobals{new_credits}+2, 5, "F");
#Setting the anti_ae global after all credits are applied.
quest::setglobal("anti_ae", 1, 5, "S5");
my $total_credits = ($qglobals{new_credits} + 1);
$client->Message(5, "You currently have $total_credits Credits.");
}

}

}
}

paaco
11-15-2008, 05:33 PM
ok I lied, seems like the first if statement works, anyone over that level gets no xp...what did I do wrong?

AndMetal
11-15-2008, 06:11 PM
I think there's 2 main issues:

You're using = instead of == (defining instead of comparing, which will always return true)
All of those nested if statements don't seem to be doing anything, except for the first one


I would highly recommend using tabs (vs spaces) to better visualize the opening & closing brackets:

sub EVENT_KILLED_MERIT {
if (($ulevel <= 8)&&($mlevel + 3 >= $ulevel)) {
if (($ulevel = 9)&&($mlevel + 4 >= $ulevel)) {
if (($ulevel = 10)&&($mlevel + 5 >= $ulevel)) {
if (($ulevel = 11)&&($mlevel + 5 >= $ulevel)) {
if (($ulevel = 12)&&($mlevel + 5 >= $ulevel)) {
if (($ulevel = 13)&&($mlevel + 6 >= $ulevel)) {
if (($ulevel = 14)&&($mlevel + 6 >= $ulevel)) {
if (($ulevel = 15)&&($mlevel + 6 >= $ulevel)) {
if (($ulevel = 16)&&($mlevel + 6 >= $ulevel)) {
if (($ulevel = 17)&&($mlevel + 7 >= $ulevel)) {
if (($ulevel = 18)&&($mlevel + 7 >= $ulevel)) {
if (($ulevel = 19)&&($mlevel + 7 >= $ulevel)) {
if (($ulevel = 20)&&($mlevel + 7 >= $ulevel)) {
if (($ulevel = 21)&&($mlevel + 8 >= $ulevel)) {
if (($ulevel = 22)&&($mlevel + 8 >= $ulevel)) {
if (($ulevel = 23)&&($mlevel + 8 >= $ulevel)) {
if (($ulevel = 24)&&($mlevel + 8 >= $ulevel)) {
if (($ulevel = 25)&&($mlevel + 9 >= $ulevel)) {
if (($ulevel = 26)&&($mlevel + 9 >= $ulevel)) {
if (($ulevel = 27)&&($mlevel + 9 >= $ulevel)) {
if (($ulevel = 28)&&($mlevel + 10 >= $ulevel)) {
if (($ulevel = 29)&&($mlevel + 10 >= $ulevel)) {
if (($ulevel = 30)&&($mlevel + 10 >= $ulevel)) {
if (($ulevel = 31)&&($mlevel + 11 >= $ulevel)) {
if (($ulevel = 32)&&($mlevel + 11 >= $ulevel)) {
if (($ulevel = 33)&&($mlevel + 12 >= $ulevel)) {
if (($ulevel = 34)&&($mlevel + 12 >= $ulevel)) {
if (($ulevel = 35)&&($mlevel + 12 >= $ulevel)) {
if (($ulevel = 36)&&($mlevel + 12 >= $ulevel)) {
if (($ulevel = 37)&&($mlevel + 13 >= $ulevel)) {
if (($ulevel = 38)&&($mlevel + 13 >= $ulevel)) {
if (($ulevel = 39)&&($mlevel + 13 >= $ulevel)) {
if (($ulevel = 40)&&($mlevel + 13 >= $ulevel)) {
if (($ulevel = 41)&&($mlevel + 14 >= $ulevel)) {
if (($ulevel = 42)&&($mlevel + 15 >= $ulevel)) {
if (($ulevel = 43)&&($mlevel + 15 >= $ulevel)) {
if (($ulevel = 44)&&($mlevel + 15 >= $ulevel)) {
if (($ulevel = 45)&&($mlevel + 16 >= $ulevel)) {
if (($ulevel = 46)&&($mlevel + 16 >= $ulevel)) {
if (($ulevel = 47)&&($mlevel + 16 >= $ulevel)) {
if (($ulevel = 48)&&($mlevel + 16 >= $ulevel)) {
if (($ulevel = 49)&&($mlevel + 17 >= $ulevel)) {
if (($ulevel = 50)&&($mlevel + 17 >= $ulevel)) {
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}

#Checking if the anti-AE global is defined to stop credits from being earned if it is
if (!defined($qglobals{anti_ae})) {

#Optional code to randomly spawn a named NPC when the target dies.
my $x = $npc->GetX();
my $y = $npc->GetY();
my $z = $npc->GetZ();
my $named = quest::ChooseRandom(1,2,3,4,5,6,7,8,9,10,11,12,13, 14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30 ,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,4 7,48,49,50);

if ($named == 50) {
quest::unique_spawn(quest::ChooseRandom(2700667,27 00670,2700673,2700676,2700683,2700685),0,0,$x,$y,$ z);
$named = undef;
}

#Checking if the exp_credit global is defined for this character
if (defined($qglobals{exp_credits})) {
#Making sure the character is not already level 50+
if ($ulevel <= 49) {
#Adding 1 point/credit to the exp_credits global
quest::setglobal("exp_credits", $qglobals{exp_credits}+1, 5, "F");

#Checking the character's level range
if ($ulevel >= 1 && $ulevel <= 5) {
#Variable to define how many exp_credits are needed to level in this level range.
my $exp_req = 3;
if ($qglobals{exp_credits} >= $exp_req) {
quest::level($ulevel+1);
#subtract the actual exp_credits global points. Note that this has to be 1 more than the exp_req global is set to.
quest::setglobal("exp_credits", $qglobals{exp_credits}-4, 5, "F");
}
my $exp_needed = ($exp_req - $qglobals{exp_credits});
$client->Message(5, "You currently need $exp_needed experience credits for your next level.");
}
#same thing as above, but for the next higher level range
if ($ulevel >= 6 && $ulevel <= 15) {
my $exp_req = 5;
if ($qglobals{exp_credits} >= $exp_req) {
quest::level($ulevel+1);
quest::setglobal("exp_credits", $qglobals{exp_credits}-6, 5, "F");
}
my $exp_needed = ($exp_req - $qglobals{exp_credits});
$client->Message(5, "You currently need $exp_needed experience credits for your next level.");
}
if ($ulevel >= 16 && $ulevel <= 30) {
my $exp_req = 12;
if ($qglobals{exp_credits} >= $exp_req) {
quest::level($ulevel+1);
quest::setglobal("exp_credits", $qglobals{exp_credits}-13, 5, "F");
}
my $exp_needed = ($exp_req - $qglobals{exp_credits});
$client->Message(5, "You currently need $exp_needed experience credits for your next level.");
}
if ($ulevel >= 31 && $ulevel <= 50) {
my $exp_req = 22;
if ($qglobals{exp_credits} >= $exp_req) {
quest::level($ulevel+1);
quest::setglobal("exp_credits", $qglobals{exp_credits}-23, 5, "F");
}
my $exp_needed = ($exp_req - $qglobals{exp_credits});
$client->Message(5, "You currently need $exp_needed experience credits for your next level.");
}
}
#If the character is level 70+, delete the exp_credit global for them since it is no longer needed.
if ($ulevel >= 50) {
quest::delglobal("exp_credits");
}
}

#Checking if the new_credits global is defined for this character
if (defined($qglobals{new_credits})) {
#Adding 1 point/credit to the new_credits global
quest::setglobal("new_credits", $qglobals{new_credits}+2, 5, "F");
#Setting the anti_ae global after all credits are applied.
quest::setglobal("anti_ae", 1, 5, "S5");
my $total_credits = ($qglobals{new_credits} + 1);
$client->Message(5, "You currently have $total_credits Credits.");
}

}

}
}

ok I lied, seems like the first if statement works, anyone over that level gets no xp...what did I do wrong?

What exactly are you trying to do?

There's a lot of things I can think of that would trim the script down a LOT, but I think it would be better to understand where we're trying to get first.

paaco
11-15-2008, 06:22 PM
This is the script that tells mobs to give xp and points on my server. It works in every zone. I am basically trying to make only mobs that do not con green give xp and points.

Only thing in the quest that does not work correctly is all of the nested if statements up top, rest works perfectly.

AndMetal
11-15-2008, 07:12 PM
Only thing in the quest that does not work correctly is all of the nested if statements up top, rest works perfectly.

What is sounds like you're trying to do is a string of ORs, not nested IFs. If you were trying to nest IF statements, you could also do it by using a bunch of AND statements:

if ((($ulevel <= 8) && ($mlevel + 3 >= $ulevel) )
&& (($ulevel == 9) && ($mlevel + 4 >= $ulevel))
&& (($ulevel == 10) && ($mlevel + 5 >= $ulevel))
&& (($ulevel == 11) && ($mlevel + 5 >= $ulevel))
&& (($ulevel == 12) && ($mlevel + 5 >= $ulevel))
&& (($ulevel == 13) && ($mlevel + 6 >= $ulevel))
&& (($ulevel == 14) && ($mlevel + 6 >= $ulevel))
&& (($ulevel == 15) && ($mlevel + 6 >= $ulevel))
&& (($ulevel == 16) && ($mlevel + 6 >= $ulevel))
&& (($ulevel == 17) && ($mlevel + 7 >= $ulevel))
&& (($ulevel == 18) && ($mlevel + 7 >= $ulevel))
&& (($ulevel == 19) && ($mlevel + 7 >= $ulevel))
&& (($ulevel == 20) && ($mlevel + 7 >= $ulevel))
&& (($ulevel == 21) && ($mlevel + 8 >= $ulevel))
&& (($ulevel == 22) && ($mlevel + 8 >= $ulevel))
&& (($ulevel == 23) && ($mlevel + 8 >= $ulevel))
&& (($ulevel == 24) && ($mlevel + 8 >= $ulevel))
&& (($ulevel == 25) && ($mlevel + 9 >= $ulevel))
&& (($ulevel == 26) && ($mlevel + 9 >= $ulevel))
&& (($ulevel == 27) && ($mlevel + 9 >= $ulevel))
&& (($ulevel == 28) && ($mlevel + 10 >= $ulevel))
&& (($ulevel == 29) && ($mlevel + 10 >= $ulevel))
&& (($ulevel == 30) && ($mlevel + 10 >= $ulevel))
&& (($ulevel == 31) && ($mlevel + 11 >= $ulevel))
&& (($ulevel == 32) && ($mlevel + 11 >= $ulevel))
&& (($ulevel == 33) && ($mlevel + 12 >= $ulevel))
&& (($ulevel == 34) && ($mlevel + 12 >= $ulevel))
&& (($ulevel == 35) && ($mlevel + 12 >= $ulevel))
&& (($ulevel == 36) && ($mlevel + 12 >= $ulevel))
&& (($ulevel == 37) && ($mlevel + 13 >= $ulevel))
&& (($ulevel == 38) && ($mlevel + 13 >= $ulevel))
&& (($ulevel == 39) && ($mlevel + 13 >= $ulevel))
&& (($ulevel == 40) && ($mlevel + 13 >= $ulevel))
&& (($ulevel == 41) && ($mlevel + 14 >= $ulevel))
&& (($ulevel == 42) && ($mlevel + 15 >= $ulevel))
&& (($ulevel == 43) && ($mlevel + 15 >= $ulevel))
&& (($ulevel == 44) && ($mlevel + 15 >= $ulevel))
&& (($ulevel == 45) && ($mlevel + 16 >= $ulevel))
&& (($ulevel == 46) && ($mlevel + 16 >= $ulevel))
&& (($ulevel == 47) && ($mlevel + 16 >= $ulevel))
&& (($ulevel == 48) && ($mlevel + 16 >= $ulevel))
&& (($ulevel == 49) && ($mlevel + 17 >= $ulevel))
&& (($ulevel == 50) && ($mlevel + 17 >= $ulevel))
) {

But that's not going to work, because you're never going to be all levels 50 and below at the same time. However, if you changed all of the &&'s to ||'s, it would do what you're looking for.

There's a lot of things I can think of that would trim the script down a LOT, but I think it would be better to understand where we're trying to get first.

Here's a thought on the whole if part...

I'm not sure if this will actually work (unable to test syntax, etc), but it should work in theory:


sub EVENT_KILLED_MERIT {
# $level_diff{level} == difference
my %level_diff = (
1, 3,
2, 3,
3, 3,
4, 3,
5, 3,
6, 3,
7, 3,
8, 3,
9, 4,
10, 5,
11, 5,
12, 5,
13, 6,
14, 6,
15, 6,
16, 6,
17, 7,
18, 7,
19, 7,
20, 7,
21, 8,
22, 8,
23, 8,
24, 8,
25, 9,
26, 9,
27, 9,
28, 10,
29, 10,
30, 10,
31, 11,
32, 11,
33, 12,
34, 12,
35, 12,
36, 12,
37, 13,
38, 13,
39, 13,
40, 13,
41, 14,
42, 15,
43, 15,
44, 15,
45, 16,
46, 16,
47, 16,
48, 16,
49, 17,
50, 17,
)

if ($mlevel + $level_diff{$ulevel} >= $ulevel) {
#whatever
}
}

Although this is a little more dynamic, since it accounts any values over 50:

sub EVENT_KILLED_MERIT {
if ((($ulevel <= 8) && ($mlevel + 3 >= $ulevel) )
|| (($ulevel == 9) && ($mlevel + 4 >= $ulevel))
|| (($ulevel >= 10 && $ulevel <= 12) && ($mlevel + 5 >= $ulevel))
|| (($ulevel >= 13 && $ulevel <= 16) && ($mlevel + 6 >= $ulevel))
|| (($ulevel >= 17 && $ulevel <= 20) && ($mlevel + 7 >= $ulevel))
|| (($ulevel >= 21 && $ulevel <= 24) && ($mlevel + 8 >= $ulevel))
|| (($ulevel >= 25 && $ulevel <= 27) && ($mlevel + 9 >= $ulevel))
|| (($ulevel >= 28 && $ulevel <= 30) && ($mlevel + 10 >= $ulevel))
|| (($ulevel >= 31 && $ulevel <= 32) && ($mlevel + 11 >= $ulevel))
|| (($ulevel >= 33 && $ulevel <= 36) && ($mlevel + 12 >= $ulevel))
|| (($ulevel >= 37 && $ulevel <= 40) && ($mlevel + 13 >= $ulevel))
|| (($ulevel == 41) && ($mlevel + 14 >= $ulevel))
|| (($ulevel >= 42 && $ulevel <= 44) && ($mlevel + 15 >= $ulevel))
|| (($ulevel >= 45 && $ulevel <= 48) && ($mlevel + 16 >= $ulevel))
|| (($ulevel >= 49) && ($mlevel + 17 >= $ulevel))
) {
#whatever
}
}

paaco
11-17-2008, 03:31 AM
Thanks, for the help Andmetal, here is the working version in case someone could use it. All mobs that are not green will give xp now up to lvl 50. If you use this on a server that goes over 50 you're gonna have to do some testing and add in more levels.
sub EVENT_KILLED_MERIT {

my $ulevel = quest::getlevel(3);

if ((($ulevel <= 8) && ($mlevel + 3 >= $ulevel) )
|| (($ulevel == 9) && ($mlevel + 4 >= $ulevel))
|| (($ulevel >= 10 && $ulevel <= 12) && ($mlevel + 5 >= $ulevel))
|| (($ulevel >= 13 && $ulevel <= 16) && ($mlevel + 6 >= $ulevel))
|| (($ulevel >= 17 && $ulevel <= 20) && ($mlevel + 7 >= $ulevel))
|| (($ulevel >= 21 && $ulevel <= 24) && ($mlevel + 8 >= $ulevel))
|| (($ulevel >= 25 && $ulevel <= 27) && ($mlevel + 9 >= $ulevel))
|| (($ulevel >= 28 && $ulevel <= 30) && ($mlevel + 10 >= $ulevel))
|| (($ulevel >= 31 && $ulevel <= 32) && ($mlevel + 11 >= $ulevel))
|| (($ulevel >= 33 && $ulevel <= 36) && ($mlevel + 12 >= $ulevel))
|| (($ulevel >= 37 && $ulevel <= 40) && ($mlevel + 13 >= $ulevel))
|| (($ulevel == 41) && ($mlevel + 14 >= $ulevel))
|| (($ulevel >= 42 && $ulevel <= 44) && ($mlevel + 15 >= $ulevel))
|| (($ulevel >= 45 && $ulevel <= 48) && ($mlevel + 16 >= $ulevel))
|| (($ulevel >= 49) && ($mlevel + 17 >= $ulevel))
) {


#Checking if the anti-AE global is defined to stop credits from being earned if it is
if (!defined($qglobals{anti_ae})) {

#Optional code to randomly spawn a named NPC when the target dies.
my $x = $npc->GetX();
my $y = $npc->GetY();
my $z = $npc->GetZ();
my $named = quest::ChooseRandom(1,2,3,4,5,6,7,8,9,10,11,12,13, 14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30 ,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,4 7,48,49,50);

if ($named == 50) {
quest::unique_spawn(quest::ChooseRandom(2700667,27 00670,2700673,2700676,2700683,2700685),0,0,$x,$y,$ z);
$named = undef;
}

#Checking if the exp_credit global is defined for this character
if (defined($qglobals{exp_credits})) {
#Making sure the character is not already level 50+
if ($ulevel <= 49) {
#Adding 1 point/credit to the exp_credits global
quest::setglobal("exp_credits", $qglobals{exp_credits}+1, 5, "F");

#Checking the character's level range
if ($ulevel >= 1 && $ulevel <= 5) {
#Variable to define how many exp_credits are needed to level in this level range.
my $exp_req = 3;
if ($qglobals{exp_credits} >= $exp_req) {
quest::level($ulevel+1);
#subtract the actual exp_credits global points. Note that this has to be 1 more than the exp_req global is set to.
quest::setglobal("exp_credits", $qglobals{exp_credits}-4, 5, "F");
}
my $exp_needed = ($exp_req - $qglobals{exp_credits});
$client->Message(5, "You currently need $exp_needed experience credits for your next level.");
}
#same thing as above, but for the next higher level range
if ($ulevel >= 6 && $ulevel <= 15) {
my $exp_req = 5;
if ($qglobals{exp_credits} >= $exp_req) {
quest::level($ulevel+1);
quest::setglobal("exp_credits", $qglobals{exp_credits}-6, 5, "F");
}
my $exp_needed = ($exp_req - $qglobals{exp_credits});
$client->Message(5, "You currently need $exp_needed experience credits for your next level.");
}
if ($ulevel >= 16 && $ulevel <= 30) {
my $exp_req = 12;
if ($qglobals{exp_credits} >= $exp_req) {
quest::level($ulevel+1);
quest::setglobal("exp_credits", $qglobals{exp_credits}-13, 5, "F");
}
my $exp_needed = ($exp_req - $qglobals{exp_credits});
$client->Message(5, "You currently need $exp_needed experience credits for your next level.");
}
if ($ulevel >= 31 && $ulevel <= 50) {
my $exp_req = 22;
if ($qglobals{exp_credits} >= $exp_req) {
quest::level($ulevel+1);
quest::setglobal("exp_credits", $qglobals{exp_credits}-23, 5, "F");
}
my $exp_needed = ($exp_req - $qglobals{exp_credits});
$client->Message(5, "You currently need $exp_needed experience credits for your next level.");
}
}
#If the character is level 70+, delete the exp_credit global for them since it is no longer needed.
if ($ulevel >= 50) {
quest::delglobal("exp_credits");
}
}

#Checking if the new_credits global is defined for this character
if (defined($qglobals{new_credits})) {
#Adding 1 point/credit to the new_credits global
quest::setglobal("new_credits", $qglobals{new_credits}+2, 5, "F");
#Setting the anti_ae global after all credits are applied.
quest::setglobal("anti_ae", 1, 5, "S5");
my $total_credits = ($qglobals{new_credits} + 1);
$client->Message(5, "You currently have $total_credits Credits.");
}

}

}
}