|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Quests::Custom Custom Quests here |
|
|
|
10-13-2014, 11:17 PM
|
Sarnak
|
|
Join Date: Dec 2008
Location: sydney
Posts: 35
|
|
A really messy random, timed auto-updating merchant
So I've spent too many hours trying to get this thing to work (not a coder), but I think I've finally got it.
I just want someone to look over it, point out any flaws, and maybe clean it up a little if they can be bothered. It works fine from what I can tell, I just bet it's a mess though.
Code:
#############################################################
# Programmable Auto-Updating Merchant #
# This quest allows you to have a merchant whose selling #
# items change based on a timer. You set up a blank vendor.#
# All the items are stored in the merchantlist_temp table. #
# The shouts were mainly for testing, but they would be #
# useful anyway. --kilst87 #
#############################################################
sub EVENT_SPAWN{
quest::shout("Spawned!");
quest::settimer("random_loot_timer", 5);
#sets the timer that triggers merchant to post/withdraw items
}
sub EVENT_TIMER{
my $randi = int(rand(3));
#sets $randi with a random number between 0 and 2 to decide what to sell
if($randi == 1) {
if($timer eq "random_loot_timer"){
quest::MerchantSetItem(999219, 1111, 10000);
quest::MerchantSetItem(999219, 1112, 10000);
quest::MerchantSetItem(999219, 1113, 10000);
quest::MerchantSetItem(999219, 1114, 10000);
quest::shout("Added items1!");
quest::stoptimer("random_loot_timer");
quest::settimer("itemgroup_1", 10);
}
#sets armor, stops the first timer, and starts the second timer
if($timer eq "itemgroup_1") {
quest::MerchantSetItem(999219, 1111, 0);
quest::MerchantSetItem(999219, 1112, 0);
quest::MerchantSetItem(999219, 1113, 0);
quest::MerchantSetItem(999219, 1114, 0);
quest::shout("Despawning after deleting items1");
#quest::stoptimer("itemgroup_1");
quest::respawn(999219,0);
}
#removes armor, stops second timer and respawns Merchant
}
elsif($randi == 0) {
if($timer eq "random_loot_timer"){
quest::MerchantSetItem(999219, 2111, 10000);
quest::MerchantSetItem(999219, 2112, 10000);
quest::MerchantSetItem(999219, 2113, 10000);
quest::MerchantSetItem(999219, 2114, 10000);
quest::shout("Added items!2");
quest::stoptimer("random_loot_timer");
quest::settimer("itemgroup_2", 10);
}
#sets armor, stops the first timer, and starts the second timer
if($timer eq "itemgroup_2") {
quest::MerchantSetItem(999219, 2111, 0);
quest::MerchantSetItem(999219, 2112, 0);
quest::MerchantSetItem(999219, 2113, 0);
quest::MerchantSetItem(999219, 2114, 0);
quest::shout("Despawning after deleting items2");
#quest::stoptimer("itemgroup_2");
quest::respawn(999219,0);
}
#removes armor, stops second timer and respawns Merchant
}
elsif($randi == 2) {
if($timer eq "random_loot_timer"){
quest::shout("Selling banded armor CHEAP!!");
quest::MerchantSetItem(999219, 3053, 10000);
quest::MerchantSetItem(999219, 3054, 10000);
quest::MerchantSetItem(999219, 3055, 10000);
quest::MerchantSetItem(999219, 3056, 10000);
quest::MerchantSetItem(999219, 3057, 10000);
quest::MerchantSetItem(999219, 3058, 10000);
quest::MerchantSetItem(999219, 3059, 10000);
quest::MerchantSetItem(999219, 3060, 10000);
quest::MerchantSetItem(999219, 3061, 10000);
quest::MerchantSetItem(999219, 3062, 10000);
quest::MerchantSetItem(999219, 3063, 10000);
quest::MerchantSetItem(999219, 3064, 10000);
quest::shout("Added items!3");
quest::stoptimer("random_loot_timer");
quest::settimer("itemgroup_3", 10);
}
#sets banded armor, stops the first timer, and starts the second timer
if($timer eq "itemgroup_3") {
quest::MerchantSetItem(999219, 3053, 0);
quest::MerchantSetItem(999219, 3054, 0);
quest::MerchantSetItem(999219, 3055, 0);
quest::MerchantSetItem(999219, 3056, 0);
quest::MerchantSetItem(999219, 3057, 0);
quest::MerchantSetItem(999219, 3058, 0);
quest::MerchantSetItem(999219, 3059, 0);
quest::MerchantSetItem(999219, 3060, 0);
quest::MerchantSetItem(999219, 3061, 0);
quest::MerchantSetItem(999219, 3062, 0);
quest::MerchantSetItem(999219, 3063, 0);
quest::MerchantSetItem(999219, 3064, 0);
quest::shout("Despawning after deleting items3");
#quest::stoptimer("itemgroup_3");
quest::respawn(999219,0);
}
#removes banded armor, stops second timer and respawns Merchant
}
}
Edit: Okay, it seems to break a lot when removing items (maybe because the timers are so tight?), but I've let the second timer just loop til it catches it for now.
Edit2: Also, I don't know how to check if there are still items on the merchants, and then not set the item count to 0. If the items aren't there and you set them to 0, they will appear as "quantity: --", be visable, and one is sellable. I've set the item count high to counteract this, but it's a flaw.
Edit3: Huge bug. Characters spells lock up, and you can't open vendor windows etc etc.. after the merchant has been running too long. Zoning fixes the issue.
|
|
|
|
|
|
|
10-15-2014, 11:28 PM
|
Sarnak
|
|
Join Date: Dec 2008
Location: sydney
Posts: 35
|
|
Okay, I added a check at the start to see if the items are still saved in the merchantlist_temp.
Qglobals are a heap of fun!
Also, does anyone know how/if I would be able to save user input strings to qglobals, or set is to a var?
I want an NPC to ask a question, and save/use the users $text response.
Anyway, new code:
Code:
#############################################################
# Programmable Auto-Updating Merchant #
# This quest allows you to have a merchant whose selling #
# items change based on a timer. You set up a blank vendor.#
# All the items are stored in the merchantlist_temp table. #
# The shouts were mainly for testing, but they would be #
# useful anyway. --kilst87 #
#############################################################
sub EVENT_SPAWN {
if (!defined $qglobal{vaylena_items}) {
if($qglobals{"vaylena_items"} == 1) {
quest::settimer("spawned_1", 2);
quest::resume(238);
}
elsif($qglobals{"vaylena_items"} == 2) {
quest::settimer("spawned_2", 2);
quest::resume(238);
}
elsif($qglobals{"vaylena_items"} == 3) {
quest::settimer("spawned_3", 2);
quest::resume(238);
}
}
#Set timers to delete remembered items
if (not defined $qglobal{vaylena_items}) {
quest::setglobal('vaylena_items', 0, 6, F);
quest::settimer("random_loot_timer", 5);
}
#sets qglobal if not set
}
sub EVENT_TIMER{
my $randi = int(rand(3));
#sets $randi with a random number between 0 and 2 to decide what to sell
my $shout = int(rand(10) + 20);
#set $shout with a number between 3 and 4 mins between item shouts
if($timer eq "spawned_1") {
quest::MerchantSetItem(999219, 1111, 0);
quest::MerchantSetItem(999219, 1112, 0);
quest::MerchantSetItem(999219, 1113, 0);
quest::MerchantSetItem(999219, 1114, 0);
quest::shout("Spawned!1");
quest::stoptimer("spawned_1");
quest::settimer("random_loot_timer", 5);
#deletes any saved items, starts next timer
}
if($timer eq "spawned_2") {
quest::MerchantSetItem(999219, 2111, 0);
quest::MerchantSetItem(999219, 2112, 0);
quest::MerchantSetItem(999219, 2113, 0);
quest::MerchantSetItem(999219, 2114, 0);
quest::shout("Spawned!2");
quest::stoptimer("spawned_2");
quest::settimer("random_loot_timer", 5);
#deletes any saved items, starts next timer
}
if($timer eq "spawned_3") {
quest::MerchantSetItem(999219, 3053, 0);
quest::MerchantSetItem(999219, 3054, 0);
quest::MerchantSetItem(999219, 3055, 0);
quest::MerchantSetItem(999219, 3056, 0);
quest::MerchantSetItem(999219, 3057, 0);
quest::MerchantSetItem(999219, 3058, 0);
quest::MerchantSetItem(999219, 3059, 0);
quest::MerchantSetItem(999219, 3060, 0);
quest::MerchantSetItem(999219, 3061, 0);
quest::MerchantSetItem(999219, 3062, 0);
quest::MerchantSetItem(999219, 3063, 0);
quest::MerchantSetItem(999219, 3064, 0);
quest::shout("Spawned!3");
quest::stoptimer("spawned_3");
quest::settimer("random_loot_timer", 5);
#deletes any saved items, starts next timer
}
if($randi == 1) {
if($timer eq "random_loot_timer"){
quest::MerchantSetItem(999219, 1111, 10000);
quest::MerchantSetItem(999219, 1112, 10000);
quest::MerchantSetItem(999219, 1113, 10000);
quest::MerchantSetItem(999219, 1114, 10000);
quest::shout("New crap items up!");
quest::stoptimer("random_loot_timer");
quest::settimer("itemgroup_1", 40);
quest::settimer("itemgroup_1_shout", $shout);
quest::setglobal('vaylena_items', 1, 6, F);
#post items, start shout and respawn timer, and save list to globals
}
elsif($timer eq "itemgroup_1_shout") {
quest::ze(2, "Vaylena says out of character 'Please buy my crap armor!!'")
#zonewide emote used as /ooc
}
elsif($timer eq "itemgroup_1") {
quest::respawn(999219,0);
quest::stoptimer(itemgroup_1);
#respawn when timer is up
}
}
elsif($randi == 0) {
if($timer eq "random_loot_timer"){
quest::MerchantSetItem(999219, 2111, 10000);
quest::MerchantSetItem(999219, 2112, 10000);
quest::MerchantSetItem(999219, 2113, 10000);
quest::MerchantSetItem(999219, 2114, 10000);
quest::shout("New trader selling all kinds of stuff");
quest::stoptimer("random_loot_timer");
quest::settimer("itemgroup_2", 40);
quest::settimer("itemgroup_2_shout", $shout);
quest::setglobal('vaylena_items', 2, 6, F);
#post items, start shout and respawn timer, and save list to globals
}
elsif($timer eq "itemgroup_2_shout") {
quest::ze(2, "Vaylena says out of character 'Selling all kinds of armor, check me out!!'")
#zonewide emote used as /ooc
}
elsif($timer eq "itemgroup_2") {
quest::respawn(999219,0);
quest::stoptimer(itemgroup_2);
#respawn when timer is up
}
}
elsif($randi == 2) {
if($timer eq "random_loot_timer"){
quest::MerchantSetItem(999219, 3053, 10000);
quest::MerchantSetItem(999219, 3054, 10000);
quest::MerchantSetItem(999219, 3055, 10000);
quest::MerchantSetItem(999219, 3056, 10000);
quest::MerchantSetItem(999219, 3057, 10000);
quest::MerchantSetItem(999219, 3058, 10000);
quest::MerchantSetItem(999219, 3059, 10000);
quest::MerchantSetItem(999219, 3060, 10000);
quest::MerchantSetItem(999219, 3061, 10000);
quest::MerchantSetItem(999219, 3062, 10000);
quest::MerchantSetItem(999219, 3063, 10000);
quest::MerchantSetItem(999219, 3064, 10000);
quest::shout("Leveling blacksmith selling Banded armor cheap");
quest::stoptimer("random_loot_timer");
quest::settimer("itemgroup_3", 40);
quest::settimer("itemgroup_3_shout", $shout);
quest::setglobal('vaylena_items', 3, 6, F);
#post items, start shout and respawn timer, and save list to globals
}
elsif($timer eq "itemgroup_3_shout") {
quest::ze(2, "Vaylena says out of character 'Selling armor!! Please buy my BANDED!!!'")
#zonewide emote used as /ooc
}
elsif($timer eq "itemgroup_3") {
quest::respawn(999219,0);
quest::stoptimer(itemgroup_3);
#respawn when timer is up
}
}
}
Any input still welcome.
Cheers
Edited for newest revision.
|
|
|
|
10-16-2014, 12:09 AM
|
Administrator
|
|
Join Date: May 2013
Location: United States
Posts: 1,595
|
|
If you're wanting to save user input you could use quest::setglobal(BLAH, $text, 5, "F");
It's just you'd have to find a good name for each variable and name then consecutively, so Input1, Input2, Input3, etc.
|
10-16-2014, 12:23 AM
|
Sarnak
|
|
Join Date: Dec 2008
Location: sydney
Posts: 35
|
|
double post
|
10-16-2014, 12:24 AM
|
Sarnak
|
|
Join Date: Dec 2008
Location: sydney
Posts: 35
|
|
Thanks Kingly, just saw your post. I'll try that out.
Now I'm just trying to get the timers working properly. The one for when to respawn seems to skip sometimes still.
|
|
|
|
10-18-2014, 03:34 AM
|
Sarnak
|
|
Join Date: Dec 2008
Location: sydney
Posts: 35
|
|
Cleaned up the code a bit, did some more learning regarding "if" (admittedly, not much). I figured the elsif's I was using for the /ooc and respawns were what was causing the skipping. Now it's working, and not skipping any timers.
Code:
#############################################################
# Programmable Auto-Updating Merchant #
# This quest allows you to have a merchant whose selling #
# items change based on a timer. You set up a blank vendor.#
# All the items are stored in the merchantlist_temp table. #
# The shouts were mainly for testing, but they would be #
# useful anyway. --kilst87 #
#############################################################
sub EVENT_SPAWN {
if (!defined $qglobal{vaylena_items}) {
if($qglobals{"vaylena_items"} == 1) {
quest::settimer("spawned_1", 2);
#quest::resume();
}
elsif($qglobals{"vaylena_items"} == 2) {
quest::settimer("spawned_2", 2);
#quest::resume();
}
elsif($qglobals{"vaylena_items"} == 3) {
quest::settimer("spawned_3", 2);
#quest::resume();
}
}
#Set timers to delete remembered items
if (not defined $qglobal{vaylena_items}) {
quest::setglobal('vaylena_items', 0, 6, F);
quest::settimer("random_loot_timer", 5);
}
#sets qglobal if not set
}
sub EVENT_TIMER{
my $randi = int(rand(3));
#sets $randi with a random number between 0 and 2 to decide what to sell
my $shout = int(rand(10) + 20);
#set $shout with a number between 3 and 4 mins between item shouts
if($timer eq "spawned_1") {
quest::MerchantSetItem(999219, 1111, 0);
quest::MerchantSetItem(999219, 1112, 0);
quest::MerchantSetItem(999219, 1113, 0);
quest::MerchantSetItem(999219, 1114, 0);
quest::shout("Spawned!1");
quest::stoptimer("spawned_1");
quest::settimer("random_loot_timer", 5);
#deletes any saved items, starts next timer
}
elsif($timer eq "spawned_2") {
quest::MerchantSetItem(999219, 2111, 0);
quest::MerchantSetItem(999219, 2112, 0);
quest::MerchantSetItem(999219, 2113, 0);
quest::MerchantSetItem(999219, 2114, 0);
quest::shout("Spawned!2");
quest::stoptimer("spawned_2");
quest::settimer("random_loot_timer", 5);
#deletes any saved items, starts next timer
}
elsif($timer eq "spawned_3") {
quest::MerchantSetItem(999219, 3053, 0);
quest::MerchantSetItem(999219, 3054, 0);
quest::MerchantSetItem(999219, 3055, 0);
quest::MerchantSetItem(999219, 3056, 0);
quest::MerchantSetItem(999219, 3057, 0);
quest::MerchantSetItem(999219, 3058, 0);
quest::MerchantSetItem(999219, 3059, 0);
quest::MerchantSetItem(999219, 3060, 0);
quest::MerchantSetItem(999219, 3061, 0);
quest::MerchantSetItem(999219, 3062, 0);
quest::MerchantSetItem(999219, 3063, 0);
quest::MerchantSetItem(999219, 3064, 0);
quest::shout("Spawned!3");
quest::stoptimer("spawned_3");
quest::settimer("random_loot_timer", 5);
#deletes any saved items, starts next timer
}
if($randi == 1) {
if($timer eq "random_loot_timer"){
quest::MerchantSetItem(999219, 1111, 10000);
quest::MerchantSetItem(999219, 1112, 10000);
quest::MerchantSetItem(999219, 1113, 10000);
quest::MerchantSetItem(999219, 1114, 10000);
quest::shout("New crap items up!");
quest::stoptimer("random_loot_timer");
quest::settimer("itemgroup", 40);
quest::settimer("itemgroup_1_shout", $shout);
quest::setglobal('vaylena_items', 1, 6, F);
#post items, start shout and respawn timer, and save list to globals
}
}
elsif($randi == 0) {
if($timer eq "random_loot_timer"){
quest::MerchantSetItem(999219, 2111, 10000);
quest::MerchantSetItem(999219, 2112, 10000);
quest::MerchantSetItem(999219, 2113, 10000);
quest::MerchantSetItem(999219, 2114, 10000);
quest::shout("New trader selling all kinds of stuff");
quest::stoptimer("random_loot_timer");
quest::settimer("itemgroup", 40);
quest::settimer("itemgroup_2_shout", $shout);
quest::setglobal('vaylena_items', 2, 6, F);
#post items, start shout and respawn timer, and save list to globals
}
}
elsif($randi == 2) {
if($timer eq "random_loot_timer"){
quest::MerchantSetItem(999219, 3053, 10000);
quest::MerchantSetItem(999219, 3054, 10000);
quest::MerchantSetItem(999219, 3055, 10000);
quest::MerchantSetItem(999219, 3056, 10000);
quest::MerchantSetItem(999219, 3057, 10000);
quest::MerchantSetItem(999219, 3058, 10000);
quest::MerchantSetItem(999219, 3059, 10000);
quest::MerchantSetItem(999219, 3060, 10000);
quest::MerchantSetItem(999219, 3061, 10000);
quest::MerchantSetItem(999219, 3062, 10000);
quest::MerchantSetItem(999219, 3063, 10000);
quest::MerchantSetItem(999219, 3064, 10000);
quest::shout("Leveling blacksmith selling Banded armor cheap");
quest::stoptimer("random_loot_timer");
quest::settimer("itemgroup", 40);
quest::settimer("itemgroup_3_shout", $shout);
quest::setglobal('vaylena_items', 3, 6, F);
#post items, start shout and respawn timer, and save list to globals
}
}
if($timer eq "itemgroup_1_shout") {
quest::ze(2, "Vaylena says out of character 'Please buy my crap armor!!'")
#zonewide emote used as /ooc
}
if($timer eq "itemgroup_2_shout") {
quest::ze(2, "Vaylena says out of character 'Selling all kinds of armor, check me out!!'")
#zonewide emote used as /ooc
}
if($timer eq "itemgroup_3_shout") {
quest::ze(2, "Vaylena says out of character 'Selling armor!! Please buy my BANDED!!!'")
#zonewide emote used as /ooc
}
if($timer eq "itemgroup") {
quest::respawn(999219,0);
quest::stoptimer(itemgroup);
#respawn when timer is up
}
}
|
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -4. The time now is 08:40 AM.
|
|
|
|
|
|
|
|
|
|
|
|
|