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

[TUT] SourcePawn Scripting - Tips, Basics to Advanced


Post New Thread Reply   
 
Thread Tools Display Modes
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 03-24-2020 , 10:29   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #31

It seems doesn't required, according to this article: https://support.steampowered.com/kb_...8711&l=english
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 03-27-2020 , 12:42   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #32

Minimal sample "How to stop (delete) global timer"

I see a really lot of questions about:
Quote:
- Native "KillTimer" reported: Invalid timer handle XXX (error 3)
- Handle XXX is invalid (error 1)
- TIMER_FLAG_NO_MAPCHANGE doesn't stop timer when round ends/lost etc...
when somebody wants to start single or repeatable timer and stop it on round_end, manually or using TIMER_FLAG_NO_MAPCHANGE.

To do it without errors, you have to create timer correcly and nullify global variable in correct events.

Here are minimal correct samples with comments:

1. Global single timer (timer_single.sp)
Spoiler


2. Global repeatable timer (timer_repeat.sp)
Spoiler


3. Global single per-client timer (timer_single_per-client.sp)
Spoiler


4. Global repeatable per-client timer (timer_repeat_per-client.sp)
Spoiler


5. (No global var.) Pause repeatable timer
- without the need to manage handle in global variable (timer_repeat_pause.sp)
Spoiler


-------------------

General tips:
  • Do not use TIMER_FLAG_NO_MAPCHANGE flag if you assign timer's handle to a global variable to control the timer via this variable later.
    - TIMER_FLAG_NO_MAPCHANGE flag can be safely used if you create timer without assigning its handle to a variable.

  • When you kill timer outside the timer's callback, use 'delete' keyword.

  • When you kill repeatable timer within its own callback, use "return Plugin_Stop" only!
    - Do not use "delete" or "KillTimer()" there, otherwise you might receive error:
    Quote:
    Plugin "XXX.smx" encountered error 23: Native detected error
    [SM] Invalid timer handle XXX (error 3) during timer end, displayed function is timer callback, not the stack trace
  • You should always assign zero to timer's global variable in the very last line of timer's callback (before return) if timer's handle is about to destruct, that happen:
    - for repeatable timer, when you pass "return Plugin_Stop"
    - for single time, automatically when callback finishes.

    When your global variable is array-based and you don't know how to find it within timer's callback:
    - with per-client timers, use OnClientDisconnect() forward to do it.
    - with incremental based global timers:
    Spoiler

  • Delete timer before creating it to prevent it from firing twice, since some events like "round_start" could be fire multiple times.

  • To stop timer on round end, use both "round_end" event and "OnMapEnd()" forward, because "round_end" doesn't fire when map is forcibly changed.

Good luck!

P.S. If you found some grammar mistakes, please PM me.
Attached Files
File Type: zip Timers.zip (4.1 KB, 196 views)
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]

Last edited by Dragokas; 01-09-2021 at 09:53.
Dragokas is offline
Alienmario
Senior Member
Join Date: Aug 2013
Old 03-29-2020 , 09:46   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #33

Some information on string tables would be useful, perhaps include how to dump info from here https://forums.alliedmods.net/showthread.php?t=250804
Alienmario is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 03-29-2020 , 10:45   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #34

Alienmario,

Released more user-friendly version: [DEV] String Tables Dumper
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]

Last edited by Dragokas; 04-01-2020 at 17:04.
Dragokas is offline
aleeexxx
Member
Join Date: May 2014
Location: Valhalla
Old 04-21-2020 , 11:47   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #35

you could add the multithread functions recommendation for SQL

I until recently knew that the old functions could block the main thread, the new syntax already does it in multithread

correct me if I'm wrong!
__________________
aleeexxx is offline
Send a message via MSN to aleeexxx
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 05-03-2020 , 08:24   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #36

Quote:
Originally Posted by aleeexxx View Post
you could add the multithread functions recommendation for SQL
There are actually no so-called multi-threaded functions.

There are only:
  • non-threaded (executed in the same thread as sm plugins, so each query to db cause waiting the response and pausing other plugin's operations during this time).
  • threaded (this one executes db queries in other second thread; when you execute one more query in parallel, no more threads created, it queues to the same second thread).

Quote:
Originally Posted by aleeexxx View Post
I until recently knew that the old functions could block the main thread, the new syntax already does it in multithread

correct me if I'm wrong!
Not all of them.
Some of Database methodmap functions still point to the old non-threded functions at the moment.

Example: Database.SetCharset() - it is just an alias to SQL_SetCharset, see source code.

There are also some exclusions.
Example: Database.Escape() - even if according to source code, it access the db handle, no external query is processed. Instead, client makes escaping itself based on pre-cached codepage of connection.

Most of above info is provided by Kruzya (CrazyHackGUT).
Thanks to him.

Additional info can be obtained in this article (in Russian) by R1KO.
Reading comments would be also useful.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 07-15-2020 , 14:49   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #37

Some updates I prepared long time ago:

Code:
AddAmbientSoundHook(AmbientHoo));
=>
AddAmbientSoundHook(AmbientHook);
+
Code:
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>

bool g_bBlockSound;
in header, since tutorial is intended for novice as well.

Updates for descriptions of some errors:

Addition for: "Native XXX is not bound"
- to prevent calling a native of unloaded plugin, implement OnLibraryAdded() and OnLibraryRemoved() natives.
Do not use LibraryExists() constantly because it's a very CPU demanding operation.

Unable to load plugin (bad header) - error similar to "Illegal disk size". (maybe just append it in same sentence)

Warning "Array-based enum structs will be removed in 1.11" - examples of fixing that:
1) by adding MAX_ITEM to enum is here: https://forums.alliedmods.net/showpo...32&postcount=8
2) by converting to enum struct is here: https://forums.alliedmods.net/showpo...0&postcount=45
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 07-15-2020 , 16:17   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #38

Quote:
Originally Posted by Dragokas View Post
Some updates I prepared long time ago:
Thanks!

Had already noticed and fixed AddAmbientSoundHook.

Will add a clarification for this: OnLibraryAdded() and OnLibraryRemoved() can be used instead of ever calling LibraryExists() since they both trigger when late loading a plugin that's using it.

Nice details for 1.11 enum structs change, many have been asking how to fix.
__________________
Silvers is offline
BHaType
Great Tester of Whatever
Join Date: Jun 2018
Old 08-01-2020 , 07:03   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #39

I'll just leave it as information maybe it will be useful for someone

INT & BOOL & FLOAT


PROPERTY


command


CHAR


OTHER


Code
__________________
cry

Last edited by BHaType; 08-01-2020 at 07:09.
BHaType is offline
Send a message via AIM to BHaType
Lux
Veteran Member
Join Date: Jan 2015
Location: Cat
Old 08-01-2020 , 23:55   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #40

Quote:
Originally Posted by BHaType View Post
I'll just leave it as information maybe it will be useful for someone

INT & BOOL & FLOAT


PROPERTY


command


CHAR


OTHER


Code
You should do these bench-tests without C-States skewing the results causing high variance between the VM.
Example below way too much variance.
PHP Code:
BenchMin 0.000075Avg 0.001785Max 0.034192 SetEntProp(0Prop_Send"m_bColdWorld"1

For abit of context anyone who will choose the faster function.
ClientCommand and FakeClientCommand are not comparable they do different jobs FakeClientCommandEx would be equivalent.
PHP Code:
BenchMin 0.001201Avg 0.001476Max 0.002383 FakeClientCommand(client"sm_somecommand");
BenchMin 0.000213Avg 0.000286Max 0.000483 ClientCommand(client"sm_somecommand"); 
__________________
Connect
My Plugins: KlickME
[My GitHub]

Commission me for L4D

Last edited by Lux; 08-01-2020 at 23:56.
Lux is offline
Reply


Thread Tools
Display Modes

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 05:02.


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