Raised This Month: $ Target: $400
 0% 

global values, player's indexes


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
worldspawn
Senior Member
Join Date: Aug 2009
Location: Russia, Yekaterinburg
Old 11-30-2009 , 10:34   global values, player's indexes
Reply With Quote #1

Yet another neewbies request here

so an example:
PHP Code:
new g_name[32]

public 
client_putinserver(id) {
get_user_name(idg_namecharsmax(name))
set_task(2.0"somefunc, id, _, _, "b")
}

public somefunc(id) {
set_hudmessage(210, 105, 30, 0.01, 0.76, 0, _, 1.9,_, 0.1, -1 )
show_hudmessage(id, "
Your name: %s", g_name)

this script must show you some hudmess with your name, but when new player connects in hudmess you will see his name and hudmess will be shown to all players.
Can anybody tell me how to prevent this?
worldspawn is offline
Send a message via ICQ to worldspawn Send a message via Skype™ to worldspawn
hectorz0r
Senior Member
Join Date: Oct 2008
Old 11-30-2009 , 10:37   Re: global values, player's indexes
Reply With Quote #2

If you want it to be shown to all players change id to 0 in show_hudmessage

Edited: I'm not getting your point. Not sure if you want to show the hud to everyone in server when a new player connect, is this what you looking for?

Last edited by hectorz0r; 11-30-2009 at 10:41.
hectorz0r is offline
worldspawn
Senior Member
Join Date: Aug 2009
Location: Russia, Yekaterinburg
Old 11-30-2009 , 10:41   Re: global values, player's indexes
Reply With Quote #3

nooooo, i want it ti be shown only to one
for example:
Your nick - hectorz0r
you will enter the server and see your name
but it is shown to all players and the name that shown is the last connected player's name...that's a problem for me
worldspawn is offline
Send a message via ICQ to worldspawn Send a message via Skype™ to worldspawn
Old 11-30-2009, 10:49
hectorz0r
This message has been deleted by hectorz0r. Reason: Already solved.
DarkGod
SourceMod DarkCrab
Join Date: Jul 2007
Location: Sweden
Old 11-30-2009 , 10:44   Re: global values, player's indexes
Reply With Quote #5

Why do you need it to be global?
__________________
DarkGod is offline
Send a message via AIM to DarkGod Send a message via MSN to DarkGod
addicted2sex
Senior Member
Join Date: May 2009
Location: localhost
Old 11-30-2009 , 10:47   Re: global values, player's indexes
Reply With Quote #6

PHP Code:
public client_putinserver(id) { 
set_task(2.0"somefunc, id, _, _, "b") 


public client_disconnect(id)
remove_task(id)

public somefunc(id) { 
static g_name[32]
get_user_name(id, g_name, charsmax(name)) 
set_hudmessage(210, 105, 30, 0.01, 0.76, 0, _, 1.9,_, 0.1, -1 ) 
show_hudmessage(id, "
Your name: %s", g_name) 

Use this instead. You dont need the variable to be global ... In this way you shouldnt have problems with the nick anymore ..
__________________
Let 7he gr0ovE r3Lease y0ur m!nd

Last edited by addicted2sex; 11-30-2009 at 10:53.
addicted2sex is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 11-30-2009 , 10:51   Re: global values, player's indexes
Reply With Quote #7

PHP Code:
#include <amxmodx>
 
public client_putinserver(id)
     
set_task(2.0"showName"id__"b")
 
public 
client_disconnect(id)
     
remove_task(id)
 
public 
showName(id)
{
     new 
szName[32]
 
     
get_user_name(idszNamecharsmax(szName))
 
     
set_hudmessage(210105300.010.760_1.9_0.1, -1)
     
show_hudmessage(id"Your name: %s"szName)

hectorz0r, your code will not work how he wants because your task will execute only once.. he wants the nick to be constantly printed... also, what's the deal with read_data() over there ? O.o
And also no codes would work because you two forgot a " in the set_task() and also you don't remove the task and there will be some serious load after many player connects and disconnects.

Also...
Quote:
Originally Posted by worldspawn View Post
this script must show you some hudmess with your name, but when new player connects in hudmess you will see his name and hudmess will be shown to all players.
Can anybody tell me how to prevent this?
That's because your global variable doesn't have indexes for every player, but for one, when a player connects the variable will be overwrite... if you want to use global string variables for each players you should do something like:
PHP Code:
new g_szName[33][32/* 33 because counting starts from 0 */
 
/* in a function that has a player id */
get_user_name(idg_szName[id], charsmax(g_szName[]) 
__________________

Last edited by Hunter-Digital; 11-30-2009 at 10:58.
Hunter-Digital is offline
worldspawn
Senior Member
Join Date: Aug 2009
Location: Russia, Yekaterinburg
Old 11-30-2009 , 10:53   Re: global values, player's indexes
Reply With Quote #8

i'm working with an sql version of my plugin, so i want hudmess to display some results from sql
an example:
PHP Code:
new g_result[4]

public 
get_some_res_from_sql(id)
{
//there's script that gets results
set_task(2.0"somefunc, id, _, _, "b")
}

public somefunc(id) { 
set_hudmessage(210, 105, 30, 0.01, 0.76, 0, _, 1.9,_, 0.1, -1 ) 
show_hudmessage(id, "
Your result: %s", g_result) 

i can't loop get_some_res_from_sql(id) cause it will get the results every two seconds, causing too many laggs :O

edit:
ohh i was typing too slow, 3 answers...
worldspawn is offline
Send a message via ICQ to worldspawn Send a message via Skype™ to worldspawn
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 11-30-2009 , 11:01   Re: global values, player's indexes
Reply With Quote #9

Depends what exacly you want to get from sql... if you need to take it only one time use that variable hint I said, but if you need to update player's name or something you need to hook when the player changes name also.
__________________
Hunter-Digital is offline
worldspawn
Senior Member
Join Date: Aug 2009
Location: Russia, Yekaterinburg
Old 11-30-2009 , 11:22   Re: global values, player's indexes
Reply With Quote #10

nono that value updates only when map changes, so i will test your code) thx
worldspawn is offline
Send a message via ICQ to worldspawn Send a message via Skype™ to worldspawn
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 13:43.


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