Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Addition for "3. Connect to Server" section.
Recently, they updated something in security, and a method for running client via left4dead2.exe (with arguments) in the same machine with a server is no more working. Instead, here is a walkaround to run the app directly from steam.exe. I'm attaching the full code of .bat script (to run server + join simultaneously):
Spoiler
For other games, change appID 550 by your game's Id from steam.inf file, and GAME_ALIAS value with an appropriate game name alias. |
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
|
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Something like this is useful too
Using this script instead of the random start map plugins
Spoiler
|
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
|
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
On the first page, in section...
...and subheading... Code:
SourcePawn specific editors |
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Done. Thanks.
|
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
strcmp() provides less readable and worse compatibility compared to StrContains()
|
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
You can also mention the "stringize" operator (inherited from Pawn) which converts arguments to packed strings in a macro.
I don't find it that useful but still here's an example: Code:
// Note that spaces inside parentheses count too!!! STRINGIZE( abc123 ) = " abc123 " |
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Quote:
These functions have different meanings. MAGNAT2645, interesting ability, but IMHO, useless sample =) Can't find where it could be useful. The same can be written by manual string enquoting. |
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Quote:
|
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Quote:
Code:
#define ERROR(%0) PrintToServer( "ERROR: " ... #%0 )Code:
#define ERROR(%0) PrintToServer( "ERROR: " ... %0 ) |
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Use OnClientPostAdminCheck or OnClientPutInServer : SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage);
Whether it is necessary to use "SDKUnhook(client, SDKHook_OnTakeDamage, OnTakeDamage)" in OnClientDisconnect; I want to know. |
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Quote:
Entities are automatically unhooked by SDKHooks when they leave (if they are player entities) or are deleted. |
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Using OnClientPostAdminCheck is bad for anything other than when checking for admin flags, since if Steam goes offline they are not verified and the forward will not trigger.
|
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Thanks. :)
|
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
I'm some confuses using entity reference, when I check for validate entities before using each entity does that mean I don't need entity references?
|
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Quote:
You want to use entity references and userid's for anything asynchronous such as CreateTimer, RequestFrame or when you're storing an entity index in an array. Anything that will be accessed later and not immediately in the same frame/functions where you have the entity index. |
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Quote:
but my confuses is what merit to use entity references? does OnEntityDestoyed cant handle all of the entity status change situations? or ent ref just double check here or conversely, if enf ref check passed, that mean we dont have to use IsValidEntity or IsValidEdict a digression, under which scene we should use Edict operation rather than Entity Operation? very thanks silvers patiently anser ---- for the edict i found from main thread, sorry im reading slowly |
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Follow this events order as example:
OnEntityCreated -> PostSpawn -> RequestFrame -> CreateTimer(timerReadEnt) -> EntityDestroyed > timerReadEnt in timerReadEnt you will get an exception if you use the entity index cause it's gone (or replaced by another entity with the same index). Storing the entity as EntRef allow you to post-check if that entityRef has an INVALID_REFERENCE (with EntRefToEntIndex) before using it. The logic is the same as what happens to the player. (GetClientUserId) |
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Quote:
Quote:
Quote:
PHP Code:
|
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Quote:
|
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
thanks everyone patiently anser, i got point that unique is important,
although it is a bit unsightly code to use, but i tend to use like this PHP Code:
|
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
I recently realized cleaning entity index trackers was also an option (from OnEntityDestroyed) and lately used that approach instead of entity references system, for just one entity as max. in my case. However, cleaning the appropiate variable can become inconvenient once handling enough amount of possible tracked entities, as it requires conditioning to match against the appropiate variable each case.
But as long as you handle few entity tracking variables, storing indices is perfectly adequate and efficient in terms of a gameplay session (vs. calling EntRefToEntIndex continuatedly) as long as you clear the variables at OnEntityDestroyed (aka assigning them to e.g. INVALID_ENT_REFERENCE). Obviously this approach is unproductive if perfoming extra checks other than entity != INVALID_ENT_REFERENCE for validating. |
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
AdRiAnIlloO, same mistake as I described above. Those entity can be replaced very soon. So, your kind of check will return "entity exists and valid", however, that is other entity, not the one you initially tracked. As a result you will target (and perhaps, further delete) someone else's entity, causing hard-to-trace bug. EntIndexToEntRef guarantee the index become unique and will not be replaced with another one newly created entity having same ref index.
|
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Citing your own quote.
Quote:
Or, is it that OnEntityDestroyed could be called after engine assigned the passed index to a new entity? From the SDK, entities are usually totally removed one frame after requested, for security reasons, during which I wonder if engine could free their index (haven't reached to confirm it). But basically what he is saying is the same than you and me pointed, why not to use the OnEntityDestroyed approach when it seems perfectly valid (if not loosing productivity, as I explained) against ent ref checks. |
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Well, I already explained. But, ok, show me code example of a real task according to your suggestion and I'll tell you why.
|
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Sorry for the delay, was busy. Here goes the parts of interest for my entity-tracking variable (which aims to refer to an env_sprite):
Code:
int gKingSprite = INVALID_ENT_REFERENCE; // Global scope declarationNote SM should always pass entity indices for networked (edict-full) entities (and internal entrefs for non-networked entities instead) to the entity forwards. PS: Also, I've confirmed OnEntityDestroyed only gets called upon total entity destruction (that is, after the security game frame happens originated from the common entity destroy requests from Source games): CGlobalEntityList::NotifyRemoveEntity -> SDKHooks::OnEntityDeleted, but it seems the edict (and thus, index) should be destroyed right after. |
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Yeah, in such way it is safe.
I don't remember which one case I told above, sorry. |
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Quote:
|
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Which is faster, FormatEx or strcopy?
|
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
strcopy has less logic, should be faster.
Also, if you need stringbuilder functionality, use strCat; it doesn't re-create string buffer unlike Format. |
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Thank you very much,
the various "handle.method" of the new syntax seems to be just the wrapper of the old syntax, is there a difference in their speed? Such as "ClearArray (ArrayList)" and "ArrayList.Clear()", etc. |
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
You can use either-or. The speed is irrelevant. It’s more a matter of preference rather than which one is slightly faster.
If you’re really curious about it, you can use the profiler. Pre-optimizing your plugin is a waste of time. Unless you’re actually experiencing performance issues with your plugin, don’t worry so much about choosing the fastest method/function for every part of your code. You may end up sacrificing readability, maintainability, and simplicity for a negligible difference in speed. Optimizing Plugins (SourceMod Scripting) |
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
For something like this optimizing is negligible but I wouldn't advise against optimizing especially if the plugin will be made publicly available. Many public ones have huge performance hits due to bad practices and some servers running many plugins will feel the degradation in performance due to certain unoptimized plugins.
|
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
I have a question: int i[N][33] or ArrayList i[33] Which is better? The before cause too many plugin file size after compiled
|
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
"Which is better" most of the time depends on the situation and the use case.
You should share an example and mention the "before" and "after" sizes as well. |
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Quote:
PHP Code:
PHP Code:
|
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Should be: MAXPLAYERS+1 not just MAXPLAYERS
|
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
iaNanaNana, you don't need array of lists, it is already an "array" of blocks.
Also, alloc/release handles is a heavy operation. See: PHP Code:
PHP Code:
|
Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
I would like to ask, how to calculate the number of bytes occupied by the string in IntToString, FloatToString
|
| All times are GMT -4. The time now is 22:27. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.