Skip to content

Instantly share code, notes, and snippets.

@wrdg
Last active May 7, 2024 22:12
Show Gist options
  • Save wrdg/f4c870f8751e8b185f113a75c36ad7ec to your computer and use it in GitHub Desktop.
Save wrdg/f4c870f8751e8b185f113a75c36ad7ec to your computer and use it in GitHub Desktop.
Customizable spawn loadouts for regular and donator players; changes/additions to init.c
//* Script: Customizable spawn loadouts for regular and donator players
//* Author: Wardog
//* Donate: https://wrdg.net/donate
//*
//* Notes: Creates a directory in the Server Profile folder called SpawnLoadout. You can change these files in
//* in real time, without restarting the server to take effect.
//*
//* ./SpawnLoadout/CommonItems.txt = items spawned between both donators and regulars
//* ./SpawnLoadout/Regular.txt = loadout for regular players
//* ./SpawnLoadout/Donators/STEAMIDHERE.txt = directory where steam id files go for donators; loadouts for donators
//*
//* Loadout files are autogenerated if they're missing from the server profile
//* Loadouts can be changed real time while the server is running, no need to restart the server to take effect
//!!! THESE ARE ADDITIONS TO THE INIT.C FILE, NOT TO COMPLETELY REPLACE THE INIT.C FILE
class CustomMission : MissionServer
{
private const static string m_SpawnLoadoutDirectory = "$profile:SpawnLoadout/"; // root directory for SpawnLoadout
private const static string m_DonatorDirectory = m_SpawnLoadoutDirectory + "Donators/"; // directory for donator loadout text files
private const static string m_RegularLoadout = m_SpawnLoadoutDirectory + "Regular.txt"; // file for regular loadout
private const static string m_CommonItems = m_SpawnLoadoutDirectory + "CommonItems.txt"; // file for in common items for both regular and donator
void CustomMission()
{
FileHandle templateFile;
if (!FileExist(m_SpawnLoadoutDirectory))
{
MakeDirectory(m_SpawnLoadoutDirectory)
// create default CommonItems.txt
templateFile = OpenFile(m_CommonItems, FileMode.WRITE);
FPrintln(templateFile, "Rag 4\nHuntingKnife\nMatchbox\nHatchet\nFlashlight\nBattery9V\nSodaCan_Cola\nBakedBeansCan");
CloseFile(templateFile);
// create default Regular.txt
templateFile = OpenFile(m_RegularLoadout, FileMode.WRITE);
FPrintln(templateFile, "BomberJacket_Grey\nJeans_Black\nTaloonBag_Blue\nAthleticShoes_Grey");
CloseFile(templateFile);
}
if (!FileExist(m_DonatorDirectory))
{
string template = GetDonatorFile("STEAMIDHERE");
MakeDirectory(m_DonatorDirectory);
// create template donator file
templateFile = OpenFile(template, FileMode.WRITE);
FPrintln(templateFile, "BomberJacket_Blue\nJeans_Grey\nTaloonBag_Orange\nAthleticShoes_Brown");
CloseFile(templateFile);
}
}
//!!! REPLACES EXISTING METHOD
override void StartingEquipSetup(PlayerBase player, bool clothesChosen)
{
player.RemoveAllItems(); // clear all default spawning items
FileHandle donatorFile;
string line;
TStringArray contents = new TStringArray();
string file = GetDonatorFile(player.GetIdentity().GetPlainId());
if (FileExist(file))
{
SpawnLoadout(player, ReadFileLines(file)); // spawn donator loadout
return;
}
SpawnLoadout(player, ReadFileLines(m_RegularLoadout)); // spawn regular player loadout
}
private void SpawnLoadout(PlayerBase player, ref TStringArray loadout)
{
FileHandle loadoutFile;
string line;
// creates clothes loadout
foreach (string clothes : loadout)
player.GetInventory().CreateInInventory(clothes);
// creates common items
TStringArray items = ReadFileLines(m_CommonItems);
foreach (string item : items)
{
if (item.Contains(" ")) // check for space, which signifies a quantity item
{
CreateQuantityItem(player, item);
continue;
}
player.GetInventory().CreateInInventory(item);
}
}
private void CreateQuantityItem(PlayerBase player, string item)
{
TStringArray quantity = new TStringArray();
item.Split(" ", quantity);
ItemBase quantityItem = player.GetInventory().CreateInInventory(quantity[0]);
quantityItem.SetQuantity(quantity[1].ToFloat());
}
private string GetDonatorFile(string id)
{
return string.Format("%1%2.txt", m_DonatorDirectory, id);
}
private TStringArray ReadFileLines(string path)
{
FileHandle file;
string line;
TStringArray contents = new TStringArray();
file = OpenFile(path, FileMode.READ);
while (FGets(file, line) > 0)
{
line.Trim();
if (line != string.Empty)
{
contents.Insert(line);
line = string.Empty;
}
}
CloseFile(file);
return contents;
}
}
@Rsawyer2014
Copy link

if its not a complete wipe out, where do i paste it into the init.c file? Right at the end?

@DogDaysA
Copy link

DogDaysA commented Jan 3, 2021

Is it possible to create a TStringArray into the Regular.txt file so it will pick something at random?

@Manu13371
Copy link

not working .....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment