• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

TalkAction PET System TFS 1.X [Version: 0.1]

Printer

if Printer then print("LUA") end
Senator
Premium User
Joined
Dec 27, 2009
Messages
5,782
Solutions
31
Reaction score
2,286
Location
Sweden?
Hello,

well i want to make my final release in the ot world. There is been alot of requests about pet systems, hopefully you guys can enjoy it :p

Features:
  • Higher level master is, more health your pet has!
  • Call your pet and call it back!
Missing Features:
  • Level System for the pets!
  • Evolution System!
  • Adding pet npc!
  • Release your pet and maybe other commands!
  • Duel 1 vs 1 with other players pet!
  • Pet death!
  • others...

go to data/ create new lua and name it: petSystem.lua and paste the code below:
Code:
petBaseStorage = 1000
petHealthStorage = 1001

playerPet = {
    [1] = "Dragon"
}

pets = {
    ["Dragon"] = {storageValue = 1, healthPerLevel = 10}
}

function Player.doSummonPet(self, pet)
    local monster = Game.createMonster(pet, self:getPosition(), false, false)
    if not monster then
        monster = Game.createMonster(pet, self:getPosition(), false, true)
    end

    monster:setMaster(self)
    monster:adjustStatus(self)
end

function Monster.adjustStatus(self, player)
    local maxHealth = self:getMaxHealth()
    self:setMaxHealth(10 * pets[self:getName()].healthPerLevel + maxHealth + player:getLevel())
    local storage = player:getStorageValue(petHealthStorage)
    if storage > 0 then
        self:addHealth(-maxHealth + storage)
    else
        self:addHealth(maxHealth)
    end
end

function Player.isPetAlive(self)
    if self:getStorageValue(petHealthStorage) > 0 then
        return true
    end
    return false
end

Now go to talkactions/talkactions.xml and paste this line:
Code:
<talkaction words="!pet" script="pet.lua"/>

Now go to talkactions/scripts and create new lua and name it pet.lua and paste code below:
Code:
dofile('data/petSystem.lua')

function onSay(player, words, param)
    local summon = player:getSummons()
    if #summon == 1 then
        summon = summon[1]
        player:setStorageValue(petHealthStorage, summon:getHealth())
        summon:remove()
        return false
    end

    local pet = playerPet[player:getStorageValue(petBaseStorage)]
    if not pet then
        return false
    end

    if Tile(player:getPosition()):hasFlag(TILESTATE_PROTECTIONZONE) then
        player:sendCancelMessage("You can't call your pet in protection zones.")
        return false
    end

    player:doSummonPet(pet)
    return false
end
 
Hey, is there any way I can fix this?

[11/12/2014 19:08:29] Lua Script Error: [Test Interface]
[11/12/2014 19:08:29] data/talkactions/scripts/pet.lua
[11/12/2014 19:08:29] data/petSystem.lua:12: attempt to index global 'Player' (a nil value)
[11/12/2014 19:08:29] stack traceback:
[11/12/2014 19:08:29] [C]: in function '__newindex'
[11/12/2014 19:08:29] data/petSystem.lua:12: in main chunk
[11/12/2014 19:08:29] [C]: in function 'dofile'
[11/12/2014 19:08:29] data/talkactions/scripts/pet.lua:1: in main chunk
[11/12/2014 19:08:29] Warning: [Event::checkScript] Can not load script. /scripts/pet.lua

I'm using an old version, The Forgotten Server - Version 0.2.11pl2 (Mystic Spirit)
 
Time to bring on my computer again!

Kind Regards,
Eldin.
 
Hello,

well i want to make my final release in the ot world. There is been alot of requests about pet systems, hopefully you guys can enjoy it :p

Features:
  • Higher level master is, more health your pet has!
  • Call your pet and call it back!
Missing Features:
  • Level System for the pets!
  • Evolution System!
  • Adding pet npc!
  • Release your pet and maybe other commands!
  • Duel 1 vs 1 with other players pet!
  • Pet death!
  • others...

go to data/ create new lua and name it: petSystem.lua and paste the code below:
Code:
petBaseStorage = 1000
petHealthStorage = 1001

playerPet = {
    [1] = "Dragon"
}

pets = {
    ["Dragon"] = {storageValue = 1, healthPerLevel = 10}
}

function Player.doSummonPet(self, pet)
    local monster = Game.createMonster(pet, self:getPosition(), false, false)
    if not monster then
        monster = Game.createMonster(pet, self:getPosition(), false, true)
    end

    monster:setMaster(self)
    monster:adjustStatus(self)
end

function Monster.adjustStatus(self, player)
    local maxHealth = self:getMaxHealth()
    self:setMaxHealth(10 * pets[self:getName()].healthPerLevel + maxHealth + player:getLevel())
    local storage = player:getStorageValue(petHealthStorage)
    if storage > 0 then
        self:addHealth(-maxHealth + storage)
    else
        self:addHealth(maxHealth)
    end
end

function Player.isPetAlive(self)
    if self:getStorageValue(petHealthStorage) > 0 then
        return true
    end
    return false
end

Now go to talkactions/talkactions.xml and paste this line:
Code:
<talkaction words="!pet" script="pet.lua"/>

Now go to talkactions/scripts and create new lua and name it pet.lua and paste code below:
Code:
dofile('data/petSystem.lua')

function onSay(player, words, param)
    local summon = player:getSummons()
    if #summon == 1 then
        summon = summon[1]
        player:setStorageValue(petHealthStorage, summon:getHealth())
        summon:remove()
        return false
    end

    local pet = playerPet[player:getStorageValue(petBaseStorage)]
    if not pet then
        return false
    end

    if Tile(player:getPosition()):hasFlag(TILESTATE_PROTECTIONZONE) then
        player:sendCancelMessage("You can't call your pet in protection zones.")
        return false
    end

    player:doSummonPet(pet)
    return false
end
[17/12/2014 19:56:04] [Error - TalkAction Interface]
[17/12/2014 19:56:04] data/talkactions/scripts/pet.lua
[17/12/2014 19:56:04] Description:
[17/12/2014 19:56:04] data/petSystem.lua:12: attempt to index global 'Player' (a nil value)
[17/12/2014 19:56:04] [Warning - Event::loadScript] Cannot load script (data/talkactions/scripts/pet.lua)
@Printer
0.3.6
 
[17/12/2014 19:56:04] [Error - TalkAction Interface]
[17/12/2014 19:56:04] data/talkactions/scripts/pet.lua
[17/12/2014 19:56:04] Description:
[17/12/2014 19:56:04] data/petSystem.lua:12: attempt to index global 'Player' (a nil value)
[17/12/2014 19:56:04] [Warning - Event::loadScript] Cannot load script (data/talkactions/scripts/pet.lua)
@Printer
0.3.6
OMG, only 1.0+tfs...
 
Hello,

well i want to make my final release in the ot world. There is been alot of requests about pet systems, hopefully you guys can enjoy it :p

Features:
  • Higher level master is, more health your pet has!
  • Call your pet and call it back!
Missing Features:
  • Level System for the pets!
  • Evolution System!
  • Adding pet npc!
  • Release your pet and maybe other commands!
  • Duel 1 vs 1 with other players pet!
  • Pet death!
  • others...

go to data/ create new lua and name it: petSystem.lua and paste the code below:
Code:
petBaseStorage = 1000
petHealthStorage = 1001

playerPet = {
    [1] = "Dragon"
}

pets = {
    ["Dragon"] = {storageValue = 1, healthPerLevel = 10}
}

function Player.doSummonPet(self, pet)
    local monster = Game.createMonster(pet, self:getPosition(), false, false)
    if not monster then
        monster = Game.createMonster(pet, self:getPosition(), false, true)
    end

    monster:setMaster(self)
    monster:adjustStatus(self)
end

function Monster.adjustStatus(self, player)
    local maxHealth = self:getMaxHealth()
    self:setMaxHealth(10 * pets[self:getName()].healthPerLevel + maxHealth + player:getLevel())
    local storage = player:getStorageValue(petHealthStorage)
    if storage > 0 then
        self:addHealth(-maxHealth + storage)
    else
        self:addHealth(maxHealth)
    end
end

function Player.isPetAlive(self)
    if self:getStorageValue(petHealthStorage) > 0 then
        return true
    end
    return false
end

Now go to talkactions/talkactions.xml and paste this line:
Code:
<talkaction words="!pet" script="pet.lua"/>

Now go to talkactions/scripts and create new lua and name it pet.lua and paste code below:
Code:
dofile('data/petSystem.lua')

function onSay(player, words, param)
    local summon = player:getSummons()
    if #summon == 1 then
        summon = summon[1]
        player:setStorageValue(petHealthStorage, summon:getHealth())
        summon:remove()
        return false
    end

    local pet = playerPet[player:getStorageValue(petBaseStorage)]
    if not pet then
        return false
    end

    if Tile(player:getPosition()):hasFlag(TILESTATE_PROTECTIONZONE) then
        player:sendCancelMessage("You can't call your pet in protection zones.")
        return false
    end

    player:doSummonPet(pet)
    return false
end


Why? Are you leaving Ot? Will your projects on github be shutdown? You are such a gifted coder!

Hopefully you are not leaving Otland...? Plenty of people will be saddened from your absence.
 
Im using this system and is working flawless, ONLY FOR A GM / GOD.
Normal players simply "utevo res" the dragon.

Any help is appreciated
 
Im using this system and is working flawless, ONLY FOR A GM / GOD.
Normal players simply "utevo res" the dragon.

Any help is appreciated

@Prestin32k
Check your monsterfiles, Dragon, then look for convinceable = "0", if the number is 1 and you change it to 0, it should be solved. Did you change it for another creature that you can convince maybe rather then the Dragon?

Kind Regards,
Eldin.
 
@Prestin32k
Check your monsterfiles, Dragon, then look for convinceable = "0", if the number is 1 and you change it to 0, it should be solved. Did you change it for another creature that you can convince maybe rather then the Dragon?

Kind Regards,
Eldin.

Checked this, and they are already on 0 by default.. any other suggestion?
 
NVM, it's working.

Kind Regards,
Eldin.
 
Last edited:
well, not work tfs 1.2
I do the command !pet and nothing happen
 
No one bothers on TFS 1.1 -> TFS 1.2 conversion updates to scripts because it's too easy, same as 1.0 -> 1.x because its literally only like a couple little things changed from server version that would require something in your scripts to need to be changed at all to be fully compatible anyways. So its always the same thing you are looking for to change, visit any thread that has that issue and got it solved and learn from it and then you won't be stuck behind like those who don't learn :D
 
doesnt work, tested and edited multiple times with removing alot of return false coding.

Original script, Does nothing
Removing "if not pet then return false end" changing to "if pet then return false" says attempt to index local monster a nil value.
Moved dofile to global, nothing.
 
hey guys i have a problem i have use this pet system but its not work im use linux with tfs 1.1 client 10.77 and i have no error in putty and if i say !pet its not work
 
Back
Top