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

TF2_GetPlayerClass


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Ghost Killer
Member
Join Date: Aug 2009
Old 10-03-2009 , 18:08   TF2_GetPlayerClass
Reply With Quote #1

Hi guys, I'm making a changing in a plugin to add a feature, I don't know too much of sorcepawn, but I know a little bit of C++. I'm having some doubts about what can use inside TF2_GetPlayerClass()?

For instance:

Code:
new TFClassType:classe = TF2_GetPlayerClass(client)



I can use client, attacker, victim and what else?


Is there a problem declaring this class ( new TFClassType:classe ) in multiple lines, using the same name (classe)? (will it not work due to this?) Or should I just make a instance of it (without the " new" ). I don't mind loosing older value of this variable each time I declare it.

Also, How do I can restrict this check to only player who have choosed a class (so it will no include specs)? Cause if I don't it will generate a error inside the case (to choose what to do if player is on specified class),right?


I've finished the edition of the file, but this things I said before probably will generate an error, so I'm asking here, can I past the full code so you guys can help me "debug" it? This is for a modified version of N1G TF2 stats that will generate a ranking per class too in the webpage (which default don't).

Last edited by Ghost Killer; 10-03-2009 at 18:13.
Ghost Killer is offline
Jindo
AlliedModders Donor
Join Date: May 2009
Location: England, UK
Old 10-03-2009 , 18:24   Re: TF2_GetPlayerClass
Reply With Quote #2

Quote:
Originally Posted by Ghost Killer View Post
Hi guys, I'm making a changing in a plugin to add a feature, I don't know too much of sorcepawn, but I know a little bit of C++. I'm having some doubts about what can use inside TF2_GetPlayerClass()?
you use a client index, which is basically an integer set to a certain number relative to your server's player count.

Example:

PHP Code:
//This is an extract from some of my code, it won't work on its own, the following code is in a "player_death" event:
new client GetEventInt(GetClientOfUserId(event"attacker")); //This will get us the client index of the killer
if (TF2_GetPlayerClass(client) == TF2_GetClass("pyro")) // If the player is a pyro, continue
{
    
//do stuff

basically, whatever you assign the client index to (in most cases you'll most likely assign it to a variable called 'client') is what you use in TF2_GetPlayerClass().

If I adjust the above code to what you're possibly trying to do:

PHP Code:
new TFClassType:classe TF2_GetPlayerClass(client);
if (
classe == TFClass_Pyro// You can also use the TFClass_Classname form rather than TF2_GetClass("classname")
{
    
// do stuff

(I'm not 100% sure which of the 2 methods are more efficient/less expensive programming-wise)

Quote:
Also, How do I can restrict this check to only player who have choosed a class (so it will no include specs)? Cause if I don't it will generate a error inside the case (to choose what to do if player is on specified class),right?
I recommend looking at GetClientTeam
I'm not certain as I haven't used the function myself yet, but I believe you check like so:

PHP Code:
if (GetClientTeam(client) == 1//1 = spectator (I THINK) (If it isn't confirmed I will find out when I am in a position to)

Quote:
I've finished the edition of the file, but this things I said before probably will generate an error, so I'm asking here, can I past the full code so you guys can help me "debug" it? This is for a modified version of N1G TF2 stats that will generate a ranking per class too in the webpage (which default don't).
Besides the help above, trial and error testing on some kind of private server can teach you alot about how Sourcemod works . If you want to paste the entire thing I'm sure someone who knows a bit more about this stuff will gladly help!

Hope this helps!
__________________

Last edited by Jindo; 10-03-2009 at 19:25.
Jindo is offline
Antithasys
Moderator
Join Date: Apr 2008
Old 10-03-2009 , 18:54   Re: TF2_GetPlayerClass
Reply With Quote #3

Quote:
Originally Posted by Ghost Killer View Post
Also, How do I can restrict this check to only player who have choosed a class (so it will no include specs)? Cause if I don't it will generate a error inside the case (to choose what to do if player is on specified class),right?
PHP Code:
if (TF2_GetPlayerClass(client) == TFClass_Unknown)
{
    
//do stuff

Mite want to look here for more information. You could check the clients team as well.
__________________
[my plugins]

When you think about asking a question... consider what have you tried?
Antithasys is offline
Ghost Killer
Member
Join Date: Aug 2009
Old 10-03-2009 , 19:35   Re: TF2_GetPlayerClass
Reply With Quote #4

Thank you all guys, there is only a single remain doubt, what happens if in a code I have something like this:

Code:
new a = 5;
if (a == 5) 
{
 new a = 3;
}
new a = 7
Are one of this declarations gonna generate a problem? At the end, will "a" have the value 7? Will this code compile? I know I should use "new" just once, but if I want to use it more times, is there a problem? Cause it is gonna be tought to find where are the global declarations, since the identation of the original coder of the particular plugin I am changing was not that good in my opinion.

If it is ok, I think I've finished my code, to add per class data to db.
Ghost Killer is offline
Jindo
AlliedModders Donor
Join Date: May 2009
Location: England, UK
Old 10-03-2009 , 19:49   Re: TF2_GetPlayerClass
Reply With Quote #5

If I'm right, those will conflict, you only need to define one of those ("new"), the rest can simply be "a = #".
__________________
Jindo is offline
naris
AlliedModders Donor
Join Date: Dec 2006
Old 10-03-2009 , 20:57   Re: TF2_GetPlayerClass
Reply With Quote #6

Quote:
Originally Posted by Ghost Killer View Post
Thank you all guys, there is only a single remain doubt, what happens if in a code I have something like this:

Code:
new a = 5;
if (a == 5) 
{
 new a = 3;
}
new a = 7
Are one of this declarations gonna generate a problem? At the end, will "a" have the value 7? Will this code compile? I know I should use "new" just once, but if I want to use it more times, is there a problem? Cause it is gonna be tought to find where are the global declarations, since the identation of the original coder of the particular plugin I am changing was not that good in my opinion.

If it is ok, I think I've finished my code, to add per class data to db.
The last "new a = 7" will cause a compiler error.
The middle "new a = 3" will create a different "a" variable inside the "if" scope that will mask the other "a" variable (and cause a compiler warning) and then go "out-of-scope" and disappear after the "if" block, unmasking the original "a" variable that will still be 5.

That is really, REALLY, **REALLY** bad practice and should not EVER be done. I would never allow anyone that does that anywhere near any of the code I am responsible for at work. I wouldn't even allow them to look at it, just to be safe.
naris 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 22:43.


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