AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   global values, player's indexes (https://forums.alliedmods.net/showthread.php?t=110514)

worldspawn 11-30-2009 10:34

global values, player's indexes
 
Yet another neewbies request here:oops:

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?

hectorz0r 11-30-2009 10:37

Re: global values, player's indexes
 
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?

worldspawn 11-30-2009 10:41

Re: global values, player's indexes
 
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

DarkGod 11-30-2009 10:44

Re: global values, player's indexes
 
Why do you need it to be global?

addicted2sex 11-30-2009 10:47

Re: global values, player's indexes
 
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 ..

Hunter-Digital 11-30-2009 10:51

Re: global values, player's indexes
 
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 (Post 1002995)
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[]) 


worldspawn 11-30-2009 10:53

Re: global values, player's indexes
 
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...

Hunter-Digital 11-30-2009 11:01

Re: global values, player's indexes
 
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.

worldspawn 11-30-2009 11:22

Re: global values, player's indexes
 
nono that value updates only when map changes, so i will test your code) thx

Hunter-Digital 11-30-2009 14:01

Re: global values, player's indexes
 
Values are per player and update only at map change ?

if so:

PHP Code:

#include <amxmodx>
 
new g_szValue[33][32/* set 32 to max strlen of your value, leave 33 as it is */
 
public client_putinserver(id)
{
     
/* assign g_szValue[id] */
 
     
set_task(2.0"showValue"id__"b")
}
 
public 
client_disconnect(id)
     
remove_task(id)
 
public 
showValue(id)
{
     
set_hudmessage(210105300.010.760_1.9_0.1, -1)
     
show_hudmessage(id"Value: %s"g_szValue[id])




All times are GMT -4. The time now is 13:43.

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