Jump to content

outputChatBox expected element at argument 2, got string


crismar

Recommended Posts

So I have this script:

function adminPM(thePlayer, theCMD, theTarget, ...) 
    if theTarget ~= nil and hasObjectPermissionTo(thePlayer, "function.kickPlayer", true) then 
        local theTargetElement = getPlayerFromNamePart(theTarget) 
        if(getElementType(theTargetElement) == "player") then 
            local allArgs = {...} 
            local theReason = table.concat(allArgs, " ") 
            setElementData(theTargetElement, "lastpm", getPlayerName(thePlayer)) 
            outputChatBox("#ff0000MESAJ DE LA UN ADMINISTRATOR: #FFFFFF"..tostring(theReason), theTargetElement, 255, 0, 0, true) 
    else 
            outputChatBox("/apm [Jucator] [Mesaje]", thePlayer, 255, 0, 0, true) 
        end 
  
    end 
end 
addCommandHandler("apm", adminPM, false) 
  
function adminReply(thePlayer, theCMD, theTarget, ...) 
        local theTargetElement = getElementData(thePlayer, "lastpm") 
            local allArgs = {...} 
            local theReason = table.concat(allArgs, " ") 
            outputChatBox("#ff0000MESAJ DE LA "..getPlayerName(thePlayer)..": #FFFFFF"..tostring(theReason), theTargetElement, 255, 0, 0, true) 
end 
addCommandHandler("rpm", adminReply, false) 

Or well, part of script. The /apm part works perfectly. The /rpm part seems to do what it's supposed to be but theTargetElement doesn't get parassed as a target but as a string.

Full Debugscript error is something like: outputChatBox expected element at argument 2, got string [ 'lastpm' value ]

So it works, I just don't know how to convert theTargetElement from a string to a element. Any ideas ?

Link to comment
function adminPM(thePlayer, theCMD, theTarget, ...) 
    if theTarget ~= nil and hasObjectPermissionTo(thePlayer, "function.kickPlayer", true) then 
        local theTargetElement = getPlayerFromNamePart(theTarget) 
        if(getElementType(theTargetElement) == "player") then 
            local allArgs = {...} 
            local theReason = table.concat(allArgs, " ") 
            setElementData( theTargetElement, "lastpm",thePlayer ) 
            outputChatBox("#ff0000MESAJ DE LA UN ADMINISTRATOR: #FFFFFF"..tostring(theReason), theTargetElement, 255, 0, 0, true) 
    else 
            outputChatBox("/apm [Jucator] [Mesaje]", thePlayer, 255, 0, 0, true) 
        end 
  
    end 
end 
addCommandHandler("apm", adminPM, false) 
  
function adminReply(thePlayer, theCMD, theTarget, ...) 
        local theTargetElement = getElementData(thePlayer, "lastpm") 
            local allArgs = {...} 
            local theReason = table.concat(allArgs, " ") 
            outputChatBox("#ff0000MESAJ DE LA "..getPlayerName(thePlayer)..": #FFFFFF"..tostring(theReason), theTargetElement, 255, 0, 0, true) 
end 
addCommandHandler("rpm", adminReply, false) 

Link to comment
function adminPM(thePlayer, theCMD, theTarget, ...) 
    if theTarget ~= nil and hasObjectPermissionTo(thePlayer, "function.kickPlayer", true) then 
        local theTargetElement = getPlayerFromNamePart(theTarget) 
        if(getElementType(theTargetElement) == "player") then 
            local allArgs = {...} 
            local theReason = table.concat(allArgs, " ") 
            setElementData( theTargetElement, "lastpm",thePlayer ) 
            outputChatBox("#ff0000MESAJ DE LA UN ADMINISTRATOR: #FFFFFF"..tostring(theReason), theTargetElement, 255, 0, 0, true) 
    else 
            outputChatBox("/apm [Jucator] [Mesaje]", thePlayer, 255, 0, 0, true) 
        end 
  
    end 
end 
addCommandHandler("apm", adminPM, false) 
  
function adminReply(thePlayer, theCMD, theTarget, ...) 
        local theTargetElement = getElementData(thePlayer, "lastpm") 
            local allArgs = {...} 
            local theReason = table.concat(allArgs, " ") 
            outputChatBox("#ff0000MESAJ DE LA "..getPlayerName(thePlayer)..": #FFFFFF"..tostring(theReason), theTargetElement, 255, 0, 0, true) 
end 
addCommandHandler("rpm", adminReply, false) 

Erm sorry but could you tell me what you changed to my code ? I'm trying to learn from my mistakes too :roll:

Link to comment
function adminPM(thePlayer, theCMD, theTarget, ...) 
    if theTarget ~= nil and hasObjectPermissionTo(thePlayer, "function.kickPlayer", true) then 
        local theTargetElement = getPlayerFromNamePart(theTarget) 
        if(getElementType(theTargetElement) == "player") then 
            local allArgs = {...} 
            local theReason = table.concat(allArgs, " ") 
            setElementData( theTargetElement, "lastpm",thePlayer ) 
            outputChatBox("#ff0000MESAJ DE LA UN ADMINISTRATOR: #FFFFFF"..tostring(theReason), theTargetElement, 255, 0, 0, true) 
    else 
            outputChatBox("/apm [Jucator] [Mesaje]", thePlayer, 255, 0, 0, true) 
        end 
  
    end 
end 
addCommandHandler("apm", adminPM, false) 
  
function adminReply(thePlayer, theCMD, theTarget, ...) 
        local theTargetElement = getElementData(thePlayer, "lastpm") 
            local allArgs = {...} 
            local theReason = table.concat(allArgs, " ") 
            outputChatBox("#ff0000MESAJ DE LA "..getPlayerName(thePlayer)..": #FFFFFF"..tostring(theReason), theTargetElement, 255, 0, 0, true) 
end 
addCommandHandler("rpm", adminReply, false) 

Erm sorry but could you tell me what you changed to my code ? I'm trying to learn from my mistakes too

I've just change this :

setElementData( theTargetElement, "lastpm",getPlayerName (thePlayer) ) 
  

To :

setElementData( theTargetElement, "lastpm",thePlayer ) 

Because player name return for a player name not a player .. :)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...