My program doesn't have bugs. It just develops random features.

Difference between revisions of "Unreal Wiki:Scratchpad"

From Unreal Wiki, The Unreal Engine Documentation Site
Jump to: navigation, search
Line 74: Line 74:
 
WorldInfo.Game.ReStartPlayer(self);
 
WorldInfo.Game.ReStartPlayer(self);
 
Goto('TryAgain');
 
Goto('TryAgain');
 +
}
 +
</uscript>
 +
 +
----
 +
 +
Taehl's Objective Weapons mod-in-progress:
 +
 +
<uscript>
 +
//=============================================================================
 +
// OWweapon.
 +
// Parent class of all Objective Weapons.
 +
// Is also a playable weapon, just for kicks (and coding practice).
 +
//=============================================================================
 +
class OWweapon expands Weapon
 +
abstract;
 +
 +
var() byte clip; // ammo in current clip
 +
var() byte clipmax; // ammo in a fresh clip
 +
var() float acc; // how accurate a gun is. 0 is perfectly accurate.
 +
var() byte recoil; // add this much recoil per shot. 0 is no recoil.
 +
var() byte damage; // how much damage the gun does.
 +
var() float rpm; // how many rounds are fired per minute.
 +
var() float reloadtime; // how many seconds it takes to reload.
 +
 +
////////////////////////////////////////////////////////
 +
function fire( float Value ) {
 +
if (clip>0) GoToState('shoot');
 +
else GoToState('reloading');
 +
}
 +
 +
function altfire( float Value ) {
 +
if (clip>0) GoToState('altshoot');
 +
else GoToState('reloading');
 +
}
 +
 +
exec function reload() {
 +
// local pawn p;
 +
if (clip<clipmax) GoToState('reloading');
 +
}
 +
 +
function dorecoil(float value) {
 +
local float up, side;
 +
up = ((value+(FRand()*value*10))/50);
 +
side = ((value+((FRand()-0.3)*value*10))/100); // recoil left or right, but more right
 +
PlayerPawn(Owner).alookup = up;
 +
PlayerPawn(Owner).aturn = side;
 +
}
 +
 +
function fireeffects() {
 +
local Vector realLoc, X,Y,Z;
 +
local UT_ShellCase s;
 +
realLoc = Owner.Location + CalcDrawOffset() + X*60;
 +
Spawn(class'WeaponLight',,'',realLoc,rot(0,0,0));
 +
// s = Spawn(class'UT_ShellCase',Pawn(Owner), '', realLoc + FireOffset.Y * Y + Z);
 +
s = Spawn(class'UT_ShellCase',, '', realLoc + FireOffset.Y * Y + Z);
 +
// s.Eject(((FRand()*0.3+0.2)*X + (FRand()*0.2+0.2)*Y + (FRand()*0.3+1.0) * Z)*160);
 +
s.Eject(((FRand()*0.3+0.4)*X + (FRand()*0.2+0.2)*Y + (FRand()*0.3+1.0) * Z)*160);
 +
}
 +
 +
function ProcessTraceHit(Actor Other, Vector HitLocation, Vector HitNormal, Vector X, Vector Y, Vector Z) {
 +
if (Other == Level)
 +
Spawn(class'UT_LightWallHitEffect',,, HitLocation+HitNormal*9, Rotator(HitNormal));
 +
else if ((Other != self) && (Other != Owner) && (Other != None) ) {
 +
if ( FRand() < 0.2 ) X *= 5;
 +
Other.TakeDamage(damage, Pawn(Owner), HitLocation, 300.0*X, 'shot');
 +
if ( !Other.IsA('Pawn') && !Other.IsA('Carcass') )
 +
spawn(class'SpriteSmokePuff',,,HitLocation+HitNormal*9);
 +
}
 +
}
 +
 +
////////////////////////////////////////////////////////
 +
state shoot {
 +
ignores fire, altfire, reload;
 +
Begin:
 +
CheckVisibility(); // no idea what this stuff does... best not to remove it?
 +
bPointing=True;
 +
Owner.MakeNoise(2*Pawn(Owner).SoundDampening);
 +
if (PlayerPawn(Owner) != None) {
 +
PlayerPawn(Owner).ClientInstantFlash(-0.4, vect(650, 450, 190));
 +
PlayerPawn(Owner).ShakeView(ShakeTime, ShakeMag, ShakeVert);
 +
}
 +
clip--; // remove a bullet from clip and shoot.
 +
TraceFire(acc);
 +
fireeffects();
 +
Owner.PlaySound(FireSound,SLOT_None,(1*Pawn(Owner).SoundDampening));
 +
PlayAnim( 'Fire', 1, 0.05);
 +
dorecoil(recoil);
 +
sleep(60/rpm);
 +
GoToState('Idle');
 +
Finish();
 +
}
 +
 +
state altshoot {
 +
ignores fire, altfire, reload;
 +
Begin:
 +
GoToState('shoot');
 +
// ProjectileFire(ProjectileClass, ProjectileSpeed, bWarnTarget);
 +
Finish();
 +
}
 +
 +
state reloading {
 +
ignores fire, altfire, reload;
 +
Begin:
 +
if (AmmoType.AmmoAmount > 0) { // if player has spare ammo
 +
Owner.PlaySound(CockingSound, SLOT_None,1*Pawn(Owner).SoundDampening);
 +
PlayAnim('Down',1,0.05);
 +
Sleep(reloadtime);
 +
if (AmmoType.UseAmmo(clipmax)) clip = clipmax; // fill clip
 +
else {
 +
clip = AmmoType.AmmoAmount; // else partially fill clip
 +
AmmoType.AmmoAmount = 0; // and deplete ammo
 +
}
 +
Owner.PlaySound(SelectSound, SLOT_None,1*Pawn(Owner).SoundDampening);
 +
PlayAnim('Select',1,0.05);
 +
FinishAnim();
 +
}
 +
GoToState('Idle');
 +
Finish();
 +
}
 +
</uscript>
 +
 +
<uscript>
 +
//=============================================================================
 +
// OWshotgun.
 +
// fully remade from an older project to work as an objective weapon.
 +
//=============================================================================
 +
class OWshotgun expands OWWeapon;
 +
 +
// copied from olweapons.u - kinda fixes third person mesh
 +
#exec MESH IMPORT MESH=QuadShotthird ANIVFILE=MODELS\QuadShotPickup_a.3D DATAFILE=MODELS\QuadShotPickup_d.3D X=0 Y=0 Z=0
 +
#exec MESH ORIGIN MESH=QuadShotthird X=-164 Y=0 Z=70 YAW=64 Pitch=-7
 +
#exec MESH SEQUENCE MESH=QuadShotthird SEQ=All  STARTFRAME=0  NUMFRAMES=1
 +
#exec MESHMAP SCALE MESHMAP=QuadShotthird X=0.02 Y=0.02 Z=0.04
 +
#exec MESHMAP SETTEXTURE MESHMAP=QuadShotthird NUM=4 TEXTURE=GunPick1
 +
// also copied from olweapons. fixes first-person model bugs
 +
#exec MESH IMPORT MESH=QuadShotHeldr ANIVFILE=MODELS\QuadShotHeld_a.3D DATAFILE=MODELS\QuadShotHeld_d.3D
 +
#exec MESH ORIGIN MESH=QuadShotHeldr X=0 Y=0 Z=0 YAW=128
 +
#exec MESH SEQUENCE MESH=QuadShotHeldr SEQ=still STARTFRAME=29  NUMFRAMES=1
 +
#exec MESH SEQUENCE MESH=QuadShotHeldr SEQ=stillfire STARTFRAME=0  NUMFRAMES=1
 +
#exec MESH SEQUENCE MESH=QuadShotHeldr SEQ=all  STARTFRAME=0  NUMFRAMES=30
 +
#exec MESH SEQUENCE MESH=QuadShotHeldr SEQ=fire STARTFRAME=0  NUMFRAMES=9
 +
#exec MESH SEQUENCE MESH=QuadShotHeldr SEQ=reload STARTFRAME=8  NUMFRAMES=21  Rate=24
 +
#exec MESH SEQUENCE MESH=QuadShotHeldr SEQ=select STARTFRAME=25  NUMFRAMES=5  Rate=8 GROUP=Select
 +
#exec MESH SEQUENCE MESH=QuadShotHeldr SEQ=down STARTFRAME=8  NUMFRAMES=6 Rate=20
 +
#exec MESHMAP SCALE MESHMAP=QuadShotHeldr X=0.01 Y=0.01 Z=0.02
 +
 +
var float clipb; // why a float? to use for volume of shoot sound.
 +
var byte shots;
 +
var byte clipstore;
 +
 +
////////////////////////////////////////////////////////
 +
state shoot {
 +
ignores fire, altfire, reload;
 +
Begin:
 +
clipstore = clip;
 +
GoToState('altshoot');
 +
Finish();
 +
}
 +
 +
state altshoot {
 +
ignores fire, altfire, reload;
 +
Begin:
 +
CheckVisibility(); // no idea what this stuff does... perhaps chop it out?
 +
bPointing=True;
 +
Owner.MakeNoise(2*Pawn(Owner).SoundDampening);
 +
if (PlayerPawn(Owner) != None) {
 +
PlayerPawn(Owner).ClientInstantFlash(-0.4, vect(650, 450, 190));
 +
PlayerPawn(Owner).ShakeView(ShakeTime, ShakeMag, ShakeVert);
 +
}
 +
if (clipstore>1) clip=1;
 +
for(clipb=0;clipb<clip;clipb+=1) {
 +
for(shots=0;shots<7;shots++) TraceFire(acc);
 +
fireeffects(); 
 +
}
 +
clipb = clip;
 +
Owner.PlaySound(FireSound,SLOT_None,clipb);
 +
PlayAnim( 'Fire', 1, 0.05);
 +
dorecoil((recoil*(1+(clip/2)))); // do recoil depending on barrels fired
 +
clip = clipstore-1;
 +
if (clip>clipmax) clip=0; // fix wraparound bug
 +
clipstore = 0;
 +
sleep(60/rpm);
 +
GoToState('Idle');
 +
Finish();
 +
}
 +
 +
state reloading {
 +
ignores fire, altfire, reload;
 +
Begin:
 +
if (AmmoType.UseAmmo(1) && clip<clipmax) {
 +
PlayAnim( 'Reload', 1.05, 0.05);
 +
Owner.PlaySound(CockingSound,SLOT_None,1*Pawn(Owner).SoundDampening);
 +
clip++;
 +
FinishAnim();
 +
GoToState('idle');
 +
}
 +
Finish();
 
}
 
}
 
</uscript>
 
</uscript>

Revision as of 00:20, 25 May 2008

This page is for pasting code you want to show someone as an example or to get assistance with. This allows you to easily collaborate with someone to solve a problem, and allows easy comparisons of the edits.

You are free to remove any existing code from below, and paste your code between the <uscript> </uscript> tags. If the page hasn't been edited in 24 hours, you can assume it isn't needed anymore and can be removed. A full edit history will be available, so don't worry about losing anything.


BattleTeamArena.BattleBotController:

state Reboot
{
ignores SeePlayer, EnemyNotVisible, HearNoise, ReceiveWarning, NotifyLanded, NotifyPhysicsVolumeChange,
		NotifyHeadVolumeChange, NotifyLanded, NotifyHitWall, NotifyBump, ExecuteWhatToDoNext;
 
	event DelayedWarning() {}
	function DoRangedAttackOn(Actor A) {}
	function WhatToDoNext() {}
	function Celebrate() {}
	function bool SetRouteToGoal(Actor A) {	return true; }
	function SetAttractionState() {}
	function EnemyChanged(bool bNewEnemyVisible) {}
	function WanderOrCamp() {}
	function Timer() {}
 
	function BeginState(Name PreviousStateName)
	{
		if ((DefensePoint != None) && (UTHoldSpot(DefensePoint) == None)) FreePoint();
		if (NavigationPoint(MoveTarget) != None) {
          NavigationPoint(MoveTarget).FearCost = 2 * NavigationPoint(MoveTarget).FearCost + 600;
		  WorldInfo.Game.bDoFearCostFallOff = true;
		}
		PendingMover = None;
		Enemy = None;
		StopFiring();
		bFrustrated = false;
		BlockedPath = None;
		bInitLifeMessage = false;
		bPlannedJump = false;
		bInDodgeMove = false;
		bReachedGatherPoint = false;
		bFinalStretch = false;
		bWasNearObjective = false;
		bPreparingMove = false;
		bPursuingFlag = false;
		bHasSuperWeapon = false;
		bHasTranslocator = false;
		ImpactJumpZ = 0.f;
		RouteGoal = None;
		NoVehicleGoal = None;
		SquadRouteGoal = None;
		bUsingSquadRoute = true;
		bUsePreviousSquadRoute = false;
		MoveTarget = None;
		ImpactVelocity = vect(0,0,0);
		LastSeenTime = -1000;
		bEnemyInfoValid = false;
	}
 
Begin:
	if ( WorldInfo.Game.bGameEnded )
		GotoState('RoundEnded');
	Sleep(0.1);
TryAgain:
	if (UTGame(WorldInfo.Game) == None) {
      destroy();
	} else {
      Sleep(0.1);
	  LastRespawnTime = WorldInfo.TimeSeconds;
	  WorldInfo.Game.ReStartPlayer(self);
	  Goto('TryAgain');
	}
 
MPStart:
	Sleep(0.1);
	WorldInfo.Game.ReStartPlayer(self);
	Goto('TryAgain');
}

Taehl's Objective Weapons mod-in-progress:

//=============================================================================
// OWweapon.
// Parent class of all Objective Weapons.
// Is also a playable weapon, just for kicks (and coding practice).
//=============================================================================
class OWweapon expands Weapon
	abstract;
 
var() byte clip;		// ammo in current clip
var() byte clipmax;		// ammo in a fresh clip
var() float acc;		// how accurate a gun is. 0 is perfectly accurate.
var() byte recoil;		// add this much recoil per shot. 0 is no recoil.
var() byte damage;		// how much damage the gun does.
var() float rpm;		// how many rounds are fired per minute.
var() float reloadtime;	// how many seconds it takes to reload.
 
////////////////////////////////////////////////////////
function fire( float Value ) {
	if (clip>0) GoToState('shoot');
	else GoToState('reloading');
}
 
function altfire( float Value ) {
	if (clip>0) GoToState('altshoot');
	else GoToState('reloading');
}
 
exec function reload() {
//	local pawn p;
	if (clip<clipmax) GoToState('reloading');
}
 
function dorecoil(float value) {
	local float up, side;
	up = ((value+(FRand()*value*10))/50);
	side = ((value+((FRand()-0.3)*value*10))/100);	// recoil left or right, but more right
	PlayerPawn(Owner).alookup = up;
	PlayerPawn(Owner).aturn = side;
}
 
function fireeffects() {
	local Vector realLoc, X,Y,Z;
	local UT_ShellCase s;
	realLoc = Owner.Location + CalcDrawOffset() + X*60;
	Spawn(class'WeaponLight',,'',realLoc,rot(0,0,0));		
//	s = Spawn(class'UT_ShellCase',Pawn(Owner), '', realLoc + FireOffset.Y * Y + Z);
	s = Spawn(class'UT_ShellCase',, '', realLoc + FireOffset.Y * Y + Z);
//	s.Eject(((FRand()*0.3+0.2)*X + (FRand()*0.2+0.2)*Y + (FRand()*0.3+1.0) * Z)*160); 
	s.Eject(((FRand()*0.3+0.4)*X + (FRand()*0.2+0.2)*Y + (FRand()*0.3+1.0) * Z)*160);
}
 
function ProcessTraceHit(Actor Other, Vector HitLocation, Vector HitNormal, Vector X, Vector Y, Vector Z) {
	if (Other == Level) 
		Spawn(class'UT_LightWallHitEffect',,, HitLocation+HitNormal*9, Rotator(HitNormal));
	else if ((Other != self) && (Other != Owner) && (Other != None) ) {
		if ( FRand() < 0.2 ) X *= 5;
		Other.TakeDamage(damage, Pawn(Owner), HitLocation, 300.0*X, 'shot');
		if ( !Other.IsA('Pawn') && !Other.IsA('Carcass') )
			spawn(class'SpriteSmokePuff',,,HitLocation+HitNormal*9);
	}		
}
 
////////////////////////////////////////////////////////
state shoot {
ignores fire, altfire, reload;
Begin:
	CheckVisibility();		// no idea what this stuff does... best not to remove it?
	bPointing=True;
	Owner.MakeNoise(2*Pawn(Owner).SoundDampening);
	if (PlayerPawn(Owner) != None) {
		PlayerPawn(Owner).ClientInstantFlash(-0.4, vect(650, 450, 190));
		PlayerPawn(Owner).ShakeView(ShakeTime, ShakeMag, ShakeVert);
	}
	clip--;					// remove a bullet from clip and shoot.
	TraceFire(acc);
	fireeffects();
	Owner.PlaySound(FireSound,SLOT_None,(1*Pawn(Owner).SoundDampening));
	PlayAnim( 'Fire', 1, 0.05);
	dorecoil(recoil);
	sleep(60/rpm);
	GoToState('Idle');
Finish();
}
 
state altshoot {
ignores fire, altfire, reload;
Begin:
	GoToState('shoot');
	// ProjectileFire(ProjectileClass, ProjectileSpeed, bWarnTarget);
Finish();
}
 
state reloading {
ignores fire, altfire, reload;
Begin:
	if (AmmoType.AmmoAmount > 0) {				// if player has spare ammo
		Owner.PlaySound(CockingSound, SLOT_None,1*Pawn(Owner).SoundDampening);
		PlayAnim('Down',1,0.05);
		Sleep(reloadtime);
		if (AmmoType.UseAmmo(clipmax)) clip = clipmax;	// fill clip
		else {
			clip = AmmoType.AmmoAmount;			// else partially fill clip
			AmmoType.AmmoAmount = 0;			// and deplete ammo
		}
		Owner.PlaySound(SelectSound, SLOT_None,1*Pawn(Owner).SoundDampening);	
		PlayAnim('Select',1,0.05);
		FinishAnim();
	}
	GoToState('Idle');
Finish();
}
//=============================================================================
// OWshotgun.
// fully remade from an older project to work as an objective weapon.
//=============================================================================
class OWshotgun expands OWWeapon;
 
// copied from olweapons.u - kinda fixes third person mesh
#exec MESH IMPORT MESH=QuadShotthird ANIVFILE=MODELS\QuadShotPickup_a.3D DATAFILE=MODELS\QuadShotPickup_d.3D X=0 Y=0 Z=0
#exec MESH ORIGIN MESH=QuadShotthird X=-164 Y=0 Z=70 YAW=64 Pitch=-7
#exec MESH SEQUENCE MESH=QuadShotthird SEQ=All  STARTFRAME=0  NUMFRAMES=1
#exec MESHMAP SCALE MESHMAP=QuadShotthird X=0.02 Y=0.02 Z=0.04
#exec MESHMAP SETTEXTURE MESHMAP=QuadShotthird NUM=4 TEXTURE=GunPick1
// also copied from olweapons. fixes first-person model bugs
#exec MESH IMPORT MESH=QuadShotHeldr ANIVFILE=MODELS\QuadShotHeld_a.3D DATAFILE=MODELS\QuadShotHeld_d.3D
#exec MESH ORIGIN MESH=QuadShotHeldr X=0 Y=0 Z=0 YAW=128
#exec MESH SEQUENCE MESH=QuadShotHeldr SEQ=still STARTFRAME=29  NUMFRAMES=1
#exec MESH SEQUENCE MESH=QuadShotHeldr SEQ=stillfire STARTFRAME=0  NUMFRAMES=1
#exec MESH SEQUENCE MESH=QuadShotHeldr SEQ=all  STARTFRAME=0  NUMFRAMES=30
#exec MESH SEQUENCE MESH=QuadShotHeldr SEQ=fire STARTFRAME=0  NUMFRAMES=9
#exec MESH SEQUENCE MESH=QuadShotHeldr SEQ=reload STARTFRAME=8  NUMFRAMES=21  Rate=24
#exec MESH SEQUENCE MESH=QuadShotHeldr SEQ=select STARTFRAME=25  NUMFRAMES=5  Rate=8 GROUP=Select
#exec MESH SEQUENCE MESH=QuadShotHeldr SEQ=down STARTFRAME=8  NUMFRAMES=6 Rate=20
#exec MESHMAP SCALE MESHMAP=QuadShotHeldr X=0.01 Y=0.01 Z=0.02
 
var float clipb;			// why a float? to use for volume of shoot sound.
var byte shots;
var byte clipstore;
 
////////////////////////////////////////////////////////
state shoot {
ignores fire, altfire, reload;
Begin:
	clipstore = clip;
	GoToState('altshoot');
Finish();
}
 
state altshoot {
ignores fire, altfire, reload;
Begin:
	CheckVisibility();		// no idea what this stuff does... perhaps chop it out?
	bPointing=True;
	Owner.MakeNoise(2*Pawn(Owner).SoundDampening);
	if (PlayerPawn(Owner) != None) {
		PlayerPawn(Owner).ClientInstantFlash(-0.4, vect(650, 450, 190));
		PlayerPawn(Owner).ShakeView(ShakeTime, ShakeMag, ShakeVert);
	}
	if (clipstore>1) clip=1;
		for(clipb=0;clipb<clip;clipb+=1) {
			for(shots=0;shots<7;shots++) TraceFire(acc);
		fireeffects();  
		}
	clipb = clip;
	Owner.PlaySound(FireSound,SLOT_None,clipb);
	PlayAnim( 'Fire', 1, 0.05);
	dorecoil((recoil*(1+(clip/2))));	// do recoil depending on barrels fired
	clip = clipstore-1;
	if (clip>clipmax) clip=0;				// fix wraparound bug
	clipstore = 0;
	sleep(60/rpm);
	GoToState('Idle');
Finish();
}
 
state reloading {
ignores fire, altfire, reload;
Begin:
	if (AmmoType.UseAmmo(1) && clip<clipmax) {
	PlayAnim( 'Reload', 1.05, 0.05);
	Owner.PlaySound(CockingSound,SLOT_None,1*Pawn(Owner).SoundDampening);
	clip++;
	FinishAnim();
	GoToState('idle');
	}
Finish();
}