PDA

View Full Version : Random item drop??


Kindbud
02-07-2009, 02:23 AM
hey guys long time.. saw all the badass custom stuff in your servers a while back, and im hoping you can help me out here... i have this code i found and i'd like to modify it to spawn a random item from an array of items when the fly is killed. can anyone help me out plz plz plz lol

class flybonus expands Mutator;

var bool Initialized;

function PostBeginPlay()
{
//
// Install only once
//
if (Initialized)
return;
Initialized = True;

Level.Game.RegisterDamageMutator( Self );
}

function MutatorTakeDamage(
out int ActualDamage,
Pawn Victim,
Pawn InstigatedBy,
out Vector HitLocation,
out Vector Momentum,
name DamageType
)
{
local Shockwave explosion;

if (Victim.Health <= ActualDamage)
{
if (Victim.IsA('Fly'))
{
Spawn(class 'UnrealI.purplelight',,,Victim.Location);
Spawn(class 'UnrealI.respawn',,,Victim.Location);
// **SPAWN CODE FOR RANDOM DROP HERE**
}

}

//
// Pass on the event to the next handler
//
if ( NextDamageMutator != None )
NextDamageMutator.MutatorTakeDamage( ActualDamage, Victim, InstigatedBy, HitLocation, Momentum, DamageType );
}
defaultproperties
{
}

Mr.BOoK
02-07-2009, 07:51 PM
I don't know the syntax of uscript, but am familiar with others. Give me a couple of days and should be able to come up with somthing.

Mr.BOoK
02-10-2009, 12:21 AM
Here is what i got. I didn't use an array but instead used nested selects. I made a(what i hope is equivalent to static in java) static int variable as a counter that is tested in the selects to sequentially spawn items in. You could nest as deep as you need to.The boolean var resets on the last one to reset the value of i in the beginning selection. Given some more time and documentation(to read) on uscript syntax,i think it's possible to create a dynamic array of Inventory then instantiate subclasses of inventory in it, spawning them some how. This compiles though.




class flybonus expands Mutator;

var bool Initialized;
var bool val;
var int i;

function PostBeginPlay()
{
if (Initialized)
return;
Initialized = True;
Level.Game.RegisterDamageMutator( Self );
}

function MutatorTakeDamage(out int ActualDamage, Pawn Victim,
Pawn InstigatedBy, out Vector HitLocation,
out Vector Momentum, name DamageType)
{
local Shockwave explosion;
if ((Victim.Health <= ActualDamage) && (Victim.IsA('Fly')))
{
if(!val)
{
i=0;
val=true;
}

Spawn(class 'UnrealI.purplelight',,,Victim.Location);
Spawn(class 'UnrealI.respawn',,,Victim.Location);

if(i == 0)
{
Spawn(class 'Ammo',,,Victim.Location);
}
else
{
if(i == 1)
Spawn(class 'JumpBoots',,,Victim.Location);
else
{
Spawn(class 'Armor',,,Victim.Location);
val=false;
}
}
}

if ( NextDamageMutator != None )
{
NextDamageMutator.MutatorTakeDamage( ActualDamage, Victim,
InstigatedBy, HitLocation, Momentum, DamageType );
}
}

defaultproperties
{
}

Kindbud
02-11-2009, 12:04 AM
sweet dude whatever works hehe. that looks like it will do just fine. i really appreciate it!