Quote:
Originally Posted by nG Inverse
That's like asking why we would use GetPlayerHealth when we can store it in a variable. If you need the variable use it. Otherwise stick to the native calls.
|
It's nothing like that mate, you simply can't obtain a players current health without the use of GetPlayerHealth at some point in time.. unless you assume that it's 100 from the time of connect, which isn't very reliable.
This is more like saving the players name on connect so you don't have a bajillion useless calls of GetPlayerName throughout your script.
Here is a very primitive example of state collection incase you didn't quite get what I'm on about,
A variable to store the state within,
PHP код:
new gPlayerCurrentState[MAX_PLAYERS];
Gathering the current state,
PHP код:
/*
0 PLAYER_STATE_NONE Empty (while initializing)
1 PLAYER_STATE_ONFOOT Player is on foot
2 PLAYER_STATE_DRIVER Player is the driver of a vehicle
3 PLAYER_STATE_PASSENGER Player is passenger of a vehicle
4 PLAYER_STATE_EXIT_VEHICLE (unused)used internally
5 PLAYER_STATE_ENTER_VEHICLE_DRIVER (unused)used internally
6 PLAYER_STATE_ENTER_VEHICLE_PASSENGER (unused)used internally
7 PLAYER_STATE_WASTED Player is dead or on class selection
8 PLAYER_STATE_SPAWNED Player is spawned
9 PLAYER_STATE_SPECTATING Player is spectating*/
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(newstate == PLAYER_STATE_NONE)
{
gPlayerCurrentState[playerid] = 0;
}
if(newstate == PLAYER_STATE_ONFOOT)
{
gPlayerCurrentState[playerid] = 1;
}
if(newstate == PLAYER_STATE_DRIVER)
{
gPlayerCurrentState[playerid] = 2;
}
if(newstate == PLAYER_STATE_PASSENGER)
{
gPlayerCurrentState[playerid] = 3;
}
if(newstate == PLAYER_STATE_WASTED)
{
gPlayerCurrentState[playerid] = 7;
}
if(newstate == PLAYER_STATE_SPAWNED)
{
gPlayerCurrentState[playerid] = 8;
}
if(newstate == PLAYER_STATE_SPECTATING)
{
gPlayerCurrentState[playerid] = 9;
}
return 1;
Using the stored state we've already collected,
PHP код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if (newkeys & KEY_SPRINT)
{
if(gPlayerCurrentState[playerid] == PLAYER_STATE_DRIVER)
{
//do something
}
}
return 1;
Also with this I'm just assuming 'GetPlayerState' is gathered directly from the client?, so wouldn't avoiding this be more efficient for both client and server?, especially when GetPlayerState is being called for my players and sometimes all players depending on the situation at 200ms, 500ms, 1000ms, 3000ms, thats without command calls containing GetPlayerState, native callbacks,other filterscripts and includes..
It really just seems useless to keep get get getting it constantly, as for the memory usage.. I couldn't honestly care less about that, my server uses 60mb of ram at the best of times..