• 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 Please help with my script

arthuraio

Member
Joined
Apr 9, 2015
Messages
123
Reaction score
13
Hello OtLanders,

I wrote a script that make an item teleport the user to his/her town temple and it worked, BUT not like I wanted!!

1 - I want the MagicEffect to happen where the user was standing before using the item, but it never happens, already tried alot of function, I only got it to work when the user uses the item out of his/her inventory, but that is also something that I don't want! (DONE)

2 - I also want that the user get drunk, but not working.... (DONE)

here is my script. P.S: I'm new at scripting.

Code:
local drunk12 = createConditionObject(2048)
    setConditionParam(drunk12, 2, 40000)

function onUse(cid, item, fromPosition, itemEx, toPosition)

    local player = Player(cid)
 
    if getCreatureCondition(cid, CONDITION_INFIGHT) == TRUE or isPlayerPzLocked(cid) == TRUE then
         doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
         doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You can't use it right now.")
    else
         doSendMagicEffect(getCreaturePosition(cid), CONST_ME_ENERGYHIT)
         doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
         doSendMagicEffect(getCreaturePosition(cid), CONST_ME_ENERGYHIT)
         doRemoveItem(itemEx.uid, 1)
         doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You feel... Wrong.")
         doAddCondition(cid, drunk12)

    end
    return true
end
 
Last edited:
Code:
local drunk = createConditionObject(CONDITION_DRUNK)
setConditionParam(drunk, CONDITION_PARAM_TICKS, 5000)

function onUse(cid,item,frompos,item2,topos)
    if isPzLocked(cid) then
        doSendMagicEffect(getThingPos(cid), 2)
        doPlayerSendTextMessage(cid,22,"You can't use it right now.")
    else
        doSendMagicEffect(frompos,11)
        doTeleportThing(cid,getTownTemplePosition(getPlayerTown(cid)))
        doSendMagicEffect(getThingPos(cid),11)
        doRemoveItem(item2.uid)
        doPlayerSendSendTextMessage(cid,22,"You feel... wrong.")
        doAddCondition(cid, drunk)
    end
    return true
end
 
Last edited:
i add exhaustion
Code:
local tps = {
exausted = 10, -- in seconds
storage = 97854
}

local Islam = createConditionObject(CONDITION_DRUNK)
setConditionParam(Islam, CONDITION_PARAM_TICKS, 20000)-- time of DRUNK  << 20000 = 20 sec

function onUse(cid, item, fromPosition, itemEx, toPosition)
local function Sir_Islam(cid)
return isPlayer(cid) and doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid))) and doAddCondition(cid,Islam) and setPlayerStorageValue(cid,tps.storage,os.time()+tps.exausted)
end
  
if getCreatureCondition(cid, CONDITION_INFIGHT) == TRUE or isPlayerPzLocked(cid) == TRUE then
return doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF) and doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You can't use it right now.")
end
if (getPlayerStorageValue(cid, tps.storage) >= os.time()) then
return doPlayerSendCancel(cid, "wait " .. getPlayerStorageValue(cid, tps.storage) - os.time() .. " seconds to use this item again.")
end
    addEvent(Sir_Islam,1*1000,cid)
    doSendMagicEffect(getCreaturePosition(cid), CONST_ME_ENERGYHIT)
    doRemoveItem(itemEx.uid, 1)
    return true
end
 
Thanks for answering, but both of you focused on making the "drunk" prat work and now it works, thanks alot.

But I still want the HITENERGY magic effect to appear in the user where he/she was standing. I already made the magic effect appear after the teleportation. I need to make appear before too.

I'm using TFS 1.0
 
Code:
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_ENERGYHIT)
This line sends the magic effect where the user was standing.
When you teleport away, you most likely will not see this effect on the character being teleported, instead others around you will see it.
 
Code:
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_ENERGYHIT)
This line sends the magic effect where the user was standing.
When you teleport away, you most likely will not see this effect on the character being teleported, instead others around you will see it.

No, it's only sending on the teleport location, I'm testing using the item 2 sqm from the teleport location to see if it's happening and it's not! D=

No one knows about any function that get the lastposition before using the item, to send the magicEffect there?
 
How about a bit of logic?
If you teleport player and āfter that ask for player location. What pos you get?
Pos before or pos now.
 
Yeah, sorry.... Now it's updated.
i just tested ur script on tfs 0.3.6 and it works fine the magic effect happens before teleporting

try this it may help u

Code:
local tps = {
exausted = 10, -- in seconds
storage = 97854
}

local Islam = createConditionObject(CONDITION_DRUNK)
setConditionParam(Islam, CONDITION_PARAM_TICKS, 20000)-- time of DRUNK << 20000 = 20 sec

function onUse(cid, item, fromPosition, itemEx, toPosition)
local function Sir_Islam(cid)
return isPlayer(cid) and doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid))) and doAddCondition(cid,Islam) and setPlayerStorageValue(cid,tps.storage,os.time()+tps.exausted)
end

if getCreatureCondition(cid, CONDITION_INFIGHT) == TRUE or isPlayerPzLocked(cid) == TRUE then
return doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF) and doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You can't use it right now.")
end
if (getPlayerStorageValue(cid, tps.storage) >= os.time()) then
return doPlayerSendCancel(cid, "wait " .. getPlayerStorageValue(cid, tps.storage) - os.time() .. " seconds to use this item again.")
end
addEvent(Sir_Islam,1*1000,cid)
doSendMagicEffect(fromPosition, CONST_ME_ENERGYHIT)
doRemoveItem(itemEx.uid, 1)
return true
end
 
Last edited by a moderator:
i just tested ur script on tfs 0.3.6 and it works fine the magic effect happens before teleporting

try this it may help u

Code:
local tps = {
exausted = 10, -- in seconds
storage = 97854
}

local Islam = createConditionObject(CONDITION_DRUNK)
setConditionParam(Islam, CONDITION_PARAM_TICKS, 20000)-- time of DRUNK << 20000 = 20 sec

function onUse(cid, item, fromPosition, itemEx, toPosition)
local function Sir_Islam(cid)
return isPlayer(cid) and doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid))) and doAddCondition(cid,Islam) and setPlayerStorageValue(cid,tps.storage,os.time()+tps.exausted)
end

if getCreatureCondition(cid, CONDITION_INFIGHT) == TRUE or isPlayerPzLocked(cid) == TRUE then
return doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF) and doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You can't use it right now.")
end
if (getPlayerStorageValue(cid, tps.storage) >= os.time()) then
return doPlayerSendCancel(cid, "wait " .. getPlayerStorageValue(cid, tps.storage) - os.time() .. " seconds to use this item again.")
end
addEvent(Sir_Islam,1*1000,cid)
doSendMagicEffect(fromPosition, CONST_ME_ENERGYHIT)
doRemoveItem(itemEx.uid, 1)
return true
end

That was my first try before posting here, the magiceffect will only appear if the item is used out of the inventory. I want it to happen in any circunstance.... I getting a beatdown to solve this...
 
guys, I need a "player:getOldPosition" or something like that, anyone have an idea?? Please help me =(

-------EDIT-------

Nevermind, I got it to work after a week of headache. Thanks for all the help you guys trid to give.
 
Last edited:
Back
Top