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

Withdraw bug


willunited
 Share

Recommended Posts

Similiar topic is here: [http://www.touchofde…s-of-my-money/.](http://www.touchofdeathforums.com/community/index.php?/topic/128955-engine-is-jealous-of-my-money/.)

Eclipse does have a small problem with overflow. Here's a fix which will **STOP** the player from gaining gold after a certain amount. Note that it will not put the overflow into another stack, which would be a better idea.

* * *

Server-side

Add (anywhere):

```

' Returns 0, if there is no overflow, or the overflow, if one exists. '

Public Function AddCheckOverflow(ByVal a As Currency, ByVal b As Currency) As Long ' Currency is 8 bytes, as opposed to Long's 4 bytes. ''

If a + b > 2147483647 Then ' 2147483647 = 2**31 - 1 '

AddCheckOverflow = CLng((a - 2147483647) + ![B)](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/cool.png)

Else

AddCheckOverflow = 0

End If

End Function

```

Then replace Function GiveInvItem with the following function:

```

Function GiveInvItem(ByVal index As Long, ByVal itemnum As Long, ByVal ItemVal As Long, Optional ByVal sendUpdate As Boolean = True) As Boolean

Dim i As Long

' Check for subscript out of range

If IsPlaying(index) = False Or itemnum <= 0 Or itemnum > MAX_ITEMS Then

GiveInvItem = False

Exit Function

End If

i = FindOpenInvSlot(index, itemnum)

' Check to see if inventory is full

If i <> 0 Then

If AddCheckOverflow(GetPlayerInvItemValue(index, i), ItemVal) <> 0 Then

ItemVal = 2147483647 - GetPlayerInvItemValue(index, i)

End If

Call SetPlayerInvItemNum(index, i, itemnum)

Call SetPlayerInvItemValue(index, i, GetPlayerInvItemValue(index, i) + ItemVal)

If sendUpdate Then Call SendInventoryUpdate(index, i)

GiveInvItem = True

Else

Call PlayerMsg(index, "Your inventory is full.", BrightRed)

GiveInvItem = False

End If

End Function

```

There are probably more errors like this.
Link to comment
Share on other sites

Not necessarily an error, just people being silly and not understanding the bounds of a LONG value and various other ones(And nobody ever implementing a proper solution, but then again why would you ever have such abysmal amounts of gold in your game?).
Link to comment
Share on other sites

Soul it is not working. MAX_LONG was undefined, i defined it in modConstants server side.

I am getting the overflow error at picking up currency from map, so how to fix it?

If i paste the same code into "Sub PlayerMapGetItem(ByVal index As Long)" i get undefined ItemVal error
Link to comment
Share on other sites

> Soul it is not working. MAX_LONG was undefined, i defined it in modConstants server side.

Sorry about that, I thought I changed it everywhere but I must have missed that one spot.

> If i paste the same code into "Sub PlayerMapGetItem(ByVal index As Long)" i get undefined ItemVal error

You can't just copy and paste it around, it's not a general solution. Also all of these checks should be done server-side.

Anyway, in PlayerMapGetItem server-side, change:

```

Call SetPlayerInvItemValue(index, n, GetPlayerInvItemValue(index, n) + MapItem(mapNum, i).Value)

```

to:

```

If AddCheckOverflow(GetPlayerInvItemValue(index, n), MapItem(mapNum, i).Value) = 0 Then

Call SetPlayerInvItemValue(index, n, GetPlayerInvItemValue(index, n) + MapItem(mapNum, i).Value)

Else

Call SetPlayerInvItemValue(index, n, 2147483647)

End If

```

* * *

So here's a generalization.

Change:

```

Call SetPlayerInvItemValue(index, n, a + ![B)](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/cool.png)

```

to:

```

If AddCheckOverflow(GetPlayerInvItemValue(index, n), MapItem(mapNum, i).Value) = 0 Then

Call SetPlayerInvItemValue(index, n, a + ![B)](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/cool.png)

Else

Call SetPlayerInvItemValue(index, n, 2147483647)

End If

```

* * *

> Not necessarily an error, just people being silly and not understanding the bounds of a LONG value and various other ones(And nobody ever implementing a proper solution, but then again why would you ever have such abysmal amounts of gold in your game?).

I agree, but the engine should always be fool-proof, and not crash if someone was to manage to somehow exploit the game to gain that much gold, or if someone decides to add too much gold.
Link to comment
Share on other sites

> but then again why would you ever have such abysmal amounts of gold in your game?).

2,147,483,647

2.1 Bil? I know runescape players with 1 Trillion. The truth is, the higher the number, it makes the player feel rich, and sends a subliminal message that makes them want to play more. That's why you would have such abysmal amounts of gold ^-^
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...