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

GlobalEvent Random Encounter

tetra20

DD
Joined
Jan 17, 2009
Messages
1,315
Solutions
4
Reaction score
323
Location
Egypt
I Think The Thread Name Already Tells what Does This Mean I Will Begin By Screenshots
While Walking In Town or Hunting.. You May Trigger A RE
Before I Start i would Like To SAY
Sorry For This Noobie Npc i really sux at npcs Script
Here The Npc Summon
4ieuma.png

Here I Ask Him For A Quest
ll1s3.png

Here I Finish My Quest And The Npc Appear to Take His Wallet Back
nfi7o9.png

In globalevent/scripts/retimer.lua
Code:
function isWalkable(cid, pos)
pos.stackpos = 0
if getTileThingByPos(pos).uid ~= 0 then
local n = getTileInfo(pos)
if n.protection == false and n.house == false and getTopCreature(pos).uid == 0 and doTileQueryAdd(cid, pos) == RETURNVALUE_NOERROR then
return true
end
end
end

function onThink(interval)
local random = math.random(1,1000)
local list = getPlayersOnline()
  if (#list == 0) then
  return true
  end
local winner = list[math.random(#list)]
   if random == 1 and table.maxn(list) ~= 0 and getPlayerName(winner) ~= "Account Manager" and getPlayerStorageValue(winner, 12345) == 0 and isWalkable(winner, getThingPos(winner)) then
     local summon = doCreateNpc("pilaster", getThingPos(winner))
     doPlayerSetStorageValue(winner, 12345, 1)
     doCreatureSetNoMove(winner, true)
     doPlayerSendTextMessage(winner, 25, "Pilaster Is Following you For an Unknown Reason.Find Out Why(The Npc Will Leave in 5 Minutes).")
     for mw = 1, 20 do
     local o = 20 - mw
     addEvent(doSendMagicEffect, mw * 1000, getThingPos(summon), 49)
     end
     if summon then
     addEvent(doRemoveCreature,5*60*1000 ,summon)
     end
     addEvent(doCreatureSetNoMove,2*1000,winner,false)
     addEvent(doPlayerSetStorageValue,5*60*1000,winner,12345,0)
   end
   return true
end
In globalevents/globalevent.xml
Code:
<globalevent name="retimer" interval="120000" event="script" value="retimer.lua"/>
Now In Creaturescripts/scripts/re1.lua
Code:
function onKill(cid, target, damage, flags)
local random = math.random(1,15)
   if isPlayer(cid) and isMonster(target) and getPlayerStorageValue(cid, 4904) == 1 and random <= 5 then
   doCreateNpc("pilaster", getThingPos(cid))
   doPlayerSendTextMessage(cid, 25, "Pilaster Have Been Following you in Stealth Find out What he want..")
   doPlayerSetStorageValue(cid, 12345, 2)
   end
   return true
end
In Creaturescripts/scripts/logout.lua
Code:
function onLogout(cid)
   doPlayerSetStorageValue(cid, 12345,0) --re storage
   return true
end
In Creaturescripts/Creaturescripts.xml
Code:
<event type="kill"   name="re1" event="script" value="re1.lua"/>
  <event type="logout" name="PlayerLogout" event="script" value="logout.lua"/>
In Creaturescripts/Login.lua
Code:
registerCreatureEvent(cid, "re1")
Now In Npcs/scripts/pilaster.lua
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
function onCreatureAppear(cid)  npcHandler:onCreatureAppear(cid)  end
function onCreatureDisappear(cid)  npcHandler:onCreatureDisappear(cid)  end
function onCreatureSay(cid, type, msg)  npcHandler:onCreatureSay(cid, type, msg)  end
function onThink()  npcHandler:onThink()  end
function creatureSayCallback(cid, type, msg)
   local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
   local storage = 12345
   if(msgcontains(msg, 'quest') or msgcontains(msg, 'help')) then
     if getPlayerStorageValue(cid,storage) == 1 then
       npcHandler:say("I Have Been Wandering Around Searching for my Lost Wallet if you can Find it I will reward you.I Think I Lost it In The Sewer While Fighting A Rotowrm Try killing Some Rotworms until you find it.You Can Find me Near The Bank After You Find My Wallet", cid)
       doRemoveCreature(getNpcCid())
       npcHandler:releaseFocus(cid)
       setPlayerStorageValue(cid, 4904, 1)
     else
       npcHandler:say("Sorry But This Random Encounter isn't to you", cid)
     end
   end
   if msgcontains(msg, 'done') then
      if getPlayerStorageValue(cid, storage) == 2 then
       npcHandler:say("Thank You This is My Wallet.Here is your Reward 2 CC", cid)
       setPlayerStorageValue(cid, storage, 0)
       setPlayerStorageValue(cid, 4904, 0)
       doPlayerAddItem(cid, 2160, 2)
       doRemoveCreature(getNpcCid())
       npcHandler:releaseFocus(cid)
     else
     npcHandler:say("You Don't Have My wallet go Search For It", cid)
     end
   end
   return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
In Npcs/Pilaster.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Pilaster" script="pilaster.lua" walkinterval="0" floorchange="0">
   <health now="100" max="100"/>
   <look type="128" head="17" body="54" legs="114" feet="0" addons="2"/>
   <parameters>
     <parameter key="message_greet" value="Hi |PLAYERNAME|.Please Say {quest} if you want to hear my Story or say {done} to finish the quest."/>
   </parameters>
</npc>
How Does This Work?
While Moving Around.You May Encounter A Random Encounter.And it should either give you a quest or a Free Item.You Should make more Scripts or edit This One.

Why I Made It Abit Complicated (Not Organized)
1-Cause i don't want a really ignorant one who don't know how to edit a simple Lua to use it
2-Cause i got no time to organize it so if you want to use it then oragnize it :)

The Chance of a RE is 0.01% and in every 2 minutes if the chance == 0.01% 1 player may trigger an re

Thats All.
Have Fun
---Edit
Multi Re's Script
Code:
function isWalkable(cid, pos)
pos.stackpos = 0
if getTileThingByPos(pos).uid ~= 0 then
local n = getTileInfo(pos)
if n.protection == false and n.house == false and getTopCreature(pos).uid == 0 and doTileQueryAdd(cid, pos) == RETURNVALUE_NOERROR then
return true
end
end
end

function onThink(interval)
local random = math.random(1,3)
local list = getPlayersOnline()
local npcs = {
   ["Pilaster"] = {storageid=12345}
   ---Npc Name = Random Encounter Storage
   }
 
   if (#list == 0) then
     return true
  end
   local winner = list[math.random(#list)]
   if random == 1 and table.maxn(list) ~= 0 and getPlayerName(winner) ~= "Account Manager" and getPlayerStorageValue(winner, 12345) == 0 and isWalkable(winner,getThingPos(winner)) then
     for i,v in pairs(npcs) do
       local summon = doCreateNpc(i, getThingPos(winner))
       doPlayerSetStorageValue(winner, v, 1)
       doCreatureSetNoMove(winner, true)
       doPlayerSendTextMessage(winner, 25, "Pilaster Is Following you For an Unknown Reason.Find Out Why(The Npc Will Leave in 5 Minutes).")
         for mw = 1, 20 do
           local o = 20 - mw
           addEvent(doSendMagicEffect, mw * 1000, getThingPos(summon), 49)
         end
           if summon then
           addEvent(doRemoveCreature,5*60*1000 ,summon)
           end
       addEvent(doCreatureSetNoMove,2*1000,winner,false)
       addEvent(doPlayerSetStorageValue,5*60*1000,winner,v,0)
     end
   end
   return true
end
NOT TESTED
 
Last edited:
Back
Top