• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua TFS 0.3.6 If party is created, do something

waqmaz

Member
Joined
Jun 17, 2015
Messages
203
Reaction score
11
I am trying to make a function that if someone create party then the leader get an item. Which function should I use? I think a one of the creaturesctipts:
WEAPONS
onUseWeapon(cid, var)
SPELLS
onCastSpell(cid, var)
CREATURESCRIPTS
onLogin(cid)
onLogout(cid)
onAdvance(cid, skill, oldLevel, newLevel)
onStatsChange(cid, attacker, type, combat, value)
onDirection(cid, old, current)
onOutfit(cid, old, current)
onSendMail(cid, receiver, item, openBox)
onReceiveMail(cid, sender, item, openBox)
onTradeRequest(cid, target, item)
onTradeAccept(cid, target, item, targetItem)
onJoinChannel(cid, channel, users)
onLeaveChannel (cid, channel, users)
onLook(cid, thing, position, lookDistance)
onThink(cid, interval)
onTextEdit(cid, item, newText)
onReportBug(cid, comment)
onAreaCombat(cid, tileItem, tilePosition, isAggressive)
onPush(cid, target)
onTarget(cid, target)
onFollow(cid, target)
onCombat(cid, target)
onAttack(cid, target)
onCast(cid, target)
onKill(cid, target, lastHit)
onDeath(cid, corpse, deathList)
onPrepareDeath(cid, deathList)
GLOBALEVENTS
onThink(interval, lastExecution, thinkInterval)
onStartup()
onShutdown()
onRecord(current, old, cid)
onTimer()
MOVEMENTS
onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
onStepOut(cid, item, position, lastPosition, fromPosition, toPosition, actor)
onEquip(cid, item, slot)
onDeEquip(cid, item, slot)
onAddItem(moveItem, tileItem, position, cid)
onRemoveItem(moveItem, tileItem, position, cid)
TALKACTIONS
onSay(cid, words, param, channel)
 
nope, you cant use a creature event to see when a player joins a party, but if you really dont want to do source edits, you could do contuniuos checks to see if the player is in a party and give items that way
 
Since you can't see when the leader leaves a party (doPlayerLeaveParty is making a creature leave it), you can't remove the item from the leader.
So doing continuous checks means the leader would continuously get the item unless you use getPlayerItemCount/getPlayerItemById and remove it manually once disbanded.

EDIT: Nevermind, you could just check if isInParty(cid) and if it returns false then remove item if they have it.
 
Something like this (I think?)
Bad pun.
Code:
function onThink(interval, lastExecution, thinkInterval)
    local ItemID = xxxx
    local Leader = getPlayerByNameWildcard(getPartyLeader(cid))
    if isInParty(cid) then
        if getPlayerItemById(Leader, ItemID) == false then
            doPlayerGiveItem(Leader, ItemID)
        end
    end
    if isInParty(cid) == false then
        if getPlayerItemById(cid, ItemID) then
            doPlayerRemoveItem(cid, ItemID)
        end
    end
    return true
end
 
Something like this (I think?)
Bad pun.
Code:
function onThink(interval, lastExecution, thinkInterval)
    local ItemID = xxxx
    local Leader = getPlayerByNameWildcard(getPartyLeader(cid))
    if isInParty(cid) then
        if getPlayerItemById(Leader, ItemID) == false then
            doPlayerGiveItem(Leader, ItemID)
        end
    end
    if isInParty(cid) == false then
        if getPlayerItemById(cid, ItemID) then
            doPlayerRemoveItem(cid, ItemID)
        end
    end
    return true
end
you need a for loop .. getPlayersOnline() .. this is worst solution..would be laggy,since onThink doesn't have cid
 
you need a for loop .. getPlayersOnline() .. this is worst solution..would be laggy,since onThink doesn't have cid
Code:
function onThink(interval, lastExecution, thinkInterval)
    for _, pid in ipairs(getOnlinePlayers()) do
    local ItemID = xxxx
    local Leader = getPlayerByNameWildcard(getPartyLeader(pid))
    if isInParty(pid) then
        if getPlayerItemById(Leader, ItemID) == false then
            doPlayerGiveItem(Leader, ItemID)
        end
    end
    if isInParty(pid) == false then
        if getPlayerItemById(pid, ItemID) then
            doPlayerRemoveItem(pid, ItemID)
        end
    end
    return true
end
 
Although this showcases what you can do, nobody should use this code as-is, as the leader can simply throw the item on the ground and get the item infinitely.
 
Although this showcases what you can do, nobody should use this code as-is, as the leader can simply throw the item on the ground and get the item infinitely.
Unless you use <attribute key="moveable" value="0" /> on the item
 
Code:
function onThink(interval, lastExecution, thinkInterval)
    for _, pid in ipairs(getOnlinePlayers()) do
    local ItemID = xxxx
    local Leader = getPlayerByNameWildcard(getPartyLeader(pid))
    if isInParty(pid) then
        if getPlayerItemById(Leader, ItemID) == false then
            doPlayerGiveItem(Leader, ItemID)
        end
    end
    if isInParty(pid) == false then
        if getPlayerItemById(pid, ItemID) then
            doPlayerRemoveItem(pid, ItemID)
        end
    end
    return true
end

It causes lags, isn't it?
 
Code:
function onThink(interval, lastExecution, thinkInterval)
    for _, pid in ipairs(getOnlinePlayers()) do
    local ItemID = xxxx
    local Leader = getPlayerByNameWildcard(getPartyLeader(pid))
    if isInParty(pid) then
        if getPlayerItemById(Leader, ItemID) == false then
            doPlayerGiveItem(Leader, ItemID)
        end
    end
    if isInParty(pid) == false then
        if getPlayerItemById(pid, ItemID) then
            doPlayerRemoveItem(pid, ItemID)
        end
    end
    return true
end

It causes lags, isn't it?
It shouldnt, the first one would though since it doesn't have getOnlinePlayers() in the script, and I put cid in the script without listing it in the function.
 
making this through a source edit is not that hard.
it will be more effective since doesnt require a continuous check
you just need to see how things work in creatureevents
and so create a new lua callback onJoinParty

its not hard at all because its just a copy/modification of a already done logic

please dont be lazy
 
making this through a source edit is not that hard.
it will be more effective since doesnt require a continuous check
you just need to see how things work in creatureevents
and so create a new lua callback onJoinParty

its not hard at all because its just a copy/modification of a already done logic

please dont be lazy
"please dont be lazy"
Maybe he doesn't know how to source edit. If you're going to try and help, don't say "its not that hard", instead you should actually provide something yourself instead of being lazy :)
 
making this through a source edit is not that hard.
it will be more effective since doesnt require a continuous check
you just need to see how things work in creatureevents
and so create a new lua callback onJoinParty

its not hard at all because its just a copy/modification of a already done logic

please dont be lazy
Not everyone knows c++ so they with what they do know. ;)
 
Back
Top