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

global / locals


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
blade81
Senior Member
Join Date: Apr 2005
Old 05-10-2005 , 21:07  
Reply With Quote #1

Can someone show me how to init global variables and use them local on determined player.
I mean a variable with the same name use on all players with independent values.
Can somebody show an ES example?


Quote:
global_var 0 //init

{

(
player1 set global_var to 5 // locall player_death.cfg for example
)

global_var 0 //global value

(
player2 set global_var to 25 // locall player_hurt.cfg for example
)

global_var 0 //global value

}
thx for help
blade81 is offline
Cr3V3TT3
Senior Member
Join Date: Jul 2004
Location: V'dauban
Old 05-11-2005 , 07:40  
Reply With Quote #2

Quote:
Originally Posted by blade81
Can someone show me how to init global variables and use them local on determined player.
I mean a variable with the same name use on all players with independent values.
Can somebody show an ES example?
Scripts are server side i think its not possible with the same name.
Cr3V3TT3 is offline
Send a message via MSN to Cr3V3TT3
blade81
Senior Member
Join Date: Apr 2005
Old 05-11-2005 , 12:07  
Reply With Quote #3

Is there a possibility to create a kind of array for each individual player? to store individual player infos like damage, hits etc.
blade81 is offline
Mattie
Veteran Member
Join Date: Jan 2005
Old 05-11-2005 , 13:15  
Reply With Quote #4

Quote:
Originally Posted by blade81
Is there a possibility to create a kind of array for each individual player? to store individual player infos like damage, hits etc.
Yes, but not in the way you might be used to in other coding languages. Take a look at ajax's script for example:

http://forums.alliedmods.net/showthread.php?t=37864

I believe it does this.
-Mattie
Mattie is offline
blade81
Senior Member
Join Date: Apr 2005
Old 05-11-2005 , 20:08  
Reply With Quote #5

If i make it explained as down then I get only id's from player instead valvues of them.
Is something missing in this code?

Code:
player_spawn.cfg

es_setinfo vartext 0
es_setinfo varname 0

es_format varname "hitcount_%1" event_var(userid) 
es alias expand es_setinfo "server_var(varname)" 0 
es expand
Code:
player_hurt.cfg

es_format varname "hitcount_%1" event_var(attacker) 
es es_math server_var(varname) + 1
Code:
player_death.cfg
es_format vartext "hitstotal_%1" server_var(varname)
es es_msg server_var(vartext)
blade81 is offline
Mattie
Veteran Member
Join Date: Jan 2005
Old 05-12-2005 , 07:47  
Reply With Quote #6

Quote:
Originally Posted by blade81
If i make it explained as down then I get only id's from player instead valvues of them.
Is something missing in this code?

Code:
player_spawn.cfg

es_setinfo vartext 0
es_setinfo varname 0

es_format varname "hitcount_%1" event_var(userid) 
es alias expand es_setinfo "server_var(varname)" 0 
es expand
Code:
player_hurt.cfg

es_format varname "hitcount_%1" event_var(attacker) 
es es_math server_var(varname) + 1
Code:
player_death.cfg
es_format vartext "hitstotal_%1" server_var(varname)
es es_msg server_var(vartext)
If you wanted to see what was in "hitstotal_1", for example, the player_death.cfg needs to be adjusted. The last line is just telling you to look-up the name of the variable stored in "vartext". That'll just be the literal name "hitstotal_1", for example. You need to look 'inside' that variable another level.

For example, this should work:
Code:
// player_death.cfg
es_format vartext "hitstotal_%1" server_var(varname)
setinfo varvalue 0
es_copy varvalue server_var(vartext)
es es_msg server_var(varvalue)
This causes us to es_copy the value from the variable name "server_var(vartext)" to the variable name "varvalue". In the other scripts above you didn't to es_copy it into another variable because es_math and the like uses variable names. es_msg assumes anything you pass it is a literal string, so you need to dig deeper to get the information.

Does this make sense? Hope this helps,
-Mattie
Mattie is offline
blade81
Senior Member
Join Date: Apr 2005
Old 05-12-2005 , 08:01  
Reply With Quote #7

Doh!
Thanks much Mattie! That is very helpful.
blade81 is offline
blade81
Senior Member
Join Date: Apr 2005
Old 05-12-2005 , 17:53  
Reply With Quote #8

@ Mattie I tried and tried it but it wont work. I think the problem is that es_math does not add + 1 if a player has been hurt. The value of varval is 0 or 1 somtimes -1 But it should work. I will not give up i have to make some projects, i need this array replacement.


CPU: AMD Dual opteron 250
Platform: Linux Gentoo
sigscan=1 (if i turn sigscan off then nothing works)
blade81 is offline
Mattie
Veteran Member
Join Date: Jan 2005
Old 05-12-2005 , 18:00  
Reply With Quote #9

Quote:
Originally Posted by blade81
@ Mattie I tried and tried it but it wont work. I think the problem is that es_math does not add + 1 if a player has been hurt. The value of varval is 0 or 1 somtimes -1 But it should work. I will not give up i have to make some projects, i need this array replacement.


CPU: AMD Dual opteron 250
Platform: Linux Gentoo
sigscan=1 (if i turn sigscan off then nothing works)
I'm surprised you're even able to get it running on an AMD Dual Opteron with sigscan 1. Do you know if your server is running srcds_amd or srcds_i686? If it's the latter, things might work.

I'm not sure what the problem might be with es_math. If you come up with a reproducible case, let me know and I'll see what I can figure out.

-Mattie
Mattie is offline
blade81
Senior Member
Join Date: Apr 2005
Old 05-12-2005 , 18:38  
Reply With Quote #10

Code:
init() {
	# Initialises the various variables
	# Set up the defaults
	GAME=""
	DEBUG=""
	RESTART="yes"
	HL=./srcds_amd
	HL_DETECT=1

But there is a "detectcpu()" function in srcds_run too.
I dont know when this function called.
blade81 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 23:18.


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