Jump to content

[SOLVED]Script Error


Recommended Posts

Posted (edited)

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
Posted

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 

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

Posted
try to use a timer
setTimer(setCameraTarget,5000,1,player2, player2) 

Problem isn't about a timer, it is about a bug:

Bad argument @ 'setCameraTarget' [Expected element at argument , got string 'super' 

That's what i get, when i use the command.

Posted
Replace player2 with target. and use my function.

Nice, it needed to change player2 with target, Thanks solved :) Appreciate it.

np.

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