Jump to content

[SOLVED]Script Error


Recommended Posts

Here in this script, there's a problem i don't understand:

addCommandHandler ("revive", function(player, cmd, player2) 
    target = getPlayerFromName(player2) 
        if target then 
            if isElementDead(target) then 
                local x, y, z = getElementPosition(target) 
                    spawnPlayer(target, x, y, z) 
                        outputChatBox ("You've Revived"..target, player, 0, 255, 0, false) 
                    outputChatBox (getPlayerFromName(player).."revived you", target, 0, 255, 0, false) 
                else 
            outputChatBox("syntax: /revive player name", player) 
        end 
    end 
end) 

I made this script to revive dead people

i get this error:

Bad Argument @ 'getPlayerFromName [Expected string at argument 1, got nil] 

How it's nil? I don't understand, how can i make it so...

Edited by Guest
Link to comment

Try this it should work

addCommandHandler ("revive",  
function(player, cmd, player2) 
    local target = getPlayerFromPartialName(player2) 
        if target then 
            if isPedDead(target) then 
                local x, y, z = getElementPosition(target) 
                spawnPlayer(target, x, y, z) 
                outputChatBox ("You've Revived"..target, player, 0, 255, 0, false) 
                outputChatBox (getPlayerName(player).."revived you", target, 0, 255, 0, false) 
            end 
         else 
        outputChatBox("This player does no longer exist!", player) 
    end 
end) 
  
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 

Link to comment
Try this it should work
addCommandHandler ("revive",  
function(player, cmd, player2) 
    local target = getPlayerFromPartialName(player2) 
        if target then 
            if isPedDead(target) then 
                local x, y, z = getElementPosition(target) 
                spawnPlayer(target, x, y, z) 
                outputChatBox ("You've Revived"..target, player, 0, 255, 0, false) 
                outputChatBox (getPlayerName(player).."revived you", target, 0, 255, 0, false) 
            end 
         else 
        outputChatBox("This player does no longer exist!", player) 
    end 
end) 
  
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 

Yup, it works, but there's still a bug, I have setCameraMatrix already made, how can i stop it, when player be revived? I tried "

setCameraTarget(player2, player2) 

but doesn't work.

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