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

Lua Talk Action takes two parameters

Albanon

New Member
Joined
Mar 5, 2011
Messages
93
Reaction score
1
I have a spell called utevoresmort it's a talk action that summons a creature to your target

so it's utevoresmort Bob

and bob gets a creature spawned beside him

what I'd like to do is make it so the talk action can take two parameters, one being the creature summoned

so utevoresmort bob dragon

and a dragon will appear next to bob
but you can change dragon to any creature


how do I do that?


Here's my script so far.



Code:
function onSay(cid, words, param, channel)

  


    local playerVoc = getPlayerVocation(cid)
    local pid = cid
  
    -- if ( playerVoc ~= 9 )then
    --    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "you are the wrong vocation.")
    --    return
    --end
  
    if (param == '') then
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "you must target someone for the spell to work.")
    return true
    end
  
  
    if(param ~= '' ) then
        pid = getPlayerByNameWildcard(param)
        local position = getCreaturePosition(pid)
        doChallengeCreature(pid, doCreateMonster("dragon", position))
        if(not pid or (isPlayerGhost(pid))) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player " .. param .. " is not currently online.")
            return true
        end
    end

  
  
  
    return true
end


also, can anyone explain what isplayerghost does?
 
I have a spell called utevoresmort it's a talk action that summons a creature to your target

so it's utevoresmort Bob

and bob gets a creature spawned beside him

what I'd like to do is make it so the talk action can take two parameters, one being the creature summoned

so utevoresmort bob dragon

and a dragon will appear next to bob
but you can change dragon to any creature


how do I do that?


Here's my script so far.



Code:
function onSay(cid, words, param, channel)




    local playerVoc = getPlayerVocation(cid)
    local pid = cid

    -- if ( playerVoc ~= 9 )then
    --    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "you are the wrong vocation.")
    --    return
    --end

    if (param == '') then
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You must target someone for the spell to work.")
    return true
    end


    if(param ~= '' ) then
        pid = getPlayerByNameWildcard(param)
        local position = getCreaturePosition(pid)
        doChallengeCreature(pid, doCreateMonster("dragon", position))
        if(not pid or (isPlayerGhost(pid))) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Player " .. param .. " is not currently online.")
            return true
        end
    end




    return true
end


also, can anyone explain what isplayerghost does?

This is how we can use multiple params:
Code:
local split = string.explode(param, ",")
We have assigned the variable split to be the seperate params, which are separated in this scenario by a comma.
The first param would them be called split[1] and the second split[2]

utevoresmort split[1], split[2]

isPlayerGhost(pid) is just checking to see if they player designated in split[1] is in ghost mode or not, if he is in ghost mode then it will return as if the player was offline (in my code below I removed that part and added the check to to beginning of the script instead).


Code:
function onSay(cid, words, param, channel)

local playerVoc = getPlayerVocation(cid)
local pid = cid
local split = string.explode(param, ",")

-- if ( playerVoc ~= 9 )then
--    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "you are the wrong vocation.")
--    return
--end

if (split[1] == nil) then
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You must target someone for the spell to work.")
    return true
end
if not getPlayerByNameWildcard(split[1]) then
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "A player named "..split[1].." is not online.")
    return true
end

if (split[2] == nil) then
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You did not specify a monster.")
    return true
end

if not isCreature(getCreatureByName(split[2])) then
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "A monster with this name doesn't exist.")
    return true
end


    if split[1] ~= '' then
        pid = getPlayerByNameWildcard(split[1])
        local position = getCreaturePosition(pid)
        doChallengeCreature(pid, doCreateMonster(''..string.lower(split[2])..'', position))
    end
return true
end
 
This is how we can use multiple params:
Code:
local split = string.explode(param, ",")
We have assigned the variable split to be the seperate params, which are separated in this scenario by a comma.
The first param would them be called split[1] and the second split[2]

utevoresmort split[1], split[2]

isPlayerGhost(pid) is just checking to see if they player designated in split[1] is in ghost mode or not, if he is in ghost mode then it will return as if the player was offline (in my code below I removed that part and added the check to to beginning of the script instead).


Code:
function onSay(cid, words, param, channel)

local playerVoc = getPlayerVocation(cid)
local pid = cid
local split = string.explode(param, ",")

-- if ( playerVoc ~= 9 )then
--    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "you are the wrong vocation.")
--    return
--end

if (split[1] == nil) then
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You must target someone for the spell to work.")
    return true
end
if not getPlayerByNameWildcard(split[1]) then
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "A player named "..split[1].." is not online.")
    return true
end

if (split[2] == nil) then
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You did not specify a monster.")
    return true
end

if not isCreature(getCreatureByName(split[2])) then
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "A monster with this name doesn't exist.")
    return true
end


    if split[1] ~= '' then
        pid = getPlayerByNameWildcard(split[1])
        local position = getCreaturePosition(pid)
        doChallengeCreature(pid, doCreateMonster(''..string.lower(split[2])..'', position))
    end
return true
end


This is great! thank you so much for explaining this, and writing it down for me! I am going to study this. I put it in, and it works great - sorry, I think im using crying damnson .36

I really like the way you wrote the code, it makes it a lot easier for me to understand! thanks!

Why is this line written the way it is?

doChallengeCreature(pid, doCreateMonster(''..string.lower(split[2])..'', position))

what is string.lower exactly? is it talking about lower case, or is it talking about the second exploded string variable?


is there any way to teleport the player's body to the person who sent the attack, if the creature kills the target?
 
Last edited:
Back
Top