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

Lua Code of friendly fire true/false

fironfox

New Member
Joined
Dec 14, 2012
Messages
42
Reaction score
1
Have any code for tfs 1.0 what make "friendly fire" true or false if have storage X? Ex: In battlefield event for dont attack player of the same team, with same storage X.
 
events/scripts/creature.lua
Code:
function Creature:onTargetCombat(target)
    if not self then
        return true
    end

    if self:isPlayer() and target:isPlayer() then
        local party = self:getParty()
        if party then
            local targetParty = target:getParty()
            if targetParty and targetParty == party then
                return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
            end
        end
    end
    return true
end

this is what i use for not being to able to attack party members. u can easily adjust for storagevalues.
 
events/scripts/creature.lua
remove ur old "function creatureontarget" with this one

Code:
function Creature:onTargetCombat(target)
    if not self then
        return true
    end

    if target:isPlayer() then
        if target:getStorageValue(STORAGENUMBER) == 1 then
            return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
        end
    end
    return true
end

simply like that. u might need to change 1 into the correct number though, and obviously change "STORAGENUMBER" into the number u should use.

also you need to change inside events.xml
Code:
    <event class="Creature" method="onTargetCombat" enabled="0" />

to
Code:
    <event class="Creature" method="onTargetCombat" enabled="1" />
 
Ok, but i need to check if player have STORAGE X and target have X too, if have return false. But if selfplayer have STORAGE X and target have Y return true. How i make this code?

EDIT:
Code:
dofile('data/lib/events/BATTLEFIELD_lib.lua')

function Creature:onTargetCombat(target)
    if not self then
        return true
    end

    if self:isPlayer() and target:isPlayer() then
        if (self:getStorageValue(bf.teamOne.storage) > 0 and target:getStorageValue(bf.teamOne.storage) > 0) or 
            (self:getStorageValue(bf.teamTwo.storage) > 0 and target:getStorageValue(bf.teamTwo.storage) > 0) then

            return RETURNVALUE_YOUMAYNOTATTACKTHISPLAYER
        end
    end

    return true
end

Are correctly?
 
Last edited:
Tfs 1.0 don't support these events :s i try to update my source but without sucess... U have any tutorial for me to update my source with this event to work?
 
Tfs 1.0 don't support these events :s i try to update my source but without sucess... U have any tutorial for me to update my source with this event to work?
The codes that the sailor cat provided are for 1.x...

@Edit: Nvm, I think that those events were introduced in 1.1 or 1.2. Sorry.
@Edit2: You can take that code and make an onhealthchange/onmanachange script.
 
The codes that the sailor cat provided are for 1.x...

@Edit: Nvm, I think that those events were introduced in 1.1 or 1.2. Sorry.
@Edit2: You can take that code and make an onhealthchange/onmanachange script.
Yeap i know this, but i have updated my source to work "onGainExperience" i think isn't so hard to make these others events work..

how i use this code with onhealthchange?
 
Last edited:
Back
Top