Raised This Month: $401 Target: $400
 100% 

[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-23-2020 , 17:45   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #31

New link to add: https://wiki.alliedmods.net/Csgo_quirks
(it's for discussion, since 2015 year topic, maybe too outdated, need overview from somebody in CSGO world).

Sound hooks source code:

Those wiki-page prototype is wrong, so use info from inc-file instead: https://github.com/alliedmodders/sou...sound.inc#L322
Here is a sample that compile correctly even without 'view_as' on both sm 1.10, 1.9 (sorry for some dirty example previous time):
Spoiler


Various:

PHP Code:
ChangeClientTeam(clientCS_TEAM_NONE
missing ";"
Also, the snippet doesn't work for me in CS:GO. Flag should be CS_TEAM_SPECTATOR. In such case it works correctly.

Quote:
net_graph 3
net_graph 4 will show you a bit more info - sv, var. Useful when server experience CPU overloading.

Quote:
SDKHooks Extension - Many useful functions and forwards, e.g. hooking OnTakeDamage, entity PreThink and OnEntityCreated/Destroyed forwards etc.
I would add notice:
Updated list and callback prototypes are always available in inc-file: https://github.com/alliedmodders/sou...e/sdkhooks.inc

Quote:
On Listen servers a clients index via console is also 0
"via console" in Bold (or something), for noobs like me, since I was thinking client is physically 0 there.

Quote:
Hiding particles might not work for all games or might only work on Windows. This is an engine limitation.
Little correction/addition =>
Quote:
Hiding some particles or entities might not work for all games or might only work on Windows.
(under "some" I mean like "prop_glowing_object" in L4D1 that doesn't hide via transmit hook)

Code:
blah[0] == 0; or blah[0] == '\0';
or just !blah[0]


Connect to Server

Quote:
so, later you could only run it manually and insecurely)
re-phrase please into:
Quote:
so, later you could only run it by executing exe-file directly)
Append the end of this line:
Quote:
- Setup port forwarding for 27016 port (or whichever port your game server uses) + client port.
+ after this item, please, add new one:
Quote:
- Configure firewall to allow same port (tcp/udp) + 27005 port or the one specified in +clientport argument. More details: https://developer.valvesoftware.com/...dicated_Server


Common Scripting Mistakes

"Native XXX is not bound" - dependency plugin is not installed, not loaded yet or failed. If dependency is optional,
always check is native available using GetFeatureStatus() before calling it, or check for library presence if dependency register one.

"Instruction contained invalid parameter" - source code is successfully compiled despite of syntax or structure error since parser is not ideal, example: un-initialized variable.
In this case, error log can point to a wrong plugin name, e.g. normal plugin that leads to raising event in other - guilty plugin.

Quote:
you need to compile the plugin with an older version of SM, e.g. 1.9
There are many questions "how to find it?". I'd suggest highlight "1.9" with hyperlink: https://www.sourcemod.net/downloads....=1.9-dev&all=1
(or alternate: https://www.sourcemod.net/smdrop/1.9/ )

======
P.S. More code samples coming soon.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D1 fun (Bloody Witch)
[My plugins] [My tools] [GitHub] [Articles]

Last edited by Dragokas; 03-23-2020 at 17:48.
Dragokas is offline
Silvers
AlliedModders Donor
Join Date: Aug 2010
Location: SpaceX
Old 03-24-2020 , 10:17   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #32

Thanks added.

Is + client port really necessary? I don't have mine forwarded and people can connect only when I forward the main port 27016.
__________________
Silvers is offline
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 #33

It seems doesn't required, according to this article: https://support.steampowered.com/kb_...8711&l=english
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D1 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 #34

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 withing 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
  • Before "return Plugin_Stop" line don't forget to assign zero to global variable (if you have it).
    In special cases with per-client timers, use OnClientDisconnect() forward to do it.

  • 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, 1 views)
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D1 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 04:57.


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