Gothrim
New Member
- Joined
- Jan 23, 2009
- Messages
- 20
- Reaction score
- 0
I've got another problem and it's hard to bite.
I'm trying to make animals reproduce themselves.
What i mean?
For example, there is a pig...
After 60 * 60 * 1000 ticks a pig is spawning another pig...
Now, there is 2 pigs and both of them after ticks is spawning another pig...
That same with wolves, deers, rabbits, dogs, cats, rats, chickens...
I've made it thus
creaturescripts - rat.lua
But onThink is bad(i mean - he is turning on this script every 1 second. I think that should be laggy)
and math.random is very, very bad - there is a 1200 frequency for a rat... That means the chances for a new rat in one second is 1 to 1200 and 1 to 20 for a rat spawn in a minute... Where is a problem?
If there is a 2 rats, the chance is 1 to 10 for a rat in a minute... if there is 20 rats its one to one, that means in every minute there will be a rat...
As you see, it's too much - i need a constant value of time to control birthrate of animals.
Thanks for all your help.
I'm trying to make animals reproduce themselves.
What i mean?
For example, there is a pig...
After 60 * 60 * 1000 ticks a pig is spawning another pig...
Now, there is 2 pigs and both of them after ticks is spawning another pig...
That same with wolves, deers, rabbits, dogs, cats, rats, chickens...
I've made it thus
creaturescripts - rat.lua
Code:
function onThink(cid)
local freq = 1200
if(math.random(1, freq) == 1) then
doCreateMonster("rat", getCreaturePosition(cid))
else
return false
end
end
But onThink is bad(i mean - he is turning on this script every 1 second. I think that should be laggy)
and math.random is very, very bad - there is a 1200 frequency for a rat... That means the chances for a new rat in one second is 1 to 1200 and 1 to 20 for a rat spawn in a minute... Where is a problem?
If there is a 2 rats, the chance is 1 to 10 for a rat in a minute... if there is 20 rats its one to one, that means in every minute there will be a rat...
As you see, it's too much - i need a constant value of time to control birthrate of animals.
Thanks for all your help.