Solved Need plugin help

Jakkee

Retired Staff
Retired Staff
Plugin Developer
Jul 28, 2014
1,465
932
113
Australia
okay, so here is the code, hilited:
JavaScript:
// this is a javascript object:
var GatherRate = {
    // this line creates the "GatherRate" object's "Enabled" property
    // return true or false as boolean and not as string
    get Enabled () { return DataStore.Get("GatherRate", "Enabled");},
    get Rate () {return DataStore.Get("GatherRate", "Rate");}
};


function On_PluginInit(){
    // create ini if it doesn't exist
    if(!Plugin.InitExists("Config")){
        var ini = Plugin.CreateIni("Config");
        ini.AddSetting("Main", "Enabled", true);
        ini.AddSetting("Main", "GatherRate", 2);
        ini.Save();
    }

    // no doubt it exists now
    var ini = Plugin.GetIni("Config");

    // store the settings in the ds, when you load the server
    // its faster to read it from the memory, then open a file every time

    // this line will store the "Enabled" value as a boolean instead of a string
    DataStore.Add("GatherRate", "Enabled", ini.GetSetting("Main", "Enabled")=="true"?true:false);

    DataStore.Add("GatherRate", "Rate", parseFloat(ini.GetSetting("Main", "GatherRate")));
}

// use this if you want to gather faster, but not more
function On_GatherEvent(Player, GatherEvent){
    // check if gatherrate is enbaled
    if(GatherRate.Enabled){
        // multiply the gathered quantity with the desired gathering rate
        GatherEvent.Quantity *= GatherRate.Rate;
    }
}

// use this if you want to gather faster and more as well
// with this if you set gatherrate to 9, you should get ~900 woods from a woodpile
/*function On_GatherEvent(Player, GatherEvent){
    if(GatherEvent.Enabled){
        var qty = GatherEvent.Quantity;
        var qty = parseInt(Math.floor((qty * GatherRate.Rate) - qty)); // I'm not sure if you need parseint or not
        Player.Inventory.AddItem(GatherEvent.Item, qty);
        Player.InventoryNotice(qty + " x " + GatherEvent.Item);
    }
}*/
Config file doesn't generate.
Tried to make the Config file myself and it seems it doesn't read it.
Server says it was loaded successfully & no errors...
 

balu92

Retired Staff
Retired Staff
Trusted Member
Jul 11, 2014
338
75
28
34
Config file doesn't generate.
Tried to make the Config file myself and it seems it doesn't read it.
Server says it was loaded successfully & no errors...
You don't have a config.ini file after a magma reload?
 

Jakkee

Retired Staff
Retired Staff
Plugin Developer
Jul 28, 2014
1,465
932
113
Australia
I done fougerite.reload a few times and restarted the server.
No file
 

balu92

Retired Staff
Retired Staff
Trusted Member
Jul 11, 2014
338
75
28
34
Yeah, i meant fougerite.reload, bad habits.... nvm, what version of fougerite do you use?
 

Jakkee

Retired Staff
Retired Staff
Plugin Developer
Jul 28, 2014
1,465
932
113
Australia
Yeah, i meant fougerite.reload, bad habits.... nvm, what version of fougerite do you use?
Using 1.0.3F.

I just typed this up and it works just fine
JavaScript:
function On_PluginInit() {
    if(!Plugin.IniExists("Settings"))
    {
        Plugin.CreateIni("Settings");
        var iniCfg =  Plugin.GetIni("Settings");
        iniCfg.AddSetting("Config", "Enabled", "True");
        iniCfg.AddSetting("Config", "GatherRate", 8);
        iniCfg.Save();
    }
}

function On_PlayerGathering(p, ge) {
try{
    var iniCfg =  Plugin.GetIni("Settings");
    if (iniCfg.GetSetting("Config", "GatherRate") == "False") {
        return;
    }
        var Rate = parseFloat(iniCfg.GetSetting("Config", "GatherRate"));
        var Gathered = (Math.round(ge.Quantity) * (Rate-1));
        p.Inventory.AddItem(ge.Item, Gathered);
        p.InventoryNotice(Gathered + " x " + ge.Item);
    } catch (err) {
        Plugin.Log("log","Exception Message: " + err.message + "on Player On_PlayerGathering");
        Plugin.Log("log","Exception Description: " + err.description + "on RCon On_PlayerGathering");
    }
}
 

balu92

Retired Staff
Retired Staff
Trusted Member
Jul 11, 2014
338
75
28
34
I mispelled it:
JavaScript:
if(!Plugin.InitExists("Config")){
IniExists and NOT InitExists :D
change that and it will work ;)