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

2 Functions

Koncu

New Member
Joined
May 25, 2010
Messages
28
Reaction score
0
Hi there,

I am curious if you can actually write 2 functions in one line because it could save me huge amount of work.

My current code is:

Code:
function onLogout(cid)
        if (getPlayerVocation(cid) == 1) then
    doCreatureChangeOutfit(cid, {lookType=549})
  
    return 1
end

I was trying to add or function (not sure if this is the correct way) and it did not work

Code:
function onLogout(cid) or not function onDeath(cid)
        if (getPlayerVocation(cid) == 1) then
    doCreatureChangeOutfit(cid, {lookType=549})
  
    return 1
end

What the code does?

When character log outs it changes the outfit if vocation = 1

But because when someone dies it doesn't work I was trying to fix that, unfortunately with no luck

(it's the logout.lua in creaturescripts folder)
 
Code:
function onLogout(cid)
       if (getPlayerVocation(cid) == 1) then
           doCreatureChangeOutfit(cid, {lookType=549})
       end
    return 1
end
it should work, you need always open a function and close with "end" as you open { need close }
 
You can use this code on logout.lua:
Code:
function onLogout(cid)
    if getPlayerVocation(cid) == 1 then
        doCreatureChangeOutfit(cid, {lookType = 549})
      end
      
    return true
end

And for fix the death problem you probably need add this three lines on your playerdeath script.
Code:
if getPlayerVocation(cid) == 1 then
        doCreatureChangeOutfit(cid, {lookType = 549})
  end
 
Code:
function onLogout(cid)
       if (getPlayerVocation(cid) == 1) then
           doCreatureChangeOutfit(cid, {lookType=549})
       end
    return 1
end
it should work, you need always open a function and close with "end" as you open { need close }
You can use this code on logout.lua:
Code:
function onLogout(cid)
    if getPlayerVocation(cid) == 1 then
        doCreatureChangeOutfit(cid, {lookType = 549})
      end
     
    return true
end

And for fix the death problem you probably need add this three lines on your playerdeath script.
Code:
if getPlayerVocation(cid) == 1 then
        doCreatureChangeOutfit(cid, {lookType = 549})
  end

Yes the first code does work when you log out but it does not when you die and I have added another function called onDeath, even in playerdeath.lua
 
use onPrepareDeath, not onDeath
with onDeath you cannot do anything to the creature since it has died
however with onPrepareDeath, it will execute anything in that script right before the creature dies
 
Code:
function onLogout(cid)
       if (getPlayerVocation(cid) == 1) then
           doCreatureChangeOutfit(cid, {lookType=549})
       end
    return 1
end

onPrepareDeath = onLogout

Then use 2 tags with the same script with different event types.
(Will only work if they are exactly the same including parameters.)
 
use onPrepareDeath, not onDeath
with onDeath you cannot do anything to the creature since it has died
however with onPrepareDeath, it will execute anything in that script right before the creature dies

1. I have tried adding onPrepareDeath but I got an error
Code:
[10/10/2016 19:37:39] [Warning - Actions::registerEvent] Duplicate registered item id: 7477
[10/10/2016 19:37:39] [Warning - Event::loadScript] Event onDeath not found (data/creaturescripts/scripts/playerdeath.lua)

Apparently, it has to be onDeath event, and so I have decided to use logout instead but I think its because of the "event type" that is used

Code:
    <event type="logout" name="Logout" event="script" value="logout.lua"/>
    <event type="death" name="PlayerDeath" event="script" value="playerdeath.lua"/>

but yes..still it does not work when I die

Code:
function onLogout(cid)
       if (getPlayerVocation(cid) == 1) then
           doCreatureChangeOutfit(cid, {lookType=549})
       end
    return 1
end

onPrepareDeath = onLogout

Then use 2 tags with the same script with different event types.
(Will only work if they are exactly the same including parameters.)

the same with yours :/

(btw - all is done in creaturescripts folder and creaturescripts.xml and im using tfs0.3.6)
 
type="preparedeath"

And use the same file in mine.
Plus you should create a new file to do that, don't use logout.lua and playerdeath.lua

And don't forget to register the preparedeath on login.
 
The playerdeath.lua did not exist in the first place so I had to create one. I have replaced the event type to:

Code:
    <event type="preparedeath" name="PlayerDeath" event="script" value="playerdeath.lua"/>

Current: playerdeath.lua
Code:
function onPrepareDeath(cid)
if (getPlayerVocation(cid) == 2) then
    doPlayerSetVocation(cid,1)
    setCreatureMaxHealth(cid, getCreatureMaxHealth(cid)-400)
    doCreatureAddHealth(cid, 1)
    setCreatureMaxMana(cid, getCreatureMaxMana(cid)-400)
   doCreatureChangeOutfit(cid, {lookType=549})
return true
 end
end

current logout.lua
Code:
function onLogout(cid)
if (getPlayerVocation(cid) == 2) then
    doPlayerSetVocation(cid,1)
    setCreatureMaxHealth(cid, getCreatureMaxHealth(cid)-400)
    doCreatureAddHealth(cid, 1)
    setCreatureMaxMana(cid, getCreatureMaxMana(cid)-400)
   doCreatureChangeOutfit(cid, {lookType=549})

   return true
end
end

I don't know but maybe it's worth mentioning that when I delete this script from logout.lua the character does not want to log off when ctrl+Q pressed.
@edit
I can log off only when I delete the entire logout.lua script, but can't if I delete only IF satement

Here's the last piece of code which may cause issues (talkactions.lua script)

Code:
local config = {
--[vocation id] = {required level, new vocation, looktype, effect, hp, mana}
--naruto
[1] = { 25, 2, 556, 83, 400, 400},
[2] = { 50, 3, 557, 83, 400, 400},
}
function onSay(cid, words, param, channel)

if exhaustion.get(cid, 103) then
    doPlayerSendCancel(cid, 'Slow down.')
    return true
end
exhaustion.set(cid, 103, 0)

doPlayerSay(cid, "transformation")
local voc = config[getPlayerVocation(cid)]
if voc then
if getPlayerLevel(cid) >= voc[1] then
    doPlayerSetVocation(cid, voc[2])
    local outfit = {lookType = voc[3]}
    doCreatureChangeOutfit(cid, outfit)
    doSendMagicEffect(getCreaturePosition(cid), voc[4])
    setCreatureMaxHealth(cid, getCreatureMaxHealth(cid)+voc[5])
    setCreatureMaxMana(cid, getCreatureMaxMana(cid)+voc[6])
    doCreatureAddHealth(cid, 1)

    else
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You need " .. voc[1] .. " level to transform.")
 
end
    else
    doPlayerSendCancel(cid, "You cannot transform.")
end
return true
end
because you have return true inside the if statement
it will only let you log out if that statement passes lol
 
Back
Top