WiKi Examples - Moderation?!
#1

Hey there,

noticed some really, really bad wikipedia examples going against every single logical thought.

Is anyone moderating them? Seeing that wiki examples are being particularly used by newbies, it's a very inappropriate misguidance in the early beginning of understanding how to script efficiently.

Regards
Reply
#2

You are the moderator. If it's wrong feel free to edit it, out of curiousity what's the wrong page(s).. I (or someone else) might have a look at it.
Reply
#3

If u register at Wiki
u can edit the pages yourself
everyone is moderator there as long as u are registered
Reply
#4

Yeah I am aware how in general wiki systems work however this can become very quickly messy so I wondered whether there is some sort of higher instance.

Let me take the OnPlayerUpdate entry (https://sampwiki.blast.hk/wiki/OnPlayerUpdate) as an example:

OnPlayerUpdate, as the warning already forshadows, gets called very frequently per second per player. Now OnPlayerUpdate is at the same time great for small anti cheat systems - such as detecting whether someone suddenly has a blacklisted gun - however as you can read as well on the forums, it shall be only used if you know what you are doing.

Let's take a look at the first example being made:

Quote:

Example: Make your own callback - OnPlayerChangeWeapon(playerid, oldweapon, newweapon)

Already starts of badly in the first line:

Quote:

public OnPlayerUpdate(playerid)
{
new iCurWeap = GetPlayerWeapon(playerid); // Return the player's current weapon

Using this example in your code, each time OnPlayerUpdate gets called a new variable eating up 32bit of memory gets declared. Each of those 32bit are being used until your server is closed/restarted as PAWN uses static memory allocation, no dynamic during runtime - they never the freed until then.

It goes further two lines below when the example function OnPlayerChangeWeapon gets called. 3 parameters are being passed, another 3*32bit. However this is not the real problem.

The worst few lines in this example are in OnPlayerChangeWeapon when two Strings of 24 cells each (2*24*32bit) and one string of 128 cells get declared.

You can imagine that players on your server will scroll through their weapons pretty often. Each time they do, in total 5760 bit / 720 byte memory is being used.

This can be easily avoided by either using globals in a clever way or not using OnPlayerUpdate for complex systems - it's not supposed to be used for that anyways.

On the long run and if you have a greater, far-developed script with lots of players you'll definitely have problems.
Reply
#5

Pawn, as you mentioned, is static so variable creation starts at compile time, not run time, so you never use up more then those 720 bytes. And OnPlayerUpdate was introduced especially for creating custom accurate callbacks like that, why else would you possibly need it ? You have timers for tick functions and GetTickCount() for accurate time tests, etc.. And run a few test in term of memory usage and amx size, when dealing with local and global variables
Reply
#6

Quote:
Originally Posted by dice7
Pawn, as you mentioned, is static so variable creation starts at compile time, not run time, so you never use up more then those 720 bytes. And OnPlayerUpdate was introduced especially for creating custom accurate callbacks like that, why else would you possibly need it ? You have timers for tick functions and GetTickCount() for accurate time tests, etc.. And run a few test in term of memory usage and amx size, when dealing with local and global variables
nice way of putting it. I have a custom OnVirtualWorldChange callback that is pretty much coded the same as the article in question (well, what i mean is i create a variable / assign a value to said variable under OnPlayerUpdate), and i never thought twice about it as i'm content with using a SUPER small amount of ram (we're not even talking about 1kb lol) in order to accurately tell when a player is switching vw / have complete control over it; as vw is a big part of my server.

Ram is meant to be used, i think i can spare a kb or two if need be :P.

Reply
#7

Quote:
Originally Posted by Kyosaur!!
Quote:
Originally Posted by dice7
Pawn, as you mentioned, is static so variable creation starts at compile time, not run time, so you never use up more then those 720 bytes. And OnPlayerUpdate was introduced especially for creating custom accurate callbacks like that, why else would you possibly need it ? You have timers for tick functions and GetTickCount() for accurate time tests, etc.. And run a few test in term of memory usage and amx size, when dealing with local and global variables
nice way of putting it. I have a custom OnVirtualWorldChange callback that is pretty much coded the same as the article in question (well, what i mean is i create a variable / assign a value to said variable under OnPlayerUpdate), and i never thought twice about it as i'm content with using a SUPER small amount of ram (we're not even talking about 1kb lol) in order to accurately tell when a player is switching vw / have complete control over it; as vw is a big part of my server.

well, you actually could make that thing even without OnPlayerUpdate, as you just need to call the "OnVirtualWorldChange" if the players is set into a new virtual world, which MUST be done via "SetPlayerVirtualWorld", right?

So you could just make a thing like this:
pawn Код:
#define SetVirtualWorld(%1,%2) SetPlayerVirtualWorld(%1,%2); SetPVarInt(%1,"vworld",%2); OnVirtualWorldChange(%1,%2)

public OnVirtualWorldChange(playerid, virtualworld) {
// etc
}
Now you would just need to replace each "SetPlayerVirtualWorld" (except the one in the definition lol) with "SetVirtualWorld".
Reply
#8

Код:
SetPVarInt(%1,"vworld",%2);
What for? You have GetPlayerVirtualWorld.
Reply
#9

Quote:
Originally Posted by Seif_
Quote:
Originally Posted by [XAC
Klinsen ]
Quote:
Originally Posted by Kyosaur!!
Quote:
Originally Posted by dice7
Pawn, as you mentioned, is static so variable creation starts at compile time, not run time, so you never use up more then those 720 bytes. And OnPlayerUpdate was introduced especially for creating custom accurate callbacks like that, why else would you possibly need it ? You have timers for tick functions and GetTickCount() for accurate time tests, etc.. And run a few test in term of memory usage and amx size, when dealing with local and global variables
nice way of putting it. I have a custom OnVirtualWorldChange callback that is pretty much coded the same as the article in question (well, what i mean is i create a variable / assign a value to said variable under OnPlayerUpdate), and i never thought twice about it as i'm content with using a SUPER small amount of ram (we're not even talking about 1kb lol) in order to accurately tell when a player is switching vw / have complete control over it; as vw is a big part of my server.

well, you actually could make that thing even without OnPlayerUpdate, as you just need to call the "OnVirtualWorldChange" if the players is set into a new virtual world, which MUST be done via "SetPlayerVirtualWorld", right?

So you could just make a thing like this:
pawn Код:
#define SetVirtualWorld(%1,%2) SetPlayerVirtualWorld(%1,%2); SetPVarInt(%1,"vworld",%2); OnVirtualWorldChange(%1,%2)

public OnVirtualWorldChange(playerid, virtualworld) {
// etc
}
Now you would just need to replace each "SetPlayerVirtualWorld" (except the one in the definition lol) with "SetVirtualWorld".
You don't need to. You can just name it SetPlayerVirtualWorld and it'll overwrite SetPlayerVirtualWorld.
Yeah seif's right. If i was going to define it, i'd much rather do it like this:


pawn Код:
stock SetPlayerVirtualWorldEx(playerid, worldid)
{
    CallRemoteFunction("OnPlayerVirtualWorldChange", "iii", playerid, GetPlayerVirtualWorld(playerid), worldid);
    return SetPlayerVirtualWorld(playerid, worldid);
}

#define SetPlayerVirtualWorld SetPlayerVirtualWorldEx

that way i don't have to change anything. There are two problems with this way though. I dont want to put that in EVERY script that uses SetPlayerVirtualWorld (quite a lot of my scripts do, as its a vital part of my server) and also, i think that would be less efficient (Making a remote call every time i set a players virtual world is probably just as bad as using OnPlayerUpdate).

In the end, both ways have their down sides, but i just prefer OnPlayerUpdate. I normally stay away from OnPlayerUpdate, but i figure this is what it was made for / cant be TO bad (other wise, why add it in the first place) :P.

Reply
#10

like what they said register at wiki u can edit anything
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)