PDA

View Full Version : Charm Up-grader.


Zamthos
03-29-2013, 11:55 PM
My charm up-grader will upgrade you from Rank 1 to Rank 2, but after that he just gives back your items, any ideas? Code below:

sub EVENT_SAY
{
my $charm = quest::saylink("Charm", 1);
my $token = quest::varlink(140226);

if($text=~/Hail/i)
{
plugin::Whisper("Hello, young $class, would you like a $charm?");
plugin::Whisper("To upgrade your charm you must hand me the charm and an $token.");
#plugin::Whisper("In development, try again later.");
}

if($text=~/Charm/i)
{
quest::summonitem(140126);
}
}

sub EVENT_ITEM
{
@charmlist = qw(
140126
140127
140128
140129
140130
140131
140132
140133
140134
140135
140136
140137
140138
140139
140140
140141
140142
140143
140144
140145
140146
140147
140148
140149
140150
140151
140152
140153
140154
140155
140156
140157
140158
140159
140160
140161
140162
140163
140164
140165
140166
140167
140168
140169
140170
140171
140172
140173
140174
140175
140176
140177
140178
140179
140180
140181
140182
140183
140184
140185
140186
140187
140188
140189
140190
140191
140192
140193
140194
140195
140196
140197
140198
140199
140200
140201
140202
140203
140204
140205
140206
140207
140208
140209
140210
140211
140212
140213
140214
140215
140216
140217
140218
140219
140220
140221
140222
140223
140224
140225
);
my $n = 0;
while ($charmlist[$n])
{
my $charmid = $charmlist[$n];

if (plugin::check_handin(\%itemcount, $charmid => 1, 140226 => 1))
{
plugin::Whisper("Here is your upgraded charm!");
quest::summonitem($charmid+1, 1);
}
else
{
plugin::return_items(\%itemcount);
quest::givecash($copper,$silver,$gold,$platinum);
}
$n++;
}
}

lerxst2112
03-30-2013, 12:26 AM
Think about the logic there. Check if the first item matches, if it does give the upgrade, otherwise return the items. By the time you get to checking the second item you've already given everything back.

I'm no expert, but it seems to me you would want to check the whole list for matches before giving anything back.

sorvani
03-30-2013, 01:14 AM
improper use of return items.
see: http://www.peqtgc.com/phpBB3/viewtopic.php?p=65083#p65083

Zamthos
03-30-2013, 02:30 AM
Revised version, haven't tested, is this the way mentioned in that post?

sub EVENT_SAY
{
my $charm = quest::saylink("Charm", 1);
my $token = quest::varlink(140226);

if($text=~/Hail/i)
{
plugin::Whisper("Hello, young $class, would you like a $charm?");
plugin::Whisper("To upgrade your charm you must hand me the charm and an $token.");
#plugin::Whisper("In development, try again later.");
}

if($text=~/Charm/i)
{
quest::summonitem(140126);
}
}

sub EVENT_ITEM
{
@charmlist = qw(
140126
140127
140128
140129
140130
140131
140132
140133
140134
140135
140136
140137
140138
140139
140140
140141
140142
140143
140144
140145
140146
140147
140148
140149
140150
140151
140152
140153
140154
140155
140156
140157
140158
140159
140160
140161
140162
140163
140164
140165
140166
140167
140168
140169
140170
140171
140172
140173
140174
140175
140176
140177
140178
140179
140180
140181
140182
140183
140184
140185
140186
140187
140188
140189
140190
140191
140192
140193
140194
140195
140196
140197
140198
140199
140200
140201
140202
140203
140204
140205
140206
140207
140208
140209
140210
140211
140212
140213
140214
140215
140216
140217
140218
140219
140220
140221
140222
140223
140224
140225
);
my $n = 0;
while ($charmlist[$n])
{
my $charmid = $charmlist[$n];

if (plugin::check_handin(\%itemcount, $charmid => 1, 140226 => 1))
{
plugin::Whisper("Here is your upgraded charm!");
quest::summonitem($charmid+1, 1);
}
$n++;
}
plugin::return_items(\%itemcount);
quest::givecash($copper,$silver,$gold,$platinum);
}

c0ncrete
03-30-2013, 06:28 AM
very inefficient to loop through the entire list of valid charms (100?) instead of just checking the item ids that were turned in (max of 4).
put this at the top of your file to be able to use the ~~ operator:
use 5.012;

foreach my $itemid (%itemcount)
{
next unless $itemid ~~ [140126..140225];
if (plugin::check_handin(\%itemcount, $charmid => 1, 140226 => 1))
{
plugin::Whisper("Here is your upgraded charm!");
quest::summonitem($itemid+1, 1);
}
}
plugin::return_items(\%itemcount);
quest::givecash($copper, $silver, $gold, $platinum);

c0ncrete
03-30-2013, 11:14 AM
oops. that should read:
foreach my $itemid (keys %itemcount)

Zamthos
03-30-2013, 04:16 PM
The one you gave me actually doesn't work, in the fact that he just eats the items, the second one I posted, the revised one, works correctly.

c0ncrete
03-30-2013, 06:33 PM
that $charmid should be $itemid. was half asleep both times i posted.