I’m having a problem with an NPC I have. I’ll explain what its meant to do, what the problem is and link you the code. I’ve tried several things to fix it but to no avail. I just cant seem to get my head around the problem. I’m not an amazing scripter but I feel like I’m missing something simple here but I cant place my finger on it. I was hoping you guys could help me.
NPC:
When a player throws a bush at this NPC, it records and displays how many bushes have been thrown at it. When 5 bushes have been thrown at it, it lays a gold rupee.
Problem:
The NPC seems to get stuck in a continous loop despite me using the if command. It increments this.bush over and over after being hit with only one bush.
I only need it to increment once then wait for another bush to be thrown.
Code:
timereverywhere;
timeout=.05;
if (created) {
showcharacter;
setcharprop #3,head771.gif;
setcharprop #C0,orange;
setcharprop #C1,white;
setcharprop #C2,blue;
setcharprop #C3,red;
setcharprop #C4,black;
setcharprop #n,Bush Farmer;
setcharprop #2,no-shield.gif;
shieldpower = 1;
dir = 2;
ap = 60;
}
if (playertouchsme) {say2
Hi there.#b
My father left me this farm#b
in his will and I’m trying to#b
live up to his name of the#b
biggest supplier of bush-berries#b
in all of Arathor.#b
But…I can barely keep up#b
with the other farmers!#b
I’m not used to such hard work!#b
Perhaps you could help me?#b
All you’d need to do is pick#b
up the bushes and throw them to#b
me. I’ll pay you 100 rupees for#b
every 50 bushes?#b;
}
if (peltwithbush){
this.bush=this.bush+1;
message #v(this.bush);
}
if (this.bush=5){
lay goldrupee;
this.bush=0;
}
I apologise for it not being in a code snippet box. I dont know the command to place it in one. And also thanks in advance for fixing what probably seems to some of you as a pretty simple code.
This NPC runs on the more active flags/triggers like ‘peltwithbush’, as such, you don’t need “timereverywhere; timeout=.05;” (Which was causing the uncontrolled looping)
Also:
[pre]
if (peltwithbush){
this.bush++; //Future Reference, this is the same as var = var +1; and var += 1;
message #v(this.bush);
if (this.bush == 5){ // ‘=’ is for Assigning Variables, ‘==’ is for comparisons.
lay goldrupee;
this.bush=0;
}
}
[/pre]
Your response did more than help me fix my problem, it made me understand what was causing it in the first place and how to use those commands in other situations. It’s all a learning curve
Thanks again!
___Merged doublepost__________________
I seem to be having another problem with the NPC. After I’ve pelt it with a bush, it increments if I just touch it or slash it. And the message only updates if the player touchs the NPC.
Code:
if (created) {
// Initialize the attributes
showcharacter;
setcharprop #3,head771.gif;
setcharprop #C0,orange;
setcharprop #C1,white;
setcharprop #C2,blue;
setcharprop #C3,red;
setcharprop #C4,black;
setcharprop #n,Bush Farmer;
setcharprop #2,no-shield.gif;
shieldpower = 1;
dir = 2;
ap = 60;
}
if (playertouchsme) {say2
Hi there.#b
My father left me this farm#b
in his will and I’m trying to#b
live up to his name of the#b
biggest supplier of bush-berries#b
in all of Arathor.#b
But…I can barely keep up#b
with the other farmers!#b
I’m not used to such hard work!#b
Perhaps you could help me?#b
All you’d need to do is pick#b
up the bushes and throw them to#b
me. I’ll pay you 100 rupees for#b
every 50 bushes?#b;
}
if (peltwithbush){
this.bush++;
message #v(this.bush);
}
if (this.bush == 5){
lay goldrupee;
this.bush=0;
}
I’ll be blunt, ‘if(created){}’ is a tad broken with our GServer, but that isn’t your problem.
Apparently this situation is a tad flawed, tested it myself, lol. The flag is more passive than I thought, however.
[pre]if (waspelt && peltwithbush){ //‘waspelt’ is only activated when pelted.
this.bush++;
message #v(this.bush);
if (this.bush == 5){ //Inside of the waspelt condition to run at the same time.
lay goldrupee;
this.bush=0;
}
}[/pre]
However, remember that some things don’t work due to bugs in the Gserver. Not everything will work as intended, but maybe around 80-90% does. Usually, in such cases, we have work-arounds that will assist in accomplishing those goals. But, not all the time.