Jump to content

[HELP] Infinite running script


Ludo

Recommended Posts

Hi everyone. I have a little problem with a script, because it gives me these errors:

ERROR: Infinite/too long execution (script_name)

Aborting; infinite running script in script_name

This script is for get the country code of a player who joins.

Anyway here is my script:

IPList = { 
    ["31.201.76.0 - 31.201.76.255"] = "AD", 
    --A list of table values (about 1300) 
} 
  
function getPlayerCountry(player) 
    theIP = getPlayerIP(player) 
    IP1 = tostring(math.adjust(tonumber(gettok(theIP, 1, 46)))) 
    IP2 = tostring(math.adjust(tonumber(gettok(theIP, 2, 46)))) 
    IP3 = tostring(math.adjust(tonumber(gettok(theIP, 3, 46)))) 
    IP4 = tostring(math.adjust(tonumber(gettok(theIP, 4, 46)))) 
    IP = tonumber(tostring(IP1..IP2..IP3..IP4)) 
    for ip1, ip2 in pairs(IPList) do 
        if ip1 and ip2 then 
            IPStart = tostring(gettok(ip1, 1, 45)) 
            IPEnd = tostring(gettok(ip1, 2, 45)) 
            IPCode = tostring(ip2) 
            if IPStart ~= "" and IPEnd ~= "" and IPCode ~= "" then 
                IPS1 = tostring(math.adjust(tonumber(gettok(IPStart, 1, 46)))) 
                IPS2 = tostring(math.adjust(tonumber(gettok(IPStart, 2, 46)))) 
                IPS3 = tostring(math.adjust(tonumber(gettok(IPStart, 3, 46)))) 
                IPS4 = tostring(math.adjust(tonumber(gettok(IPStart, 4, 46)))) 
                IPE1 = tostring(math.adjust(tonumber(gettok(IPEnd, 1, 46)))) 
                IPE2 = tostring(math.adjust(tonumber(gettok(IPEnd, 2, 46)))) 
                IPE3 = tostring(math.adjust(tonumber(gettok(IPEnd, 3, 46)))) 
                IPE4 = tostring(math.adjust(tonumber(gettok(IPEnd, 4, 46)))) 
                IPS = tonumber(tostring(IPS1..IPS2..IPS3..IPS4)) 
                IPE = tonumber(tostring(IPE1..IPE2..IPE3..IPE4)) 
                if IP >= IPS and IP <= IPE then 
                    flag = IPCode 
                end 
            end 
        end 
    end 
    return flag or "N/A" 
end 

math.adjust is a function i use for adjust the numbers, anyway that is not the problem cause i get the errors also if I don 't use it. Can anyone help me please?

Link to comment

Try this:

  
IPList = { 
    ["31.201.76.*"] = "AD", 
    --A list of table values (about 1300) 
} 
  
function getPlayerCountry(player) 
    theIP = getPlayerIP(player) 
    IP1 = tostring(math.adjust(tonumber(gettok(theIP, 1, 46)))) 
    IP2 = tostring(math.adjust(tonumber(gettok(theIP, 2, 46)))) 
    IP3 = tostring(math.adjust(tonumber(gettok(theIP, 3, 46)))) 
    IP4 = tostring(math.adjust(tonumber(gettok(theIP, 4, 46)))) 
    IP = tonumber(tostring(IP1..IP2..IP3..IP4)) 
    for ip1, ip2 in pairs(IPList) do 
        if ip1 and ip2 then 
            IPStart = tostring(gettok(ip1, 1, 45)) 
            IPEnd = tostring(gettok(ip1, 2, 45)) 
            IPCode = tostring(ip2) 
            if IPStart ~= "" and IPEnd ~= "" and IPCode ~= "" then 
                IPS1 = tostring(math.adjust(tonumber(gettok(IPStart, 1, 46)))) 
                IPS2 = tostring(math.adjust(tonumber(gettok(IPStart, 2, 46)))) 
                IPS3 = tostring(math.adjust(tonumber(gettok(IPStart, 3, 46)))) 
                IPS4 = tostring(math.adjust(tonumber(gettok(IPStart, 4, 46)))) 
                IPE1 = tostring(math.adjust(tonumber(gettok(IPEnd, 1, 46)))) 
                IPE2 = tostring(math.adjust(tonumber(gettok(IPEnd, 2, 46)))) 
                IPE3 = tostring(math.adjust(tonumber(gettok(IPEnd, 3, 46)))) 
                IPE4 = tostring(math.adjust(tonumber(gettok(IPEnd, 4, 46)))) 
                IPS = tonumber(tostring(IPS1..IPS2..IPS3..IPS4)) 
                IPE = tonumber(tostring(IPE1..IPE2..IPE3..IPE4)) 
                if IP >= IPS and IP <= IPE then 
                    flag = IPCode 
                end 
            end 
        end 
    end 
    return flag or "N/A" 
end 
  

Link to comment
Try this:
  
IPList = { 
    ["31.201.76.*"] = "AD", 
    --A list of table values (about 1300) 
} 
  
function getPlayerCountry(player) 
    theIP = getPlayerIP(player) 
    IP1 = tostring(math.adjust(tonumber(gettok(theIP, 1, 46)))) 
    IP2 = tostring(math.adjust(tonumber(gettok(theIP, 2, 46)))) 
    IP3 = tostring(math.adjust(tonumber(gettok(theIP, 3, 46)))) 
    IP4 = tostring(math.adjust(tonumber(gettok(theIP, 4, 46)))) 
    IP = tonumber(tostring(IP1..IP2..IP3..IP4)) 
    for ip1, ip2 in pairs(IPList) do 
        if ip1 and ip2 then 
            IPStart = tostring(gettok(ip1, 1, 45)) 
            IPEnd = tostring(gettok(ip1, 2, 45)) 
            IPCode = tostring(ip2) 
            if IPStart ~= "" and IPEnd ~= "" and IPCode ~= "" then 
                IPS1 = tostring(math.adjust(tonumber(gettok(IPStart, 1, 46)))) 
                IPS2 = tostring(math.adjust(tonumber(gettok(IPStart, 2, 46)))) 
                IPS3 = tostring(math.adjust(tonumber(gettok(IPStart, 3, 46)))) 
                IPS4 = tostring(math.adjust(tonumber(gettok(IPStart, 4, 46)))) 
                IPE1 = tostring(math.adjust(tonumber(gettok(IPEnd, 1, 46)))) 
                IPE2 = tostring(math.adjust(tonumber(gettok(IPEnd, 2, 46)))) 
                IPE3 = tostring(math.adjust(tonumber(gettok(IPEnd, 3, 46)))) 
                IPE4 = tostring(math.adjust(tonumber(gettok(IPEnd, 4, 46)))) 
                IPS = tonumber(tostring(IPS1..IPS2..IPS3..IPS4)) 
                IPE = tonumber(tostring(IPE1..IPE2..IPE3..IPE4)) 
                if IP >= IPS and IP <= IPE then 
                    flag = IPCode 
                end 
            end 
        end 
    end 
    return flag or "N/A" 
end 
  

Ehm you didn' t change anything except that *

Anyway it doesn 't work

Link to comment

sometimes no script name is given when this happens.

i doubt the name of the file matters.

this can also occur if the loop is taking too long... its possible running ur adjust function 10,000 times is too much for the loop.

silly question but have u tried with a smaller loop to see if the function is working?

Link to comment
no script name is given when this happens.

i doubt the name of the file matters.

this can also occur if the loop is taking too long... its possible running ur adjust function 10,000 times is too much for the loop.

silly question but have u tried with a smaller loop to see if the function is working?

I hope I understood that you said: If you mean a smaller table, yes i did and the script works good. With this table it gives me this errors. Anyway i tried 4 different things:

1 - Table of about 700 lines - Error

2 - Table of about 700 lines using "break" - Good

3 - Table of about 1300 lines - Error

4 - Table of about 1300 lines using "break" - Error

Link to comment

For example if the Ip is 95.100.4.20 it becomes 95100004020

I need this function or the script won' t work.

Anyway i did another function before that, using a different system without table.adjust and it gives me the same error anyway..

Link to comment

wow all that just to remove the dots...

u do know thats what gettok does? so really the function isnt needed.

if u havent resolved this by tonight, i'll fix it for u.

but i have to go out for a couple of hours now and ul have probably sorted it by then.

good luck... i'll check back in a bit.

Link to comment

Try:

  
IPList = { 
    ["31.201.76.*"] = "AD", 
} 
  
function getPlayerCountry(player) 
    theIP = getPlayerIP(player) 
    IP1 = tostring(math.adjust(tonumber(gettok(theIP, 1, 46)))) 
    IP2 = tostring(math.adjust(tonumber(gettok(theIP, 2, 46)))) 
    IP3 = tostring(math.adjust(tonumber(gettok(theIP, 3, 46)))) 
    IP4 = tostring(math.adjust(tonumber(gettok(theIP, 4, 46)))) 
    IP = tonumber(tostring(IP1...IP2...IP3...IP4)) 
    for ip1, ip2 in pairs(IPList) do 
        if ip1 and ip2 then 
            IPStart = tostring(gettok(ip1, 1, 45)) 
            IPEnd = tostring(gettok(ip1, 2, 45)) 
            IPCode = tostring(ip2) 
            if IPStart ~= "" and IPEnd ~= "" and IPCode ~= "" then 
                IPS1 = tostring(math.adjust(tonumber(gettok(IPStart, 1, 46)))) 
                IPS2 = tostring(math.adjust(tonumber(gettok(IPStart, 2, 46)))) 
                IPS3 = tostring(math.adjust(tonumber(gettok(IPStart, 3, 46)))) 
                IPS4 = tostring(math.adjust(tonumber(gettok(IPStart, 4, 46)))) 
                IPE1 = tostring(math.adjust(tonumber(gettok(IPEnd, 1, 46)))) 
                IPE2 = tostring(math.adjust(tonumber(gettok(IPEnd, 2, 46)))) 
                IPE3 = tostring(math.adjust(tonumber(gettok(IPEnd, 3, 46)))) 
                IPE4 = tostring(math.adjust(tonumber(gettok(IPEnd, 4, 46)))) 
                IPS = tonumber(tostring(IPS1...IPS2...IPS3...IPS4)) 
                IPE = tonumber(tostring(IPE1...IPE2...IPE3...IPE4)) 
                if IP >= IPS and IP <= IPE then 
                    flag = IPCode 
                end 
            end 
        end 
    end 
    return flag or "N/A" 
end 
  

Link to comment

Man it isn' t don't needed.

And yes, i know what gettok does. Maybe you didn' t understand that I tiped...

If the ip is 5.100.4.20, with math.adjust it becomes: 005.100.004.020, then using gettok i remove the points and i do a string containin 005100004020. I hope you have understood now..

For Draken:

Try:
  
IPList = { 
    ["31.201.76.*"] = "AD", 
} 
  
function getPlayerCountry(player) 
    theIP = getPlayerIP(player) 
    IP1 = tostring(math.adjust(tonumber(gettok(theIP, 1, 46)))) 
    IP2 = tostring(math.adjust(tonumber(gettok(theIP, 2, 46)))) 
    IP3 = tostring(math.adjust(tonumber(gettok(theIP, 3, 46)))) 
    IP4 = tostring(math.adjust(tonumber(gettok(theIP, 4, 46)))) 
    IP = tonumber(tostring(IP1...IP2...IP3...IP4)) 
    for ip1, ip2 in pairs(IPList) do 
        if ip1 and ip2 then 
            IPStart = tostring(gettok(ip1, 1, 45)) 
            IPEnd = tostring(gettok(ip1, 2, 45)) 
            IPCode = tostring(ip2) 
            if IPStart ~= "" and IPEnd ~= "" and IPCode ~= "" then 
                IPS1 = tostring(math.adjust(tonumber(gettok(IPStart, 1, 46)))) 
                IPS2 = tostring(math.adjust(tonumber(gettok(IPStart, 2, 46)))) 
                IPS3 = tostring(math.adjust(tonumber(gettok(IPStart, 3, 46)))) 
                IPS4 = tostring(math.adjust(tonumber(gettok(IPStart, 4, 46)))) 
                IPE1 = tostring(math.adjust(tonumber(gettok(IPEnd, 1, 46)))) 
                IPE2 = tostring(math.adjust(tonumber(gettok(IPEnd, 2, 46)))) 
                IPE3 = tostring(math.adjust(tonumber(gettok(IPEnd, 3, 46)))) 
                IPE4 = tostring(math.adjust(tonumber(gettok(IPEnd, 4, 46)))) 
                IPS = tonumber(tostring(IPS1...IPS2...IPS3...IPS4)) 
                IPE = tonumber(tostring(IPE1...IPE2...IPE3...IPE4)) 
                if IP >= IPS and IP <= IPE then 
                    flag = IPCode 
                end 
            end 
        end 
    end 
    return flag or "N/A" 
end 
  

Someone already posted this.. and it doesn' t work, thank you anyway.

Link to comment

I understand better now thx..

ok if ur still having problems.. try this:

  
function getPlayerCountry(player) 
    local IPStart,IPEnd,IPS,IPE 
    local IP = getCodedIP(getPlayerIP(player)) 
    for k,v in pairs(IPList) do 
        IPStart = tostring(gettok(k, 1, 45)) 
        IPEnd = tostring(gettok(k, 2, 45)) 
        IPS = getCodedIP(IPStart) 
        IPE = getCodedIP(IPEnd) 
        if IP >= IPS and IP <= IPE then 
            return v 
        end 
    end 
    return "N/A" 
end 
  
function getCodedIP(ip) 
    local temp1,temp2 = "","" 
    for a = 1,4 do 
        temp1 = tonumber(gettok(ip, a, 46)) 
        if temp1 < 10 then temp1 = "00" .. temp1 else 
        if temp1 < 100 then temp1 = "0" .. temp1 end 
        end 
        temp2 = temp2 .. temp1 
    end 
    return temp2 
end 

ive made a function to do what u said urs did since u didnt provide one.

this should work however i dont have 1300 ip's to test it on, so ul have to let me know.

this converts a normal ip into a 12 digit number like u said, and then compares it with the ips in the table.

then returns the flag string from the table if the number is between start and end numbers,

or returns the string N/A if nothing is found.

Link to comment

1300 is a lot to search through but i would think u should be able to manage a loop of that size

unless ur trying to run this function on few people at the same time (ie: get the locations of all players at once) then its never gonna work.

u can of course slow the loop down with various methods but then the string returned will be delayed.

have u thought about having a look how its done in the admin resource? since country flags are shown there too.

theres definitely a better way than looping through all these ip's in the table.

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