Jump to content

Script Error, help.


Recommended Posts

Here, In this script i have something wrong, i don't understand. This script is for reviving players, after their death, when i try to /revive [player name or even id] It returns to that "else"

                else 
                    outputChatBox ("There's no online player with this name.", source) 

However, the player's available..... What's wrong here?

server:

addCommandHandler ("revive", function(user, cmd, user2) 
        if isObjectInACLGroup ( "user.".. getAccountName ( getPlayerAccount ( user ) ), aclGetGroup ( "Admin" ) ) then 
            if cmd and user2 then 
                local ID = tonumber(user2) 
                  if ID then 
                    local target = exports.ID_System:getPlayerFromID(ID) 
                  else 
                    local target = exports.ID_System:getPlayerFromPartialName(user2) 
                end 
            if target then 
                if isPedDead(target) then 
                local x, y, z = getElementPosition (target) 
                    spawnPlayer(target, x, y, z) 
                else 
                    outputChatBox("This player is still alive", source) 
            end 
                else 
                    outputChatBox ("There's no online player with this name.", source) 
            end 
                else 
                    outputChatBox ("[syntax] /revive [iD/Partial Name]", source) 
            end 
end 
end) 

Link to comment
Remove local from line 6 and 8. And change source to user.

Still nothing..

I believe, it won't do change, as 'source' is the handler of the command, and local will work, as the script's still in the same function, yup? Anyways, help please :/ !

addCommandHandler ("revive", function(user, cmd, user2) 
        if isObjectInACLGroup ( "user.".. getAccountName ( getPlayerAccount ( user ) ), aclGetGroup ( "Admin" ) ) then 
            if cmd and user2 then 
                local ID = tonumber(user2) 
                  if ID then 
                    local target = exports.ID_System:getPlayerFromID(ID) 
                  else 
                    local target = exports.ID_System:getPlayerFromPartialName(user2) 
                end 
            if target then 
                if isPedDead(target) then 
                local x, y, z = getElementPosition (target) 
                    spawnPlayer(target, x, y, z) 
                else 
                    outputChatBox("This player is still alive", user) 
            end 
                else 
                    outputChatBox ("There's no online player with this name.", user) 
            end 
                else 
                    outputChatBox ("[syntax] /revive [iD/Partial Name]", user) 
        end 
    end 
end) 

Link to comment
Nope, it restricted inside the if statement.

You are totally Right :) ! Thanks for your help, man.

But, here's something:

target = exports.ID_System:getPlayerFromPartialName(user2) 

This part, doesn't work, as when i write a player name, it returns to the same 'else' which i showed, before. But, when i write a player ID, it works fine.

Link to comment
I guess there might be something wrong with the function getPlayerFromPartialName.
function getPlayerFromPartialName ( source, player_name, script ) 
    if ( player_name ) then 
        local sucess, value = getNameMatches ( player_name ) 
            if ( sucess ) then 
                local matches = ( type ( value ) == "table" ) and #value or 1 
                if ( matches == 1 ) then 
                    if ( script ) then return value else  
                        local player_nick = getPlayerName ( value ) 
                        local player_id = getElementData ( value, "ID" ) 
                        outputChatBox ( "(" .. player_id .. ") " .. player_nick, source, 255, 255, 0 ) 
                    end  
                else     
                    outputChatBox ( "Players matching your search are: ", source, 255, 255, 0 ) 
                    for k, player in ipairs ( value ) do 
                        local player_nick = getPlayerName ( value[k] ) 
                        local player_id = getElementData ( value[k], "ID" ) 
                        outputChatBox ( "(" .. player_id .. ") " .. player_nick, source, 255, 255, 0 ) 
                    end 
                    return true, true 
                end      
            else 
                if ( script ) then return false else 
                    outputChatBox ( "Players matching your search are: ", source, 255, 255, 0 ) 
                    outputChatBox ( value, source, 255, 0, 0 ) 
                end  
            end 
    end 
end  

Here's the function.

Link to comment
I guess there might be something wrong with the function getPlayerFromPartialName.
function getPlayerFromPartialName ( source, player_name, script ) 
    if ( player_name ) then 
        local sucess, value = getNameMatches ( player_name ) 
            if ( sucess ) then 
                local matches = ( type ( value ) == "table" ) and #value or 1 
                if ( matches == 1 ) then 
                    if ( script ) then return value else  
                        local player_nick = getPlayerName ( value ) 
                        local player_id = getElementData ( value, "ID" ) 
                        outputChatBox ( "(" .. player_id .. ") " .. player_nick, source, 255, 255, 0 ) 
                    end  
                else     
                    outputChatBox ( "Players matching your search are: ", source, 255, 255, 0 ) 
                    for k, player in ipairs ( value ) do 
                        local player_nick = getPlayerName ( value[k] ) 
                        local player_id = getElementData ( value[k], "ID" ) 
                        outputChatBox ( "(" .. player_id .. ") " .. player_nick, source, 255, 255, 0 ) 
                    end 
                    return true, true 
                end      
            else 
                if ( script ) then return false else 
                    outputChatBox ( "Players matching your search are: ", source, 255, 255, 0 ) 
                    outputChatBox ( value, source, 255, 0, 0 ) 
                end  
            end 
    end 
end  

Here's the function.

It is in the same script, which is ID_system, I think it may help?

function processIDCommands ( source, command, input ) 
    if ( tonumber ( input ) ) then 
        local player, playername = getPlayerFromID ( tonumber(input) ) 
            if ( player ) then 
                outputChatBox ( "Player that matches that id: ", source, 255, 255, 0 ) 
                outputChatBox ( "(" .. input .. ") " .. playername, source, 255, 255, 0, true ) 
            else 
                outputChatBox ( playername, source, 255, 0, 0 ) -- in this case, playername carries the error. It's just to minimize the amount of code if an error is ecountered. 
            end 
    else 
        local player = getPlayer ( source, input ) 
        if ( player ) then 
            outputChatBox ( "Player that matches that id: ", source, 255, 255, 0 ) 
            outputChatBox ( "(" .. tostring ( getElementData ( player, "ID" ) ) .. ") " .. getPlayerName ( player ), source, 255, 255, 0, true ) 
        end  
    end 
end      
addCommandHandler ( "id", processIDCommands ) 

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