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

Noob needs some help ;)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
surfhope
Member
Join Date: Aug 2010
Location: Austria
Old 02-17-2012 , 08:22   Noob needs some help ;)
Reply With Quote #1

Good afternoon,

I hope that I'm here in the right section for my matter of concern.

In fact I'm speaking about a script that I wrote yesterday, I was able to get rid of most errors/warnings. But there are still two warnings left and and would like the get rid of them too.

bans.sp(51) : warning 217: loose indentation
bans.sp(79) : warning 217: loose indentation

PHP Code:
#include sourcemod 
 
public OnPluginStart() 

PrintToChatAll("The ban plugin has been enabled!"); 
CreateConVar("sm_sban_enable""1""Var for activation"); 

 
public 
OnPluginEnd() 

PrintToChatAll("The ban plugin has been disabled!"); 

 
public 
OnClientAuthorized(client, const String:auth[]) 

decl String:ip[17]; 
GetClientIPclientipsizeof(ip)); 
 
new 
String:error[255
new 
Handle:db SQL_DefConnect(errorsizeof(error)) 
  
if (
db == INVALID_HANDLE

    
PrintToServer("Could not connect: %s"error
} else { 
        new 
String:query1[100]; 
        
Format(query1sizeof(query1), "SELECT * FROM bans WHERE steamid = '%s' OR ip = '%s'"authip); 
        new 
Handle:rowin
         
        if ((
rowin SQL_Query(dbquery1)) != INVALID_HANDLE
        { 
          
        if (
SQL_GetRowCount(rowin) != 0
        { 
         new 
String:query2[100]; 
         
Format(query2sizeof(query2), "SELECT time FROM bans WHERE steamid = '%s' OR ip = '%s'"authip); 
         new 
Handle:rowin1
         new 
bantime
         new 
String:buffer[100]; 
          
         
CloseHandle(rowin); 
          
         if ((
rowin1 SQL_Query(dbquery2)) != INVALID_HANDLE
         { 
          
          if(
SQL_FetchRow(rowin1)) 
         { 
          
bantime SQL_FetchString(rowin10buffersizeof(buffer)); 
         } 
          
         
CloseHandle(rowin1); 
                     
         new 
String:query3[100];     
         
Format(query3sizeof(query3), "SELECT reason FROM bans WHERE steamid = '%s' OR ip = '%s'"authip); 
         new 
banreason
         
         new 
Handle:rowin2
                  
         if ((
rowin2 SQL_Query(dbquery3)) != INVALID_HANDLE
         { 
           
          
         if(
SQL_FetchRow(rowin2)) 
         { 
          
banreason SQL_FetchString(rowin20buffersizeof(buffer)); 
         } 
          
         
CloseHandle(rowin2); 
                  
         if (
bantime == 0KickClient(client"You're banned from this server!\nReason: %s\nTime: Endless"banreason);         
         else 
KickClient(client"You're banned from this server!\nReason: %s\nTime: %s"banreasonbantime);     
        } 
         
        } 
        } 
        } 
       } 
 
        
CloseHandle(db); 

Thanks in advance
Hope
__________________

Last edited by surfhope; 02-17-2012 at 08:23.
surfhope is offline
Send a message via Skype™ to surfhope
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 02-17-2012 , 08:48   Re: Noob needs some help ;)
Reply With Quote #2

Here:
PHP Code:
#include sourcemod 

public OnPluginStart() 

    
PrintToChatAll("The ban plugin has been enabled!"); 
    
CreateConVar("sm_sban_enable""1""Var for activation"); 


public 
OnPluginEnd() 

    
PrintToChatAll("The ban plugin has been disabled!"); 


public 
OnClientAuthorized(client, const String:auth[]) 

    
decl String:ip[17]; 
    
GetClientIPclientipsizeof(ip)); 
    
    new 
String:error[255
    new 
Handle:db SQL_DefConnect(errorsizeof(error)) 
    
    if (
db == INVALID_HANDLE
    { 
        
PrintToServer("Could not connect: %s"error
    } else { 
        new 
String:query1[100]; 
        
Format(query1sizeof(query1), "SELECT * FROM bans WHERE steamid = '%s' OR ip = '%s'"authip); 
        new 
Handle:rowin
        
        if ((
rowin SQL_Query(dbquery1)) != INVALID_HANDLE
        { 
            
            if (
SQL_GetRowCount(rowin) != 0
            { 
                new 
String:query2[100]; 
                
Format(query2sizeof(query2), "SELECT time FROM bans WHERE steamid = '%s' OR ip = '%s'"authip); 
                new 
Handle:rowin1
                new 
bantime
                new 
String:buffer[100]; 
                
                
CloseHandle(rowin); 
                
                if ((
rowin1 SQL_Query(dbquery2)) != INVALID_HANDLE
                { 
                    
                    if(
SQL_FetchRow(rowin1)) 
                    { 
                        
bantime SQL_FetchString(rowin10buffersizeof(buffer)); 
                    } 
                    
                    
CloseHandle(rowin1); 
                    
                    new 
String:query3[100];     
                    
Format(query3sizeof(query3), "SELECT reason FROM bans WHERE steamid = '%s' OR ip = '%s'"authip); 
                    new 
banreason
                    
                    new 
Handle:rowin2
                    
                    if ((
rowin2 SQL_Query(dbquery3)) != INVALID_HANDLE
                    { 
                        
                        
                        if(
SQL_FetchRow(rowin2)) 
                        { 
                            
banreason SQL_FetchString(rowin20buffersizeof(buffer)); 
                        } 
                        
                        
CloseHandle(rowin2); 
                        
                        if (
bantime == 0KickClient(client"You're banned from this server!\nReason: %s\nTime: Endless"banreason);         
                        else 
KickClient(client"You're banned from this server!\nReason: %s\nTime: %s"banreasonbantime);     
                    } 
                    
                } 
            } 
        } 
    } 
    
    
CloseHandle(db); 

You should take a read in the scriptingfaq in this category.
Identitation is the key.

Yours sincerely
Impact
__________________

Last edited by Impact123; 02-17-2012 at 08:48.
Impact123 is offline
surfhope
Member
Join Date: Aug 2010
Location: Austria
Old 02-17-2012 , 09:17   Re: Noob needs some help ;)
Reply With Quote #3

Quote:
Originally Posted by Impact123 View Post
Here:
PHP Code:
#include sourcemod 

public OnPluginStart() 

    
PrintToChatAll("The ban plugin has been enabled!"); 
    
CreateConVar("sm_sban_enable""1""Var for activation"); 


public 
OnPluginEnd() 

    
PrintToChatAll("The ban plugin has been disabled!"); 


public 
OnClientAuthorized(client, const String:auth[]) 

    
decl String:ip[17]; 
    
GetClientIPclientipsizeof(ip)); 
    
    new 
String:error[255
    new 
Handle:db SQL_DefConnect(errorsizeof(error)) 
    
    if (
db == INVALID_HANDLE
    { 
        
PrintToServer("Could not connect: %s"error
    } else { 
        new 
String:query1[100]; 
        
Format(query1sizeof(query1), "SELECT * FROM bans WHERE steamid = '%s' OR ip = '%s'"authip); 
        new 
Handle:rowin
        
        if ((
rowin SQL_Query(dbquery1)) != INVALID_HANDLE
        { 
            
            if (
SQL_GetRowCount(rowin) != 0
            { 
                new 
String:query2[100]; 
                
Format(query2sizeof(query2), "SELECT time FROM bans WHERE steamid = '%s' OR ip = '%s'"authip); 
                new 
Handle:rowin1
                new 
bantime
                new 
String:buffer[100]; 
                
                
CloseHandle(rowin); 
                
                if ((
rowin1 SQL_Query(dbquery2)) != INVALID_HANDLE
                { 
                    
                    if(
SQL_FetchRow(rowin1)) 
                    { 
                        
bantime SQL_FetchString(rowin10buffersizeof(buffer)); 
                    } 
                    
                    
CloseHandle(rowin1); 
                    
                    new 
String:query3[100];     
                    
Format(query3sizeof(query3), "SELECT reason FROM bans WHERE steamid = '%s' OR ip = '%s'"authip); 
                    new 
banreason
                    
                    new 
Handle:rowin2
                    
                    if ((
rowin2 SQL_Query(dbquery3)) != INVALID_HANDLE
                    { 
                        
                        
                        if(
SQL_FetchRow(rowin2)) 
                        { 
                            
banreason SQL_FetchString(rowin20buffersizeof(buffer)); 
                        } 
                        
                        
CloseHandle(rowin2); 
                        
                        if (
bantime == 0KickClient(client"You're banned from this server!\nReason: %s\nTime: Endless"banreason);         
                        else 
KickClient(client"You're banned from this server!\nReason: %s\nTime: %s"banreasonbantime);     
                    } 
                    
                } 
            } 
        } 
    } 
    
    
CloseHandle(db); 

You should take a read in the scriptingfaq in this category.
Identitation is the key.

Yours sincerely
Impact
Yes I know, but it was already late and I wanted to finish as fast as possible ^^
Anyway, thank you very much


New question:

How can I create a subroutine in sourcemod which returns a string?
And how do I call it?

I have an example here:

Subroutine:
PHP Code:
String:querytovalue(Handle:dbString:query)
{
    new 
String:value[200];
    new 
Handle:place;
    
Format(valuesizeof(value), "error");
    
    if((
place SQL_Query(dbquery)) != INVALID_HANDLE)
    {
    
        if (
SQL_FetchRow(place))
        {
            
SQL_FetchString(place0valuesizeof(value));
        }

        
    }


    return 
value;


Call:

PHP Code:
new String:admin[200];
admin querytovalue(dbquery); 
Please tell me what's wrong/right ;)
Thanks
__________________

Last edited by surfhope; 02-17-2012 at 15:26.
surfhope is offline
Send a message via Skype™ to surfhope
test125
New Member
Join Date: Feb 2012
Old 02-17-2012 , 15:34   Re: Noob needs some help ;)
Reply With Quote #4

There's a thing named search.......
test125 is offline
surfhope
Member
Join Date: Aug 2010
Location: Austria
Old 02-17-2012 , 15:40   Re: Noob needs some help ;)
Reply With Quote #5

Quote:
Originally Posted by test125 View Post
There's a thing named search.......
I'm sorry but I wasn't able to find anything with the search :/
__________________
surfhope is offline
Send a message via Skype™ to surfhope
surfhope
Member
Join Date: Aug 2010
Location: Austria
Old 02-18-2012 , 07:20   Re: Noob needs some help ;)
Reply With Quote #6

OK, it seems as I found out how to call it, but it doesn't return a value -.-*

PHP Code:
new String:query3[200];     
Format(query3sizeof(query3), "SELECT ban_reason FROM amx_bans WHERE player_id = '%s' OR player_ip = '%s'"authip); 
new 
len sizeof(query3);
new 
String:banreason[200]; 
                    
banreason queryToSting(dbquery3[len]); 
PHP Code:
String:queryToSting(Handle:db, const String:query[])
{
    new 
String:value[200];
    new 
Handle:place;
    
Format(valuesizeof(value), "wrong");
    
    if((
place SQL_Query(dbquery)) != INVALID_HANDLE)
    {
    
        if (
SQL_FetchRow(place))
        {
            
SQL_FetchString(place0valuesizeof(value));
        }

    }

    
CloseHandle(place);
    return 
value;

__________________
surfhope is offline
Send a message via Skype™ to surfhope
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 10:20.


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