• 0

# Quest dont work

## Question

```quest drop begin
state start begin
when kill with not npc.is_pc() and math.random(100) >= 99 begin
local mob_lvl=npc.get_level()
local player_level=pc.get_level()
if player_level - mob_lvl <= 15 and player_level - mob_lvl >= -15 then
game.drop_item_with_ovnership(50133,1)
end
end
end
end```

Why quest dont work i kill many spot monster and any drop box why ?

And wher change % drop ?

• Created

## Recommended Posts

• 0

math.random(100) >= 99 - change % drop

So, only 99 and 100.

Change to:

math.random(100) >= 50

• 0

Soo its a lv who cane drop ?

• 0

NO!
From 100 kill the script runs only 2 times. I think that you have to check the level BEFORE number/math.random.

```quest drop begin
state start begin
when kill with not npc.is_pc() begin
local mob_lvl=npc.get_level()
local player_level=pc.get_level()
if player_level - mob_lvl <= 15 and player_level - mob_lvl >= -15 then
local chance = 2 -- percent, change if you want!
if number(1,100) > (100-chance) then
game.drop_item_with_ovnership(50133,1)
end
end
end
end
end```

\$ uptime
1:26AM  up 732 days,  8:29, 1 user, load averages: 0.38, 0.31, 0.22

\$ uname -srp
FreeBSD 9.1-RELEASE amd64

• 0

If you type just 1 argument in math.random it returns 1.

On this way it should work: math.random(1,100)

• 0
```\$ lua51
Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio
> print(math.random(100))
85
>
```

math.random ([m [, n]])

This function is an interface to the simple pseudo-random generator function rand provided by ANSI C. (No guarantees can be given for its statistical properties.)

When called without arguments, returns a uniform pseudo-random real number in the range [0,1). When called with an integer number m, math.random returns a uniform pseudo-random integer in the range [1, m]. When called with two integer numbers m and n, math.random returns a uniform pseudo-random integer in the range [m, n].

I don't know how it works in 5.0, but i think it's the same...

\$ uptime
1:26AM  up 732 days,  8:29, 1 user, load averages: 0.38, 0.31, 0.22

\$ uname -srp
FreeBSD 9.1-RELEASE amd64

• 0
• VIP

I think you don't have npc.get_level function in your game

• 0
```quest drop begin
state start begin
when kill with not npc.is_pc() and math.random(1,100) >= 99 begin
local mob_lvl=npc.get_level(npc.get_race())
local player_level=pc.get_level()
if player_level - mob_lvl <= 15 and player_level - mob_lvl >= -15 then
game.drop_item_with_ownership(50133,1)
end
end
end
end```

this work

• 0
```local SUCCESS_ODD = 65	-- Success odds 65 means 65%

if math.random(1,100) <=  SUCCESS_ODD then

end```

This is way better than the others above

• 0

You can test easily what math.random(100) returns with Lua 5.0

Just use this check output: syschat(math.random(100))

I tried it again in Lua 5.2 and i just got a 1 all the time.

• 0

@iRemix: That is because you are not seeding again.

Do

`math.randomseed(os.time()) -- or math.randomseed(get_global_time())`

before the syschat.

• 1
• 0

In my 5.2 IDE i get always the same number with math.random(100)

Doesn't matter if i use math.randomseed or not.

But well, i tested it ingame with math.random(100) and it worked (without math.randomseed).

• 1
• 0

Hmm, that's weird. Make sure you are seeding with time, otherwise the number will always be the same.

But well, i tested it ingame with math.random(100) and it worked (without math.randomseed).

The game seeds automatically possibly (random guess xD)

• 0

Maybe this is not a coincidence that we have a number() quest function.

• 1

\$ uptime
1:26AM  up 732 days,  8:29, 1 user, load averages: 0.38, 0.31, 0.22

\$ uname -srp
FreeBSD 9.1-RELEASE amd64

## Create an account

Register a new account

1. 4

2. 1

3. 1

4. 12

5. 3

6. 2

7. 135

8. 2

9. 74

• ### Recently Browsing

×

• Marketplace

• #### Tools

×
• Create New...