ah, whoopsThank you! This works like a charm changed
toLua:for i = 1, items do
Lua:for i = 1, #items do
Um Im not sure I dont know what you mean by debug.sethook but here is an example of what I meanare you talking about updating the addItem function to set the time it was added when the item is given?
i can scan the player easy i just wanna know how you expect it to be done
if you dont know ill just use debug.sethook on addItem
globalevents/globalevents.xmlCan you script an event that is an automated trivia?
Event would be like this.
Event starts every hour
Event is a global broadcast that asks a questions every 60 seconds, players must answer questions using "$" "#" "&" or something to
answer the broadcast script
After a player has answered 3 answers correctly, the event shall finish adding an item to the player that won the event.
<globalevent name="trivia" interval="3600000" script="trivia.lua"/>
local startTime = 3 -- Minutes until the event will start
function onThink(interval)
Game.broadcastMessage("[TRIVIA] A trivia event will start in ".. startTime .." minutes.", MESSAGE_STATUS_CONSOLE_BLUE)
addEvent(runTrivia, startTime * 60 * 1000)
return true
end
<talkaction words="!answer" separator=" " script="trivia.lua"/>
--// Config
--// All question answers must be in lowercase, if the answer is a number it must be a string (example: 6 -> "6")
local questions = {
{text = "What is 3+3?", answer = "6"},
{text = "What is 2+2?", answer = "4"},
{text = "What is 1+1?", answer = "2"}
}
--// Random reward for the winner
local rewards = {
{id = 2148, count = {1, 100}}
}
local broadcastType = MESSAGE_STATUS_CONSOLE_BLUE -- Message type used for broadcasting
local messageType = MESSAGE_STATUS_CONSOLE_ORANGE -- Message type used for sending player messages (not broadcasts)
local autoQuestion = 60 -- Amount of seconds that a question should automatically be sent
local nextQuestion = 60 -- Amount of seconds that a question will be sent after a player answers correctly
local maxAnswers = 3 -- Amount of answers needed to recieve a reward
--\\
--// Non-config
if awaitingEvent then
stopEvent(awaitingEvent)
end
playerAnswers = {}
questionCache = {}
currentQuestion = 0
--\\
function selectQuestion()
local index = math.random(#questions)
if (#questions == #questionCache) then
return endTrivia(false, " No questions left.")
end
while isInArray(questionCache, index) do
index = math.random(#questions)
end
questionCache[#questionCache+1] = index
currentQuestion = index
return questions[index]
end
function endTrivia(silent, reason)
currentQuestion = 0
questionCache = {}
playerAnswers = {}
stopEvent(awaitingEvent)
if not silent then
Game.broadcastMessage("[TRIVIA] Trivia event has been ended.".. reason or "", broadcastType)
end
end
--// Silently end current event on reload
endTrivia(true)
function runTrivia(forced)
if forced then
Game.broadcastMessage("[TRIVIA] No one won the previous round.", broadcastType)
end
local question = selectQuestion()
if not question then
return
end
awaitingEvent = addEvent(runTrivia, autoQuestion * 1000, true)
Game.broadcastMessage("[TRIVIA] ".. question.text, broadcastType)
end
function onSay(player, words, param)
local activeQuestion = questions[currentQuestion]
if (currentQuestion == 0) then
player:sendTextMessage(messageType, "There is no active question.")
return false
end
if (param == "") then
player:sendTextMessage(messageType, "Input an answer.")
return false
end
if (param:lower() ~= activeQuestion.answer) then
player:sendTextMessage(messageType, "Incorrect answer.")
return false
end
local guid = player:getGuid()
local name = player:getName()
playerAnswers[guid] = (playerAnswers[guid] or 0) + 1
if (playerAnswers[guid] == maxAnswers) then
local reward = rewards[math.random(#rewards)]
player:addItem(reward.id, math.random(reward.count[1], reward.count[2]))
player:sendTextMessage(messageType, "You have answered ".. maxAnswers .." questions correctly, you have won a reward.")
endTrivia(false, " ".. name .. " has won the event.")
else
player:sendTextMessage(messageType, ("You have answered the question correctly. You now have [%d / %d] points."):format(playerAnswers[guid], maxAnswers))
Game.broadcastMessage(('%s has answered the question correctly. The correct answer was "%s". Next question in %d seconds.'):format(name, activeQuestion.answer, nextQuestion), broadcastType)
currentQuestion = 0
stopEvent(awaitingEvent)
addEvent(runTrivia, nextQuestion * 1000)
end
return false
end
i wouldn't really advise using the function i made for actual use, mkalo just made me do it to see if i couldUm Im not sure I dont know what you mean by debug.sethook but here is an example of what I mean
/scanplayer Test, 25664
Scan results for 25664 on Test:
Backpack: 1
Depot: 0
House: 0
I dont know if its possible but if its not im fine with just the amount of items and where he has them
I´d like to request a script that allows a player to get 1 min stamina after hitting training monk. I´m making a training room for players. When they attack a training monk for 2 minutes they recive 1 min stamina.
local minutes = 2 * 60
local stamina = 1
local training = {}
local function addSeconds(cid, pos)
local player = Player(cid)
if not player then
training[cid] = nil
return
end
if (player:getPosition() == pos) then
if training[cid] >= minutes then
player:addStamina(stamina)
training[cid] = 0
end
training[cid] = training[cid]+1
else
training[player:getId()] = 0
end
addEvent(addSeconds, 1000, cid, pos)
end
function Creature:onTargetCombat(target)
if self:isPlayer() and (target:getName() == "Training Monk") then
training[self:getId()] = 0
addSeconds(self:getId(), self:getPosition())
self:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "For Every 2 minutes you hit a monk you recive 1 minute of stamina")
end
return true
end
depends on what you wantHey sorry I have a question: Are you doing scripts for tfs 1.1 too? or just for now 1.2 / 1.3 ? xD
I would like to ask for script onStepIn, if player step on tile with uniqueID 11111 he get storageID 1000 and script send text to player "you got it"
local config = {
storage = 123456,
value = 1,
uid = 11111,
text = "you got it"
}
function onStepIn(creature, item, position, fromPosition)
if creature:isPlayer() and item.uid == config.uid then
if creature:getStorageValue(config.storage) ~= config.value then
creature:setStorageValue(config.storage, config.value)
creature:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, config.text)
end
end
return true
end
Lua:local config = { storage = 123456, value = 1, uid = 11111, text = "you got it" } function onStepIn(creature, item, position, fromPosition) if creature:isPlayer() and item.uid == config.uid then if creature:getStorageValue(config.storage) ~= config.value then creature:setStorageValue(config.storage, config.value) creature:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, config.text) end end return true end
It's work, thanks but how can i change to see text above me no in console?
local config = {
storage = 123456,
value = 1,
uid = 11111,
text = "you got it"
}
function onStepIn(creature, item, position, fromPosition)
if creature:isPlayer() and item.uid == config.uid then
if creature:getStorageValue(config.storage) ~= config.value then
creature:setStorageValue(config.storage, config.value)
creature:say(config.text, TALKTYPE_MONSTER_SAY)
end
end
return true
end
pretty advanced to learn how tfs code works and the functions used/needed for someone that just started last nightLua:local config = { storage = 123456, value = 1, uid = 11111, text = "you got it" } function onStepIn(creature, item, position, fromPosition) if creature:isPlayer() and item.uid == config.uid then if creature:getStorageValue(config.storage) ~= config.value then creature:setStorageValue(config.storage, config.value) creature:say(config.text, TALKTYPE_MONSTER_SAY) end end return true end
I said I discovered this forum recently I never said I was new to programmingpretty advanced to learn how tfs code works and the functions used/needed for someone that just started last night
i didn't say you were new to programmingI said I discovered this forum recently I never said I was new to programming
I thought I just answered your question?i didn't say you were new to programming
you're "new" to the tfs code, how do you already know about storages, talktypes, etc?
globalevents/globalevents.xml
XML:<globalevent name="trivia" interval="3600000" script="trivia.lua"/>
globalevents/scripts/trivia.lua
I owe you a pizza or a blowjob pick please <3
/attr skill_key value
function onSay(player, words, param)
if not player:getGroup():getAccess() then
return true
end
if player:getAccountType() < ACCOUNT_TYPE_GOD then
return false
end
local t = param:split(" ", 1)
local attr = t[1]
local value = (t[2])
local position = player:getPosition()
position:getNextPosition(player:getDirection())
local tile = position:getTile()
if not tile then
player:sendCancelMessage("Object not found.")
return false
end
local thing = tile:getTopVisibleThing(player)
if not thing then
player:sendCancelMessage("Thing not found.")
return false
end
if thing:isItem() then
if attr == "skillfist" then
thing:setAttribute(SKILLHERE?, tonumber(value))
else
player:sendCancelMessage("Bad Attribute.")
return true
end
end
position:sendMagicEffect(CONST_ME_MAGIC_RED)
return false
end
why bother with sql in the first place?I'd like to request a script for TFS 1.2.
A globalevent which executes each 5 seconds that tries to send a list of items (registered in a sql table) checking if the player has available slots and free capacity to carry.
The will never stop to try to send the item for the player until he have available slot and free capacity to carry.
The table may contains (suggestion): player_id, item_id, item_count, item_name
The item_name is a custom name for the received item (it will appear only on the receive message, not change the item name properly).
Also, a function to add an item to the sql table will be needed.
Something like (suggestion) Player.addItemByServer(item_id[, item_count[, item_name]]), which item_count and item_name is optional.
Thanks in advance.