mangiang submitted a new resource:
Starter Pack - Gives some items on connection
Read more about this resource...
Starter Pack [Unmaintained]
Discussion in 'Plugin Support' started by mangiang, May 11, 2017.
-
mangiang updated Starter Pack with a new update entry:
1.1
-
so for every connection for any player, all players receive 'specified' items? or is it only new players?
-
how do i make it pork chop
-
2 things it says starter pack then has just poured a cup of coffee i just want the coffee part and also how do i get it to give me pork chop upon joining thank you
-
Would you want the item to be for everyone according to a boolean in the configure file ?
-> open the ".cs" file and find
Code:#region Plugin name if (!PluginNameParameters["size"].Equals("0")) { sb.Append("<size=" + PluginNameParameters["size"] + ">"); }if (!PluginNameParameters["color"].Equals("white")) { sb.Append("<color=" + PluginNameParameters["color"] + ">"); }sb.Append("[").Append(this.Name).Append("] ");if (!PluginNameParameters["color"].Equals("white")) { sb.Append("</color>"); }if (!PluginNameParameters["size"].Equals("0")) { sb.Append("</size>"); } #endregion
2) To have the pork chop :
-> find the id of the item you want here : Oxide API for Rust . I think, you want "-253819519" but you can choose any item you want.
-> Copy that id
-> paste it instead of "107868" in the ".json" located in the config folder.Last edited by a moderator: May 12, 2017 -
is it possible you could link me a updates .cs file because im sure i would get lost i dont wuite understand how coding works
-
"This plugins gives some items to every players on connection" <--- this is why i was confused about if it gave it to 'every' player in the whole server upon one person joining. I understand now! Thanks
-
no prob
I will edit that -
this is the name o
is this right?
[DOUBLEPOST=1494559158][/DOUBLEPOST]using Oxide.Core;
using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("StarterPack", "mangiang", 1.1, ResourceId = 2461)]
[Description("Gives some basic items on connection")]
class StarterPack : RustPlugin
{
/// <summary>
/// List of Player ids
/// </summary>
List<string> ids = new List<string>();
/// <summary>
/// Items given on connection
/// </summary>
Dictionary<string, Dictionary<string, object>> items = new Dictionary<string, Dictionary<string, object>>();
/// <summary>
/// Gives items only on first connection
/// </summary>
bool OnlyFirstConnection;
/// <summary>
/// Message on connection
/// </summary>
string ConnectionMessage;
/// <summary>
/// Default message
/// </summary>
string DefaultConnectionMessage = "A cup of coffee has been poured";
/// <summary>
/// Chat parameters
/// </summary>
Dictionary<string, string> ChatParameters;
/// <summary>
/// Plugin Name parameters
/// </summary>
Dictionary<string, string> PluginNameParameters;
protected override void LoadDefaultConfig() => Puts("New configuration file created.");
private void Init() => LoadConfigValues();
void LoadConfigValues()
{
#region Items Initialisation
items.Add("Main Inventory", GetConfigValue("Items", "Main Inventory", new Dictionary<string, object> { { "991728250", "1" } }));
items.Add("Wear Inventory", GetConfigValue("Items", "Wear Inventory", new Dictionary<string, object>()));
items.Add("Belt Inventory", GetConfigValue("Items", "Belt Inventory", new Dictionary<string, object>()));
#endregion
#region Message Initialisation
ConnectionMessage = Config["Connection Message"] as string;
if (ConnectionMessage == null)
{
ConnectionMessage = DefaultConnectionMessage;
Config["Connection Message"] = ConnectionMessage;
}
#endregion
#region Only on first connection Initialisation
string str = Config["Only on first connection"] as string;
if (str == null)
{
OnlyFirstConnection = false;
Config["Only on first connection"] = OnlyFirstConnection.ToString();
}
else
{
OnlyFirstConnection = (str.Equals("True") ? true : false);
}
#endregion
#region ChatParameters Initialisation
ChatParameters = Config["Chat Parameters"] as Dictionary<string, string>;
if (ChatParameters == null)
{
ChatParameters = new Dictionary<string, string>();
ChatParameters.Add("size", "0");
ChatParameters.Add("color", "white");
Config["Chat Parameters"] = ChatParameters;
}
#endregion
#region PluginNameParameters Initialisation
PluginNameParameters = Config["Plugin Name Parameters"] as Dictionary<string, string>;
if (PluginNameParameters == null)
{
PluginNameParameters = new Dictionary<string, string>();
PluginNameParameters.Add("size", "0");
PluginNameParameters.Add("color", "orange");
Config["Plugin Name Parameters"] = PluginNameParameters;
}
#endregion
SaveConfig();
}
/// <summary>
/// Called when a player connects
/// </summary>
/// <param name="packet"></param>
void OnPlayerConnected(Network.Message packet)
{
// Add the player to the list
if (!ids.Exists(x => x.Equals(packet.connection.userid.ToString())))
{
ids.Add(packet.connection.userid.ToString());
}
}
/// <summary>
/// Called when a player wakes up
/// </summary>
/// <param name="player"></param>
void OnPlayerSleepEnded(BasePlayer player)
{
if (ids.Exists(x => x.Equals(player.UserIDString)))
{
List<string> save_ids = Interface.Oxide.DataFileSystem.ReadObject<List<string>>("StarterPack");
// If items should be given at every connection
if (!OnlyFirstConnection)
{
player.inventory.containerMain = GivePlayer("Main Inventory", items["Main Inventory"], player);
player.inventory.containerWear = GivePlayer("Wear Inventory", items["Wear Inventory"], player);
player.inventory.containerBelt = GivePlayer("Belt Inventory", items["Belt Inventory"], player);
// If 1rst connection
if (!ids.Exists(x => x.Equals(player.UserIDString)))
{
save_ids.Add(player.UserIDString);
Interface.Oxide.DataFileSystem.WriteObject("StarterPack", ids);
}
Say(player, ConnectionMessage);
}
// If items should be given ONLY at the first connection
else if (!ids.Exists(x => x.Equals(player.UserIDString)))
{
player.inventory.containerMain = GivePlayer("Main Inventory", items["Main Inventory"], player);
player.inventory.containerWear = GivePlayer("Wear Inventory", items["Wear Inventory"], player);
player.inventory.containerBelt = GivePlayer("Belt Inventory", items["Belt Inventory"], player);
// Save the 1rst connection
save_ids.Add(player.UserIDString);
Interface.Oxide.DataFileSystem.WriteObject("StarterPack", ids);
Say(player, ConnectionMessage);
}
// If not only given on the first time
ids.Remove(player.UserIDString);
}
}
#region helper functions
/// <summary>
/// Gives items to the player
/// </summary>
/// <param name="inventoryName">The name of the inventory the items are added to</param>
/// <param name="inventory">The Items</param>
/// <param name="player">The player</param>
/// <returns></returns>
ItemContainer GivePlayer(string inventoryName, Dictionary<string, object> inventory, BasePlayer player)
{
ItemContainer container;
// For all items in dictionary
var enu = inventory.GetEnumerator();
if (inventoryName.Equals("Main Inventory"))
{
container = player.inventory.containerMain;
}
else if (inventoryName.Equals("Wear Inventory"))
{
container = player.inventory.containerWear;
}
else
{
container = player.inventory.containerBelt;
}
while (enu.MoveNext())
{
container.AddItem(ItemManager.CreateByItemID(int.Parse(enu.Current.Key), int.Parse(enu.Current.Value as string)).info, 1);
}
return container;
}
/// <summary>
/// Display message
/// </summary>
/// <param name="player">The player the message is displayed to</param>
/// <param name="str">The message</param>
void Say(BasePlayer player, string str)
{
StringBuilder sb = new StringBuilder();
/*#region Plugin name
if (!PluginNameParameters["size"].Equals("0"))
{
sb.Append("<size=" + PluginNameParameters["size"] + ">");
}
if (!PluginNameParameters["color"].Equals("white"))
{
sb.Append("<color=" + PluginNameParameters["color"] + ">");
}
sb.Append("[").Append(this.Name).Append("] ");
if (!PluginNameParameters["color"].Equals("white"))
{
sb.Append("</color>");
}
if (!PluginNameParameters["size"].Equals("0"))
{
sb.Append("</size>");
}
#endregion*/
#region Message
if (!ChatParameters["size"].Equals("0"))
{
sb.Append("<size=" + ChatParameters["size"] + ">");
}
if (!ChatParameters["color"].Equals("white"))
{
sb.Append("<color=" + ChatParameters["color"] + ">");
}
sb.Append(str);
if (!ChatParameters["color"].Equals("white"))
{
sb.Append("</color>");
}
if (!ChatParameters["size"].Equals("0"))
{
sb.Append("</size>");
}
#endregion
player.ChatMessage(sb.ToString());
}
T GetConfigValue<T>(string category, string setting, T defaultValue)
{
object value;
var data = Config[category] as Dictionary<string, object>;
if (data == null)
{
data = new Dictionary<string, object>();
Config[category] = data;
}
if (data.TryGetValue(setting, out value))
return (T)Convert.ChangeType(value, typeof(T));
value = defaultValue;
data[setting] = value;
return (T)Convert.ChangeType(value, typeof(T));
}
void SetConfigValue<T>(string category, string setting, T newValue)
{
var data = Config[category] as Dictionary<string, object>;
object value;
if (data != null && data.TryGetValue(setting, out value))
{
value = newValue;
data[setting] = value;
}
SaveConfig();
}
#endregion
}
}
[DOUBLEPOST=1494559188][/DOUBLEPOST]is that the right 1 sirLast edited by a moderator: May 12, 2017 -
i got this message when i join
You disembark on the brehat island, equipped with a map ...
[DOUBLEPOST=1494559664][/DOUBLEPOST]but its in french vous debarquez sur l'ile brehat, equipe d'une carte ... -
Is the Welcome message a global? Or is it just sent to the new player? I would like it so only the individual receives the welcome message.. Thank you!
-
i want mine announced though -
-
how do you change the message?
mines in french -
Replace "Vous debarquez sur l'ile Brehat, equipe d'une carte ..." with the message you want -
-
did you reload the plugin ?
-
yes sir i did
-
It appears the "sliced pork" is the cookd pork. You can see it "sliced" when you drop it. So the id should be 991728250