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

players stack HELP


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
DigiSoft
BANNED
Join Date: Feb 2009
Old 01-08-2010 , 11:23   players stack HELP
Reply With Quote #1

OK I want to make struct like this one

Code:
struct player_t
{
    char    steam_id;
    char    ip_address[128];
    char    name;
    char    password[128];
    int        user_id;
    int        index;
    edict_t    *entity;
    IPlayerInfo *player_info;
};
Now the problem is how can I maintain this structure?
For example I can populate on ClientActive and remove players from the struct on ClientDisconnect.

Is this good method?

Can you please show me simple code of removing players from the struct on ClientDisconnect?

How should I access the struct? Always with "for" loop?
DigiSoft is offline
Keeper
Senior Member
Join Date: Nov 2006
Old 01-08-2010 , 11:40   Re: players stack HELP
Reply With Quote #2

I've created an array of this type of structure from 0 to MAX_PLAYERS-1. Then I just access the array when I need to get info on a player's index. Of course I fill it on ClientActive and clear it on ClientDisconnect. That structure looks familiar
Keeper is offline
DigiSoft
BANNED
Join Date: Feb 2009
Old 01-08-2010 , 11:50   Re: players stack HELP
Reply With Quote #3

Quote:
Originally Posted by Keeper View Post
I've created an array of this type of structure from 0 to MAX_PLAYERS-1. Then I just access the array when I need to get info on a player's index. Of course I fill it on ClientActive and clear it on ClientDisconnect. That structure looks familiar
Heheheh it looks familiar . So it is good method right?
But I am little confused.

Lets say

Code:
ClientActive
{
     //METHOD 1
     t_player player
     player->name = "sdfdsfsdfsdf"
     //METHOD 2
     //OR SHOULD I DO THIS
     player[engine->IndexOfEdict(pEntry)].name = "fsdfsdfsdfsdfsdfsdf"
}
Now If I always use method 1 then only the first element in the struct will be ALWAYS overwritten right? If so then I should use Method 2?

Quote:
I've created an array of this type of structure from 0 to MAX_PLAYERS-1.
Ok You have array and lets say there are 6 players online and in the array.
Then 7th player enters and how do you know what array index to use for the 7th players?
Hmmm I am confused with this struct little sorry


EDIT1: Hmmmmm I think your method with creating array from this struct is better but I still don't understand what player should be placed in what array index.

Last edited by DigiSoft; 01-08-2010 at 11:56.
DigiSoft is offline
Keeper
Senior Member
Join Date: Nov 2006
Old 01-08-2010 , 12:06   Re: players stack HELP
Reply With Quote #4

Code:
player_t CurrentPlayerList[MAX_PLAYERS]; // MAX_PLAYERS is defined in shareddefs.h
Then when the client joins the server, you can fill your structure this way:
Code:
player_t *SinglePlayer = &CurrentPlayerList[playerindex-1];
// then fill SinglePlayer, or you can pass the SinglePlayer pointer to 
// another method that you use to fill the information.
At that point it will be stored in the array, since SinglePlayer is a pointer to that index in the array.

Then when they disconnect you can just:
Code:
  Q_memset ( &CurrentPlayerList[playerindex-1], 0, sizeof(player_t) );
Keeper is offline
DigiSoft
BANNED
Join Date: Feb 2009
Old 01-08-2010 , 12:15   Re: players stack HELP
Reply With Quote #5

Oh thank you very much for your help.

Should I mention that I am making pure valve plugin? I am not hooking with Metamod or so.

playerindex it is unrecognized :S

Where should I take this index? From the pEntity?
DigiSoft is offline
Keeper
Senior Member
Join Date: Nov 2006
Old 01-08-2010 , 12:27   Re: players stack HELP
Reply With Quote #6

no, playerindex is just what I named it. you'd have to assign the index. something like:
Code:
int playerindex=engine->IndexOfEdict(pEntity);
Keeper is offline
DigiSoft
BANNED
Join Date: Feb 2009
Old 01-08-2010 , 12:29   Re: players stack HELP
Reply With Quote #7

Quote:
Originally Posted by Keeper View Post
no, playerindex is just what I named it. you'd have to assign the index. something like:
Code:
int playerindex=engine->IndexOfEdict(pEntity);
Yep that's what I tough and after this

Code:
player_t *SinglePlayer = &CurrentPlayerList[playerindex-1];
Now I can do:
SinglePlayer->name = "fsdfsdfsdfsdf"
SinglePlayer->steam_id = "fdsfsdfsdfsf"

Right?

I've send you PM keeper
DigiSoft is offline
frostschutz
Member
Join Date: Dec 2009
Old 01-08-2010 , 12:52   Re: players stack HELP
Reply With Quote #8

Since I'm working with a similar structure...

how do you initialize it? i.e. how do you handle the plugin being loaded / unloaded manually while there are already players on the server?
frostschutz is offline
DigiSoft
BANNED
Join Date: Feb 2009
Old 01-08-2010 , 12:59   Re: players stack HELP
Reply With Quote #9

KEEPER MY friend the structure works BEAUTIFULLY. Thank you so much. My plugin is not crashing anymore

Thanks.

frostschutz it is very simple

First you declare the structure like this
Quote:
struct player_t
{
char steam_id;
char ip_address[128];
char name;
char password[128];
int user_id;
int index;
edict_t *entity;
IPlayerInfo *player_info;
};
Now you make array from this structure Like this
Quote:
player_t CurrentPlayerList[MAX_PLAYERS];
Now you are filling this array with data. In my case I am filling it in ClientActive like this
Quote:
int playerindex = engine->IndexOfEdict(pEntity);
player_t *SinglePlayer = &CurrentPlayerList[playerindex-1];
SinglePlayer->name = "sdfsdfdsfdsfdsfsdfsdf"
SinglePlayer->steam_id = "asdasdasdasdasdasdasd"
And you remove indexes on player Disconnect like this
Quote:
Q_memset ( &CurrentPlayerList[engine->IndexOfEdict(pEntity)-1], 0, sizeof(player_t) );
VERY GOOD AND POWERFUL SOLUTION.

Thank you Keeper, over and out

EDIT1: Keeper just one more question

Quote:
for(i=0; i< "of what?"; i++)
CurrentPlayerList[i]
IS IT sizeof(CurrentPlayerList)? or gpGlobals->maxClients

Last edited by DigiSoft; 01-08-2010 at 13:03.
DigiSoft is offline
Keeper
Senior Member
Join Date: Nov 2006
Old 01-08-2010 , 13:13   Re: players stack HELP
Reply With Quote #10

You always want to use maxClients because that changes based on the maxplayers setting on the server. It should never be above MAX_PLAYERS tho.
Keeper 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 16:09.


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