So_1337
10-05-2009, 01:35 PM
Greetings. I've recently started trying to learn my way around the source and to see if I can become more of an asset around here. I've spent some time recently trying to make the TZVZ code for random duration invisibility work, and have come up short.
There are a few things that are holding me back, really, and I was hoping a more experienced coder could help me understand them. Let me start with a code block to use for reference (in client.cpp, this is inserted at line 3242):
void Client::DoInvisUpkeep() { //Null: Invis Fading Function
int Invis_Skill = GetSkill(DIVINATION);
int Invis_MaxSkill = MaxSkill(DIVINATION);
int break_Chance = 0.95*(Invis_Skill/Invis_MaxSkill); //Null: 5% chance to break with max skill.
int rngNum = 0; //This is the first point I will reference
Message(15, "Skill: %i Max Skill: %i Break Chance: %i", Invis_Skill, Invis_MaxSkill, break_Chance); //Debugging purposes
if(invisible == true) {
switch(Invis_fade) {
case 2:
BuffFadeByEffect(SE_Invisibility);
Invis_fade = -1;
invisible = false;
break;
case -1:
rngNum = MakeRandomInt(0, 100);
Message(13, "RNG: %i", rngNum); //Debugging, show the chance that was rolled
if (rngNum > (break_Chance * 100)) {
Invis_fade++;
Message(13, "You feel yourself starting to appear.");
}
break;
case 1:
case 0:
Invis_fade++;
break;
default:
break;
}
}
if(invisible_animals == true) {
switch(IVA_fade) {
case 2:
BuffFadeByEffect(SE_Invisibility);
IVA_fade = -1;
invisible_animals = false;
break;
case -1:
rngNum = MakeRandomInt(0, 100);
if (rngNum > (break_Chance * 100)) {
IVA_fade++;
Message(13, "You feel yourself starting to appear.");
}
break;
case 1:
case 0:
IVA_fade++;
break;
default:
break;
}
}
if(invisible_undead == true) {
switch(IVU_fade) {
case 2:
BuffFadeByEffect(SE_Invisibility);
IVU_fade = -1;
invisible_undead = false;
break;
case -1:
rngNum = MakeRandomInt(0, 100);
if (rngNum > (break_Chance * 100)) {
IVU_fade++;
Message(13, "You feel yourself becoming more visable.");
}
break;
case 1:
case 0:
IVU_fade++;
break;
default:
break;
}
}
}
The errors I'm receiving have to do with undeclared identifiers, and I know it's because Invis_fade, IVA_fade, and IVU_fade weren't declared with a data type. However, I can't figure out the proper way to do so. Inserting each of them with just "int Invis_fade = -1" at the reference point I commented in the code above would reset the values to -1 every time the code is called, making it worthless. However, just declaring them and leaving them would leave them null, so there'd be no way to trigger the cases in the first place.
What I have currently is a mix of Null's original code and what I've changed to get it closer to working (such as making the "Invis_Skill" and "Invis_MaxSkill" checks actually check Divination; they were returning wildly absurd values previously, because they didn't point to anything.)
I know that I'm probably way out of my depth here, but this was code that I sure wanted to see make it into the source after TheLieka released it to the public, and I'm using it to learn as I go.
I've gotten it to compile a few times just by declaring the variables at the beginning of the function, but as I said, that really had no effect, as the cases were never triggered. (I didn't paste the small snippets of code from client.h and client_process.cpp that call this function in the first place, but the code was definitely being called after invis was applied; I just can't get the check and fade working yet).
Thanks for any pointers that can be offered. I wouldn't be offended if someone took this and ran with (in fact, I'd feel very good knowing that it was coded properly by someone with experience), but I'm trying to pitch in around here, so a reply to this post doesn't mean I'll expect you to write the code for me. No obligations here! Thanks for reading.
There are a few things that are holding me back, really, and I was hoping a more experienced coder could help me understand them. Let me start with a code block to use for reference (in client.cpp, this is inserted at line 3242):
void Client::DoInvisUpkeep() { //Null: Invis Fading Function
int Invis_Skill = GetSkill(DIVINATION);
int Invis_MaxSkill = MaxSkill(DIVINATION);
int break_Chance = 0.95*(Invis_Skill/Invis_MaxSkill); //Null: 5% chance to break with max skill.
int rngNum = 0; //This is the first point I will reference
Message(15, "Skill: %i Max Skill: %i Break Chance: %i", Invis_Skill, Invis_MaxSkill, break_Chance); //Debugging purposes
if(invisible == true) {
switch(Invis_fade) {
case 2:
BuffFadeByEffect(SE_Invisibility);
Invis_fade = -1;
invisible = false;
break;
case -1:
rngNum = MakeRandomInt(0, 100);
Message(13, "RNG: %i", rngNum); //Debugging, show the chance that was rolled
if (rngNum > (break_Chance * 100)) {
Invis_fade++;
Message(13, "You feel yourself starting to appear.");
}
break;
case 1:
case 0:
Invis_fade++;
break;
default:
break;
}
}
if(invisible_animals == true) {
switch(IVA_fade) {
case 2:
BuffFadeByEffect(SE_Invisibility);
IVA_fade = -1;
invisible_animals = false;
break;
case -1:
rngNum = MakeRandomInt(0, 100);
if (rngNum > (break_Chance * 100)) {
IVA_fade++;
Message(13, "You feel yourself starting to appear.");
}
break;
case 1:
case 0:
IVA_fade++;
break;
default:
break;
}
}
if(invisible_undead == true) {
switch(IVU_fade) {
case 2:
BuffFadeByEffect(SE_Invisibility);
IVU_fade = -1;
invisible_undead = false;
break;
case -1:
rngNum = MakeRandomInt(0, 100);
if (rngNum > (break_Chance * 100)) {
IVU_fade++;
Message(13, "You feel yourself becoming more visable.");
}
break;
case 1:
case 0:
IVU_fade++;
break;
default:
break;
}
}
}
The errors I'm receiving have to do with undeclared identifiers, and I know it's because Invis_fade, IVA_fade, and IVU_fade weren't declared with a data type. However, I can't figure out the proper way to do so. Inserting each of them with just "int Invis_fade = -1" at the reference point I commented in the code above would reset the values to -1 every time the code is called, making it worthless. However, just declaring them and leaving them would leave them null, so there'd be no way to trigger the cases in the first place.
What I have currently is a mix of Null's original code and what I've changed to get it closer to working (such as making the "Invis_Skill" and "Invis_MaxSkill" checks actually check Divination; they were returning wildly absurd values previously, because they didn't point to anything.)
I know that I'm probably way out of my depth here, but this was code that I sure wanted to see make it into the source after TheLieka released it to the public, and I'm using it to learn as I go.
I've gotten it to compile a few times just by declaring the variables at the beginning of the function, but as I said, that really had no effect, as the cases were never triggered. (I didn't paste the small snippets of code from client.h and client_process.cpp that call this function in the first place, but the code was definitely being called after invis was applied; I just can't get the check and fade working yet).
Thanks for any pointers that can be offered. I wouldn't be offended if someone took this and ran with (in fact, I'd feel very good knowing that it was coded properly by someone with experience), but I'm trying to pitch in around here, so a reply to this post doesn't mean I'll expect you to write the code for me. No obligations here! Thanks for reading.