PDA

View Full Version : Noob needs some help ;)


surfhope
02-17-2012, 08:22
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

#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];
GetClientIP( client, ip, sizeof(ip));

new String:error[255]
new Handle:db = SQL_DefConnect(error, sizeof(error))

if (db == INVALID_HANDLE)
{
PrintToServer("Could not connect: %s", error)
} else {
new String:query1[100];
Format(query1, sizeof(query1), "SELECT * FROM bans WHERE steamid = '%s' OR ip = '%s'", auth, ip);
new Handle:rowin;

if ((rowin = SQL_Query(db, query1)) != INVALID_HANDLE)
{

if (SQL_GetRowCount(rowin) != 0)
{
new String:query2[100];
Format(query2, sizeof(query2), "SELECT time FROM bans WHERE steamid = '%s' OR ip = '%s'", auth, ip);
new Handle:rowin1;
new bantime;
new String:buffer[100];

CloseHandle(rowin);

if ((rowin1 = SQL_Query(db, query2)) != INVALID_HANDLE)
{

if(SQL_FetchRow(rowin1))
{
bantime = SQL_FetchString(rowin1, 0, buffer, sizeof(buffer));
}

CloseHandle(rowin1);

new String:query3[100];
Format(query3, sizeof(query3), "SELECT reason FROM bans WHERE steamid = '%s' OR ip = '%s'", auth, ip);
new banreason;

new Handle:rowin2;

if ((rowin2 = SQL_Query(db, query3)) != INVALID_HANDLE)
{


if(SQL_FetchRow(rowin2))
{
banreason = SQL_FetchString(rowin2, 0, buffer, sizeof(buffer));
}

CloseHandle(rowin2);

if (bantime == 0) KickClient(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", banreason, bantime);
}

}
}
}
}

CloseHandle(db);
}Thanks in advance
Hope

Impact123
02-17-2012, 08:48
Here:

#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];
GetClientIP( client, ip, sizeof(ip));

new String:error[255]
new Handle:db = SQL_DefConnect(error, sizeof(error))

if (db == INVALID_HANDLE)
{
PrintToServer("Could not connect: %s", error)
} else {
new String:query1[100];
Format(query1, sizeof(query1), "SELECT * FROM bans WHERE steamid = '%s' OR ip = '%s'", auth, ip);
new Handle:rowin;

if ((rowin = SQL_Query(db, query1)) != INVALID_HANDLE)
{

if (SQL_GetRowCount(rowin) != 0)
{
new String:query2[100];
Format(query2, sizeof(query2), "SELECT time FROM bans WHERE steamid = '%s' OR ip = '%s'", auth, ip);
new Handle:rowin1;
new bantime;
new String:buffer[100];

CloseHandle(rowin);

if ((rowin1 = SQL_Query(db, query2)) != INVALID_HANDLE)
{

if(SQL_FetchRow(rowin1))
{
bantime = SQL_FetchString(rowin1, 0, buffer, sizeof(buffer));
}

CloseHandle(rowin1);

new String:query3[100];
Format(query3, sizeof(query3), "SELECT reason FROM bans WHERE steamid = '%s' OR ip = '%s'", auth, ip);
new banreason;

new Handle:rowin2;

if ((rowin2 = SQL_Query(db, query3)) != INVALID_HANDLE)
{


if(SQL_FetchRow(rowin2))
{
banreason = SQL_FetchString(rowin2, 0, buffer, sizeof(buffer));
}

CloseHandle(rowin2);

if (bantime == 0) KickClient(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", banreason, bantime);
}

}
}
}
}

CloseHandle(db);
}
You should take a read in the scriptingfaq in this category.
Identitation is the key.

Yours sincerely
Impact

surfhope
02-17-2012, 09:17
Here:

#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];
GetClientIP( client, ip, sizeof(ip));

new String:error[255]
new Handle:db = SQL_DefConnect(error, sizeof(error))

if (db == INVALID_HANDLE)
{
PrintToServer("Could not connect: %s", error)
} else {
new String:query1[100];
Format(query1, sizeof(query1), "SELECT * FROM bans WHERE steamid = '%s' OR ip = '%s'", auth, ip);
new Handle:rowin;

if ((rowin = SQL_Query(db, query1)) != INVALID_HANDLE)
{

if (SQL_GetRowCount(rowin) != 0)
{
new String:query2[100];
Format(query2, sizeof(query2), "SELECT time FROM bans WHERE steamid = '%s' OR ip = '%s'", auth, ip);
new Handle:rowin1;
new bantime;
new String:buffer[100];

CloseHandle(rowin);

if ((rowin1 = SQL_Query(db, query2)) != INVALID_HANDLE)
{

if(SQL_FetchRow(rowin1))
{
bantime = SQL_FetchString(rowin1, 0, buffer, sizeof(buffer));
}

CloseHandle(rowin1);

new String:query3[100];
Format(query3, sizeof(query3), "SELECT reason FROM bans WHERE steamid = '%s' OR ip = '%s'", auth, ip);
new banreason;

new Handle:rowin2;

if ((rowin2 = SQL_Query(db, query3)) != INVALID_HANDLE)
{


if(SQL_FetchRow(rowin2))
{
banreason = SQL_FetchString(rowin2, 0, buffer, sizeof(buffer));
}

CloseHandle(rowin2);

if (bantime == 0) KickClient(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", banreason, bantime);
}

}
}
}
}

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 :D


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:

String:querytovalue(Handle:db, String:query)
{
new String:value[200];
new Handle:place;
Format(value, sizeof(value), "error");

if((place = SQL_Query(db, query)) != INVALID_HANDLE)
{

if (SQL_FetchRow(place))
{
SQL_FetchString(place, 0, value, sizeof(value));
}


}


return value;

}


Call:


new String:admin[200];
admin = querytovalue(db, query);


Please tell me what's wrong/right ;)
Thanks

test125
02-17-2012, 15:34
There's a thing named search.......

surfhope
02-17-2012, 15:40
There's a thing named search.......

I'm sorry but I wasn't able to find anything with the search :/

surfhope
02-18-2012, 07:20
OK, it seems as I found out how to call it, but it doesn't return a value -.-*


new String:query3[200];
Format(query3, sizeof(query3), "SELECT ban_reason FROM amx_bans WHERE player_id = '%s' OR player_ip = '%s'", auth, ip);
new len = sizeof(query3);
new String:banreason[200];

banreason = queryToSting(db, query3[len]);


String:queryToSting(Handle:db, const String:query[])
{
new String:value[200];
new Handle:place;
Format(value, sizeof(value), "wrong");

if((place = SQL_Query(db, query)) != INVALID_HANDLE)
{

if (SQL_FetchRow(place))
{
SQL_FetchString(place, 0, value, sizeof(value));
}

}

CloseHandle(place);
return value;
}