Blockland Forums > Modification Help
Point taxing doesn't save
Big Brother:
saveVariable or something?
Fluff-is-back:
try this one
http://pastebin.com/raw.php?i=QhQu1G6D
Headcrab Zombie:
--- Quote from: Big Brother on April 09, 2012, 05:49:10 AM ---OK I'll say this just once, if I ditch VCE - I'd have to remake EVERYTHING. That means everything on my server will be wrong and I'd need to fix it. I am not willing to do this.
--- End quote ---
Taking the time to improve your code is part of being a good programmer. It won't take long (rewriting this function would have taken less than 5 minutes if I wasn't looking for/fixing other issues), and it will potentially save many headaches, as well as save everyone the hassle of clicking save and load bricks. Using a better method will allow you to modify the values directly, and save only the ones needed, only when needed, instead of constantly saving everything
Issues/Suggestions (some are fixed in the code I gave you, some are not)
I do like that you made global variables instead of magic numbers, but if this is a bigger project with many more, I would give them all a common prefix, for example, $RP::Interest::* (I'll call it RP because I have no idea what to call it)
If the client's score is greater than Interest::CutOff[2] they will be taxed twice, once according to Percentage[0] and once according to Percentage[2]. (fixed)
Why are you setting InterestTickCount to 0? Doing this, combined with not taxing if InterestTickCount is less than 10, results in running the function every minute, but only actually doing anything every 10 minutes.
You misspelled interest in several places (fixed)
--- Code: ---$Interest::CutOff[0] = "100";
$Interest::Percentage[0] = "1";
$Interest::CutOff[2] = "20000";
$Interest::Percentage[2] = "4";
$Interest::TickTime = 10;
function interestTick()
{
cancel($interestTickShed);
$interestTickShed = schedule(60000, 0, interestTick);
$InterestTickCount++;
if($InterestTickCount < ($Interest::TickTime - 1))
return;
for(%i = 0; %i < clientGroup.getCount(); %i++)
{
%client = clientGroup.getObject(%i);
%score = %client.score;
if(%score > $Interest::CutOff[0])
%per = %score * (0.01 * $Interest::Percentage[0]);
else if(%score > $Interest::CutOff[2])
%per = %score * (0.01 * $Interest::Percentage[2]);
%per = mCeil(%per);
%score-=%per;
messageClient(%client, '', "\c2You have been taxed \c6" @ %per @ "\c2 points.");
messageClient(%client, '', "\c2You now have a total of \c6" @ %num @ "\c2 points.");
%client.setScore(%num);
}
$InterestTickCount = 0;
}
interestTick();
--- End code ---
You'd also want to to put this in server.cs
--- Code: ---LoadRequiredAddOn("Script_Player_Persistence");
if(isFunction(RegisterPersistenceVar))
{
RegisterPersistenceVar("rp", true, "");
// RegisterPersistenceVar("someOtherVariable", false, "");
}
--- End code ---
And then every client field you create for your RP will be named starting with rp, and PlayerPersistence will take care of all saving and loading for you.
You could change rp to something else too.
For default fields that you want saved, but are not saved by the default Player Persistance, add lines similar to commented out second RegisterPersistenceVar function.
Keep in mind the default Player Persistence will save some fields you may not want saved, I'm not sure how to make it unregister them
Big Brother:
Thank you for your help - keep in mind that Fluffy coded it and I believe he purposefully mis-spelled interest so it reduced the chances of colliding with an existing mod. Players are given wrenches to help them build, but if it runs off of score they can manipulate it and give themselves points.
Headcrab Zombie:
--- Quote from: Big Brother on April 09, 2012, 05:26:06 PM ---I believe he purposefully mis-spelled interest so it reduced the chances of colliding with an existing mod.
--- End quote ---
Instead of misspelling things and causing confusion, name functions with a common prefix, similar to my suggestion for global variables
--- Quote from: Big Brother on April 09, 2012, 05:26:06 PM ---Players are given wrenches to help them build, but if it runs off of score they can manipulate it and give themselves points.
--- End quote ---
Couldn't the same be done with VCE?
I thought score is what you wanted because of the setScore call
You could just change any reference of %client.score to %client.points, and add a RegisterPersistenceVar call - RegisterPersistenceVar("points", false, "");