PDA

View Full Version : review my work?


8ball
09-11-2004, 01:46 PM
was wondering if someone could review my work. ive been testing out a few things.
please respond with any errors i have.


#practice script

sub EVENT_SAY
{
if($text=~/hail/i)
{
quest::say("Greetings $name. I can perform multiple [tasks] for you.");
}
if($text=~/what tasks/i)
{
quest::say("I can raise your [level] to whatever you wish, I can [save] your
progress, and summon a [weapon] for you");
}
if($text=~/level/i)
{
quest::say("State the level you wish to be.");
}
$level = $level;
if($text=~/$level/i)
{
quest::level($level);
quest::say("You have been leveled");
}
if($text=~/save/i)
{
quest::save();
quest::say("You have been saved");
}
if($text=~/what weapon/i)
{
quest::say("I can summon a random magical weapon for you. Decide now whether you want
it or not.");
}
if($text=~/yes/i)
{
$random = int(rand(55261,24773,25989,22982,26031,54065,43148 ,7823));
quest::summonitem($random);
quest::say("Your weapon has been summoned.");
}
}

sub EVENT_ITEM
{
{
quest::say("I do not require payment of any kind.");
if($item1 > 0){quest::summonitem("$item1");}
if($item2 > 0){quest::summonitem("$item2");}
if($item3 > 0){quest::summonitem("$item3");}
if($item4 > 0){quest::summonitem("$item4");}
if($platinum != 0 || $gold !=0 || $silver != 0 || $copper != 0) {
quest::givecash($platinum, $gold, $silver, $copper);}
}
}


also, so im not accused of stealing, the return items/cash piece at the end i got from sotonin. saw it in one of his quests and decided to use it since it is really useful :D thanks sotonin

sotonin
09-11-2004, 01:50 PM
It's ok. i didnt write it either, i got it from somebody here on the forums and posted it for all to use. glad you got some use from it. )

animepimp
09-11-2004, 02:18 PM
$level = $level;
if($text=~/$level/i)
{
quest::level($level);
quest::say("You have been leveled");
}


This block of code is completely not what you want. $level = $level; will not change anything at all. if($text=~/$level/i) will only be true if they say whatever $level is. Since you didn't really give it any value it'll never be true. Or does $level store the current level of the user? If so then it will level them to their current level. essentially doing nothing at all.


$random = int(rand(55261,24773,25989,22982,26031,54065,43148 ,7823));


This is also not going to do what you want at all. rand doesn't accept input, so it'll ignore anything you give it. You will end up with a completely random number between 0 and the max rand can make.

8ball
09-11-2004, 02:39 PM
what i was trying to do with the $level = $level thing was i wanted the person to just say a number, then use quest::level($level) to level them up to there desired level.

edit---

maybe this would work?


{
int $level;
if($text=~/$level/i)
{
quest::level($level);
}
}

Cisyouc
09-11-2004, 04:28 PM
what i was trying to do with the $level = $level thing was i wanted the person to just say a number, then use quest::level($level) to level them up to there desired level.

edit---

maybe this would work?


{
int $level;
if($text=~/$level/i)
{
quest::level($level);
}
}
Try this.

{
if($text >= $ulevel)
{
quest::say("You are now level $text.");
quest::level($text);
}
if($text == $ulevel)
{
quest::say("You are already level $ulevel.");
}
if($text <= $ulevel)
{
$difference = ($ulevel-$text);
$levelto = ($text);
quest::say("Are you sure you want to de-level $difference levels? [Yes] or [No].");
}
if($text=~/yes/i)
{
if($difference != 0)
{
quest::level($levelto);
$difference="0"
$levelto="0"
}
else
{
quest::say("Yes what?");
}
}
if($text=~/no/i)
{
if($difference != 0)
{
quest::say("Alright then.");
$difference="0"
$levelto="0"
}
else
{
quest::say("No what?");
}
}
}

I think that should work. But not sure?

8ball
09-11-2004, 05:10 PM
thanks ill try that

animepimp
09-11-2004, 05:35 PM
That code should work alright, but it'll be really weird because "hi" is >= "20". so if the input any text like hailing the NPC it'll try to level("Hail") the and that will probably cause problems.

Cisyouc
09-11-2004, 06:20 PM
That code should work alright, but it'll be really weird because "hi" is >= "20". so if the input any text like hailing the NPC it'll try to level("Hail") the and that will probably cause problems.It is? err.. Lets try this..

{
if($text == $text)
{
if($text <= 255)
{
$xlevel = ($text);
if($xlevel >= $ulevel)
{
quest::say("You are now level $text.");
quest::level($xlevel);
}
if($xlevel == $ulevel)
{
quest::say("You are already level $ulevel.");
}
if($xlevel <= $ulevel)
{
$difference = ($ulevel-$xlevel);
$levelto = ($xlevel);
quest::say("Are you sure you want to de-level $difference levels? [Yes] or [No].");
}
if($text=~/yes/i)
{
if($difference != 0)
{
quest::level($levelto);
$difference="0";
$levelto="0";
$xlevel="0";
}
else
{
quest::say("Yes what?");
}
}
if($text=~/no/i)
{
if($difference != 0)
{
quest::say("Alright then.");
$difference="0"
$levelto="0"
}
else
{
quest::say("No what?");
}
}
else
{
quest::say("What was that?");
}
}
}
Mind you Its 2:20 AM Im very sleepy, this could be very very wrong, lol.

8ball
09-12-2004, 04:50 AM
thank you :D thats exactly what i was looking for

m0oni9
09-12-2004, 12:58 PM
For the random weapon thing, you could probably pick a random index out of an array -- ie, something like:
my @nums = (55261,24773,25989,22982,26031,54065,43148,7823 );
srand();
my $weapon = $nums[int(rand() * ($#nums + 1))];
print "random weapon: $weapon\n";