Skip to content

Commit

Permalink
Randomizer shuffle items
Browse files Browse the repository at this point in the history
  • Loading branch information
Die4Ever committed Apr 18, 2023
1 parent 9b90916 commit a3dc993
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
75 changes: 75 additions & 0 deletions Classes/Randomizer.uc
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
class Randomizer extends Mutator;

function InitRando()
{
ShuffleItems();
}

function ShuffleItems()
{
local Inventory item, items[512], weapons[128];
local int num_items, num_weapons, i, slot;

foreach AllActors(class'Inventory', item) {
if(item.Owner != None) continue;
if(Weapon(item) != None)
weapons[num_weapons++] = item;
else
items[num_items++] = item;
}

for(i=0; i<num_items; i++) {
slot = Rand(num_items);
if(slot != i)
SwapActors(items[i], items[slot]);
}

for(i=0; i<num_weapons; i++) {
slot = Rand(num_weapons);
if(slot != i)
SwapActors(weapons[i], weapons[slot]);
}
}

function SwapActors(Actor a, Actor b)
{
local vector locA;
local Rotator rotA;

locA = a.Location;
rotA = a.Rotation;
a.SetLocation(b.Location);
a.SetRotation(b.Rotation);
b.SetLocation(locA);
b.SetRotation(rotA);
}

simulated function PreBeginPlay()
{
InitRando();
CheckServerPackages();
}

function CheckServerPackages()
{
local string packages;

if (Level.NetMode!=NM_DedicatedServer && Level.NetMode!=NM_ListenServer){
//Not hosting a server, don't worry about it
return;
}

packages=ConsoleCommand("get Engine.GameEngine ServerPackages");
if (InStr(packages,"UT99CrowdControl")!=-1){
log("UT99CrowdControl is set in ServerPackages! Nice!");
} else {
log("UT99CrowdControl is not set in ServerPackages! Bummer!");
packages = Left(packages,Len(packages)-1)$",\"UT99CrowdControl\")";
log("Added UT99CrowdControl to ServerPackages!");
ConsoleCommand("set Engine.GameEngine ServerPackages "$packages);

This comment has been minimized.

Copy link
@Die4Ever

Die4Ever May 24, 2023

Author Collaborator

I'm wondering if there should be a called to SaveConfig() here


//Reload the level so that the serverpackages gets updated for real
log("Restarting game so that ServerPackages are reloaded");
Level.ServerTravel( "?Restart", false );
}
}
1 change: 1 addition & 0 deletions UT99CrowdControl.int
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[Public]

Object=(Name=UT99CrowdControl.CrowdControl,Class=Class,MetaClass=Engine.Mutator,Description="Crowd Control support for UT99")
Object=(Name=UT99CrowdControl.Randomizer,Class=Class,MetaClass=Engine.Mutator,Description="Randomizer for UT99")
Object=(Name=UT99CrowdControl.UT99CCStartTournyMenuItem,Class=Class,MetaClass=UMenu.UMenuModMenuItem,Description="Start Crowd Control Tournament,Crowd Control Tournament")
Object=(Name=UT99CrowdControl.UT99CCLoadTournyMenuItem,Class=Class,MetaClass=UMenu.UMenuModMenuItem,Description="Resume Crowd Control Tournament,Crowd Control Tournament")

0 comments on commit a3dc993

Please sign in to comment.