![]() |
|
|
#1 |
|
How to send key input to the server (Was: Communicate from client to server)
All right. I noticed that the base of my problem is that I don't know how to send key input from client to server.
Are there some examples, that could be read for this? I've found some posts on this forum, but there were rather old and for UT2003. It didn't work. So how to communicate key input from Client to Server? Do I need an Interaction class? Where I will put my function handling key input on the server? And where will be the function handling client input on client? I was playing with this yesterday for 4 hours and didn't get any result... :-/ I was able to detect key input all the time just on the client side... :-/ My goal is to change the state of the game on the server (move to the custom state), when the player press certain key. Thx a lot for any help or information! SK Last edited by Shadow_knight; 28th Feb 2008 at 01:10 AM. |
|
|
|
|
|
|
#2 |
|
Problem probably solved
I have overlooked two great topics about replication on UnrealWiki. Namely:
http://wiki.beyondunreal.com/wiki/Re...De-Obfuscation with a lot of general info about replication and how it works. and http://wiki.beyondunreal.com/wiki/An...At_Replication with an example that should solve my problem. I will try to make it work in several days and then I'll post my code here and if it worked. Hope this thread will at least help to summarize information about this topic (client - server communication)... SK |
|
|
|
|
|
|
#3 |
|
Registered User
Join Date: Feb. 26th, 2008
Posts: 13
|
Some other helpful links:
http://udn.epicgames.com/Two/FunctionReplication.html http://udn.epicgames.com/Two/VariableReplication.html
__________________
http://www.seethroughskin.com |
|
|
|
|
|
#4 |
|
Conclusion
At last I was able to make what I wanted. The bug was I was editing code, which I was not using (I used different package) LOL! Anyway, here is working key-detecting code:
First you need to create an interaction class for your player. You can do this with mutator and some examples are on unrealwiki. Interaction class: Code:
class AVCR_Interaction extends Interaction;
function bool KeyEvent(EInputKey Key, EInputAction Action, FLOAT Delta )
{
log("We are in keypressed");
if ((Action == IST_Press) && (Key == IK_Home))
{
AVCRxPlayer(ViewportOwner.Actor).KeyPressed();
}
if ((Action == IST_Press) && (Key == IK_Space))
{
}
if ((Action == IST_Press) && (Key == IK_PageDown))
{
AVCRxPlayer(ViewportOwner.Actor).SpeedDecreased();
}
if ((Action == IST_Press) && (Key == IK_PageUp))
{
AVCRxPlayer(ViewportOwner.Actor).SpeedIncreased();
}
return false;
}
defaultproperties
{
bActive = true
bVisible = true
}
Code:
class AVCRxPlayer extends xPlayer;
replication
{
reliable if ( Role<ROLE_Authority )
NotifyServer, bExperimentKeyPressed, SpeedIncreased, SpeedDecreased;
}
simulated function KeyPressed()
{
log("We are in KeyPressed function");
bExperimentKeyPressed = true;
NotifyServer();
}
function NotifyServer()
{
log("We are in NotifyServer");
if (AVCR_Experiment(Level.Game).IsInState('ExperimentRunning'))
{
AVCR_Experiment(Level.Game).gotoState('ExperimentEnd');
}
else
AVCR_Experiment(Level.Game).gotoState('ExperimentStart','Begin');
}
function SpeedIncreased()
{
log("We are in SpeedIncreased");
if (Pawn != none)
{
if (Pawn.GroundSpeed <= 1.8 * Pawn.Default.GroundSpeed)
Pawn.GroundSpeed += 0.2 * Pawn.Default.GroundSpeed;
}
}
function SpeedDecreased()
{
log("We are in SpeedDecreased");
if (Pawn != none)
{
if (Pawn.GroundSpeed > 0.3 * Pawn.Default.GroundSpeed)
Pawn.GroundSpeed -= 0.2 * Pawn.Default.GroundSpeed;
}
}
|
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|