Main

Forums

Wiki

Downloads

Tutorials

Walkthrough

Unreal-netiquette

Links

Submit-News

Oldunreal's hosted:
UnrealReference

Usermaps

Real-CTF

Donate for Oldunreal:

Oldunreal Donation
Oldunreallogo
  Welcome, Guest. Please Login or Register
 
  HomeHelpSearchLoginRegister  
 
 
Rechargeable Flashlight? (Read 231 times)
William R
God Member
*****
Offline



Posts: 898
Rechargeable Flashlight?
07/14/12 at 23:14:33
 
Anyone know how to make a Rechargeable Flashlight?

for a more futuristic feel.
Back to top
« Last Edit: 07/14/12 at 23:14:51 by William R »  
 
IP Logged
 
SFJake
Full Member
***
Offline


Oldunreal member

Posts: 213
Gender: male
Re: Rechargeable Flashlight?
Reply #1 - 07/15/12 at 01:21:05
 
Part of my mod actually has unused items of various kinds including rechargeable items.

I'll share exactly what my code is, I really don't think its the cleanest in any way but it works.

Code:
//=============================================================================
// RechargeableFlashlight.
//=============================================================================
class RechargeableFlashlight expands Flashlight;

var() int bRechargeAmount; //Amount to recharge every bRechargeTimer.
var() float bRechargeTimer;
var() bool bDestroySimilar; //If TRUE, destroys similar objects in the inventory that are useless when having a rechargeable version.
var() int bTimeBeforeRecharge; //This is actually counted by the amount of time it goes in the TIMER. So if bRechargeTimer is at 1.5 and this is at 3, then it will take 3 time 1.5, so 4.5 seconds.

var int bRechargeTime;

state Activated
{
	function endstate()
	{
		bRechargeTime = bTimeBeforeRecharge;
			s.Destroy();
		bActive = false;
	}

	function Tick( float DeltaTime )
	{
		TimeChange += DeltaTime*10;
		if (TimeChange > 1)
		{
			if ( s == None )
			{
				UsedUp();
				return;
			}
			Charge -= int(TimeChange);
			TimeChange = TimeChange - int(TimeChange);
		}

		if (s == None) Return;

		if ( Pawn(Owner) == None )
		{
			s.Destroy();
			UsedUp();
			return;
		}
		if (Charge<-0)
		{
			s.Destroy();
			Activate();
			return;
		}

		if (Charge<1) s.LightBrightness=byte(Charge*0.6+10);

		GetAxes(Pawn(Owner).ViewRotation,X,Y,Z);
		EndTrace = Pawn(Owner).Location + 10000* Vector(Pawn(Owner).ViewRotation);
		Trace(HitLocation,HitNormal,EndTrace,Pawn(Owner).Location, True);
		s.SetLocation(HitLocation-vector(Pawn(Owner).ViewRotation)*64);
//		s.LightRadius = fmin(Vsize(HitLocation-Pawn(Owner).Location)/200,14) + 2.0;
	}

	function BeginState()
	{
		bActive = true;
		TimeChange = 0;
		Owner.PlaySound(ActivateSound);
		GetAxes(Pawn(Owner).ViewRotation,X,Y,Z);
		EndTrace = Pawn(Owner).Location + 10000* Vector(Pawn(Owner).ViewRotation);
		Trace(HitLocation,HitNormal,EndTrace,Pawn(Owner).Location+Y*17);
		s = Spawn(class'FlashLightBeam',Owner, '', HitLocation+HitNormal*40);
		s.LightHue = LightHue;
		s.LightRadius = LightRadius;
		if (Charge<1) s.LightBrightness=byte(Charge*0.6+10);
		if (s==None) GoToState('DeActivated');
	}

Begin:
}


state DeActivated
{
	function Timer()
	{
	local inventory I;

	if ( bDestroySimilar )
	{
	for ( I = Owner.Inventory; I != None; I = I.Inventory )
		if ( I.IsA('RechargeableFlashlight') )
		{
		}
		else if ( I.IsA('SearchLight') )
		{
		}
		else if ( I.IsA('Flashlight') )
			I.Destroy();
	}

		if( Charge<Default.Charge && bRechargeTime <= 0 )
			Charge+=bRechargeAmount;
		else if ( bRechargeTime >= 1 )
			bRechargeTime--;
	}
Begin:
	bActive = False;
	SetTimer(bRechargeTimer,true);
	Owner.PlaySound(DeActivateSound);
}

defaultproperties
{
	bRechargeAmount=40
	bRechargeTimer=0.500000
	bDestroySimilar=True
	bTimeBeforeRecharge=2
	PickupMessage="You picked up the rechargeable flashlight"
	Charge=2000
}
 



Most of it is easy to configure. You can have a delay before it starts recharging, you can edit the recharging speed, you can make it delete redundant, normal Flashlights from your inventory (will keep SearchLights).

Do with this as you wish.
Back to top
 
 
IP Logged
 
William R
God Member
*****
Offline



Posts: 898
Re: Rechargeable Flashlight?
Reply #2 - 07/15/12 at 01:38:03
 
SFJake wrote on 07/15/12 at 01:21:05:
Part of my mod actually has unused items of various kinds including rechargeable items.

I'll share exactly what my code is, I really don't think its the cleanest in any way but it works.

Code:
//=============================================================================
// RechargeableFlashlight.
//=============================================================================
class RechargeableFlashlight expands Flashlight;

var() int bRechargeAmount; //Amount to recharge every bRechargeTimer.
var() float bRechargeTimer;
var() bool bDestroySimilar; //If TRUE, destroys similar objects in the inventory that are useless when having a rechargeable version.
var() int bTimeBeforeRecharge; //This is actually counted by the amount of time it goes in the TIMER. So if bRechargeTimer is at 1.5 and this is at 3, then it will take 3 time 1.5, so 4.5 seconds.

var int bRechargeTime;

state Activated
{
	function endstate()
	{
		bRechargeTime = bTimeBeforeRecharge;
			s.Destroy();
		bActive = false;
	}

	function Tick( float DeltaTime )
	{
		TimeChange += DeltaTime*10;
		if (TimeChange > 1)
		{
			if ( s == None )
			{
				UsedUp();
				return;
			}
			Charge -= int(TimeChange);
			TimeChange = TimeChange - int(TimeChange);
		}

		if (s == None) Return;

		if ( Pawn(Owner) == None )
		{
			s.Destroy();
			UsedUp();
			return;
		}
		if (Charge<-0)
		{
			s.Destroy();
			Activate();
			return;
		}

		if (Charge<1) s.LightBrightness=byte(Charge*0.6+10);

		GetAxes(Pawn(Owner).ViewRotation,X,Y,Z);
		EndTrace = Pawn(Owner).Location + 10000* Vector(Pawn(Owner).ViewRotation);
		Trace(HitLocation,HitNormal,EndTrace,Pawn(Owner).Location, True);
		s.SetLocation(HitLocation-vector(Pawn(Owner).ViewRotation)*64);
//		s.LightRadius = fmin(Vsize(HitLocation-Pawn(Owner).Location)/200,14) + 2.0;
	}

	function BeginState()
	{
		bActive = true;
		TimeChange = 0;
		Owner.PlaySound(ActivateSound);
		GetAxes(Pawn(Owner).ViewRotation,X,Y,Z);
		EndTrace = Pawn(Owner).Location + 10000* Vector(Pawn(Owner).ViewRotation);
		Trace(HitLocation,HitNormal,EndTrace,Pawn(Owner).Location+Y*17);
		s = Spawn(class'FlashLightBeam',Owner, '', HitLocation+HitNormal*40);
		s.LightHue = LightHue;
		s.LightRadius = LightRadius;
		if (Charge<1) s.LightBrightness=byte(Charge*0.6+10);
		if (s==None) GoToState('DeActivated');
	}

Begin:
}


state DeActivated
{
	function Timer()
	{
	local inventory I;

	if ( bDestroySimilar )
	{
	for ( I = Owner.Inventory; I != None; I = I.Inventory )
		if ( I.IsA('RechargeableFlashlight') )
		{
		}
		else if ( I.IsA('SearchLight') )
		{
		}
		else if ( I.IsA('Flashlight') )
			I.Destroy();
	}

		if( Charge<Default.Charge && bRechargeTime <= 0 )
			Charge+=bRechargeAmount;
		else if ( bRechargeTime >= 1 )
			bRechargeTime--;
	}
Begin:
	bActive = False;
	SetTimer(bRechargeTimer,true);
	Owner.PlaySound(DeActivateSound);
}

defaultproperties
{
	bRechargeAmount=40
	bRechargeTimer=0.500000
	bDestroySimilar=True
	bTimeBeforeRecharge=2
	PickupMessage="You picked up the rechargeable flashlight"
	Charge=2000
}
 



Most of it is easy to configure. You can have a delay before it starts recharging, you can edit the recharging speed, you can make it delete redundant, normal Flashlights from your inventory (will keep SearchLights).

Do with this as you wish.


You should make it into a Mod, Anyway thank you.
Back to top
 
 
IP Logged
 
(Moderators: Buster, pÍtßűll, DieHard SCWS)