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

Problems with scripts


Sealbreaker
 Share

Recommended Posts

since i want to script more… but often get problems i am goin to make this to my: sealbreakers problems with scripts thread =P
so... here's my next problem..... its supposed to be a script for a chest... you double klick ( open ) it and with a bit luck you get a cool item....

```
Case 1
Call Rand(1,100)
If Rand(1, 100) > 78 Then
Call PlayerMsg(index, "Suddenly you see a bright light coming out of the chest", BLACK )
Call GiveItem (index, #, 1)
Call TakeItem(index, #, 1)
If Rand(1, 100) < 10
Call PlayerMsg(index, "you jump in the air as you see what is in the chest", BLACK )
Call GiveItem (index, #, 1)
Call TakeItem(index, #, 1)
Else
Call PlayerMsg(index, "Inside the chest is nothing", RED)
Call TakeItem(index, #, 1)
End if
Exit Sub

```
Link to comment
Share on other sites

The code "Call Rand(1,100)" will not work.  Rand() is a function, not a sub; it just calculates the random of two numbers; also, you're calculating Rand() more then once; it's not like it stores it for you; so the first time you calculate it, it could return 3, then the second time it returns 81, thus making it bring "Inside the chest is nothing".

If you want it to recheck the same number if it doesn't meet the first criteria, you could always store it in a local variable (more on that in afew).

```
If Rand(1, 100) < 10

```Should be:
```
Elseif Rand(1, 100) < 10

```
So it'd be:
```
Case 1
Call Rand(1,100)
If Rand(1, 100) > 78 Then
Call PlayerMsg(index, "Suddenly you see a bright light coming out of the chest", BLACK )
Call GiveItem (index, #, 1)
Call TakeItem(index, #, 1)
ElseIf Rand(1, 100) < 10
Call PlayerMsg(index, "you jump in the air as you see what is in the chest", BLACK )
Call GiveItem (index, #, 1)
Call TakeItem(index, #, 1)
Else
Call PlayerMsg(index, "Inside the chest is nothing", RED)
Call TakeItem(index, #, 1)
End If
Exit Sub

```
With a variable added (and with that faulty "Call Rand()" taken out), it would be:
```
Case 1
Dim MyRandomVariable
MyRandomVariable = Rand(1,100)
If MyRandomVariable > 78 Then
Call PlayerMsg(index, "Suddenly you see a bright light coming out of the chest", BLACK )
Call GiveItem (index, #, 1)
Call TakeItem(index, #, 1)
ElseIf MyRandomVariable < 10
Call PlayerMsg(index, "you jump in the air as you see what is in the chest", BLACK )
Call GiveItem (index, #, 1)
Call TakeItem(index, #, 1)
Else
Call PlayerMsg(index, "Inside the chest is nothing", RED)
Call TakeItem(index, #, 1)
End If
Exit Sub

```
Also, you need Godlord's inventory script to use this code (the TakeItem and GiveItem).
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...