Re: Little coding questions - For general minor queries 5 -
BEMAmiganimans1r - 10.01.2017
Hi
i want to use
RemoveBuildingForPlayer(playerid,
But i want to use it in "OnFilterScriptInit"
its means there is no "playerid" There
so i want some thing like
RemoveBuildingForAllPlayers
Thanksss
Re: Little coding questions - For general minor queries 5 -
SyS - 10.01.2017
Quote:
Originally Posted by BEMAmiganimans1r
Hi
i want to use
RemoveBuildingForPlayer(playerid,
But i want to use it in "OnFilterScriptInit"
its means there is no "playerid" There
so i want some thing like
RemoveBuildingForAllPlayers
Thanksss
|
use foreach with player iterator.
Re: Little coding questions - For general minor queries 5 -
BEMAmiganimans1r - 10.01.2017
sorry i dont understand what you said
could you write the code for me ?
+1 rep if you write
Re: Little coding questions - For general minor queries 5 -
Jeroen52 - 10.01.2017
Quote:
Originally Posted by BEMAmiganimans1r
sorry i dont understand what you said
could you write the code for me ?
+1 rep if you write
|
Код:
//Put this in OnFilterScriptInit
for(new i = 0; i <= GetPlayerPoolSize(); i++)
{
if(!IsPlayerConnected(i)) continue;
RemoveBuildingForPlayer(i /* Use the 'i' as playerid and it will loop through all online players, the rest if your remove building info behind the comma */,
}
Remember to also put the remove building code in OnPlayerConnect, but there the playerid should be 'playerid' as is usual.
Re: Little coding questions - For general minor queries 5 -
Lordzy - 10.01.2017
Quote:
Originally Posted by Jeroen52
Код:
//Put this in OnFilterScriptInit
for(new i = 0; i <= GetPlayerPoolSize(); i++)
{
if(!IsPlayerConnected(i)) continue;
RemoveBuildingForPlayer(i /* Use the 'i' as playerid and it will loop through all online players, the rest if your remove building info behind the comma */,
}
Remember to also put the remove building code in OnPlayerConnect, but there the playerid should be 'playerid' as is usual.
|
Your code will work perfectly but I'd rather suggest a better loop :
pawn Код:
for(new i = GetPlayerPoolSize(); i != -1; i--)
Because in your current code, GetPlayerPoolSize() is called every time the loop checks it's condition to continue further.
Re: Little coding questions - For general minor queries 5 -
Jeroen52 - 10.01.2017
Quote:
Originally Posted by Lordzy
Your code will work perfectly but I'd rather suggest a better loop :
pawn Код:
for(new i = GetPlayerPoolSize(); i != -1; i--)
Because in your current code, GetPlayerPoolSize() is called every time the loop checks it's condition to continue further.
|
I'm already familiar with the backwards for loop, but I still have to do a performance test between the two before I'll change all my code.
Re: Little coding questions - For general minor queries 5 -
Lordzy - 10.01.2017
Quote:
Originally Posted by Jeroen52
I'm already familiar with the backwards for loop, but I still have to do a performance test between the two before I'll change all my code.
|
It's not the backwards loop that matters the most. I didn't want to initialize an extra variable which is why I avoided the forward loop. What matters the most is that my loop calls GetPlayerPoolSize() once only where as yours till the highest player ID connected. So basically, mine works faster.
PS : Using a list of connected players or foreach works even faster.
Re: Little coding questions - For general minor queries 5 -
PrO.GameR - 10.01.2017
Quote:
Originally Posted by Dayrion
Hmmm.. Good point PrO.GameR about the second question..
It soo interesting. *-*
I know timers have different purpose, but I'm talking about optimization, earning time during the execution in game.
|
They are both fast, and there is a matter of different purpose, don't ever get obsessed on these little optimizations, you are not creating GTA VI, here's a profiler plugin dump on my gamemode I ran a couple days ago to do an stress test, done with half dozen players all testing the server.
PHP код:
public OnPlayerUpdate 198389 3.62% 41.1 0.2 37.3 30.61% 1026.6 5.2 99.3
normal Callback_IsDefined 1929369 46.20% 524.6 0.3 65.8 29.57% 991.6 0.5 92.1
native strcmp 48956298 41.15% 467.2 0.0 53.2 13.93% 467.2 0.0 53.2
*Next is GMINIT which takes about 2% of my overall time.
Not even a little bit of lag on sight but 50 million strcmp calls!
You wanna know how much my highest performance heavy timer callback did?
PHP код:
public Something 1939 0.01% 0.1 0.1 1.4 0.05% 1.6 0.8 48.9
Re: Little coding questions - For general minor queries 5 -
wallee - 11.01.2017
In my main script other scripts are included before samp public functions. I use y_hooks in those included scripts. My question is this bad and can it cause trouble? Should i have public functions first then include other scripts? And can i even use public functions if i'm using y_hooks?
Re: Little coding questions - For general minor queries 5 -
[HLF]Southclaw - 11.01.2017
It's normal to have includes at the top of files (pretty standard in any language - you're effectively declaring what modules a particular file uses). Functions in Pawn can be used before they are declared since files are compiled in passes. The only thing that does matter are #define lines, which cannot be used before they appear. Generally, compile time-related things like that won't cause a runtime issue if there are no errors.
y_hooks is fine to use with publics, in fact it's very useful because you can guarantee that the public version of an event will always be called last after all the hooks.
Re: Little coding questions - For general minor queries 5 -
[HLF]Southclaw - 12.01.2017
You'll want a format-style function:
https://github.com/Southclaws/Scaven....pwn#L202-L214
pawn Код:
new
Float:x,
Float:y,
Float:z,
message[128]; // a string to store the message in
GetPlayerPos(playerid, x, y, z);
format(message, sizeof(message), "%f, %f, %f", x, y, z); // look up "format specifiers" for Pawn/C
SendClientMessage(playerid, COLOR_RED, message);
Re: Little coding questions - For general minor queries 5 -
renatog - 12.01.2017
Is possible to use a macro with #defined integer parameters?
Example:
PHP код:
#define Test:%0(%1) \
forward MyTestFunction_%0(%1); \
public MyTestFunction_%0(%1)
#define TEST_VALUE 10
Test:TEST_VALUE(playerid)
{
}
The macro above will generate this code:
PHP код:
forward MyTestFunction_TEST_VALUE(playerid);
public MyTestFunction_TEST_VALUE(playerid)
{
}
But I want that:
PHP код:
forward MyTestFunction_10(playerid);
public MyTestFunction_10(playerid)
{
}
Looking at the generated code by the macros, I realized that this will only happen if I use an invalid character, like that:
PHP код:
#define Test:%0(%1) \
forward MyTestFunction_:%0(%1); \
public MyTestFunction_:%0(%1)
Test:TEST_VALUE(playerid)
{
}
//Will generate
forward MyTestFunction_:10(playerid);
public MyTestFunction_:10(playerid)
{
}
But it will not even compile (Will compile running pawncc file -l) because it's not a valid function name.
I tried a ton of things, like redefine MyTestFunction_: to MyTest_ but TEST_VALUE will be replaced by 10 only if after or between invalid characters.
Thank you for understand my english.
Re: Little coding questions - For general minor queries 5 -
Dayrion - 13.01.2017
Mom . I'm wondering how can I store player's object? I mean, which is the best way to store it?
Each column for a object with coordinates?
Re: Little coding questions - For general minor queries 5 -
[HLF]Southclaw - 13.01.2017
Quote:
Originally Posted by renatog
Is possible to use a macro with #defined integer parameters?
Example:
PHP код:
#define Test:%0(%1) \
forward MyTestFunction_%0(%1); \
public MyTestFunction_%0(%1)
#define TEST_VALUE 10
Test:TEST_VALUE(playerid)
{
}
The macro above will generate this code:
PHP код:
forward MyTestFunction_TEST_VALUE(playerid);
public MyTestFunction_TEST_VALUE(playerid)
{
}
But I want that:
PHP код:
forward MyTestFunction_10(playerid);
public MyTestFunction_10(playerid)
{
}
Looking at the generated code by the macros, I realized that this will only happen if I use an invalid character, like that:
PHP код:
#define Test:%0(%1) \
forward MyTestFunction_:%0(%1); \
public MyTestFunction_:%0(%1)
Test:TEST_VALUE(playerid)
{
}
//Will generate
forward MyTestFunction_:10(playerid);
public MyTestFunction_:10(playerid)
{
}
But it will not even compile (Will compile running pawncc file -l) because it's not a valid function name.
I tried a ton of things, like redefine MyTestFunction_: to MyTest_ but TEST_VALUE will be replaced by 10 only if after or between invalid characters.
Thank you for understand my english.
|
Definition labels only cover valid "words" which are delimited by "non-word characters" (or, invalid characters for a label) so, as far as I know, you can't modify part of a "word"/label with definitions, only detect the entire thing.
Quote:
Originally Posted by Dayrion
Mom . I'm wondering how can I store player's object? I mean, which is the best way to store it?
Each column for a object with coordinates?
|
Store permanently (file, db) or store temporarily (in memory)?
In memory is easy, just an array with a slot per player and if you have multiple objects per player, then each of those slots contains a bunch more slots for the objects:
PHP код:
new PlayerObjects[MAX_PLAYERS][4];
// usage
PlayerObjects[playerid][2] = CreateObject(...);
As for permanent, that depends on what medium you intend to use.
Re: Little coding questions - For general minor queries 5 -
Dayrion - 13.01.2017
Permanent and I don't know what is the best thing (optimized?) to do. /:
Re: Little coding questions - For general minor queries 5 -
Lordzy - 13.01.2017
Quote:
Originally Posted by Dayrion
Mom . I'm wondering how can I store player's object? I mean, which is the best way to store it?
Each column for a object with coordinates?
|
Quote:
Originally Posted by Dayrion
Permanent and I don't know what is the best thing (optimized?) to do. /:
|
I'd consider using a database then. I'm not sure what you're looking forward to store, but this is an example structure:
Код:
UserID (FOREIGN KEY) | OBJECT MODEL | fX | fY | fZ | fRotX | fRotY | fRotZ | fDrawDist
Re: Little coding questions - For general minor queries 5 -
Dayrion - 13.01.2017
I got the same idea but if I want store like 5 objects, this is will be like:
Код:
OBJECT MODEL | fX | fY | fZ | fRotX | fRotY | fRotZ | fDrawDist | OBJECT1 MODEL | fX1 | fY1 | fZ1 | fRotX1 | fRotY1 | fRotZ1 | fDrawDist1 ...
So I'm asking there is an another way, a better way ^^'.
Also, I've an another question. Why and what mean preloading player's animation?
A player need to execute 2 times an animation or the animation will not work? Loading every animation one time when the player connects is like preloading them?
Re: Little coding questions - For general minor queries 5 -
PrO.GameR - 13.01.2017
Quote:
Originally Posted by Dayrion
I got the same idea but if I want store like 5 objects, this is will be like:
Код:
OBJECT MODEL | fX | fY | fZ | fRotX | fRotY | fRotZ | fDrawDist | OBJECT1 MODEL | fX1 | fY1 | fZ1 | fRotX1 | fRotY1 | fRotZ1 | fDrawDist1 ...
So I'm asking there is an another way, a better way ^^'.
Also, I've an another question. Why and what mean preloading player's animation?
A player need to execute 2 times an animation or the animation will not work? Loading every animation one time when the player connects is like preloading them?
|
If this is a SQL, then of course the following would be best:
Код:
PlayerID/Name | ObjectIndex | Model | X | Y | Z ...
Hence you'd easily be able to allow players to save more/less and only load, easily allow a developer access to unlimited objects etc.
but it's not easily achievable to do the same with INI, Although you could do a structure like INDEX_PlayerName > then still save what I suggested, still allowing the same thing, but then your server would need to open/close so many files that I wouldn't recommend.
So to sum it up if it's INI, do what you have in mind, if it's a SQL, my suggestion would be a better alternative.
About animations, first time you use an animation library it loads that in the client, preloading them means using that libraries for the player on connect for it to load for them, usually done with a null animation.
Re: Little coding questions - For general minor queries 5 -
ISmokezU - 13.01.2017
Hey i've a question,if i set my own damage system for vehicles (Unoccupied ones) would those values apply for when the vehicle is occupied?
Re: Little coding questions - For general minor queries 5 -
Jeroen52 - 13.01.2017
Quote:
Originally Posted by ISmokezU
Hey i've a question,if i set my own damage system for vehicles (Unoccupied ones) would those values apply for when the vehicle is occupied?
|
If you're making it from the ground up, possibly yes. You'll need to check if the vehicle is occupied and only apply damage when it is not. If you do not check for this you'll most likely damage it even more than you intend to do.