• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua OnUse Monster

Joined
May 23, 2010
Messages
185
Reaction score
23
Hi, how can i make a script that you can only use the item if you had killed gs, demon and behemoth? rep+
 
so you mean you want it so that if you've managed to kill a (for example) demon you'll then be able to use something?

you'll have to add a small script in Creaturescripts

give me like... 10 mins and i'll have it written
 
ok... here we go... I haven't tested this but the theory all works...


in Login.lua (creaturescripts) add:
Code:
registerCreatureEvent(cid, "KillRequirement")

in Creaturescripts.xml add:
Code:
<event type="kill" name="KillRequirement" event="script" value="killrequirement.lua"/>

in (we'll use Demon as an example) monsters/Demons/Demon.xml before </monster> add:
Code:
<script>
	<event name="KillRequirement"/>
</script>

create a file called killrequirement.lua in creaturescripts/scripts, in it put:
Code:
function onKill(cid, target, lastHit)

local demonstorage = 10001
local demonkilled = getPlayerStorageValue(cid,demonstorage)
local creature = getCreatureName(target)
 
if creature == "demon" then
      if demonkilled == -1 then
           doCreatureSetStorage(cid, demonstorage, 1)
      end
end			

end

to add more creatures, for example a rat, all you have to do is add:
Code:
local ratstorage = 10002
local ratkilled = getPlayerStorageValue(cid,demonstorage)
below the line local
Code:
demonkilled = getPlayerStorageValue(cid,demonstorage)

then below:
Code:
if creature == "Demon" then
      if demonkilled == -1 then
           doCreatureSetStorage(cid, demonstorage, 1)
      end
end
add:
Code:
if creature == "rat" then
      if ratkilled == -1 then
           doCreatureSetStorage(cid, ratstorage, 1)
      end
end

don't forget to add this script in EVERY monster you want to use for this script:
Code:
<script>
	<event name="KillRequirement"/>
</script>


hope this works, like I said I haven't tested it and I'm creating it inside this post window lol, i'll make a full tutorial later, next post will be how to make a lever you need to have killed a demon to use =)
 
ok... this part will be short and sweet, but it will basically check if the player has killed the demon, and if the player hasn't it will tell them they need to kill a demon, otherwise it'll teleport them to the place we set at the start of the script

first of all we need to go into the actions folder, in actions.xml you need to add the lines:
Code:
<!-- Kill Requirement Lever -->
<action actionid="10203" event="script" value="killrequirement.lua"/>
(the first line is just to make finding scripts in actions.xml easier, it's not a requirement)
then in the scripts folder make a new file named killrequirement.lua

in this file paste this code, i'll explain everything after:
Code:
function onUse(cid, item, frompos, item2, topos)

local demonstorage = 10001
local demonteleport = {x=1133, y=959, z=7} --Location to teleport to on the map if you pull the lever

        --Demon Kill
   	if item.uid == 10001 then
   		queststatus = getPlayerStorageValue(cid,demonstorage)
   		if queststatus == 1 then
                        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have defeated a demon, therefore you can pass.")
                        doTeleportThing(cid,demonteleport)
	                doSendMagicEffect(demonteleport,10)
   		else
   			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You need to defeat a demon to use this lever.")
   		end
	end

end

Ok, to make things simple I've made it so in the map you set the ActionID of the lever to 10203 so it knows which script to use, then you set the UniqueID to the storage for that monster, for example the Demon Lever will be: Actionid - 10203, Uniqueid - 10001.
You can replace the line under queststatus == 1 to anything you want until the "else" line, for example you may want to make it so they learn a spell or get an item (but this will require more work, as you'll need another storage added so they can't just keep pulling it)


Any problems just say :)
 
Back
Top