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

Solved TFS 1.1 - addEvent Function.

darkshin

New old member
Joined
Dec 14, 2010
Messages
231
Reaction score
22
Hello !

I'm trying to make a script that when I use an item somewhere, it addEvents that will send some animations and teleport the player.

But, I just can't do it.
Someone has a clue why it don't work?

Code:
                       addEvent(speech, 2000)
            addEvent(effect, 6000)
            addEvent(teleport, position), 8000)

local function speech()
doCreatureSay(cid, "Woow!", TALKTYPE_ORANGE_1)
end

local function effect()
doSendMagicEffect(getCreaturePosition(cid), 48)
end

local function teleport()
doTeleportThing(getCreaturePosition(cid), {x = 977, y = 1046, z = 7})
end
 
Code:
local function speech(cid)
     local player = Player(cid)
     if player then
         player:say("Woow!", TALKTYPE_MONSTER_SAY)
     end
end

local function effect(cid)
     local player = Player(cid)
     if player then
         player:getPosition():sendMagicEffect(CONST_ME_YELLOWENERGY)
     end
end

local function teleport(cid)
     local player = Player(cid)
     if player then
         player:teleportTo(Position(977, 1046, 7), false)
     end
end

-- The main function

     addEvent(speech, 2000, player.uid)
     addEvent(effect, 6000, player.uid)
     addEvent(teleport, 8000, player.uid) -- position?
     
-- end
 
Code:
local function speech(cid)
     local player = Player(cid)
     if player then
         player:say("Woow!", TALKTYPE_MONSTER_SAY)
     end
end

local function effect(cid)
     local player = Player(cid)
     if player then
         player:getPosition():sendMagicEffect(CONST_ME_YELLOWENERGY)
     end
end

local function teleport(cid)
     local player = Player(cid)
     if player then
         player:teleportTo(Position(977, 1046, 7), false)
     end
end

-- The main function

     addEvent(speech, 2000, player.uid)
     addEvent(effect, 6000, player.uid)
     addEvent(teleport, 8000, player.uid) -- position?
    
-- end

The console returned an error at the Main Function saying "attempt to index a global 'player' <nil value>.
This happened because my Main functions is called like this: function onUse(cid, item, fromPosition, target, toPosition, isHotkey)

So I changed player.uid to cid.uid and everything is working fine!

Thanks Limos!!
 
Back
Top