Raised This Month: $51 Target: $400
 12% 

Some example help please


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
chumly
Senior Member
Join Date: Jul 2006
Old 09-17-2007 , 05:24   Some example help please
Reply With Quote #1

Hi All!
I'm just starting to learn this C stuff, and need a little help with some examples. Would you be so kind as to post some example code to the follow questions?
Thanks!

1. I've been trying to filter out bots and admins from a OnClientPostAdminCheck(client) function. The current function is letting non-admins in along with admins... So, is this a problem with my code, or a error in the admflags?
Code:
      if (IsFakeClient(client) || flags & ADMFLAG_ROOT || flags & ADMFLAG_RESERVATION)
        { ... }
2. I'd like to create a server var that contains a server ip address and port of a css server. I'd like it to have a default value, and allow me to update the serverip/port, and retrieve it in code. I've been able to create it, ( but I'm not sure if I did it right ) but I'm having trouble with being able to retrieve it.
Code:
 
public OnPluginStart()
{
CreateConVar("server_address", "ip.ip.ip.ip:port", "Server redirect address:port", FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
}
Now, when I use 'SomeFunction("blah blah blah %s, %d ", server_address, server_address)' I get nothing in the string, and a large number in the digit fields. Now, I did try to break it apart to remove the ':' and use two seperate fields, but that didn't seem to work for me either... The var is saved fine, and I can see it in the public vars, I just don't know how to properly retrieve it in code.

3. I'd like to grab a random user, and do some function on him. ( eg: kick )
But, I need the user to not be an admin, and I'd like to specify how many users to do this to. eg: kick 10 random non-admin users. Could someone please post an example of this sort of thing?

4. How do you print a line to the servers console? I'd like to put some information into the server console / server log.

5. This following function seems to be returning the number of admins, but it also is adding the number of bots... How do I filter this to not include bots? ( and how would I grab the userid's while I'm looping through the players? )
Code:
public chgetadmincount()
{
    new max_clients = GetMaxClients();
    new ch_total;
    ch_total = 0;
    for (new i=1; i<=max_clients; i++)
    {
       if (IsClientInGame(i) && GetUserAdmin(i) != INVALID_ADMIN_ID)
       {
              ch_total++;
       }
    }
    SetConVarInt(ch_admins, ch_total);
    return ch_total;    
}
Thanks so much for your assistance.
Chumly
chumly is offline
Nican
Veteran Member
Join Date: Jan 2006
Location: NY
Old 09-17-2007 , 07:08   Re: Some example help please
Reply With Quote #2

ok...
1.
if (IsFakeClient(client))
You are checking if the player IS a bot, and that will never go trough because bots can not be admins change IsFakeClient(client) to !IsFakeClient(client), because ! check the inverse

2. to get a string out of a convar:
PHP Code:
new Handle:something;
public 
OnPluginStart(){
   new 
String:convarstring[64];
   
something CreateConVar("sm_addr","x.x.x.x:y");
   
GetConVarString(somethingconvarstring64);
   
// There... now convarstring holds x.x.x.x:y 

3. I have no time for that, I have school D:

4. http://sm.nican132.com/index.php?fas...e&id=27&type=&

5. Again use !IsFakeClient(client)
PHP Code:
if (IsClientInGame(i) && GetUserAdmin(i) != INVALID_ADMIN_ID && !IsFakeClient(i)) 
__________________
http://www.nican132.com
I require reputation!
Nican is offline
Send a message via ICQ to Nican Send a message via MSN to Nican
chumly
Senior Member
Join Date: Jul 2006
Old 09-19-2007 , 09:04   Re: Some example help please
Reply With Quote #3

Great stuff, Thanks for the info!
That will help out a fair bit.
Anyone able to help with an example for #3?

Thanks!
chumly is offline
Nican
Veteran Member
Join Date: Jan 2006
Location: NY
Old 09-19-2007 , 15:31   Re: Some example help please
Reply With Quote #4

Here is a code to find a random connected player

PHP Code:
stock FindRandomPlayer(){
    new 
count 0imaxplayers;
    
maxplayers GetMaxClients();
    
    
//There is nobody online, what there is to check?
    
if(GetClientCount() == 0)
        return 
0;
    
    
//Just to make sure this does not go into a infinite loop, let's make a count
    
while(count 100){
        
GetRandomInt(1maxplayers);
        if(
IsClientInGame(i))
            return 
i;        
        
count++;
    }
    return 
0;

__________________
http://www.nican132.com
I require reputation!

Last edited by Nican; 09-19-2007 at 15:33.
Nican is offline
Send a message via ICQ to Nican Send a message via MSN to Nican
dalto
Veteran Member
Join Date: Jul 2007
Old 09-19-2007 , 15:59   Re: Some example help please
Reply With Quote #5

Quote:
Originally Posted by Nican View Post
Here is a code to find a random connected player

PHP Code:
stock FindRandomPlayer(){
    new 
count 0imaxplayers;
    
maxplayers GetMaxClients();
    
    
//There is nobody online, what there is to check?
    
if(GetClientCount() == 0)
        return 
0;
    
    
//Just to make sure this does not go into a infinite loop, let's make a count
    
while(count 100){
        
GetRandomInt(1maxplayers);
        if(
IsClientInGame(i))
            return 
i;        
        
count++;
    }
    return 
0;

Ahh......this will not work consistently. It will basically try 100 times to randomly hit a player in the game. On a large server with only a few players connected it may never find anyone.

If you want to find a random player you could iterate over all the players collect the ones you want in an array and then select x of them out of the array randomly.
dalto is offline
Nican
Veteran Member
Join Date: Jan 2006
Location: NY
Old 09-19-2007 , 17:52   Re: Some example help please
Reply With Quote #6

hmm... did not think of that, works too
__________________
http://www.nican132.com
I require reputation!
Nican is offline
Send a message via ICQ to Nican Send a message via MSN to Nican
BAILOPAN
Join Date: Jan 2004
Old 09-20-2007 , 01:14   Re: Some example help please
Reply With Quote #7

Any of the Log* functions from sourcemod.inc will work but they're each subtly different so you have to find the one that you like best.

I like dalto's method, here's a sample implementation:

Code:
stock KickRandom(Handle:array) {    new index = GetRandomInt(0, GetArraySize(array)-1);    new client = GetArrayCell(array, index);    KickClient(client, "You suck");    RemoveFromArray(array, index); } stock GetRandomPlayer() {    new max_clients = GetMaxClients();    new Handle:array = CreateArray();    for (new i = 1; i <= max_clients; i++)    {       if (!IsClientConnected(i)           || IsFakeClient(i)           || GetUserAdmin(i) != INVALID_ADMIN_ID)       {          continue;       }       PushArrayCell(array, i);    }    /* Now you can browse the array, like... */    KickRandomPlayer(array);    /* Don't leak memory! */    CloseHandle(array); }
__________________
egg

Last edited by BAILOPAN; 09-20-2007 at 01:18.
BAILOPAN is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:43.


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