Zysen
=)
Name: Seymour the Trainer
Author: iuniX
Idea: Dreus_Exozol
Tested on: TFS 0.4
Information: Well, he is a NPC that trains your char for you. However, it has a certain cost and takes time. (You can't enter the char)
It's similar to offline training system.
Create a file called trainer.xml in data/npc and put this inside:
Now go to data/npc/scripts and create a file called trainer.lua, and paste this inside:
Now go and open creaturescripts/creaturescripts.xml and paste this:
Now go in the creaturescripts/scripts folder and create a file called trainer.lua:
Configuration:
price2 - price per hour
tipo_de_tempo - you put the amount of hours,minutes,or seconds (or instant)
Author: iuniX
Idea: Dreus_Exozol
Tested on: TFS 0.4
Information: Well, he is a NPC that trains your char for you. However, it has a certain cost and takes time. (You can't enter the char)
It's similar to offline training system.
Create a file called trainer.xml in data/npc and put this inside:
XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Seymour the Trainer" script="trainer.lua" walkinterval="2000" floorchange="0">
<health now="100" max="100"/>
<look type="268" head="114" body="114" legs="114" feet="114" addons="3"/>
</npc>
Now go to data/npc/scripts and create a file called trainer.lua, and paste this inside:
LUA:
local price2 = 100000
local tipo_de_tempo = 3600 --[[ Time is divided into:
3600 = hours
60 = minutes
1 = seconds
0 = instant ]]
local focuses = {}
local function isFocused(cid)
for i, v in pairs(focuses) do
if(v == cid) then
return true
end
end
return false
end
local function addFocus(cid)
if(not isFocused(cid)) then
table.insert(focuses, cid)
end
end
local function removeFocus(cid)
for i, v in pairs(focuses) do
if(v == cid) then
table.remove(focuses, i)
break
end
end
end
local function lookAtFocus()
for i, v in pairs(focuses) do
if(isPlayer(v)) then
doNpcSetCreatureFocus(v)
return
end
end
doNpcSetCreatureFocus(0)
end
function onCreatureAppear(cid)
end
function doTrainPlayer (cid, time)
setPlayerStorageValue(cid, 1338, os.time() + (time * tipo_de_tempo))
setPlayerStorageValue(cid, 1339, time)
doRemoveCreature(cid)
end
function onCreatureDisappear(cid)
if(isFocused(cid)) then
selfSay("Hmph!")
removeFocus(cid)
if(isPlayer(cid)) then
closeShopWindow(cid)
end
end
end
function onCreatureSay(cid, type, msg)
if((msg == "hi") and not (isFocused(cid))) then
selfSay("Welcome, ".. getCreatureName(cid) ..".", cid, true)
selfSay("Do you want to {train}?", cid)
addFocus(cid)
elseif((isFocused(cid)) and (msg == "train")) then
selfSay("I can train you in one hour, maybe you'll train some levels.", cid)
selfSay("How long do you want train? say: {10 hours}. Or say {price} to see my prices.", cid)
talkstatus = 1
elseif isFocused(cid) and (talstatus == 1 ) and (msg == "price") then
doPlayerPopupFYI(cid, price2 .. " gps - hour")
elseif isFocused(cid) and (talkstatus == 1) then
time = string.match(msg, "(.+) hours")
selfSay("Do you want start the training?. You must pay " .. price2 .." gold coins.", cid)
talkstatus = 2
elseif isFocused(cid) and (msg == "yes") and (talkstatus == 2) then
if time then
if doPlayerRemoveMoney(cid, time * price2) then
doTrainPlayer(cid, time)
else
selfSay("Sorry, but u don't have money. Say {price} to see my prices.", cid)
end
end
elseif isFocused(cid) and (msg == "price") then
doPlayerPopupFYI(cid, price2 .. " gps - hour")
elseif((isFocused(cid)) and (msg == "bye")) then
selfSay("Goodbye!", cid, true)
removeFocus(cid)
end
end
function onPlayerCloseChannel(cid)
if(isFocused(cid)) then
selfSay("How rude!")
removeFocus(cid)
end
end
function onPlayerEndTrade(cid)
selfSay("It was a pleasure doing business with you.", cid)
end
function onThink()
for i, focus in pairs(focuses) do
if(not isCreature(focus)) then
removeFocus(focus)
else
local distance = getDistanceTo(focus) or -1
if((distance > 4) or (distance == -1)) then
selfSay("How rude!")
removeFocus(cid)
end
end
end
lookAtFocus()
end
Now go and open creaturescripts/creaturescripts.xml and paste this:
XML:
<event type="login" name="Trainer" event="script" value="trainer.lua"/>
Now go in the creaturescripts/scripts folder and create a file called trainer.lua:
LUA:
local exp = 100000
function onLogin(cid)
local time = getPlayerStorageValue(cid, 1339)
if time > 0 then
if getPlayerStorageValue(cid, 1338) > os.time() then
doPlayerPopupFYI(cid, "You are training, please let your trainer finish.")
addEvent(doRemoveThing, 500, cid)
else
setPlayerStorageValue(cid, 1338,-1)
setPlayerStorageValue(cid, 1339, -1)
doPlayerAddExp(cid, exp * time)
doPlayerPopupFYI(cid, "Thanks for training with me.")
end
end
return true
end
Configuration:
LUA:
local price2 = 100000
local tipo_de_tempo = 3600 --[[ Time is divided into:
3600 = hours
60 = minutes
1 = seconds
0 = instant
price2 - price per hour
tipo_de_tempo - you put the amount of hours,minutes,or seconds (or instant)
Yours,
Zysen.
Zysen.
Last edited: