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

arena

Hahstudios

New Member
Joined
Mar 11, 2010
Messages
49
Solutions
3
Reaction score
1
im using tfs v1.2

origional: "Svargrond arena" for TFS 0.3.2 100% working.
im needing some help with an arena script. the npc works and it allows me to go through the door to get to the first tp but it wont allow me to go through the tp to get into arena room 1.

creaturescripts
arenakill.lua
Lua:
function onKill(cid, target)
    local room = getArenaMonsterIdByName(getCreatureName(target))
    if room > 0 then
        setPlayerStorageValue(cid, room, 1)
        setPlayerStorageValue(cid, 4999, 1)
        doPlayerSendTextMessage(cid,MESSAGE_EVENT_DEFAULT,'You can enter next room!')
    end
    return TRUE
end


movements

movenments.xml
XML:
<movevent event="StepIn" uniqueid="8625" script="rebirthlvl.lua"/>
    <movevent event="StepIn" actionid="42300" script="arenaroom.lua"/>
    <movevent event="StepIn" actionid="42301" script="arenaroom.lua"/>
    <movevent event="StepIn" actionid="42302" script="arenaroom.lua"/>
    <movevent event="StepIn" actionid="42303" script="arenaroom.lua"/>
    <movevent event="StepIn" actionid="42304" script="arenaroom.lua"/>
    <movevent event="StepIn" actionid="42305" script="arenaroom.lua"/>
    <movevent event="StepIn" actionid="42306" script="arenaroom.lua"/>
    <movevent event="StepIn" actionid="42307" script="arenaroom.lua"/>
    <movevent event="StepIn" actionid="42308" script="arenaroom.lua"/>
    <movevent event="StepIn" actionid="42309" script="arenaroom.lua"/>
    <movevent event="StepIn" actionid="42310" script="didarenalevel.lua"/>
    <movevent event="StepIn" actionid="42321" script="leavearena.lua"/>
    <movevent event="StepIn" actionid="42322" script="leavearena.lua"/>
    <movevent event="StepIn" actionid="42323" script="leavearena.lua"/>
    <movevent event="StepIn" actionid="42324" script="leavearena.lua"/>
    <movevent event="StepIn" actionid="42325" script="leavearena.lua"/>
    <movevent event="StepIn" actionid="42326" script="leavearena.lua"/>
    <movevent event="StepIn" actionid="42327" script="leavearena.lua"/>
    <movevent event="StepIn" actionid="42328" script="leavearena.lua"/>
    <movevent event="StepIn" actionid="42329" script="leavearena.lua"/>
    <movevent event="StepIn" actionid="42330" script="leavearena.lua"/>
arenaroom.lua
Lua:
function onStepIn(cid, item, position, fromPosition)
    if InitArenaScript == 0 then
        InitArenaScript = 1
        -- make arena rooms free
        for i = 0,9 do
            setGlobalStorageValue(42300+i, 0)
            setGlobalStorageValue(42400+i, 0)
        end
        checkArenaRooms({})
    end
    local arena_room = item.actionid
    local player_arena = getPlayerStorageValue(cid, 42355)
    if getPlayerStorageValue(cid, arena_room+getPlayerStorageValue(cid, 42355)*10-1) == 1 or arena_room+getPlayerStorageValue(cid, 42355)*10-1 == 42299 or getPlayerStorageValue(cid, 4999) == 1 then
        if getGlobalStorageValue(cid, arena_room) == 0 then
            local monster_uid = getGlobalStorageValue(arena_room+100)
            if monster_uid > 0 then
                if isCreature(monster_uid) == TRUE then
                    doRemoveCreature(monster_uid)
                end
            end
            local spawn_pos = getThingPos(arena_room)
            local monster = doCreateMonster(arena_monsters[arena_room+getPlayerStorageValue(cid, 42355)*10], {x=spawn_pos.x-1,y=spawn_pos.y-1,z=spawn_pos.z})
            setGlobalStorageValue(arena_room+100, monster)
            doTeleportThing(cid, spawn_pos, TRUE)
            setGlobalStorageValue(arena_room, cid)
            setGlobalStorageValue(arena_room-1, 0)
            setPlayerStorageValue(cid, 42350, os.time()+arena_room_max_time)
        else
            doTeleportThing(cid, fromPosition, TRUE)
            doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_ORANGE,getCreatureName(getGlobalStorageValue(cid, arena_room))..' is now in next room. Wait a moment and try again.')
        end
    else
        doTeleportThing(cid, fromPosition, TRUE)
        doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_ORANGE,'First kill monster!')
    end
    if arena_room == 42300 then
        setPlayerStorageValue(cid, 42351, 0)
        setPlayerStorageValue(cid, 42352, 1)
    end
    return TRUE
end

function checkArenaRooms(param)
    addEvent(checkArenaRooms, 1000, {})
    for i = 42300, 42309 do
        local player = getGlobalStorageValue(i)
        if isPlayer(player) == TRUE then
            local player_storage = getPlayerStorageValue(player, 42350)
            if player_storage <= os.time() then
                doTeleportThing(player, arenaKickPosition, TRUE)
                setPlayerStorageValue(player, 42350, 0)
                setGlobalStorageValue(i, 0)
                doPlayerSendTextMessage(player,MESSAGE_STATUS_CONSOLE_ORANGE,'You have been kicked from arena! You have only ' .. arena_room_max_time .. ' seconds for one room.')
            elseif player_storage - 10 <= os.time() then
                doPlayerSendTextMessage(player,MESSAGE_EVENT_DEFAULT,'Masz ' .. player_storage - os.time() .. ' sekund, zeby przejsc do kolejnego pokoju!')
            end
        else
            setGlobalStorageValue(i, 0)
        end
    end
end

lib
arena.lua
Lua:
-- arena script
InitArenaScript = 0
arena_room_max_time = 300 -- time in seconds for one arena room
arenaKickPosition = {x=1124, y=1466, z=7} -- position where kick from arena when you leave/you did arena level
arena_monsters = {}
arena_monsters[42300] = 'Demon' -- first monster from 1 arena
arena_monsters[42301] = 'Demon'
arena_monsters[42302] = 'Demon'
arena_monsters[42303] = 'Demon'
arena_monsters[42304] = 'Demon'
arena_monsters[42305] = 'Demon'
arena_monsters[42306] = 'Demon'
arena_monsters[42307] = 'Demon'
arena_monsters[42308] = 'Demon'
arena_monsters[42309] = 'Demon'
arena_monsters[42310] = 'Demon' -- first monster from 2 arena
arena_monsters[42311] = 'Demon'
arena_monsters[42312] = 'Demon'
arena_monsters[42313] = 'Demon'
arena_monsters[42314] = 'Demon'
arena_monsters[42315] = 'Demon'
arena_monsters[42316] = 'Demon'
arena_monsters[42317] = 'Demon'
arena_monsters[42318] = 'Demon'
arena_monsters[42319] = 'Demon'
arena_monsters[42320] = 'Demon' -- first monster from 3 arena
arena_monsters[42321] = 'Demon'
arena_monsters[42322] = 'Demon'
arena_monsters[42323] = 'Demon'
arena_monsters[42324] = 'Demon'
arena_monsters[42325] = 'Demon'
arena_monsters[42326] = 'Demon'
arena_monsters[42327] = 'Demon'
arena_monsters[42328] = 'Demon'
arena_monsters[42329] = 'Demon'

function getArenaMonsterIdByName(name)
    name = string.lower(tostring(name))
    for i = 42300, 42329 do
        if tostring(arena_monsters[I]) == name then
            return i
        end
    end
    return 0
end


anyone that can help me i would greatly appreciate it![/I]
 
Solution
cid is a reference to the players creature id. In TFS 1.0+, the player object is being passed along directly.
So basically any code with cid in it is deprecated.
So this:
Lua:
setPlayerStorageValue(cid, room, 1)

Should be this:
Lua:
player:setStorageValue(room, 1)

Docs: Metatable:Player · otland/forgottenserver Wiki · GitHub

I'm not to sure if TFS 1.0+ has a onKill creature event. But it has an onDeath event, which can be tweaked to function like an onKill. (just see who killed you, if that creature is a player then that player is considered the killer).
forgottenserver/creaturescripts.xml at master · otland/forgottenserver · GitHub

If you look here:
forgottenserver/playerdeath.lua at master ·...
cid is a reference to the players creature id. In TFS 1.0+, the player object is being passed along directly.
So basically any code with cid in it is deprecated.
So this:
Lua:
setPlayerStorageValue(cid, room, 1)

Should be this:
Lua:
player:setStorageValue(room, 1)

Docs: Metatable:Player · otland/forgottenserver Wiki · GitHub

I'm not to sure if TFS 1.0+ has a onKill creature event. But it has an onDeath event, which can be tweaked to function like an onKill. (just see who killed you, if that creature is a player then that player is considered the killer).
forgottenserver/creaturescripts.xml at master · otland/forgottenserver · GitHub

If you look here:
forgottenserver/playerdeath.lua at master · otland/forgottenserver · GitHub
You see that the onDeath function passes along this data:
onDeath(player, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)

player (the victim), corpse (the container/the body on the ground), killer (the one who killed the victim)

So effectively, your onKill(cid, target) is:
cid = killer
target = player
on a TFS 1.0+ compatible script.
 
Solution
Back
Top