AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Function question (https://forums.alliedmods.net/showthread.php?t=251611)

Kazalu 11-16-2014 03:51

Function question
 
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?

HamletEagle 11-16-2014 04:40

Re: Function question
 
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 ? ).

Kazalu 11-16-2014 04:42

Re: Function question
 
Thanks, I am sorry, I found the answer after I asked the question, my bad.And thank you for your answer.

HamletEagle 11-16-2014 04:53

Re: Function question
 
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.


All times are GMT -4. The time now is 17:31.

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