this is a python network so u can play from 2 different computers on the same game but u both have to be connected to the same INTERNET IP or SERVER for it to work witch is better then split screen x]
the code below is the setup script name it Setup.py
from GameLogic import *
#START THIS SETUP ONE TIME AS A SERVER AND ONE TIME AS A CLIENT
#BEVORE YOU START THIS SETUP AS A CLIENT REPLACE THE * IN THE
#LINE BELOW WITH THE SERVER IP
#(FOR EXAMPLE: GameLogic.IP = "192.123.100.1")
GameLogic.IP = "*********"
#THE CODE BELOW SETS UP IF YOU PLAY THE CLIENT OR THE SERVER
#TO START THE SERVER PRESS F1 TO START THE CLIENT F2
cont = GameLogic.getCurrentController()
obj = cont.getOwner()
scene = getCurrentScene()
Server = cont.getSensor("F1")
Client = cont.getSensor("F2")
if Server.isPositive():
Server = scene.getObjectList()["OBServer"]
Server.Activ = 1
if Client.isPositive():
Client = scene.getObjectList()["OBClient"]
Client.Activ = 1
this is the Server script name it Server.py
#------------Setup--------------#
from GameLogic import *
from socket import *
from cPickle import *
cont = GameLogic.getCurrentController()
obj = cont.getOwner()
if obj.OneTime == 0:
Host = ''
ServerPort = 10000
GameLogic.sServer = socket(AF_INET,SOCK_DGRAM)
GameLogic.sServer.bind((Host,ServerPort))
GameLogic.sServer.setblocking(0)
obj.OneTime = 1
PosYou = obj.getPosition()
scene = getCurrentScene()
Client = scene.getObjectList()["OBClient"]
PosClient = [0,0,0]
#------------RECEIVE/SEND--------------#
try:
Data, CLIP = GameLogic.sServer.recvfrom(1024)
UPData = loads(Data)
PosClient = [UPData[0],UPData[1],UPData[2]]
Client.setPosition(PosClient)
Data = dumps((PosYou))
GameLogic.sServer.sendto(Data,CLIP)
except:
pass
#---------------THE-END----------------#
this is the Client script name it Client.py(duh)
#------------Setup--------------#
from GameLogic import *
from socket import *
from cPickle import *
cont = GameLogic.getCurrentController()
obj = cont.getOwner()
if obj.OneTime == 0:
ServerIP = GameLogic.IP
Serverport = 10000
Clientname = ''
ClientPort = 10001
GameLogic.sClient = socket(AF_INET,SOCK_DGRAM)
GameLogic.sClient.bind((Clientname,ClientPort))
GameLogic.host = (ServerIP,Serverport)
GameLogic.sClient.setblocking(0)
obj.OneTime = 1
PosYou = obj.getPosition()
scene = getCurrentScene()
Server = scene.getObjectList()["OBServer"]
PosServer = [0,0,0]
#------------RECEIVE/SEND--------------#
Data = dumps((PosYou))
GameLogic.sClient.sendto(Data,GameLogic.host)
try:
Data, SRIP = GameLogic.sClient.recvfrom(1024)
UPData = loads(Data)
PosServer = [UPData[0],UPData[1],UPData[2]]
Server.setPosition(PosServer)
except:
pass
#---------------THE-END----------------#
then load them all into ur game like thisand then after that name ur 2 players. name one Client
and the other Server
and now add these properties
after that add an sensor called propety and name it sActiv and in the property box type Activ and in the value box type in 1 and it should look like this
after ur done with that connect it with with every controller u have so it wont mess up on the connection .
after add 2 sensors they both have to be keybord sensors and ont should be called F1 and other called F2 (duh) and it has to be a capitol “F” or it wont work:eek: and they should look like thisand then connect them to the setup.py control like this
DONT CONNET ANYTHING TO THE SETUP.PY CONTROL BUT THE F1 and F2 SENSORS!!and that pretty much raps it up YAY!!!
i would like the blender foundation for the book and tutorials in the book they really made me improve allot :D:yes: THANKS A MILLION x]
the script and simple game is ready in the attachment it’s 2 posts down srry[ATTACH]128265[/ATTACH]
Attachments
BasicNetwork.blend (142 KB)