News UnrealEd Files Mods FragBU Liandri Archives
BeyondUnreal Forums

Go Back   BeyondUnreal Forums > Unreal Development > Coding

Reply
 
Thread Tools Display Modes
Old 27th Feb 2008, 11:48 AM   #1
Shadow_knight
Carpe diem!
 
Shadow_knight's Avatar
 
Join Date: Jan. 29th, 2008
Location: Prague
Posts: 48
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.
Shadow_knight is offline   Reply With Quote
Old 28th Feb 2008, 08:21 AM   #2
Shadow_knight
Carpe diem!
 
Shadow_knight's Avatar
 
Join Date: Jan. 29th, 2008
Location: Prague
Posts: 48
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
Shadow_knight is offline   Reply With Quote
Old 28th Feb 2008, 10:58 AM   #3
Ominae392
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
Ominae392 is offline   Reply With Quote
Old 1st Mar 2008, 11:37 AM   #4
Shadow_knight
Carpe diem!
 
Shadow_knight's Avatar
 
Join Date: Jan. 29th, 2008
Location: Prague
Posts: 48
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
}
Then in your custom player controller class you need to have this:
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;
	}
}
Thats pretty much it. This code is making your bot speed up and speed down (by pressing PageUp/Down keys) and it is switching the states of the game when the Home key is pressed (the code of the new gametype is not interesting, so I havent put it here).
Shadow_knight is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 02:04 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.

Copyright ©1998 - 2012, BeyondUnreal, Inc.
Privacy Policy | Terms of Use
Bandwidth provided by AtomicGamer