• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[Request]Monster procreation ;)

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
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.
 
creaturescripts.xml
Code:
	<event type="think" name="Procreation" event="script" value="procreation.lua"/>
procreation.lua
Code:
local x = {}
local time = 1 * 60 * 60
function onThink(cid, interval)
	if not x[cid] then
		x[cid] = os.time() + time
	elseif os.time() >= x[cid] then
		x[cid] = os.time() + time
		local v = doCreateMonster(getCreatureName(cid), getThingPos(cid), false)
		if isCreature(v) then
			doSendMagicEffect(getThingPos(v), CONST_ME_TELEPORT)
		end
	end
	return true
end
monster file
Code:
	<script>
		<event name="Procreation"/>
	</script>
 
Back
Top