Jump to content

[HELP] Get phone (SOLVED)


Fortitu

Recommended Posts

I created phone system and I have command to get your phone number. But it's not work.

There is code:

  
function getphonenumber(thePlayer, cmd) 
    if (getPlayerName(thePlayer) == "Ervin_Balog") then 
        local phonenumber3 = "222222222" 
    end 
    if (getPlayerName(thePlayer) == "Alex_James") then 
        local phonenumber3 = "755167267" 
    end 
    if (getPlayerName(thePlayer) == "John_Skot") then 
        local phonenumber3 = "752786786" 
    end 
  
    if phonenumber3 then 
        outputChatBox("Your phone number is "..phonenumber3..".",thePlayer,255,150,30,true) 
    end 
end 
addCommandHandler("getphone",getphonenumber) 
  

(It's not writing any errors to log.)

Edited by Guest
Link to comment
function getphonenumber(thePlayer) 
    if (getPlayerName(thePlayer) == "Ervin_Balog") then 
        phonenumber3 = "222222222" 
    elseif (getPlayerName(thePlayer) == "Alex_James") then 
        phonenumber3 = "755167267" 
    elseif (getPlayerName(thePlayer) == "John_Skot") then 
        phonenumber3 = "752786786" 
    end 
  
    if phonenumber3 then 
        outputChatBox("Your phone number is "..phonenumber3..".",thePlayer,255,150,30,true) 
    end 
end 
addCommandHandler("getphone",getphonenumber) 

Link to comment
Thanks! It works.

But I have another problem now, do you know what means this error:

bad argument #1 to 'ipairs' (table expected, got number)

The error explain itself, i don't think it can be explained better than that.

Link to comment

I sent bad error, my mistake I'm sorry.

That was error of something else.

My problem is not writing errors to log, but it's not working too.

There is code:

  
function callphonenumber(thePlayer, cmd, tostring(phonenumber2), ...) 
    if phonenumber2 then 
         
        -- PHONENUMBER2 
        if (phonenumber2 == "222222222") then 
            local player2 = getPlayerFromName("Ervin_Balog") 
        elseif (phonenumber2 == "755167267") then 
            local player2 = getPlayerFromName("Alex_James") 
        elseif (phonenumber2 == "752786786") then 
            local player2 = getPlayerFromName("John_Skot") 
        elseif (phonenumber2 == "756842354") then 
            local player2 = getPlayerFromName("Bohumil_Jentky") 
        end 
         
        -- PHONENUMBER1 
        if (getPlayerName(thePlayer) == "Ervin_Balog") then 
            local phonenumber1 = "222222222" 
        elseif (getPlayerName(thePlayer) == "Alex_James") then 
            local phonenumber1 = "755167267" 
        elseif (getPlayerName(thePlayer) == "John_Skot") then 
            local phonenumber1 = "752786786" 
        elseif (getPlayerName(thePlayer) == "Bohumil_Jentky") then 
            local phonenumber1 = "756842354" 
        end 
         
        if player2 and phonenumber1 then 
            local msg = table.concat({...}, " ") 
            if (msg and msg ~= "") then 
                outputChatBox("[PHONE-"..phonenumber1.."]: ".. msg .." ",player2,255,150,30,true) 
                outputChatBox("Message has been sent.",thePlayer,255,150,30,true) 
            end 
        end 
    end 
end 
addCommandHandler("phone",callphonenumber) 
  

Link to comment

Does it really works this way?

function callphonenumber(thePlayer, cmd, tostring(phonenumber2), ...) 

i don't think so, remove tostring and put it inside the function itself.

-- at line 4 add this 
  
phonenumber2 = tostring(phonenumber2) 

Link to comment

Your code isn't working properly because of two things:

1. You can't call the functions just when you specify arguments of some function(tostring in this case).

2. local variables are accessible only "before first end" after if statement they're not visible anymore so when you try to use them UH OH code doesn't work.

so all you have is to remove local keywords and tostring from the arguments instead of using it there use it inside.

  
    function callphonenumber(thePlayer, cmd, phonenumber2, ...) 
        if phonenumber2 then 
            phonenumber2 = tostring(phonenumber2) 
            
            -- PHONENUMBER2 
            if (phonenumber2 == "222222222") then 
                player2 = getPlayerFromName("Ervin_Balog") 
            elseif (phonenumber2 == "755167267") then 
                player2 = getPlayerFromName("Alex_James") 
            elseif (phonenumber2 == "752786786") then 
                player2 = getPlayerFromName("John_Skot") 
            elseif (phonenumber2 == "756842354") then 
                player2 = getPlayerFromName("Bohumil_Jentky") 
            end 
            
            -- PHONENUMBER1 
            if (getPlayerName(thePlayer) == "Ervin_Balog") then 
                phonenumber1 = "222222222" 
            elseif (getPlayerName(thePlayer) == "Alex_James") then 
                phonenumber1 = "755167267" 
            elseif (getPlayerName(thePlayer) == "John_Skot") then 
                phonenumber1 = "752786786" 
            elseif (getPlayerName(thePlayer) == "Bohumil_Jentky") then 
                phonenumber1 = "756842354" 
            end 
            
            if player2 and phonenumber1 then 
                local msg = table.concat({...}, " ") 
                if (msg and msg ~= "") then 
                    outputChatBox("[PHONE-"..phonenumber1.."]: ".. msg .." ",player2,255,150,30,true) 
                    outputChatBox("Message has been sent.",thePlayer,255,150,30,true) 
                end 
            end 
        end 
    end 
    addCommandHandler("phone",callphonenumber) 
  

Try to test code below to understand it better:

console outputs nil

  
function test(a) 
    if a then 
        local myLocal = 5 
    end 
    print(myLocal) 
end 
  
test(1) 
  

Best regards

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