Solved Need plugin help

Jakkee

Retired Staff
Retired Staff
Plugin Developer
Jul 28, 2014
1,465
932
113
Australia
-Fougerite Version: 1.0.3F
-Error only happens when player gathers.

Hey there,
So I am trying to create a CFG file to change the gather rate, The problem is that the plugin is give me errors:
Code:
Error invoking function On_PlayerGathering in GatherRate plugin.
OverflowException: Number overflow.
Any want to help a noob? :p

Thy Code
JavaScript:
function On_PluginInit() {
    if(!Plugin.IniExists("Config"))
    {
        Plugin.CreateIni("Config");
        var iniCfg = Plugin.GetIni("Config");
        iniCfg.AddSetting("Config", "Enabled", "True");
        iniCfg.AddSetting("Config", "GatherRate", 2);
        iniCfg.Save();
    }
}

function On_PlayerGathering(Player, GatherEvent) {
        var iniCfg =  Plugin.GetIni("Config");
        if (iniCfg.GetSetting("Config", "Enabled") == "False") {
            return;
        }
        var mult = parseInt(Data.GetConfigValue("GatherRate", "Config", "GatherRate"));
        Player.Inventory.AddItem(GatherEvent.Item, Math.floor(GatherEvent.Quantity * (mult-1)));
        Player.InventoryNotice(GatherEvent.Quantity * (mult - 1) + " x " + GatherEvent.Item);
}
 
Last edited:

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,093
4,784
113
At your house.
github.com
Hey there,
So I am trying to create a CFG file to change the gather rate, The problem is that the plugin is give me errors:
Code:
Error invoking function On_PlayerGathering in GatherRate plugin.
OverflowException: Number overflow.
Any want to help a noob? :p

Thy Code
Code:
function On_PluginInit() {
    if(!Plugin.IniExists("Config"))
    {
        Plugin.CreateIni("Config");
        var iniCfg = Plugin.GetIni("Config");
        iniCfg.AddSetting("Config", "Enabled", "True");
        iniCfg.AddSetting("Config", "GatherRate", 2);
        iniCfg.Save();
    }
}

function On_PlayerGathering(Player, GatherEvent) {
        var iniCfg =  Plugin.GetIni("Config");
        if (iniCfg.GetSetting("Config", "Enabled") == "False") {
            return;
        } 
        var mult = parseInt(Data.GetConfigValue("GatherRate", "Config", "GatherRate"));
}
I don't think that you need the item added into the inv. When i created Rust fix (Infinite item glitch plugin) i simply modified the quantity.
Player.Inventory.AddItem(GatherEvent.Item, Math.floor(GatherEvent.Quantity * (mult-1)));
JavaScript:
var quantity = GatherEvent.Quantity;
GatherEvent.Quantity = quantity * (mult -1);
 

Jakkee

Retired Staff
Retired Staff
Plugin Developer
Jul 28, 2014
1,465
932
113
Australia
I worked out what was wrong. I can not create a Cfg file with this code, It just creates a Ini file and its not reading the ini file.
JavaScript:
function On_PluginInit() {
    if(!Plugin.IniExists("GatherRate"))
    {
        Plugin.CreateIni("GatherRate");
        var Cfg =  Plugin.GetIni("GatherRate");
        Cfg.AddSetting("Config", "GatherRate", 2);
        Cfg.Save();
So I made it super simple and it works! Yay!
JavaScript:
function On_PlayerGathering(Player, GatherEvent) {
    var mult = parseInt(Data.GetConfigValue("GatherRate", "Config", "GatherRate"));
    Player.Inventory.AddItem(GatherEvent.Item, Math.floor(GatherEvent.Quantity * (mult-1)));
    Player.InventoryNotice(GatherEvent.Quantity * (mult - 1) + " x " + GatherEvent.Item);
}
Now, Just to get it to create a Cfg file would be nice.
 
Last edited by a moderator:

balu92

Retired Staff
Retired Staff
Trusted Member
Jul 11, 2014
338
75
28
34
I worked out what was wrong. I can not create a Cfg file with this code, It just creates a Ini file and its not reading the ini file.
Code:
function On_PluginInit() {
    if(!Plugin.IniExists("GatherRate"))
    {
        Plugin.CreateIni("GatherRate");
        var Cfg =  Plugin.GetIni("GatherRate");
        Cfg.AddSetting("Config", "GatherRate", 2);
        Cfg.Save();
So I made it super simple and it works! Yay!
Code:
function On_PlayerGathering(Player, GatherEvent) {
    var mult = parseInt(Data.GetConfigValue("GatherRate", "Config", "GatherRate"));
    Player.Inventory.AddItem(GatherEvent.Item, Math.floor(GatherEvent.Quantity * (mult-1)));
    Player.InventoryNotice(GatherEvent.Quantity * (mult - 1) + " x " + GatherEvent.Item);
}
Now, Just to get it to create a Cfg file would be nice.
Well, Plugin.CreateIni will create an ini file, but to tell you a secret: ini files are way better then cfg files ;)
 

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,093
4,784
113
At your house.
github.com
I worked out what was wrong. I can not create a Cfg file with this code, It just creates a Ini file and its not reading the ini file.
Code:
function On_PluginInit() {
    if(!Plugin.IniExists("GatherRate"))
    {
        Plugin.CreateIni("GatherRate");
        var Cfg =  Plugin.GetIni("GatherRate");
        Cfg.AddSetting("Config", "GatherRate", 2);
        Cfg.Save();
So I made it super simple and it works! Yay!
Code:
function On_PlayerGathering(Player, GatherEvent) {
    var mult = parseInt(Data.GetConfigValue("GatherRate", "Config", "GatherRate"));
    Player.Inventory.AddItem(GatherEvent.Item, Math.floor(GatherEvent.Quantity * (mult-1)));
    Player.InventoryNotice(GatherEvent.Quantity * (mult - 1) + " x " + GatherEvent.Item);
}
Now, Just to get it to create a Cfg file would be nice.
I just realised you were reading null. xDDD
 

balu92

Retired Staff
Retired Staff
Trusted Member
Jul 11, 2014
338
75
28
34
I just realised you were reading null. xDDD
you mean like here:
Code:
var mult = parseInt(Data.GetConfigValue("GatherRate", "Config", "GatherRate"));
I guess you are right :D
 
  • Funny
Reactions: DreTaX

balu92

Retired Staff
Retired Staff
Trusted Member
Jul 11, 2014
338
75
28
34
I would do it like this:
Code:
// 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);
    }
}*/
 

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,093
4,784
113
At your house.
github.com
I would do it like this:
Code:
// 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);
    }
}*/
Oh come on, i just made.

And you wont even use it. (Javascript twice, fail)
 

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,093
4,784
113
At your house.
github.com
Yes, i wiped the cache in my browser, it should work.

[java]public void ShouldWork() {
System.out.println("Yes, it does");
}[/java]

Okay, no paste fail. xD
 
  • Funny
Reactions: balu92

balu92

Retired Staff
Retired Staff
Trusted Member
Jul 11, 2014
338
75
28
34
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);
    }
}*/
 
  • Useful
Reactions: Jakkee