Jump to content

Unable to get targetPlayer.


keymetaphore

Recommended Posts

function issueJail(source, command, targetPlayer, reason)
local source = getPlayerFromName(source)
local targetPlayer = getPlayerFromName(targetPlayer)
if targetPlayer and reason then

outputChatBox("Spēlētājs " ..targetPlayer.." ir saņēmis brīdinājumu par "..reason..".", source, 255,0, 0)
outputChatBox("Jūs esat RP pārkāpuma ierakstu no administratora " .. source .. ".", targetPlayer, 255, 0, 0)
outputChatBox("Sakrājot vairākus šādus brīdinājumus, jūs saņemsiet liegumu no servera.", targetPlayer, 255, 0, 0)
outputChatBox("Jūsu pārkāpums: "..reason..".", targetPlayer, 255, 0, 0)
outputChatBox("Vai brīdinājums ir izsniegts nepatiesi? Ziņo forumā!", targetPlayer, 255, 0, 0)
outputChatBox("", targetPlayer, 255, 0, 0)
outputChatBox("", targetPlayer, 255, 0, 0)
outputChatBox("", targetPlayer, 255, 0, 0)
else
outputChatBox("Sintakse: /"..command.. " [Daļa no vārda/ID] [Iemesls]", source, 255, 194, 14) return false
end
end
addCommandHandler("pwarn", issueJail)

So, I wrote this code, and I keep getting this error - 

Attempt to concatenate local ' targetPlayer'  (a userdata value)

I tried to use it with getPlayerName() too, but it didn't work. Any hints?

 

Link to comment
On 2/1/2017 at 19:25, MrTasty said:

Line 6 should be getPlayerName(targetPlayer) while all the other targetPlayer can remain as they are.

Got a warning - Bad argument @ 'getPlayerName'[Expected element at argument 1, got string 'James'] ( it's a full name ) 

function issueJail(source, command, targetPlayer, reason)


if targetPlayer and reason then
local targetPlayer = getPlayerName(targetPlayer)
outputChatBox("Spēlētājs " ..targetPlayer.." ir saņēmis brīdinājumu par "..reason..".", source, 255,0, 0)
outputChatBox("Jūs esat RP pārkāpuma ierakstu no administratora " .. source .. ".", targetPlayer, 255, 0, 0)
outputChatBox("Sakrājot vairākus šādus brīdinājumus, jūs saņemsiet liegumu no servera.", targetPlayer, 255, 0, 0)
outputChatBox("Jūsu pārkāpums: "..reason..".", targetPlayer, 255, 0, 0)
outputChatBox("Vai brīdinājums ir izsniegts nepatiesi? Ziņo forumā!", targetPlayer, 255, 0, 0)
outputChatBox("", targetPlayer, 255, 0, 0)
outputChatBox("", targetPlayer, 255, 0, 0)
outputChatBox("", targetPlayer, 255, 0, 0)
else
outputChatBox("Sintakse: /"..command.. " [Daļa no vārda/ID] [Iemesls]", source, 255, 194, 14) return false
end
end
addCommandHandler("pwarn", issueJail)

 

Link to comment
5 hours ago, koragg said:

Try : getPlayerFromPartialName (targetPlayer)

https://wiki.multitheftauto.com/wiki/GetPlayerFromPartialName

That's not a built-in mta function so you'll need to copy the whole wiki code into your file before using it. 

Did it, with the whole function. 

Attempt to concetanate (might be wrong) local targetPlayer(a userdata value)


function getPlayerFromPartialName(name)
    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil
    if name then
        for _, player in ipairs(getElementsByType("player")) do
            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower()
            if name_:find(name, 1, true) then
                return player
            end
        end
    end
end

function issueJail(source, command, targetPlayer, reason)

if targetPlayer and reason then
local targetPlayer = getPlayerFromPartialName(targetPlayer)

outputChatBox("Spēlētājs " ..targetPlayer.." ir saņēmis brīdinājumu par "..reason..".", source, 255,0, 0)
outputChatBox("Jūs esat RP pārkāpuma ierakstu no administratora " .. source .. ".", targetPlayer, 255, 0, 0)
outputChatBox("Sakrājot vairākus šādus brīdinājumus, jūs saņemsiet liegumu no servera.", targetPlayer, 255, 0, 0)
outputChatBox("Jūsu pārkāpums: "..reason..".", targetPlayer, 255, 0, 0)
outputChatBox("Vai brīdinājums ir izsniegts nepatiesi? Ziņo forumā!", targetPlayer, 255, 0, 0)
outputChatBox("", targetPlayer, 255, 0, 0)
outputChatBox("", targetPlayer, 255, 0, 0)
outputChatBox("", targetPlayer, 255, 0, 0)
else
outputChatBox("Sintakse: /"..command.. " [Daļa no vārda/ID] [Iemesls]", source, 255, 194, 14) return false
end
end
addCommandHandler("pwarn", issueJail)

rip, still need help

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...