AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Comparing strings (https://forums.alliedmods.net/showthread.php?t=84979)

P4rD0nM3 02-03-2009 19:07

Comparing strings
 
Dunno if this goes here.

Let's say...

steamid1 = 0:0:28033812
steamid2 = 0:0:28033


if(containi(steamid1, steamid2[i]) != -1) { blah }

When this happens 0:0:28033812 is also affected since it has 0:0:28033 inside of it.

What would be the best solution for this? Should I be even using containi?

Exolent[jNr] 02-03-2009 19:07

Re: Comparing strings
 
equal()

P4rD0nM3 02-03-2009 19:28

Re: Comparing strings
 
But using equal() would only allow that specific SteamID.

I was wondering if you can have 0:0:28033XX SteamID's be allowed and if it goes out of that range then they won't be affected. This way all the cafe terminals will have an admin account and if someone out there connects then they won't get admin.

Emp` 02-03-2009 19:44

Re: Comparing strings
 
Try with str_to_num starting after the last colon.

Then check if that number is within your desired numbers.

Ex.
Code:

new string[] = "steam:2300" //just a random id
new num = str_to_num( string[6] );
if( num > 2300 && num < 2400 )
    //do stuff here


P4rD0nM3 02-03-2009 19:56

Re: Comparing strings
 
Hey Emp, would that include 0:0:?

All it says is

str_to_num - Returns a string converted to a number

When you do...

new num = str_to_num( string[10] )

Does that mean it'll count to 10 and strip the rest? Like for STEAM:0:0:1234567890 it'll strip STEAM:0:0: and then 1234567890 will be in num?

Emp` 02-03-2009 19:58

Re: Comparing strings
 
If you are using steamids as the string (STEAM_0:0:XXXX)
Then the last colon is the 10th character, so you would do
Code:

str_to_num( string_name[10] )
For more information on this method, check out String Slicing.

P4rD0nM3 02-03-2009 20:10

Re: Comparing strings
 
What if I have STEAM_0:0:123 and STEAM_0:0:234 and my own SteamID which is STEAM_0:0:28033.

Like.

Code:
new const adminIDs[][] = {   "steam_0:0:123", // range   "steam_0:0:234", // range   "steam_0:0:28033" // mine }

str_to_num only strips the front one? What if I want to strip the back one too or simply the ones at the back like steam_0:0:1231131?

Emp` 02-03-2009 20:14

Re: Comparing strings
 
You'll have to separate it into two ranges or something.

Code:

if within first range
  func()
else if within second range
  func()
else if equal to random steam id
  func()


P4rD0nM3 02-03-2009 20:26

Re: Comparing strings
 
Damn, all that just to get admin and ban someone...screw these people they should just call the manager. Haha, thanks though! At least I could do it for my ID.


All times are GMT -4. The time now is 01:38.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.