AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Strings and pawn (https://forums.alliedmods.net/showthread.php?t=51827)

sskillz 02-24-2007 15:17

Strings and pawn
 
Hello, I just started making my plugin and its almost complete, I have a string which goes like this: "%STEAMID%STEAMID%STEAMID"

now how I get each STEAMID? and how can I kick each one from the server?
10x ahead It just stupid using string with pawn (sorry I come from per :|)

Also I could test if a string starts with "CHK" ;\

10x.

mysticssjgoku4 02-24-2007 15:33

Re: Strings and pawn
 
Quote:

Originally Posted by sskillz (Post 444977)
Hello, I just started making my plugin and its almost complete, I have a string which goes like this: "%STEAMID%STEAMID%STEAMID"

now how I get each STEAMID? and how can I kick each one from the server?
10x ahead It just stupid using string with pawn (sorry I come from per :|)

Also I could test if a string starts with "CHK" ;\

10x.

Code:
public test(id) {     //Getting the SteamID     new steamid[32] //Must make the variable to hold 32 characters (STRING)     get_user_steamid(id,steamid,31) //GET THE INFO, store it in steamid for a len* of 31. (31 = 32 chars because it starts at 0, not 1)         //Getting a Name     new name[32]     get_user_name(id,name,31)         //Kicking the STEAMID     new target_id = cmd_target(id,steamid) //Player ID     new target_uid = get_user_userid(target_id) //The Player's actual slot ID |Only retrieved for the RAW Kick COmmand|         new command[128]     format(command,127,"kick #%d ^"You have been kicked.^"",target_uid)     server_cmd(command)         //To Add strings together here are some types:     // %s = string     // %f = float     // %i = integer         new combined[80]         //This will produce "STEAMIDSTEAMIDSTEAMID"     format(combined,79,"%s%s%s",steamid,steamid,steamid)         //This will produce "STEAMID STEAMID STEAMID"     format(combined,79,"%s %s %s",steamid,steamid,steamid)         //This will produce "STEAMID STEAMID NAME"     format(combined,79,"%s %s %s",steamid,steamid,name)             //This will produce "STEAMID STEAMID 12"     new num = 12 //This is an integer, notice its not indexed (or is not an array)     format(combined,79,"%s %s %i",steamid,steamid,num)         //This will produce "STEAMID STEAMID 24.5"     new Float:num_float = 24.5 //This is a float, a float is just a decimal number. You must start the new var with "Float:" and it must be a decimal     format(combined,79,"%s %s %f",steamid,steamid,num_float) }

Zenith77 02-24-2007 19:05

Re: Strings and pawn
 
goku: No.

To split strings, like your trying to do, use this stock.

Code:
stock ExplodeString( p_szOutput[][], p_nMax, p_nSize, p_szInput[], p_szDelimiter ) { // Function by xeroblood     new nIdx = 0, l = strlen(p_szInput)     new nLen = (1 + copyc( p_szOutput[nIdx], p_nSize, p_szInput, p_szDelimiter ))     while( (nLen < l) && (++nIdx < p_nMax) )         nLen += (1 + copyc( p_szOutput[nIdx], p_nSize, p_szInput[nLen], p_szDelimiter ))     return nIdx }

You can use it like this:
Code:
new string[] = "STEAM%STEAM%STEAM"; new steamid[3][32]; // This will be all 3 steam ids split from the string. ExplodeString(steamid, 2, 31, string, '%'); // variable 'steamid' now contains all steamids in the first dimension (steamid[0], steamid[1], steamid[2]).

You can kick them, continuing on the code above, like this:
Code:
new i; for (i = 0; i < 2; i++)      server_cmd("kick ^"%s^" ^"You were kicked due to your steamid.^"", steamid[i]);

Let me know if you have any compile time errors.

mysticssjgoku4 02-24-2007 20:14

Re: Strings and pawn
 
Oh I misunderstood what he was asking :S.

sskillz 02-25-2007 08:17

Re: Strings and pawn
 
Hello again,
Thank you so much!
I had that ExplodeString routine but I didn't know excatly how to use it, Now I know.

Some obious questions:
Is 32 here is max length of the steamid?
new steamid[3][32];

I didn't know kick steamID from the console works :| I was sure I tried it :\

Anyway thanks ill continue from here :D

sskillz 02-25-2007 09:54

Re: Strings and pawn
 
You forgot one of the parameters with the explode (input string).
Also that kick didn't work for me, after look in how amx_kick can kick steamIDs
I learned how to kick them :) here is what I did in the end:

Code:

new steamid[32][32];
                    ExplodeString(steamid,2,31,buf,'%');
                       
                    //Handle Data
                        server_print("(SnapShooter) GOT PEOPLE TO KICK");
                        server_print("(SnapShooter) READ(%i bytes): %s",z,buf);
                       
                        new i;
            for (i = 1; i <= 32; i++) {
                            if (strlen(steamid[i]) > 5) {
                        new reason[43] = "(SnapShooteR) Please activate SnapShooter!";                       
                        new player = cmd_target(1, steamid[i], 0);       
                        new userid = get_user_userid(player);
                        server_cmd("kick #%d ^"%s^"", userid, reason)
                            }
                        }


Zenith77 02-25-2007 09:58

Re: Strings and pawn
 
Ok, pretty decent for your level. But use get_players() for your for loop. Check in funcwiki on how to use it.

And instead of this:
Code:
 new reason[43] = "(SnapShooteR) Please activate SnapShooter!"; server_cmd("kick #%d ^"%s^"", userid, reason)

Just do this:
Code:
server_cmd("kick #%d ^"(SnapShooteR) Please activate SnapShooter!^"", userid);

No point in creating a buffer there ;-).

sskillz 02-25-2007 12:36

Re: Strings and pawn
 
Yea i know i didn't have to use reason...
Where did you suggest me to use get players?
I mean I know where it needs to be but it also means if ill use get_players
I'll have to loop more times than this...

Zenith77 02-25-2007 13:58

Re: Strings and pawn
 
No you won't. Use it in the loop where you kick people.


All times are GMT -4. The time now is 00:45.

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