Multiplayer-Spiel mit Irrlicht

  • Ich habe ein kleines Multiplayer Spiel mit irrlicht gebastelt. es ist noch nicht fertig und der Code ist leider total unübersichtlich.
    Wenn ich es zeitlich schaffe werde ich demnächst den code verbessern. Ich konnte das script auch nicht richtig testen, da ich nur 1 pc und ein lappi(das zu schlecht für die engine ist(800mhz)) zur verfügung habe. deshalb hoffe ich, dass es funktioniert^^

    Man muss die servereinstellungen im server und client noch anpassen.

    link zu den daten -->

    Server:

    Spoiler anzeigen
    [autoit]

    #cs ----------------------------------------------------------------------------

    [/autoit] [autoit][/autoit] [autoit]

    AutoIt Version: 3.3.6.1
    Author: Jaik
    Version: 0.1
    Script Function:
    Server

    [/autoit] [autoit][/autoit] [autoit]

    #ce ----------------------------------------------------------------------------

    [/autoit] [autoit][/autoit] [autoit]

    ; Script Start - Add your code below here

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #include <Array.au3>

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Dim $iListenSocket
    Dim $sServer_Ip = "192.9.200.69"
    Dim $iServer_Port = "1450"
    Global $ConnectedSocket
    Global $iTempSocket
    Dim $aSockets[1]
    Dim $sSend
    Dim $aClientPositions[100][5]
    Dim $pTemp
    Dim $s_die
    Dim $tmp

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    TCPStartup()
    $iListenSocket = TCPListen($sServer_Ip, $iServer_Port)
    ;WriteConsole($iListenSocket& @CRLF)

    [/autoit] [autoit][/autoit] [autoit]

    ;-------------------------------------------------------------FORM---------------------------
    Dim $hForm = GUICreate("WormKiller Server",860,950,0,0,-1,-1)
    GUISetCursor(2)
    GUISetBkColor(0x808080,$hForm)
    $hConsole = GUICtrlCreateEdit("",10,10,840,930,BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_READONLY,$ES_WANTRETURN,$WS_VSCROLL), 0)
    GUICtrlSetFont(-1, 12, 800, 0, "")
    GUICtrlSetColor(-1, 0x0000FF)
    GUICtrlSetBkColor(-1, 0x808080)
    GUICtrlSetCursor(-1, 2)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    GUISetState(@SW_SHOW,$hForm)
    WriteConsole( "Wormkiller Server"&@CRLF&@CRLF )
    ;------------------------------------------------------------/FORM--------------------------
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    ExitLoop
    EndSwitch

    $iTempSocket = TCPAccept($iListenSocket)
    If $iTempSocket <> -1 Then Client_Connect($iTempSocket)

    Client_recv()


    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    TCPCloseSocket($iListenSocket)
    Exit

    [/autoit] [autoit][/autoit] [autoit]

    Func Client_Connect($socket)
    WriteConsole("Client Connected:" & $socket)
    _ArrayAdd($aSockets, $socket)
    ;TCPCloseSocket($socket)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func Client_recv()

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 1 To UBound($aSockets) -1
    $recv = TCPRecv($aSockets[$i],1000)
    if @error Then
    TCPCloseSocket($aSockets[$i])
    _ArrayDelete($aSockets,$i)
    Return
    EndIf
    $recv = BinaryToString($recv)
    ;If $recv <> "" Then
    ;WriteConsole($aSockets[$i]&" --> "&$recv&@CRLF)

    Select

    Case StringInStr($recv,"position",1) ;Wenn $recv = Position
    $sResult = StringTrimLeft($recv,9)
    $recv = ""
    Dim $aResult = StringSplit($sResult,",",2)

    $aClientPositions[$i][0] = $aSockets[$i] ;socket nr.
    $aClientPositions[$i][1] = $aResult[0] ;X
    $aClientPositions[$i][2] = $aResult[1] ;Y
    $aClientPositions[$i][3] = $aResult[2] ;Z
    $aClientPositions[$i][4] = $aResult[3]
    ;WriteConsole($aClientPositions[$i][4]&"--::--")
    if $aClientPositions[$i][4] <> -1 And $aClientPositions[$i][4] <> "" Then
    $s_die = $aClientPositions[$i][4]
    WriteConsole($s_die&"--::--")
    SendDie()
    EndIf
    ;ende position
    WriteConsole('position='&$aClientPositions[$i][0]&","&$aClientPositions[$i][1]&","&$aClientPositions[$i][2]&","&$aClientPositions[$i][3]&","&$i&","&$aClientPositions[$i][4]&",")
    $pTemp = 1
    Case StringInStr($recv,"exit",1)
    TCPCloseSocket($iListenSocket)
    Exit
    EndSelect
    $recv = ""
    ;EndIf
    Next
    If $pTemp = 1 Then
    SendPositions()
    $pTemp = -1
    EndIf

    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func SendDie()
    ConsoleWrite("----"&$s_die&"----")
    $t = UBound($aSockets) -1
    If $s_die <> -1 Then
    For $i = 1 To $t -1
    ;If $aClientPositions[$i][3] == $s_die Then
    ;$sSendDie = "dieClient"
    $sSendDie = "dieClient"
    $sSendDie = StringToBinary($sSendDie)
    If $s_die <= $t Then
    TCPSend($aSockets[$s_die],$sSendDie) ; Array variable subscript badly formatted.:
    WriteConsole("Spieler --> "&$s_die& " erschossen von spieler "& $tmp)
    Else
    WriteConsole("ERROR, socketnummer ist nicht gültig")
    EndIf
    $s_die = -1
    ;EndIf
    Next
    EndIf
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func SendPositions()
    $t = UBound($aSockets) -1
    For $i = 1 To $t

    If $aClientPositions[$i][1] <> "" Then
    ;MsgBox(0,"t ="&$t,"t ="&$t&" i= "&$i & " socket= "&$aSockets[$i])
    For $j = 1 To $t
    If $aClientPositions[$j][0] <> $aSockets[$i] Then
    $sSend = 'position='&$aClientPositions[$j][0]&","&$aClientPositions[$j][1]&","&$aClientPositions[$j][2]&","&$aClientPositions[$j][3]&","&$j&","&$i&","&$aClientPositions[$j][4]&","
    If $aClientPositions[$j][4] <> -1 Then WriteConsole("Spieler "&$aClientPositions[$j][4]& " getroffen! ")
    ;WriteConsole("Sockets zum Senden --> "&$aSockets[$i]&@CRLF)
    ;WriteConsole("Positions zum Senden --> "&$sSend&@CRLF)
    $sSend = StringToBinary($sSend)
    TCPSend($aSockets[$i],$sSend)
    Sleep(20)
    $s_die = -1
    EndIf
    Next
    EndIf
    Next
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func WriteConsole( $sText )
    If $sText <> "" Then GUICtrlSetData($hConsole, GUICtrlRead($hConsole) & $sText & @CRLF )
    EndFunc

    [/autoit]

    Client:

    Spoiler anzeigen
    [autoit]

    #cs ----------------------------------------------------------------------------

    [/autoit] [autoit][/autoit] [autoit]

    AutoIt Version: 3.3.6.1
    Author: Jaik
    Version: 0.0.1

    Script Function:
    Kleiner Mulitplayer Ego-Shooter

    [/autoit] [autoit][/autoit] [autoit]

    #ce ----------------------------------------------------------------------------

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; ////////////////////////////////////////////////////////////////////////////
    ; Includes for extension libraries
    #include "au3Irrlicht2.au3"
    #include <Array.au3>

    [/autoit] [autoit][/autoit] [autoit]

    opt("MustDeclareVars", True)
    HotKeySet("{ESC}", "_exit")

    [/autoit] [autoit][/autoit] [autoit]

    Func _exit()
    _IrrStop()
    Exit
    EndFunc ; _exit

    [/autoit] [autoit][/autoit] [autoit]

    ; ////////////////////////////////////////////////////////////////////////////
    ; global variables

    [/autoit] [autoit][/autoit] [autoit]

    ; irrlicht objects
    DIM $BSPMesh ; irr_mesh
    DIM $BSPNode ; irr_node
    DIM $Camera ; irr_camera
    DIM $CameraNode ; irr_node
    DIM $MapCollision ; irr_selector
    DIM $BitmapFont ; irr_font
    DIM $ret ; irr_selector
    DIM $pKeyEvent ; $IRR_KEY_EVENT PTR
    Dim $keyCode
    DIM $pMouseEvent ; $IRR_MOUSE_EVENT PTR
    Global $POS[3] ; single
    Dim $POS2[3]
    DIM $metrics ; wstring * 256
    DIM $XStrafe ; integer
    DIM $ZStrafe ; integer
    DIM $YStrafe ; integer
    DIM $SPIN ; single
    DIM $TILT ; single
    DIM $vX[3] ; $IRR_VECTOR
    DIM $vY[3] ; $IRR_VECTOR
    DIM $vZ[3] ; $IRR_VECTOR
    DIM $MX ; single
    DIM $MY ; single
    Dim $crossfade
    Dim $knife1
    Dim $gameOverScreen
    local $SkyDome
    Global $MD2Mesh
    Global $MeshTexture
    Global $SceneNode[10]
    Dim $markiert
    Global $SpwanPoint[1000][3]
    Dim $killedCounter = 1
    Dim $endtime
    Global $dif
    dim $BitmapFont
    Dim $timer
    Dim $timer2
    Dim $begin
    Dim $levelSend = 1
    Dim $levelTime = 35
    Dim $HUDTime
    Dim $respawn = -1
    Dim $camOrientation[3]

    [/autoit] [autoit][/autoit] [autoit]

    ;----------------------SERVER variablen--------------------------
    Dim $iListenSocket
    Dim $sServer_Ip = "192.9.200.69";
    Dim $iServer_Port = "1450"
    Global $ConnectedSocket
    Global $socket
    Dim $recv
    Dim $aClientPositions[100][5]
    Dim $numClients
    Dim $myID
    Dim $die = -1 ; -1 = niemand erschossen, 0-n = Spielernummern
    ;--------------------------------------------------------------------

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ;--------------------------------------EINSTELLUNGEN-------------------------------------
    Dim $breite = 800
    Dim $hoehe = 600

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ;----------------------------------------------------------------------------------------

    [/autoit] [autoit][/autoit] [autoit]

    ; ////////////////////////////////////////////////////////////////////////////
    SpawnPoints($levelSend)

    [/autoit] [autoit][/autoit] [autoit]

    ; -----------------------------------------------------------------------------
    ; start the irrlicht interface
    ; here we
    _IrrStart( $IRR_EDT_DIRECT3D9, $breite, $hoehe, $IRR_BITS_PER_PIXEL_32, _
    $IRR_WINDOWED, $IRR_SHADOWS, $IRR_CAPTURE_EVENTS, $IRR_VERTICAL_SYNC_ON )

    [/autoit] [autoit][/autoit] [autoit]

    ; send the window caption
    _IrrSetWindowCaption( "WormKiller" )
    $BitmapFont = _IrrGetFont ( "media/fonthaettenschweiler.bmp" )
    $crossfade = _IrrGetTexture( "media/crossfade.tga" )
    $knife1 = _IrrGetTexture( "media/knife1.tga" )
    ; first we load the example map into the scene for details on this please
    ; read example 5
    ;_IrrAddZipFile( "media/map-20kdm2.pk3", $IRR_IGNORE_CASE, $IRR_IGNORE_PATHS )
    ;$BSPMesh = _IrrGetMesh( "20kdm2.bsp" )
    ;----------------------------------------------------------------------------------Map in bearbeitung-------------------------------------------------------
    _IrrAddZipFile( "media/wormmap.zip", $IRR_IGNORE_CASE, $IRR_IGNORE_PATHS )
    $BSPMesh = _IrrGetMesh( "worm1.bsp" )
    ;-----------------------------------------------------------------------------------------------------------------------------------------------------------

    [/autoit] [autoit][/autoit] [autoit]

    $BSPNode = _IrrAddMeshToSceneAsOcttree( $BSPMesh )

    [/autoit] [autoit][/autoit] [autoit]

    ; next we add a first person perspective camera to the scene
    $Camera = _IrrAddCamera( 0,0,0, 0,0,0 )
    ; $Camera = _IrrAddFPSCamera()

    [/autoit] [autoit][/autoit] [autoit]

    ; and move it into the middle of the map
    $CameraNode = $Camera
    _IrrSetNodePosition( $CameraNode, 1750, 149, 1369 )
    _IrrSetNodeRotation( $CameraNode, 4, -461.63, 0 )

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $MapCollision = _IrrGetCollisionGroupFromComplexMesh( $BSPMesh, $BSPNode )

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $CameraNode = $Camera
    $ret = _IrrAddCollisionAnimator($MapCollision, _
    $CameraNode, _
    30.0,30.0,30.0, _
    0.0,-5.0,0.0, _
    0.0,50.0,0.0 )

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $SkyDome = _IrrAddSkyDomeToScene( _
    _IrrGetTexture("media/skydome2.jpg"), _
    16, 8, 1.0, 1.2)
    _IrrAddRotationAnimator($SkyDome, 0, 0.01, 0)
    ; hide the mouse pointer
    _IrrHideMouse()

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 0 To 9
    loadBot(0, 0, 0, $i)
    Next
    servConnect()

    [/autoit] [autoit][/autoit] [autoit]

    ; -----------------------------------------------------------------------------
    ; while the irrlicht environment is still running
    $timer = TimerInit()
    $timer2 = TimerInit()
    WHILE _IrrRunning()
    ; is it time for another frame
    if TimerDiff($timer) > 16.7 then
    ; calculate the time the next frame starts
    $timer = TimerInit()
    ; begin the scene, erasing the canvas with sky-blue before rendering
    _IrrBeginScene( 240, 255, 255 )

    [/autoit] [autoit][/autoit] [autoit]

    ; We need to set the mouse back to the center of the screen
    $MX = 0.5
    $MY = 0.5
    _IrrSetMousePosition( $MX, $MY )

    [/autoit] [autoit][/autoit] [autoit]

    ; get the position of the camera
    $POS = _IrrGetNodePosition( $CameraNode)

    keyKonfig() ;STEUERUNG ÜBER WASD-SPACE
    ; while there are key events waiting to be processed


    _MouseClick() ;Mausklicks

    [/autoit] [autoit][/autoit] [autoit]

    $camOrientation = _IrrGetCameraOrientation( $Camera, $vX,$vY,$vZ)

    [/autoit] [autoit][/autoit] [autoit]

    ; these vectors will be different lengths depending on how much the camera
    ; is rotated we can use these values to add the fowards distance to both the
    ; X and Z position by different amounts that are related to the direction
    ; that the camera is pointed
    If $respawn = 1 Then ;------------------____---<//////>
    Dim $rspawn = Random(0,810,1)
    $POS[0] = $SpwanPoint[$rspawn][0]
    $POS[1] = $SpwanPoint[$rspawn][1]
    $POS[2] = $SpwanPoint[$rspawn][2]
    $respawn = -1
    EndIf
    $POS[0] += $vY[0] * $ZStrafe + $vY[2] * $XStrafe
    $POS[2] -= $vY[0] * $XStrafe - $vY[2] * $ZStrafe
    $POS[1] += $YStrafe;
    ;$POS[1] -= $vY[0] * $YStrafe - $vY[2] * $YStrafe

    [/autoit] [autoit][/autoit] [autoit]

    ; update the position of the camera we call this before Draw Scene so that
    ; the objects positions are updated before we draw the scene
    _IrrSetNodePosition($CameraNode, $POS[0], $POS[1], $POS[2])

    [/autoit] [autoit][/autoit] [autoit]

    ; while there are mouse events waiting
    while _IrrMouseEventAvailable()
    ; read the mouse event out
    $pMouseEvent = _IrrReadMouseEvent()

    [/autoit] [autoit][/autoit] [autoit]

    ; if this is a mouse move event
    if __getMouseEvt($pMouseEvent, $EVT_MOUSE_IACTION) = $IRR_EMIE_MOUSE_MOVED then
    ; create a wide string with a list of the positions in
    $metrics = "POSITION " & __getMouseEvt($pMouseEvent, $EVT_MOUSE_IX) & " " & __getMouseEvt($pMouseEvent, $EVT_MOUSE_IY)
    endif
    wend

    [/autoit] [autoit][/autoit] [autoit]

    $SPIN += ( $MX - 0.5 ) * 2.0

    [/autoit] [autoit][/autoit] [autoit]

    $TILT += ( $MY - 0.5 ) * 2.0

    [/autoit] [autoit][/autoit] [autoit]

    if $TILT > 1.5 then $TILT = 1.5
    if $TILT < -1.5 then $TILT = -1.5
    _IrrSetCameraTarget( _
    $Camera, $POS[0] + sin ( $SPIN ) * 1000, _
    -$TILT * 1500, _
    $POS[2] + cos ( $SPIN ) * 1000 )

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]



    CameraCollision() ;überprüft ob Bot markiert wurde.
    ; draw the scene
    _IrrDrawScene()
    _IrrDraw2DImageElement($crossfade, $breite/2 -10, $hoehe/2 -10, 0,0,20,20, $IRR_USE_ALPHA )
    _IrrDraw2DImageElement($knife1, $breite-200, $hoehe-200, 0,0,200,200, $IRR_USE_ALPHA )
    _IrrDraw2DImageElement($gameOverScreen, 0,0 , 0,0,800,600, $IRR_USE_ALPHA )
    _Irr2DFontDraw( $BitmapFont, $endtime, $breite/2 -30, $hoehe/2 +20, 500, 500 )

    ; end drawing the scene and render it
    _IrrEndScene()
    Endif
    if TimerDiff($timer2) > 2 Then
    ; calculate the time the next frame starts
    $timer2 = TimerInit()
    if($POS[0] <> $POS2[0] Or $POS[1] <> $POS2[1] Or $POS[2] <> $POS2[2] Or $die <> -1) Then
    servSendPos()
    EndIf
    Server_recv()
    for $i = 0 To 2
    $POS2[$i] = $POS[$i]
    Next
    EndIf
    WEND

    [/autoit] [autoit][/autoit] [autoit]

    ; -----------------------------------------------------------------------------
    ; Stop the irrlicht engine and release resources
    _IrrStop()

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func loadBot($lx,$ly,$lz,$nr) ;///////////////////////////////////
    Dim $lx,$ly,$lz,$nr
    Dim $rx,$ry,$rz
    $MD2Mesh = _IrrGetMesh( "media/worm.obj" )
    $MeshTexture = _IrrGetTexture( "media/worm.pcx" )
    $SceneNode[$nr] = _IrrAddMeshToScene( $MD2Mesh )
    _IrrSetNodeMaterialTexture( $SceneNode[$nr], $MeshTexture, 0 )
    _IrrSetNodeScale( $SceneNode[$nr], 15, 15, 15 )
    _IrrSetNodeMaterialFlag( $SceneNode[$nr], $IRR_EMF_LIGHTING, $IRR_OFF )
    _IrrSetNodePosition( $SceneNode[$nr], $lx, $ly, $lz)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func setPosition($lx,$ly,$lz,$nr)
    Dim $lx,$ly,$lz,$nr
    Dim $rx,$ry,$rz
    ;if(Int($POS[0]) <> $lx And Int($POS[1]) <> $ly And Int($POS[2]) <> $lz) Then
    _IrrRemoveNode($SceneNode[$nr])
    _IrrRemoveTexture($MeshTexture) ; no longer needed
    $sceneNode[$nr] = 0
    loadBot($lx,$ly,$lz,$nr)
    ;EndIf
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func CameraCollision()
    $markiert =_IrrGetCollisionNodeFromCamera($Camera)
    Dim $t = UBound($sceneNode) -1

    For $i = 1 To $t;ZIEL MARKIERT
    If $markiert = $sceneNode Then
    $crossfade = _IrrGetTexture( "media/crossfade2.tga" )
    ;MouseClick("left")
    Else
    $crossfade = _IrrGetTexture( "media/crossfade.tga" )

    EndIf
    Next
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func keyKonfig()
    while _IrrKeyEventAvailable()

    [/autoit] [autoit][/autoit] [autoit]

    ; read the key event out. the key event has three parameters the key
    ; scan code, the direction of the key and flags that indicate whether
    ; the control key or the shift keys were also pressed
    $pKeyEvent = _IrrReadKeyEvent()

    [/autoit] [autoit][/autoit] [autoit]

    ; arbitrate based on the key that was prwa essed
    $keyCode = __getKeyEvt($pKeyEvent, $EVT_KEY_IKEY)
    select
    case $keyCode = $KEY_KEY_D ; Left Arrow
    ; if the key is going down
    if __getKeyEvt($pKeyEvent, $EVT_KEY_IDIRECTION) = $IRR_KEY_DOWN then
    $XStrafe = 6
    else
    if $XStrafe = 6 then
    $XStrafe = 0
    endif
    endif

    [/autoit] [autoit][/autoit] [autoit]

    case $keyCode = $KEY_KEY_W ; Up Arrow
    ; if the key is going down
    if __getKeyEvt($pKeyEvent, $EVT_KEY_IDIRECTION) = $IRR_KEY_DOWN then
    $ZStrafe = 6
    else
    if $ZStrafe = 6 then
    $ZStrafe = 0
    endif
    endif

    [/autoit] [autoit][/autoit] [autoit]

    case $keyCode = $KEY_KEY_A ; Right Arrow
    ; if the key is going down
    if __getKeyEvt($pKeyEvent, $EVT_KEY_IDIRECTION) = $IRR_KEY_DOWN then
    $XStrafe = -6
    else
    if $XStrafe = -6 then
    $XStrafe = 0
    endif
    endif

    [/autoit] [autoit][/autoit] [autoit]

    case $keyCode = $KEY_KEY_S ; Down Arrow
    ; if the key is going down
    if __getKeyEvt($pKeyEvent, $EVT_KEY_IDIRECTION) = $IRR_KEY_DOWN then
    $ZStrafe = -6
    else
    if $ZStrafe = -6 then
    $ZStrafe = 0
    endif
    endif

    case $keyCode = $KEY_SPACE ; Spacebar
    ; if the key is going down
    if __getKeyEvt($pKeyEvent, $EVT_KEY_IDIRECTION) = $IRR_KEY_DOWN then
    $YStrafe = 7
    else
    if $YStrafe = 7 then
    $YStrafe = 0
    endif
    endif

    endselect
    wend
    EndFunc

    Func _MouseClick()
    While _IrrMouseEventAvailable()
    $pMouseEvent = _IrrReadMouseEvent()

    If __getMouseEvt($pMouseEvent, $EVT_MOUSE_IACTION) = $IRR_EMIE_LMOUSE_PRESSED_DOWN then ;MAUSKLICK!!!
    $knife1 = _IrrGetTexture( "media/knife2.tga" )

    Dim $t = UBound($sceneNode) -1
    For $i = 1 To $t
    If $markiert = $sceneNode[$i] Then ;Schleife die über alle nodes geht
    ;_IrrPlayNodeMD2Animation( $SceneNode, $IRR_EMAT_Death_Fallback )
    $die = $i
    _IrrRemoveNode($SceneNode[$i])
    _IrrRemoveTexture($MeshTexture) ; no longer needed
    $levelTime += 1; Für jeden Abschuss gibt es 5 Sekunden extra
    loadBot(0, 0, 0, $i) ;wird vermutlich nicht mehr gebraucht weil über den server gespawnt wird
    EndIf
    ;ConsoleWrite($POS[0]&","&$POS[1]- 51&","&$POS[2]&@CRLF)
    Next
    EndIf
    If __getMouseEvt($pMouseEvent, $EVT_MOUSE_IACTION) = $IRR_EMIE_LMOUSE_LEFT_UP then ;MAUSKLICK!!!
    $knife1 = _IrrGetTexture( "media/knife1.tga" )
    EndIf
    WEnd
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func SpawnPoints($level)
    ;Dim $spawnFilePath = FileOpenDialog("Spawnpunkt Datei auswählen", @ScriptDir & "\spawnpoints", "Spawnpoints(*.sp)", 1)
    ; Dim $spawnFilePath = InputBox("Spawnpoints einfügen","example.sp/example.txt")
    ; Dim $spawnFile = FileOpen(@ScriptDir&"\spawnpoints\"&$spawnFilePath)
    Dim $level = 1; rausnehmen bei mehreren Dateien
    Dim $spawnFile = FileOpen(@ScriptDir&"\spawnpoints\level"&$level&".sp")
    ConsoleWrite("LEVEL - "&$level&@CRLF)

    [/autoit] [autoit][/autoit] [autoit]

    If $spawnFile = -1 Then
    MsgBox(0, "Error", "keine Datei mit Spawnpoints gefunden")
    Exit
    EndIf
    ;ConsoleWrite($spawnFile)
    Dim $split[5]
    Global $i = 0
    ; Read in lines of text until the EOF is reached
    While 1
    Dim $line = FileReadLine($spawnFile)
    If @error = -1 Then ExitLoop
    ;ConsoleWrite($line&@CRLF)
    $split = StringSplit($line,",")
    $SpwanPoint[$i][0] = $split[1]
    $SpwanPoint[$i][1] = $split[2]
    $SpwanPoint[$i][2] = $split[3]
    $i = $i+ 1
    Wend
    ;_ArrayDisplay($SpwanPoint,"Spawn Points")
    FileClose($spawnFile)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ;----------------Server verbindung aufbauen-----------------------

    [/autoit] [autoit][/autoit] [autoit]

    Func servConnect()

    TCPStartup()
    $socket = TCPConnect( $sServer_Ip, $iServer_Port )
    ConsoleWrite($iListenSocket&"<-- Socket"& @CRLF)

    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func servSendPos()
    Dim $sCoords

    If $socket <> -1 Then
    $sCoords = StringToBinary("position="&Int($POS[0])&","&Int($POS[1])&","&Int($POS[2])&","&$die&",") ; X,Y,Z - Koordinaten werden übergeben ; getroffene id wird gesendet (SceneNode[1] <-- spielerID)
    TCPSend($socket,$sCoords)
    $die = -1 ; $die wird zurückgesetzt
    ;Sleep(100)
    EndIf
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func Server_recv()
    Dim $sResult
    Dim $aResult
    Dim $recv = TCPRecv($socket,1000)
    if @error Then
    TCPCloseSocket($socket)
    Return
    EndIf
    $recv = BinaryToString($recv)

    If $recv <> "" Then
    ;ConsoleWrite($socket&" --> "&$recv&@CRLF)

    Select
    Case StringInStr($recv,"position",1) ;Wenn $recv = Position
    $sResult = StringTrimLeft($recv,9)
    $recv = "";
    ;MsgBox(0,"",$sResult)
    $aResult = StringSplit($sResult,",",2)

    ;ConsoleWrite($sResult)
    Dim $nr = $aResult[4]
    $myID = $aResult[5]
    $aClientPositions[$nr][0] = $aResult[1] ;$aResult[4] ist die Spieler-ID, die vom Server übergeben wir
    $aClientPositions[$nr][1] = $aResult[2]
    $aClientPositions[$nr][2] = $aResult[3]
    $aClientPositions[$nr][3] = $aResult[4]
    ;_ArrayDisplay($aClientPositions)
    ConsoleWrite($aClientPositions[$nr][0]&","&$aClientPositions[$nr][1]&","&$aClientPositions[$nr][2]&","&$aClientPositions[$nr][3]&@CRLF)
    setPosition($aClientPositions[$nr][0],$aClientPositions[$nr][1],$aClientPositions[$nr][2],$aClientPositions[$nr][3])
    Case StringInStr($recv,"exit",1)
    Exit
    Case StringInStr($recv,"dieClient",1)
    $respawn = 1
    EndSelect

    EndIf

    EndFunc

    [/autoit]
  • Schön schön, aber funktionieren tuts nicht^^
    Also ich hab mir deine zip-Datei runtergeladen und die IPs geändert ( an meine angepasst ). Dann habe ich den Server gestartet, danach den Client und auf einem anderen Rechner ebenflals den Client. Ich kann zwar rumlaufen und so, aber ich sehe den anderen ( Also den zweiten spieler ) nicht, bzw. ich kann den Wurm nicht kaputt machen oder so.

    mfg
    Hauke

  • mhm..^^ was hast du den für ein OS? wenn man beide mal bewegt hat, müsst man sich gegenseitig sehen. das ist ein schönheitsfehler.. Mit dem respawnen gibts glaube ich noch probleme. ich organisiere mir auf nächste woche einen 2. pc dann kann ich *hoffentlich* alle fehler beheben :D
    bei mir funktioniert es aber größtenteils. ich vermute das ich noch nen Timer einbauen muss

  • sieht aufjedenfall richtig gut aus. leider konnte ich nicht testen ob der multiplayer funktioniert. mit welchen programm hast du die map erstellt.

  • Die Map hab ich mit GtkRadiant erstellt. Hier gibts ein gutes Tutorial.

    Mit Windows 7 gibts anscheinend Probleme. Ich hab grade nur ein Win XP da, deshalb muss ich warten bis ich mein lappi wieder bekomme^^

  • hmmm, client wirft fehler:

    Spoiler anzeigen

    E:\test\test3\AutoOS\Client_alt.au3(262,9) : ERROR: $lx already declared as parameter
    Dim $lx,
    ~~~~~~~^
    E:\test\test3\AutoOS\Client_alt.au3(262,13) : ERROR: $ly already declared as parameter
    Dim $lx,$ly,
    ~~~~~~~~~~~^
    E:\test\test3\AutoOS\Client_alt.au3(262,17) : ERROR: $lz already declared as parameter
    Dim $lx,$ly,$lz,
    ~~~~~~~~~~~~~~~^
    E:\test\test3\AutoOS\Client_alt.au3(262,21) : ERROR: $nr already declared as parameter
    Dim $lx,$ly,$lz,$nr
    ~~~~~~~~~~~~~~~~~~~^
    E:\test\test3\AutoOS\Client_alt.au3(274,9) : ERROR: $lx already declared as parameter
    Dim $lx,
    ~~~~~~~^
    E:\test\test3\AutoOS\Client_alt.au3(274,13) : ERROR: $ly already declared as parameter
    Dim $lx,$ly,
    ~~~~~~~~~~~^
    E:\test\test3\AutoOS\Client_alt.au3(274,17) : ERROR: $lz already declared as parameter
    Dim $lx,$ly,$lz,
    ~~~~~~~~~~~~~~~^
    E:\test\test3\AutoOS\Client_alt.au3(274,21) : ERROR: $nr already declared as parameter
    Dim $lx,$ly,$lz,$nr
    ~~~~~~~~~~~~~~~~~~~^
    E:\test\test3\AutoOS\Client_alt.au3(398,48) : ERROR: $level already declared as parameter
    Dim $level = 1; rausnehmen bei mehreren Dateien
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    E:\test\test3\AutoOS\Client_alt.au3 - 9 error(s), 0 warning(s)

  • Ich habe leider gerade keine Zeit um an dem programm weiterzuarbeiten.

    DrAcHe981 - lvls gibt es nicht mehr, der code ist nurnoch drin.. müsste man wieder umproggen :)

    @m-obi - Da fragst du den falschen^^ Ich nehm(in autoit) halt immer Dim :)

    WhiteLion - wahrscheinlich bei win7 oder/und 64 bit?


    Ich hab mal die letzte Version hochgeladen :) -->Hier<--

    server_1 und client_1 sollte stabil(er) laufen. vielleicht kann sich ja jmd. etwas nützliches abgucken :D

    Einmal editiert, zuletzt von J@ik (19. Oktober 2012 um 14:01)

  • @m-obi - Da fragst du den falschen^^ Ich nehm(in autoit) halt immer Dim :)

    Davon kann ich abraten, denn Dim kann sich genauso wie eine Variable, die ohne vorherige Deklaration verwendet wird, unterschiedlich verhalten.

    &quot;Beispiel&quot;
    [autoit]

    Func Foo($baz)
    Dim $bar = $baz+1
    ConsoleWrite($bar)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Foo(2)
    MsgBox(0, "", $bar) ; würde Fehler geben
    $bar = 7
    MsgBox(0, "", $bar) ; gibt 7 aus
    Foo(99)
    MsgBox(0, "", $bar) ; Gibt 100 aus

    [/autoit]

    Wie man sieht, wird $bar beim ersten Aufruf von Foo lokal erstellt und nach Funktionsende gelöscht. Danach exisitert aber die globale Variable $bar und diese wird verändert. So kann es vorkommen, dass ein Fehler auftritt, aber man an der falschen Stelle nach der Ursache sucht.
    Ich mache das bei größeren Projekten immer so: Globale Variablen werden außerhalb einer Funktion mit Global, in Funktionen werden alle Variablen mit Local deklariert. Leider ist AutoIt, was die Variablendeklaration angeht nicht besonders einheitlich.