Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[EO] Checkpoint Attribute


Alatar
 Share

Recommended Posts

I was bored and decided to make something like adding a new attribute to Origins. The Checkpoint Attribute is a simple addition to [EO] that sets the basic of a checkpoint tile and stores it in a .ini file, so when a player dies he/she respawns there. This can easily be optimized in order to increase the utility of it, because the code below is a scratch of what could it be.
No credits are needed ^^, hope you people find it useful ;D

**Design**:

- frmEditor_Map: Add a new option button below optSlide named “optCheckpoint”.

**Code**:

**Server-Side**:

- modConstants: Below this:
```
Public Const TILE_TYPE_SLIDE As Byte = 14
```Add this:
```
Public Const TILE_TYPE_CHECKPOINT As Byte = 15
```
- modDatabase: In AddChar, below:
```
Player(Index).Class = ClassNum
```Add:
```
Call PutVar(App.Path & "\Data\accounts\checkpoints.ini", "*SERVEROPTIONS*", "" & GetPlayerName(Index), "" & 0)
```
- modPlayer: In PlayerMove, below this:
```
' Check if it's a trap tile
        If .Type = TILE_TYPE_TRAP Then
            amount = .Data1
            SendActionMsg GetPlayerMap(Index), "-" & amount, BrightRed, ACTIONMSG_SCROLL, GetPlayerX(Index) * 32, GetPlayerY(Index) * 32, 1
            If GetPlayerVital(Index, HP) - amount <= 0 Then
                KillPlayer Index
                PlayerMsg Index, "You're killed by a trap.", BrightRed
            Else
                SetPlayerVital Index, HP, GetPlayerVital(Index, HP) - amount
                PlayerMsg Index, "You're injured by a trap.", BrightRed
                Call SendVital(Index, HP)
            End If
            Moved = YES
        End If
```
Add this before the End With:
```
        If .Type = TILE_TYPE_CHECKPOINT Then
            SetCheckpoint Index, .Data1, .Data2, .Data3
        End If
```
In the same module, in Sub OnDeath, find this:
```
    With Map(GetPlayerMap(Index))
      ' to the bootmap if it is set
        If .BootMap > 0 Then
            PlayerWarp Index, .BootMap, .BootX, .BootY
        Else
            Call PlayerWarp(Index, START_MAP, START_X, START_Y)
        End If
    End With
```Replace with this:
```
    With Map(GetPlayerMap(Index))
        'Checkpoint
        If ValCheckPoint(Index) = True Then
            WarpToCheckpoint Index
        ' to the bootmap if it is set
        ElseIf .BootMap > 0 Then
            PlayerWarp Index, .BootMap, .BootX, .BootY
        Else
            Call PlayerWarp(Index, START_MAP, START_X, START_Y)
        End If
    End With
```
And at the end of the module add this subs:

```
'Checkpoint
Public Sub SetCheckpoint(ByVal Index As Long, ByVal MapNum As Long, ByVal x As Long, ByVal y As Long)
    PlayerMsg Index, "Checkpoint activated!", BrightGreen
    Call PutVar(App.Path & "\Data\accounts\checkpoints.ini", "*SERVEROPTIONS*", "" & GetPlayerName(Index), "" & 1)
    Call PutVar(App.Path & "\Data\accounts\checkpoints.ini", "" & GetPlayerName(Index), "MAPNUM", "" & MapNum)
    Call PutVar(App.Path & "\Data\accounts\checkpoints.ini", "" & GetPlayerName(Index), "X", "" & x)
    Call PutVar(App.Path & "\Data\accounts\checkpoints.ini", "" & GetPlayerName(Index), "Y", "" & y)
End Sub

Public Sub WarpToCheckpoint(ByVal Index As Long)
    Dim MapNum As Integer
    Dim x As Integer
    Dim y As Integer

    MapNum = GetVar(App.Path & "\Data\accounts\checkpoints.ini", "" & GetPlayerName(Index), "MAPNUM")
    x = GetVar(App.Path & "\Data\accounts\checkpoints.ini", "" & GetPlayerName(Index), "X")
    y = GetVar(App.Path & "\Data\accounts\checkpoints.ini", "" & GetPlayerName(Index), "Y")
    Call PlayerWarp(Index, MapNum, x, y)
End Sub

Public Function ValCheckPoint(ByVal Index As Long) As Boolean
    If GetVar(App.Path & "\Data\accounts\checkpoints.ini", "*SERVEROPTIONS*", "" & GetPlayerName(Index)) = 1 Then
        ValCheckPoint = True
    Else
        ValCheckPoint = False
    End If
End Function
```

**Client-Side**:

- modConstants: Below this:
```
Public Const TILE_TYPE_SLIDE As Byte = 14
```Add this:
```
Public Const TILE_TYPE_CHECKPOINT As Byte = 15
```
- modGameEditors: Find this
```
' slide
If frmEditor_Map.optSlide.Value Then
.Type = TILE_TYPE_SLIDE
.Data1 = MapEditorSlideDir
.Data2 = 0
.Data3 = 0
End If
```
Below it, add this:
```
'Checkpoint
If frmEditor_Map.optCheckpoint.Value Then
If movedMouse Then Exit Sub
X = X - (CurX * 32)
Y = Y - (CurY * 32)
.Type = TILE_TYPE_CHECKPOINT
.Data1 = GetPlayerMap(MyIndex)
.Data2 = CurX
.Data3 = CurY
End If
```
- modText: Find this:
```
Case TILE_TYPE_SLIDE
DrawText TexthDC, tX, tY, "S", QBColor(BrightCyan)
```
Below, add this:

```
Case TILE_TYPE_CHECKPOINT
DrawText TexthDC, tX, tY, "CP", QBColor(BrightGreen)
```
Link to comment
Share on other sites

  • 1 month later...
  • 2 weeks later...
Bug here:
```
  If GetVar(App.Path & "\Data\accounts\checkpoints.ini", "*SERVEROPTIONS*", "" & GetPlayerName(Index)) = 1 Then
```
Needs to be changed to:
```
  If GetVar(App.Path & "\Data\accounts\checkpoints.ini", "*SERVEROPTIONS*", "" & GetPlayerName(Index)) = "1" Then
```
These "" tell that it's an integer and not a preset value that has been dimmed or a function. This is a very important fix, as it will cause regular players to crash the client/server.
Link to comment
Share on other sites

  • 2 months later...
  • 2 weeks later...
  • 2 weeks later...
  • 5 months later...
  • 9 months later...
  • 3 weeks later...
@Ansonla:

> theres something wrong with this code. i don't know why. someone fix it. it's not working for me.

there is nothing wong with the code, you did it wrong…

about the tut:
Thanks alot, i needed this! map 1 and 2 are tutorial maps in my game :P and i don't want players to respawn inside the tutorial cave :S well, Thanks alot
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...