Tuesday, July 11, 2006

Okay, there are 4 pieces of Unreal script required to make everything work...
I want to:-

1. monitor which keys are pressed in unreal
2. make an object move based on the keypress
3. constantly be sending the positions of the players out via udp

okay, lets start with send the positions of the players out via udp.
a class is needed Ive called it "udptest".

---------------------------------------

class udptest extends UdpLink;

event prebeginplay()
{
local UdpLink.ipaddr dest;

Log("ullo charlie");
BindPort(9001, true);
StringToIpAddr("192.168.2.8", dest);
dest.port = 9000;

SendText(dest , "imtext"); //this is the first message to be sent via UDP
}

defaultproperties {}


---------------------------------------

Then we need a mutator to actually do stuff... its called "watcher"

---------------------------------------

class Watcher extends mutator;

var() int counter;
var UdpLink myudp;

event PreBeginPlay()
{
SetTimer(1.0,true);
myudp=Spawn(class'udptest'); //ensure the class we just made runs
}


function Timer()
{

local UdpLink.ipaddr dest;
local Controller C;

myudp.StringtoIpAddr("192.168.2.8",dest);
dest.port=9000;

for (C = Level.ControllerList; C != None; C = C.NextController)
{
if(C.Pawn != None) {
myudp.SendText(dest , "nextthree");
myudp.SendText(dest , C.Pawn.Location.X);
myudp.SendText(dest , C.Pawn.Location.Y);
myudp.SendText(dest , C.Pawn.Location.Z);
}
}
}

DefaultProperties
{
FriendlyName="Watcher"
Description="I log the positions of the players every second and send this informaton to ip:192.168.2.8 , port:9000"
}


---------------------------------------

Now then, monitoring keypresses... a mutator which starts an interaction, the mutator is called "keyinteract_mut"
note: I dont understand most of this code, I pretty much copied it off the wiki other than the bit that refrences keyinteract_inter, which is my final class

---------------------------------------

class keyinteract_mut extends Mutator;

var bool bAffectSpectators; // If this is set to true, an interaction will be created for spectators
var bool bAffectPlayers; // If this is set to true, an interaction will be created for players
var bool bHasInteraction;

function PreBeginPlay()
{
Log("key interact Mutator Started");
}

simulated function Tick(float DeltaTime)
{
local PlayerController PC;

// If the player has an interaction already, exit function.
if (bHasInteraction)
Return;
PC = Level.GetLocalPlayerController();

// Run a check to see whether this mutator should create an interaction for the player
if ( PC != None && ((PC.PlayerReplicationInfo.bIsSpectator && bAffectSpectators) || (bAffectPlayers && !PC.PlayerReplicationInfo.bIsSpectator)) )
{
PC.Player.InteractionMaster.AddInteraction("keyinteract_inter.keyinteract_inter", PC.Player); // Create the interaction/ run my class
bHasInteraction = True; // Set the variable so this lot isn't called again
}
}

DefaultProperties
{
FriendlyName="interaction creator"
Description="I do something that starts let interactions happen, apparently im needed if you want triggers to go off with key presses"
bAffectSpectators=false
bAffectPlayers=true
RemoteRole=ROLE_SimulatedProxy
bAlwaysRelevant=true
}


---------------------------------------

and finally what to do with keypresses, a class called "keyinteract_inter"
note: for this I have a series of movers in my map waiting to certain triggers eg.
a mover with the tag "move1" will activate (accordin to the code) when Numpad0 is pressed.

---------------------------------------

Class keyinteract_inter extends Interaction;

Function Initialize()
{
Log("Interaction Initialized");

}


function bool KeyEvent(EInputKey Key, EInputAction Action, FLOAT Delta )
{

if ((Action == IST_Press) && (Key == IK_NumPad0))
{
ViewportOwner.Actor.TriggerEvent('move1',ViewportOwner.Actor,None);
}

if ((Action == IST_Press) && (Key == IK_NumPad1))
{
ViewportOwner.Actor.TriggerEvent('move2',ViewportOwner.Actor,None);
}

if ((Action == IST_Press) && (Key == IK_NumPad2))
{
ViewportOwner.Actor.TriggerEvent('move3',ViewportOwner.Actor,None);
}
if ((Action == IST_Press) && (Key == IK_Y))
{
ViewportOwner.Actor.TriggerEvent('move35',ViewportOwner.Actor,None);
}

if ((Action == IST_Press) && (Key == IK_Z))
{
ViewportOwner.Actor.TriggerEvent('move36',ViewportOwner.Actor,None);
}

return false;
}


DefaultProperties
{
bActive=True
}


---------------------------------------

1 Comments:

Anonymous Anonymous said...

Hi there, just found your work at Unreal Art and really like it. It would be great to see your drawings created realtime ingame. Have you though of using the AnimNotify function to spawn simple (2 poly 8bit textured) footprints from the foot bones on specific frames.Player controller paint brush mutator.Are you still working with Unreal? What are you up to now? Regards Lewi

9:38 pm  

Post a Comment

<< Home