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

Is it possible to add chance on stepin function?

FenX

Advanced OT User
Joined
Jul 8, 2019
Messages
360
Solutions
1
Reaction score
159
Hello guys,

Say I take this simple onstepin script
Lua:
local config = {
    [9238] = Position(33456, 31346, 8),
    [9239] = Position(33199, 31978, 8)
}

function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return true
    end

    local targetPosition = config[item.uid]
    if not targetPosition then
        return true
    end

    player:teleportTo(targetPosition)
    targetPosition:sendMagicEffect(CONST_ME_WATERSPLASH)
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, '')
    return true
end
Is it possible to add a line which will, for example, give the player 50% chance to be teleported to the location?

Also how would I add a line which would deal damage to the player if they are teleported? I like reading the code and going through various scripts to create edits of my own (I'm not entirely experienced enough to just write code from scratch that is 100% functioning properly so I look at other code/scripts to use as an example). So I had the idea of simply taking this line:
Lua:
    doTargetCombatHealth(0, player, COMBAT_PHYSICALDAMAGE, -200, -200, CONST_ME_DRAWBLOOD)
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, '')
And add it to:
Lua:
    player:teleportTo(targetPosition)
    targetPosition:sendMagicEffect(CONST_ME_WATERSPLASH)
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, '')
    return true
end
Would that work? 😅

Thanks in advance 😋
 
Solution
Something like this?
Lua:
local config = {
    [9238] = Position(33456, 31346, 8),
    [9239] = Position(33199, 31978, 8)
}

function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return true
    end

    local targetPosition = config[item.uid]
    if not targetPosition then
        return true
    end
    local chance = 50
    if math.random(1, 100) <= chance then
        player:teleportTo(targetPosition)
        doTargetCombatHealth(0, player, COMBAT_PHYSICALDAMAGE, -200, -200, CONST_ME_NONE)
        targetPosition:sendMagicEffect(CONST_ME_WATERSPLASH)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, '')
        return true
    else...
Here's a starting point.
Lua:
if math.random(2) == 1 then
    -- 50% chance to do something
end

And instead of asking if it'll work, try it before asking.
 
Something like this?
Lua:
local config = {
    [9238] = Position(33456, 31346, 8),
    [9239] = Position(33199, 31978, 8)
}

function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return true
    end

    local targetPosition = config[item.uid]
    if not targetPosition then
        return true
    end
    local chance = 50
    if math.random(1, 100) <= chance then
        player:teleportTo(targetPosition)
        doTargetCombatHealth(0, player, COMBAT_PHYSICALDAMAGE, -200, -200, CONST_ME_NONE)
        targetPosition:sendMagicEffect(CONST_ME_WATERSPLASH)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, '')
        return true
    else
        player:sendCancelMessage('Sorry, you could not be teleported to your destination.')
    end
end
 
Solution
Something like this?
Lua:
local config = {
    [9238] = Position(33456, 31346, 8),
    [9239] = Position(33199, 31978, 8)
}

function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return true
    end

    local targetPosition = config[item.uid]
    if not targetPosition then
        return true
    end
    local chance = 50
    if math.random(1, 100) <= chance then
        player:teleportTo(targetPosition)
        doTargetCombatHealth(0, player, COMBAT_PHYSICALDAMAGE, -200, -200, CONST_ME_NONE)
        targetPosition:sendMagicEffect(CONST_ME_WATERSPLASH)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, '')
        return true
    else
        player:sendCancelMessage('Sorry, you could not be teleported to your destination.')
    end
end
Pretty much yeah, works well 👍🤗
 
Back
Top