Dantez
Moim sekretem jest ciasto
- Joined
- May 22, 2008
- Messages
- 1,206
- Reaction score
- 202
Author: Dantez
Version: 1.0
Platform: The Forgotten Server 0.3.6pl1
Version: 1.0
Platform: The Forgotten Server 0.3.6pl1
Dzia?anie:
Mini World Change polegaj?cy na remontowaniu domku za pomoc? np. drewna. Trzeba uzbiera? X item?w o ID Y, kt?re licz? si? dla ca?ego serwera. Po uzbieraniu X ilo?ci, domek zostaje wyremontowany i mo?e otworzy? nam przej?cie np. do skrzynki, expa, czy innego NPC - wszystko zale?y od konfiguracji/mapy. World change trwa do restartu serwera.NPC Keywords:
house - kr?tkie infowood - zabiera drewno
left - pokazuje ile drewna brakuje do uko?czenia
Konfiguracja:
[LUA]pos = {{STARTPOS_1, ENDPOS_1}, {STARTPOS_2, ENDPOS_2}},[/LUA]Tablica do modyfikacji domku.
[LUA]itemRequired = ID_PRZEDMIOTU,
itemRequiredCount = ILO??_PRZEDMIOT?W,[/LUA]
Skrypt:
Tablica potrzebna do tamtego kodu:[LUA]['woodenHouseEvent'] = {
[5268] = {1036, 5155, 5154},
[5274] = {1036, 5155, 5154},
[5275] = {1036, 5155, 5154},
[5270] = {1037, 5152, 5153},
[5272] = {1037, 5152, 5153},
[5273] = {1037, 5152, 5153},
[5278] = 1213,
[5279] = 1213,
[5280] = 1214,
[5282] = 1210,
[5283] = 1211,
[5276] = 1263,
[5277] = 1264,
[9224] = 405,
[9225] = 405,
[9226] = 405,
[9227] = 405,
[9228] = 405,
[9229] = 405,
[9230] = 405,
[9231] = 405,
[9232] = 405,
[5502] = 1754,
[5503] = 1755,
[2784] = 0,
[5298] = 0,
[5747] = 0,
[5708] = 0,
[6220] = 0,
[6221] = 0,
[5265] = 1042,
[5263] = 1038,
}[/LUA]
npc/Elpis.xml
[XML]<?xml version="1.0" encoding="UTF-8"?>
<npc name="Elpis" script="WoodenHouseEvent.lua" walkinterval="2000" floorchange="0">
<health now="100" max="100"/>
<look type="153" head="57" body="59" legs="40" feet="76" addons="0"/>
</npc>[/XML]
npc/scripts/WoodenHouseEvent.lua
[LUA]local config = {
worldStateStorage = 7432,
worldCountStorage = 7433,
itemRequired = 5901,
itemRequiredCount = 1000,
WoodenEventTable = "woodenHouseEvent",
pos = {{{x=960, y=1008, z=7}, {x=968, y=1012, z=7}}, {{x=964, y=1008, z=6}, {x=968, y=1012, z=6}}},
}
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
function onCreatureAppear(cid) npcHandlernCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandlernCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandlernCreatureSay(cid, type, msg) end
function onThink() npcHandlernThink() end
function greetCallback(cid)
if(getStorage(config.worldStateStorage) == 1) then
npcHandler:setMessage(MESSAGE_GREET, "Thanks for your help, you guys are the best.")
else
npcHandler:setMessage(MESSAGE_GREET, "Hey! Can you help me rebuild my {house}?")
end
return true
end
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
local worldCount = getStorage(cid, config.worldCountStorage)
if(msgcontains(msg, 'house')) then
if(getStorage(config.worldStateStorage) < 1) then
selfSay("I need {wood} to repair the walls. Can you bring some?", cid)
talkState[talkUser] = 1
else
selfSay("I have everything I wanted. Thanks.", cid)
end
elseif(msgcontains(msg, 'wood') and talkState[talkUser] == 1) then
local count = getPlayerItemCount(cid, config.itemRequired)
talkState[talkUser] = 0
if(count > 1) then
count = worldCount + count > config.itemRequiredCount and config.itemRequiredCount - worldCount or count
doPlayerRemoveItem(cid, config.itemRequired, count)
doSetStorage(config.worldCountStorage, worldCount + count)
selfSay("Thanks for " .. count .. " wood.", cid)
if(worldCount + count >= config.itemRequiredCount) then
selfSay("Now I can rebuild my house. Thanks all!")
doSetStorage(config.worldCountStorage, 0)
doSetStorage(config.worldStateStorage, 1)
for _, v in pairs(config.pos) do
chunk(v[1], v[2], config.WoodenEventTable)
end
end
else
selfSay("You do not have any wood.", cid)
end
elseif(msgcontains(msg, 'left')) then
if(getStorage(config.worldStateStorage) < 1) then
selfSay("Still " .. config.itemRequiredCount - worldCount .. " wood chunks left.", cid)
else
selfSay("I've already rebuilded my house.", cid)
end
end
return true
end
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())[/LUA]
globalevents.xml
[XML]<globalevent name="WoodenHouseWorldChange" type="start" event="script" value="WoodenHouseWorldChange.lua"/>[/XML]
globalevents/WoodenHouseWorldChange.lua
[LUA]local config = {
worldStateStorage = 7432,
worldCountStorage = 7433,
}
function onStartup()
doSetStorage(config.worldCountStorage, 0)
doSetStorage(config.worldStateStorage, 0)
return true
end[/LUA]