|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Archive::Quests Archive area for Quests's posts that were moved here after an inactivity period of 90 days. |
|
|
|
09-06-2004, 07:05 AM
|
Hill Giant
|
|
Join Date: Jun 2004
Posts: 135
|
|
Buffing PERL Script (Formatting)
Hey all, it's me again =D. I wondered if anyone could help me with some formatting on a buffing NPC I am working on. See, if it doesn't work, I will end up redoing around 4000-5000 lines of code, so, I dont really want to continue with it until I know it works, hehe. I already did the first 5000 lines of code for categories and pricing and stuff, this is the part where u give him money.
Code:
sub EVENT_ITEM
{
{
if($ulevel < 10)
{
if($platinum == "100")
{
if($copper == "1")
{
quest::castspell($userid,1200);
quest::say("Good luck on your journies $name .");
}
}
}
elsif($ulevel > 9)
{
if($ulevel < 20)
{
if($platinum == "200")
{
if($copper == "1")
{
quest::castspell($userid,1200);
quest::say("Good luck on your journies $name .");
}
}
}
}
elsif($ulevel > 19)
{
if($ulevel < 30)
{
if($platinum == "300")
{
if($copper == "1")
{
quest::castspell($userid,1200);
quest::say("Good luck on your journies $name .");
}
}
}
}
elsif($ulevel > 29)
{
if($ulevel < 40)
{
if($platinum == "400")
{
if($copper == "1")
{
quest::castspell($userid,1200);
quest::say("Good luck on your journies $name .");
}
}
}
}
elsif($ulevel > 39)
{
if($ulevel < 50)
{
if($platinum == "500")
{
if($copper == "1")
{
quest::castspell($userid,1200);
quest::say("Good luck on your journies $name .");
}
}
}
}
elsif($ulevel > 49)
{
if($ulevel < 60)
{
if($platinum == "600")
{
if($copper == "1")
{
quest::castspell($userid,1200);
quest::say("Good luck on your journies $name .");
}
}
}
}
elsif($ulevel > 59)
{
if($ulevel < 70)
{
if($platinum == "700")
{
if($copper == "1")
{
quest::castspell($userid,1200);
quest::say("Good luck on your journies $name .");
}
}
}
}
elsif($ulevel > 69)
{
if($ulevel < 80)
{
if($platinum == "800")
{
if($copper == "1")
{
quest::castspell($userid,1200);
quest::say("Good luck on your journies $name .");
}
}
}
}
elsif($ulevel > 79)
{
if($ulevel < 90)
{
if($platinum == "900")
{
if($copper == "1")
{
quest::castspell($userid,1200);
quest::say("Good luck on your journies $name .");
}
}
}
}
elsif($ulevel > 89)
{
if($ulevel < 100)
{
if($platinum == "1000")
{
if($copper == "1")
{
quest::castspell($userid,1200);
quest::say("Good luck on your journies $name .");
}
}
}
}
}
}
as you can see, you pay more for buffs as you gain levesl, so, I just wanted to know if this format would work, that way if it wont, I only have to redo about 90 lines instead of 4000-5000 lines =D. If you want to look at the entire code file, send me an email at
xteam_leader@yahoo.com it is probably about 100 kb now and is in a notepad, lol. Soooo much code, been working for hours on it so far.
|
|
|
|
|
|
|
09-06-2004, 08:06 AM
|
Discordant
|
|
Join Date: Jan 2004
Location: 47
Posts: 339
|
|
Hmm, all these nested if / elsif / else ... not too easy to work on.
Why not try a different scheme : store values for your quest in an array, and test them. Much easier to read and modify imho :
Code:
sub EVENT_ITEM{
my @data=(
{ "minlevel" => 1,
"maxlevel" =>9,
"plat" => 100,
"copper" => 1,
"spellid" => 1200,
"saying" => "Good luck on your journey, $name"
},
{ "minlevel" => 10,
"maxlevel" =>19,
"plat" => 200,
"copper" => 1,
"spellid" => 1200,
"saying" => "Good luck on your journey, $name"
},
{ "minlevel" => 20,
"maxlevel" => 30,
"plat" => 300,
"copper" => 1,
"spellid" => 1200,
"saying" => "Good luck on your journey, $name"
}
);
foreach $entry (@data){
if($ulevel >= $entry->{'minlevel'}
&& $ulevel <= $entry->{'maxlevel'}
&& $copper == $entry->{'copper'}
&& $platinum == $entry->{'plat'}
){
quest::castspell($userid, $entry->{'spellid'});
quest::say($entry->{'saying'});
last;
}
}
}
#the following is for testing only, remove or comment out if you want to include this in a real quest
sub wannatry{
$userid=1234;
$name="MyCharName";
$platinum=100; $copper=1;
$ulevel=7;
EVENT_ITEM();
}
package quest;
sub say{
print shift, "\n";
}
sub castspell{
print "NPC now casting spell ", shift, "\n";
}
package main;
wannatry();
i ddn't test it fully, but should work for a start. i hope this helps.
|
|
|
|
|
|
|
09-06-2004, 08:18 AM
|
Hill Giant
|
|
Join Date: Jun 2004
Posts: 135
|
|
hehe, well, I already wrote about 200 lines with nesting =\ and not quite sure if I want to redo all of it, hehe, just wanted to know if it was possible that it would work =D. Ty though for the help. And you are right, it is very hard programming in the way I set it up, lol, very very very hard. I am counting it by patterns now, only way I recognize syntax and stuffs, lol
{
{
{
elsif
}
}
}
like that, if it doesn't look like that, or whatever pattern I am on, hehe, then I didn't do it yet, lol. It looks more like 2 horns, here:
Code:
elsif($ulevel > 89)
{
if($ulevel < 100)
{
if($platinum == "1000")
{
if($copper == "1")
{
quest::castspell($userid,1200);
quest::say("Good luck on your journies $name .");
}
}
elsif($platinum == "1100")
{
if($copper == "2")
{
quest::castspell($userid,1201);
quest::say("Good luck on your journies $name .");
}
}
}
}
ya, like that, and the pattern changes and gets longer every time I add on, at one point though, I wont be able to use the patterns becuz it will be too long, and I have 54 things, up there are only 2. Well, I am going to continue on then with pattersn, and then at one point, just searching through the stuff to see if I put the write values in, hehe.
|
|
|
|
09-06-2004, 08:39 AM
|
Demi-God
|
|
Join Date: Jun 2004
Location: Heaven.
Posts: 1,260
|
|
try selfcast(spellid);, ive never gotten cast() to work.
__________________
namespace retval { template <class T> class ReturnValueGen { private: T x; public: ReturnValueGen() { x = 0; }; T& Generator() { return x; }; }; } int main() { retval::ReturnValueGen<int> retvalue; return retvalue.Generator(); }
C++ is wonderful.
|
09-06-2004, 11:47 AM
|
Dragon
|
|
Join Date: Jan 2004
Posts: 860
|
|
The way you wrote it, it will always cost either 100 or 200 plat, higher levels won't be able to buy anything. Because if level is 99 $ulevel < 10 will be false and the next check $ulevel > 9 will be true, so it will skip all the other elsifs even though it fails the $ulevel < 20. You need to either combine these into one line as elsif($ulevel > 9 && $ ulevel < 20) or just get rid of the ($ulevel > 9) because if it ever gets to that else their level must be over 9 regardless.
|
09-06-2004, 12:17 PM
|
Hill Giant
|
|
Join Date: Jun 2004
Posts: 135
|
|
How it is set-up is that it first checks to see if you meet the first req, then it throws another at you and if you fail that one, it skips all of that and goes through the rest of the code. This is how code works, if you meet a requirement, then you go to that, but if you don't, you skip it. So, you meet that req, but the second one you dont meet, so then you go back and into another elsif.
But, if you are right, would this be able to fix it?
Code:
elsif($ulevel < 100)
{
if($ulevel > 89)
{
for the last one. I still think my way is going to work, but if it doesn't, then what you are saying is that should fix it.
|
09-06-2004, 02:00 PM
|
Dragon
|
|
Join Date: Jan 2004
Posts: 860
|
|
Yeah that way should work the way you want. And you also don't need the double {'s at the beginning and end, but again they shouldn't hurt.
|
09-06-2004, 02:05 PM
|
Hill Giant
|
|
Join Date: Jun 2004
Posts: 135
|
|
You were right, lol, I am redoing all 5079 lines, lol, been working about 1 1/2 hours now and a bit more than halfway done, hehe. Tx alot, I was being stupid =P
|
|
|
|
09-06-2004, 03:05 PM
|
Hill Giant
|
|
Join Date: Jun 2004
Posts: 135
|
|
It doesn't work, lol.
Anyone Wanna help, I have lots and lots of errors, I think 5:
Bareword found where operator expected at Untitled line 120, near "if($text=~/ShapeChange30"
Lines 110-125:
Code:
{
if($ulevel > 89)
{
quest::say("ShapeChange25 is 1000 Platinum Pieces and 1 Copper Piece.");
}
}
}
#####################################################################################
#ShapeChange30#ShapeChange30#ShapeChange30#ShapeChange30#ShapeChange30#ShapeChange30#
#####################################################################################
if($text=~/ShapeChange30)
{
if($ulevel < 10)
{
quest::say("ShapeChange30 is 200 Platinum Pieces and 2 Copper Piece.");
}
(Might be a runaway multi-line // string starting on line 47)
Lines 47-101:
Code:
if($text=~/ShapeChange25)
{
if($ulevel < 10)
{
quest::say("ShapeChange25 is 100 Platinum Pieces and 1 Copper Piece.");
}
elsif($ulevel < 20)
{
if($ulevel > 9)
{
quest::say("ShapeChange25 is 200 Platinum Pieces and 1 Copper Piece.");
}
}
elsif($ulevel < 30)
{
if($ulevel > 19)
{
quest::say("ShapeChange25 is 300 Platinum Pieces and 1 Copper Piece.");
}
}
elsif($ulevel < 40)
{
if($ulevel > 29)
{
quest::say("ShapeChange25 is 400 Platinum Pieces and 1 Copper Piece.");
}
}
elsif($ulevel < 50)
{
if($ulevel > 39)
{
quest::say("ShapeChange25 is 500 Platinum Pieces and 1 Copper Piece.");
}
}
elsif($ulevel < 60)
{
if($ulevel > 49)
{
quest::say("ShapeChange25 is 600 Platinum Pieces and 1 Copper Piece.");
}
}
elsif($ulevel < 70)
{
if($ulevel > 59)
{
quest::say("ShapeChange25 is 700 Platinum Pieces and 1 Copper Piece.");
}
}
elsif($ulevel < 80)
{
if($ulevel > 69)
{
quest::say("ShapeChange25 is 800 Platinum Pieces and 1 Copper Piece.");
}
}
syntax error at Untitled line 120, near "if($text=~/ShapeChange30"
Lines 115-125:
Code:
}
}
#####################################################################################
#ShapeChange30#ShapeChange30#ShapeChange30#ShapeChange30#ShapeChange30#ShapeChange30#
#####################################################################################
if($text=~/ShapeChange30)
{
if($ulevel < 10)
{
quest::say("ShapeChange30 is 200 Platinum Pieces and 2 Copper Piece.");
}
syntax error at Untitled line 126, near "elsif"
Lines 120-130:
Code:
if($text=~/ShapeChange30)
{
if($ulevel < 10)
{
quest::say("ShapeChange30 is 200 Platinum Pieces and 2 Copper Piece.");
}
elsif($ulevel < 20)
{
if($ulevel > 9)
{
quest::say("ShapeChange30 is 300 Platinum Pieces and 2 Copper Pieces.");
If you want to see all of the code, please go to this site:
http://<br />
<a href="http://www.r...html</a><br />
Or
http://<br />
<a href="http://www.r...html</a><br />
|
|
|
|
09-06-2004, 03:21 PM
|
Discordant
|
|
Join Date: Jan 2004
Location: 47
Posts: 339
|
|
you didn't close the match pattern in the if clause :
Code:
if($text=~/ShapeChange30)
should be
Code:
if($text=~/ShapeChange30/)
on all such lines.
This might not solve all your pbs, but it's a start imho. i hope this helps.
|
09-06-2004, 04:15 PM
|
Hill Giant
|
|
Join Date: Jun 2004
Posts: 135
|
|
Lol, tx, I didn't see that at all, =P, lol. I feel blind now, lol, and it would actually be something like if($text=~/ShapeChange/i), that way doesn't have to match the caps. once again thx, I can't believe I didn't see that I forgot to do that. When you are typing a 10,000 line code file, you sometimes forget some of the small things, ehhe.
|
09-09-2004, 04:22 PM
|
Hill Giant
|
|
Join Date: Jun 2004
Posts: 135
|
|
THE BUFFER NPC IS NOW DONE!
|
|
|
|
09-10-2004, 03:36 AM
|
Hill Giant
|
|
Join Date: Dec 2003
Posts: 166
|
|
Glancing at the script, just a couple of insights. Take it for what you will:
For your level range checking, you do not need as many checks. Consider the following:
Code:
if ($x >= 10 && $x <= 20)
{
print "x is between 10 and 20 inclusive\n";
}
elsif ($x >= 21 && $x <= 30)
{
print "x is between 21 and 30 inclusive\n";
}
Instead, try:
Code:
if ($x > 30)
{
print "x is larger than 30!\n";
}
elsif ($x >= 20)
{
print "x is between 30 and 20 inclusive\n";
}
As for all of these "if ($text =~ ...)" lines, after the first if statement, you may as well use elsif from then on.
Code:
if($text=~/hail/i)
...
elsif($text=~/categorys/i)
...
Also, the whole structure of the NPC telling what buffs he casts, etc., could probably be done with an array/hash more elegantly, and would take less code. I'm not going to draw that up, though .
Good effort on your script. I would suggest practicing with perl a bit more, and then attempt to redesign it. People have a habit of not wanting to redo or throw out their code, but in the end it will give you a better result, and likely increase your skills.
|
|
|
|
09-10-2004, 09:56 AM
|
Hill Giant
|
|
Join Date: Jun 2004
Posts: 135
|
|
Hey all, for some reason, this script isn't really working. The NPC is buffing itself instead of the players =/. Any ideas?
Code:
quest::castspell($userid,spell)
That is the correct usage, right? Or am I doing something wrong? Please tell me the correct usage, hehe.
Also, thx moonie. The code is already done though and works perfectly except for the above =/. I could have sworn it was $userid...
|
09-10-2004, 10:18 AM
|
Demi-God
|
|
Join Date: Jun 2004
Location: Heaven.
Posts: 1,260
|
|
Quote:
Originally Posted by Deimos
Hey all, for some reason, this script isn't really working. The NPC is buffing itself instead of the players =/. Any ideas?
Code:
quest::castspell($userid,spell)
That is the correct usage, right? Or am I doing something wrong? Please tell me the correct usage, hehe.
Also, thx moonie. The code is already done though and works perfectly except for the above =/. I could have sworn it was $userid...
|
Read my reply above where I mentioned this ahead of time.
__________________
namespace retval { template <class T> class ReturnValueGen { private: T x; public: ReturnValueGen() { x = 0; }; T& Generator() { return x; }; }; } int main() { retval::ReturnValueGen<int> retvalue; return retvalue.Generator(); }
C++ is wonderful.
|
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 06:34 AM.
|
|
|
|
|
|
|
|
|
|
|
|
|