Raised This Month: $13 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
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)
[My plugins] [My tools] [GitHub] [Articles]
Dragokas is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine
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.0 KB, 36 views)
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch)
[My plugins] [My tools] [GitHub] [Articles]

Last edited by Dragokas; 04-17-2020 at 12:48.
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
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)
[My plugins] [My tools] [GitHub] [Articles]

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
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)
[My plugins] [My tools] [GitHub] [Articles]
Dragokas 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 06:51.


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