• 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!

[CreatureEvent] Replace monster

Savly

Member
Joined
Jan 28, 2012
Messages
316
Reaction score
21
I'm using TFS 0.3.6 8.6.
I need a script that replaces a monster when you attack it.
Example: You see a rat, you click attack and it becomes a skunk.

Of course this would make no sense, but it's an example to make the idea more clear.
It will be replaced with a monster with the same name and looktype, just the name in monsters.xml will be different.
Why I want this?
To make non hostile monsters become hostile when you attack them.
 
Here you go:

First go to creaturescripts/creaturescripts.xml and add this line below:
Lua:
<event type="target" name="Transform" event="script" value="transform.lua"/>

Then goto Creaturescripts/scripts/login.lua and add this line under "function onLogin(cid)":
Lua:
registerCreatureEvent(cid, "Transform")

Now create new lua inside Creaturescripts/scripts and name it "transform" and paste the code below:
Lua:
local Cyko = {
	target = "Rat",
	transform = "Skunk"
}

function onTarget(cid, target)
	if isPlayer(cid) then
		if isMonster(target) and getCreatureName(target) == Cyko.target then
		doRemoveCreature(target)
		doCreateMonster(Cyko.transform, getThingPos(cid))   
		return false
	else
		return true
		end
	end
end

Enjoy!
 
Thanks :)
Is it possible to make it in a way that it spawns on the same place as the old monster? so a person doesn't see it gets replaced.
 
Last edited:
Lua:
local c = {
	target = "Rat",
	transform = "Skunk"
}
 
function onTarget(cid, target)
	if isPlayer(cid) then
								--getCreatureMaster(target) == nil for 0.4
								--getCreatureMaster(target) ~= target for 0.3.6
		if isMonster(target) and getCreatureMaster(target) == nil and getCreatureName(target):lower() == c.target:lower() then
			local newPos = getCreaturePosition(target)
			doRemoveCreature(target)
			doCreateMonster(c.transform, newPos)   
			return false
		else
			return true
		end
	end
end
 
Perfect, nice that it also checks if it's a summen, didn't even thought of that :)

Just have 1 question
Lua:
getCreatureMaster(target) ~= target
What does ~= mean? (just to learn, so I can make more scripts myself)
 
Perfect, nice that it also checks if it's a summen, didn't even thought of that :)

Just have 1 question
Lua:
getCreatureMaster(target) ~= target
What does ~= mean? (just to learn, so I can make more scripts myself)

This is a "not" operator which checks if one value is different than second.
 
Back
Top