Solved tfs 0.3.6 and now 1.2, doplayer say and others

narkotyko

New Member
Joined
Jan 16, 2016
Messages
22
Reaction score
0
Hello how can i make doplayer say, or addevent and say in talktype_orange_1 in tfs 1.2?
Ok all know without addevent any ideas? Here is my code,
HTML:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, 77)
combat:setArea(createCombatArea(FALA_G_P))
function onGetFormulaValues(player, skill, attack, factor)
    local min = (player:getLevel() / 5) + (skill * attack * 0.03) + 7
    local max = (player:getLevel() / 5) + (skill * attack * 0.05) + 11
    return -min, -max
end
combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function player_look(cid)
if getPlayerLookDir(cid) == 1 then   --right           
//do combat1

elseif getPlayerLookDir(cid) == 2 then    --down
 //do combat2           

elseif getPlayerLookDir(cid) == 3 then   --left
 //do combat3             

elseif getPlayerLookDir(cid) == 0 then   --up
 //do combat4           
     end
     end
function mow_1(cid)   
       doPlayerSendTextMessage(cid,TALKTYPE_ORANGE_1, 'test')   
       doPlayerSendTextMessage(cid,TALKTYPE_ORANGE_1, 'test2')
           //how add function player_look here?
     end
function onCastSpell(creature, variant)
//how add function mow_1 here?

return TRUE
end
</code>
 
Last edited:

magista

RL name " Amir reda "
Joined
Jul 22, 2011
Messages
147
Reaction score
17
Location
Egypt
there are alot of ways to call a function but i think easiest to use AddEvent(mow_1(creature), 1000)
or you can use it directly like this mow_1(creature)
 
Last edited:

WibbenZ

Global Moderator
Staff member
Global Moderator
Joined
Oct 16, 2008
Messages
6,180
Reaction score
1,116
Location
Sweden
on 1.2 there is no AddEvent function ;c
Lua:
function x(cid)
    local player = Player(cid)
    if player then
        ....
    end
end

addEvent(x, 10 * 1000, creature:getId())
 
OP
N

narkotyko

New Member
Joined
Jan 16, 2016
Messages
22
Reaction score
0
addEvent(x, 10 * 1000, creature:getId())
why creature:get id? Is work but i getting traceback
Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
data/spells/scripts/zoltagruba.lua:32: attempt to index global 'creature' (a nil
value)
stack traceback:
[C]: in function '__index' data/spells/scripts/spellname.lua:32: in function <data/spells/scripts/spellname.lua:29>

+ why doCreatureSay(cid,'test',TALKTYPE_ORANGE_1) wont work?
 
Last edited:

WibbenZ

Global Moderator
Staff member
Global Moderator
Joined
Oct 16, 2008
Messages
6,180
Reaction score
1,116
Location
Sweden
why creature:get id? Is work but i getting traceback
Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
data/spells/scripts/zoltagruba.lua:32: attempt to index global 'creature' (a nil
value)
stack traceback:
[C]: in function '__index' data/spells/scripts/spellname.lua:32: in function <data/spells/scripts/spellname.lua:29>

+ why doCreatureSay(cid,'test',TALKTYPE_ORANGE_1) wont work?
1.x uses userdata values insted of "integers", you have to make sure it's still a valid userdata value before executing anything.
If the player logs before the script is executed you could (atleast in the past) crash the server by running w/e function ex player:getName()
Thats because creature does not exist, maybe player? Or post the script.
If thats a function from the script it's not converted, if you feel lazy you could use cid:getId() but thats not really correct since you will still be running the compat functions for the rest of the file.

Post the script.
 
OP
N

narkotyko

New Member
Joined
Jan 16, 2016
Messages
22
Reaction score
0
This wont work :(
Code:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, 77)
combat:setArea(createCombatArea(FALA_G_P))
function onGetFormulaValues(player, skill, attack, factor)
    local min = (player:getLevel() / 5) + (skill * attack * 0.03) + 7
    local max = (player:getLevel() / 5) + (skill * attack * 0.05) + 11
    return -min, -max
end
combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
function onCastSpell(creature, variant)
addEvent(speak,0,creature:getId()) 
if isPlayer(cid) == TRUE and
getPlayerLookDir(cid) == 1 then   --right           
combat:execute(creature, variant)
elseif isPlayer(cid) == TRUE and
getPlayerLookDir(cid) == 2 then    --down
combat:execute(creature, variant)         
elseif isPlayer(cid) == TRUE and
getPlayerLookDir(cid) == 3 then   --left
 combat:execute(creature, variant)             
elseif isPlayer(cid) == TRUE and
getPlayerLookDir(cid) == 0 then   --up
combat:execute(creature, variant)      
end
return TRUE
end
function speak(cid)
doCreatureSay(cid,'Test',TALKTYPE_ORANGE_1)
end
On tfs 0.3.6 was more easy o_O

#ref anyone? :C
 
Last edited by a moderator:

Itutorial

Advanced OT User
Joined
Dec 23, 2014
Messages
1,417
Reaction score
310
I almost didn't help you because you sound like a 5 year old trying to explain what they want.

Code:
local combat = Combat()
    combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
    combat:setParameter(COMBAT_PARAM_EFFECT, 77)
    combat:setArea(createCombatArea(FALA_G_P))

function onGetFormulaValues(player, skill, attack, factor)
    local min = (player:getLevel() / 5) + (skill * attack * 0.03) + 7
    local max = (player:getLevel() / 5) + (skill * attack * 0.05) + 11
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onCastSpell(creature, variant)
    player = Player(creature) // <--- Adds player user data if possible
        if player then // <-- Checks if the userdata was added
            combat:execute(creature, variant)
            player:say("Test", TALKTYPE_ORANGE_1, player:getPosition()) // <-- Look how i did it.
end
return TRUE
end
Learn how to space your code and add tabs.
 

lokolokio

Excellent OT User
Joined
Jan 7, 2009
Messages
151
Reaction score
42
Location
Mexico
Try this...

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, 77)
combat:setArea(createCombatArea(FALA_G_P))
function onGetFormulaValues(player, skill, attack, factor)
    local min = (player:getLevel() / 5) + (skill * attack * 0.03) + 7
    local max = (player:getLevel() / 5) + (skill * attack * 0.05) + 11
    return -min, -max
end
combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onCastSpell(creature, variant)
    addEvent(speak, 0, creature:getId())
    local p = Player(creature)
    if p then
        if p:getDirection() == 1 then   --right        
            combat:execute(creature, variant)
        elseif p:getDirection() == 2 then    --down
            combat:execute(creature, variant)      
        elseif p:getDirection() == 3 then   --left
            combat:execute(creature, variant)          
        elseif p:getDirection() == 0 then   --up
            combat:execute(creature, variant)    
        end
    return TRUE
    end
end
function speak(cid)
    local p = Player(cid)
    if not p then
        return
    end
    p:say("TEST!", TALKTYPE_MONSTER_SAY)
    return true
end
 
Last edited:
OP
N

narkotyko

New Member
Joined
Jan 16, 2016
Messages
22
Reaction score
0
Ty you both very much everythink is work but when i try use this
p:getDirection() == 1 then
is looks like wont work, even if i change 1 to NORTH or anything else still wont work. Any idea why?
 

Itutorial

Advanced OT User
Joined
Dec 23, 2014
Messages
1,417
Reaction score
310
Wow, this is really bad.

Code:
function onCastSpell(creature, variant)
    addEvent(speak, 0, creature:getId())
    local p = Player(cid)
See anything wrong here?
 

lokolokio

Excellent OT User
Joined
Jan 7, 2009
Messages
151
Reaction score
42
Location
Mexico
Thanks @Itutorial , I edited it, the problem consist in 'local p = Player(cid)', where cid is nill, now I changed it to 'local p = Player(creature)' now it shot works @narkotyko , also sorry for that mistake, and also, the direction available are:
Code:
DIRECTION_NORTH
DIRECTION_EAST
DIRECTION_SOUTH
DIRECTION_WEST
DIRECTION_SOUTHWEST
DIRECTION_SOUTHEAST
DIRECTION_NORTHWEST
DIRECTION_NORTHEAST
and not only "NORTH, SOUTH, EAST, WEST, ETCETERA", need the DIRECTION_
 
OP
N

narkotyko

New Member
Joined
Jan 16, 2016
Messages
22
Reaction score
0
Also 1,2,3,0 work on direction, thanks you guys so much! :) Is there any way to add exhaust between function?
Code:
addEvent(speak, 0, creature:getId())
    local p = Player(creature)
    if p then <<before this i wanna 2 second exhaust
 
Last edited:
Top