Raised This Month: $ Target: $400
 0% 

Function question


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kazalu
Senior Member
Join Date: Dec 2013
Location: Romania
Old 11-16-2014 , 03:51   Function question
Reply With Quote #1

I am wondering if variables keep their values from one function to another?
I mean if I have like that:
<<
new var;

public func1()
{
var = 2;
}

public func2()
{
var = var * 2;
return var;
}
>>

the variable returned will be 4 or will it be 0( like it would in other languages like C++ )?

2nd question: how can I detect a player's death?

Last edited by Kazalu; 11-16-2014 at 04:23.
Kazalu is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 11-16-2014 , 04:40   Re: Function question
Reply With Quote #2

Please use code/php/small tags, it's easy to read.

If you change the variable value in a function, it will keep this value until it's changed again.

Code:
new var public sth() {     var = 1 + 2//here it would become 3 } public sth2() {     var = var + 1//here it would become 4 }

For the 2nd question you should search before asking something. You need to register DeathMsg event or to hook Ham_Killed. Also you have a forward in csx for that( client_death ? ).
__________________

Last edited by HamletEagle; 11-16-2014 at 04:41.
HamletEagle is offline
Kazalu
Senior Member
Join Date: Dec 2013
Location: Romania
Old 11-16-2014 , 04:42   Re: Function question
Reply With Quote #3

Thanks, I am sorry, I found the answer after I asked the question, my bad.And thank you for your answer.
Kazalu is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 11-16-2014 , 04:53   Re: Function question
Reply With Quote #4

DeathMsg may be better in most cases, speacking about the time that it needs to register and to execute. Also, in Ham_Killed you can't know directly if it was a headshot or not, you would need to hook trace attack and see if TR_iHitgroup is 1, then set a bool or whatever to true and check it in Ham_Killed.
__________________
HamletEagle 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 17:31.


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