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

Basic sidescroller crap (making npcs + players fall + player falling damage)


zidsal
 Share

Recommended Posts

The code will only check to see if your not on a ground area and then warp you. + hurt the player if he falls for more then 1 tile. ( just in case the title is not a clear enough hint for you.)

I would like to thank V rage who helped me make the function on checking how close someone is to a blocked tile (what I used as ground).

I'm no longer going to use this so here yo guys go ALL SERVER SIDE:

I will not spoon feed you here only supply the code up to you to choose where to place it.

make  PULLINGDELAY a global variable

```
'gravity for npcs
    If MapNPC(MapNum, MapNpcNum).num > 0 Then
        If CheckNpcGroundDistance(MapNum, MapNpcNum) <> 0 Then
            Do While CheckNpcGroundDistance(MapNum, MapNpcNum) <> 0
                Call SetMapNpcY(MapNum, MapNpcNum, GetNpcY(MapNum, MapNpcNum) + 1)

                If CheckNpcGroundDistance(MapNum, MapNpcNum) = 0 Then
                    Exit Do
                End If
            Loop
        End If
    End If
```
that will make it so if a npc is not on a block tile (what I use for ground) or he fall until he hits a ground tile.

```
                'gravity players
                For I = 1 To MAX_PLAYERS
                    If IsPlaying(I) Then
                        If CheckGroundDistance(I) <> 0 Then
                            'calculate fall damage
                            Call SetPlayerHP(I, ((GetPlayerHP(I) - CheckGroundDistance(I)) + 1))
                            Call SendHP(I)

                            If GetPlayerHP(I) = 0 Then
                                Call KillPlayer(I)
                            End If

                            'drop the player (and sometimes to his doom :D)
                            Do While CheckGroundDistance(I) <> 0
                                If GetTickCount > PULLINGDELAY + 150 Then 'delay for jumping This will build up per tile makes it alot easier to double jump
                                Call PlayerWarp(I, GetPlayerMap(I), GetPlayerX(I), GetPlayerY(I) + 1)     
                                PULLINGDELAY = GetTickCount
                                End If
                            Loop
                        End If
                    End If
                Next I
```
will do the same thing for players

add this functions

```
Function CheckGroundDistance(ByVal index As Long)
Dim GroundDistance As Integer

Dim Y As Integer

        For Y = 0 To 20
            Dim var3 As Integer
            Dim distancey As Integer

            var3 = Map(GetPlayerMap(index)).Tile(GetPlayerX(index), Y).Type

                If var3 = TILE_TYPE_BLOCKED Then
                    GroundDistance = ((Y - GetPlayerY(index)) - 1)
                        If GroundDistance >= 0 Then
                            CheckGroundDistance = GroundDistance
                            Exit For
                    End If
                End If
        Next Y
End Function
``````
Function CheckNpcGroundDistance(ByVal MapNum As Long, ByVal MapNpcNum As Long)
Dim GroundDistance As Integer

Dim Y As Integer

        For Y = 0 To 20
            Dim var3 As Integer
            Dim distancey As Integer

            var3 = Map(MapNum).Tile(GetNpcX(MapNum, MapNpcNum), Y).Type

                If var3 = TILE_TYPE_BLOCKED Then
                    GroundDistance = ((Y - GetNpcY(MapNum, MapNpcNum) - 1))
                        If GroundDistance >= 0 Then
                            CheckNpcGroundDistance = GroundDistance
                            Exit For
                        End If
                End If
        Next Y
End Function

```
```
Public Function KillPlayer(index)

    If IsPlaying(index) Then
        Call SetPlayerHP(index, 0)

        If SCRIPTING = 1 Then
            MyScript.ExecuteStatement "Scripts\Main.txt", "OnDeath " & index
        Else
            If Map(GetPlayerMap(index)).BootMap > 0 Then
                Call PlayerWarp(index, Map(GetPlayerMap(index)).BootMap, Map(GetPlayerMap(index)).BootX, Map(GetPlayerMap(index)).BootY)
            Else
                Call PlayerWarp(index, START_MAP, START_X, START_Y)
            End If
        End If

        Call SetPlayerHP(index, GetPlayerMaxHP(index))
        Call SetPlayerMP(index, GetPlayerMaxMP(index))
        Call SetPlayerSP(index, GetPlayerMaxSP(index))

        Call SendHP(index)
        Call SendMP(index)
        Call SendSP(index)
    End If
End Function
```
Link to comment
Share on other sites

@DDuИ༐t:

> Is this laggy?

depends how you use it. it will be laggy if you put the check in a vb6 timer as the timers are off by a bit *cought* use gettickcount *cought*. The code its self is not laggy.
Link to comment
Share on other sites

@zidsal:

> depends how you use it. it will be laggy if you put the check in a vb6 timer as the timers are off by a bit *cought* use gettickcount *cought*. The code its self is not laggy.

Wow, why would you release this? It's not even complete… trying to get credit?
Link to comment
Share on other sites

it does everything I said in the title and did I ever say credit me in the post no?. There's nothing wrong with realising it. I will put a declaimers in first post after thinking about it about how its not up to your perfect coding skills.

all you would need to do is add jumping which would be adding to player rec and then when he jumps set the players jumping value to 1 and in the falling code check to see if the the jumping value is 0 and if it is 0 carry on the code else the player must be jumping so leave him to it.
Link to comment
Share on other sites

@zidsal:

> it does everything I said in the title and did I ever say credit me in the post no?. There's nothing wrong with realising it. I will put a declaimers in first post after thinking about it about how its not up to your perfect coding skills.
>
> all you would need to do is add jumping which would be adding to player rec and then when he jumps set the players jumping value to 1 and in the falling code check to see if the the jumping value is 0 and if it is 0 carry on the code else the player must be jumping so leave him to it.

When did I say I had perfect coding skills?
Link to comment
Share on other sites

@MrMiguuâ„¢:

> When did I say I had perfect coding skills?

http://www.thefreedictionary.com/patronizing

Now unless you have anything to add to the conversation I would appreciate it you left as this is only going to end in flaming.
Link to comment
Share on other sites

@Zultar:

> lol v-rage.. and zidsal if this isnt your code and it's mostly mrmiguu's i doubt you have any business releasing this. unless you made this by yourself

He himself has done it, don't put up accusations witouth proof.
Link to comment
Share on other sites

Please guys… refrain from the flame wars. To clarify the situation: it was mostly my fault for causing this "flame-war" due to the fact that I was upset for him releasing code relevant to gravity and jump. I don't care anymore but I was mad at the time that I posted because I wanted to be the only person to release any sort of side-scrolling features for Eclipse on the forums. He beat me to it, that's all.
Link to comment
Share on other sites

here are the facts:

1.MrMiguu SS was created way before this. This is just the simple basics all you would need is some form of jumping to finish the basics.

2\. I did test this currently:
it is possible to jump over 1 square and if running 2 squares but thats only if you put it in a sub like GameAi because vb6 timers are shit.

I would suggest putting this in a function that activates when gravity needs to happen e.g playermove sub or another sub that is constanly running.
If your going to go about this using playermove sub and you are NOT going to use a jump button you will need to extend gettickcount (currently set to 150ms I thing). Otherwise it will be impossible to move up :D.

3\. There is currently 1 error that can crash the server. If a player is below block tiles he will fall. If there are no bock tiles to fall onto he will fall off the map and crash the server. Should not be too hard to fix just add a check on the x axis to see if going to fall off the map aka.

```
if player(i) <= 29 (map ends at 30 I thing) then
exit do
end if
```
4\. **I did forget to mention I would like to thank V rage who helped me work out how to calculate how close someone is to a blocked tile.** I will update the first post now.

5\. Although I had some help fomr Vrage this is my work.
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...