Raised This Month: $1944 Target: $400
 486% 

[TUT] SourcePawn Scripting - Tips, Basics to Advanced


Post New Thread Reply   
 
Thread Tools Display Modes
Silvers
AlliedModders Donor
Join Date: Aug 2010
Location: SpaceX
Old 01-29-2020 , 12:28   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #11

Quote:
Originally Posted by Desktop View Post
Very very nice!

Will you add enum structs?
Thanks, I'm not actually very familiar with structs, with the constant changes to enum I've put off learning them. I've linked to some articles which explain it better.


Quote:
Originally Posted by Dragokas View Post
--- post #10
Wow thanks again. Made the changes to batch and added bunch of info. Will update later with more.

Quote:
Originally Posted by Dragokas View Post
- #file hides path in log and that full path is the only ability to find what version smx is compiled from for troubleshooting purposes since sm doesn't expose version number in error logs.
Version number is quite vital information that's missing. For this I keep a backup of every plugin and every version I release. That way you can match the file number to the error most of the time.



Have formatted and updated the article with more info and examples.
__________________

Last edited by Silvers; 01-31-2020 at 19:13.
Silvers is offline
Crasher_3637
AlliedModders Donor
Join Date: May 2012
Old 01-31-2020 , 18:29   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #12

Very much needed; thank you for taking the time to put all of this together. I really wish a tutorial like this was already around way back.
__________________
AFK like JFK
Crasher_3637 is offline
Silvers
AlliedModders Donor
Join Date: Aug 2010
Location: SpaceX
Old 01-31-2020 , 18:50   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #13

It has taken many hours to write but hopefully useful to new scripters, even some vets who might have missed something. Still plenty more to add, I just haven't gotten round to it yet.

The SM wiki pretty much covers all this but it can be difficult to navigate through all the pages and find all the info. I still look through the wiki for bits I might have missed etc.
__________________
Silvers is offline
MAGNAT2645
Senior Member
Join Date: Nov 2015
Location: AlliedMods.net
Old 02-01-2020 , 12:53   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #14

Quote:
StringMap.FindString is slightly quicker than ArrayList.FindString and probably significantly faster for larger arrays.
But StringMap doesn't have a method named FindString.
StringMap API

Quote:
FormatEx instead of Format. When input and output buffers are the same.
When input and output buffers aren't the same.

Quote:
Storing cvar handles, using HookConVarChange and storing the returned cvar values in global variables is more efficient than constantly using GetConvar* calls.
I heard that GetConVar* natives cache their values so you don't need to use variables to store each value. (BUT i'm not sure 100%)
Checked C++ source for these natives and found nothing about caching.
__________________

Last edited by MAGNAT2645; 02-01-2020 at 13:00.
MAGNAT2645 is offline
Silvers
AlliedModders Donor
Join Date: Aug 2010
Location: SpaceX
Old 02-01-2020 , 14:43   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #15

Quote:
Originally Posted by MAGNAT2645 View Post
But StringMap doesn't have a method named FindString.
StringMap API
Oops meant to be .GetValue.

Quote:
Originally Posted by MAGNAT2645 View Post
When input and output buffers aren't the same.
Oops, thanks.

Quote:
Originally Posted by MAGNAT2645 View Post
I heard that GetConVar* natives cache their values so you don't need to use variables to store each value. (BUT i'm not sure 100%)
Checked C++ source for these natives and found nothing about caching.
I read this too somewhere but does not seem to be the case. Benchmarking shows what I suggested is quicker. It might still be fast without hooking ConVar change etc, but if you have hundreds of cvars, hundreds of plugins and using them in Think hooks or OnGameFrame etc it'll add up and to squeeze out some extra CPU cycles can't harm. It's not very difficult to setup the whole thing.
__________________

Last edited by Silvers; 02-01-2020 at 14:44.
Silvers is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine
Old 02-01-2020 , 17:59   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #16

Common Scripting Mistakes section:
Quote:
Originally Posted by Silvers
GetClientOfUserId to retrieve a clients index from userid, if they have disconnected the value will be 0.
People can erroneously conclude that if returned value != 0, IsClientInGame check is not required.
However, here is
https://hlmod.ru/threads/datapack-i-...99/post-444752
2 mentions (R1KO, komashchenko) that sometimes it is the case when GetClientOfUserId() != 0, but client is not in game.
(this require correction in your next code sample too).

SomeFunction() - no offence. This part break my mind. Not the best sample, IMHO.



Already included in 1st post /or skipped (from discussion in PM)
Spoiler
Attached Files
File Type: sp Get Plugin or Get Source (ac_debug.sp - 161 views - 1.3 KB)
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch)
[My plugins] [My tools] [GitHub] [Articles]

Last edited by Dragokas; 03-29-2020 at 09:40.
Dragokas is offline
Silvers
AlliedModders Donor
Join Date: Aug 2010
Location: SpaceX
Old 02-01-2020 , 19:11   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #17

Excellent thank you. All changes made.


Request to all:
I would like to compile a recommended list of plugins and extensions to fix issues in various games. Please help by recommending ones for different games.
__________________

Last edited by Silvers; 02-01-2020 at 21:23.
Silvers is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine
Old 02-02-2020 , 05:35   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #18

Skip it. Already included in 1st post:
Spoiler
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch)
[My plugins] [My tools] [GitHub] [Articles]

Last edited by Dragokas; 03-29-2020 at 09:37.
Dragokas is offline
xZk
Senior Member
Join Date: Nov 2017
Location: cl
Old 02-02-2020 , 12:11   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #19

L4D2 recommendations:

[L4D2]Character_manager
[L4D2] Real Zoey Unlock
Save Weapon 4.3 (forked)
[L4D2]Defib_Fix
[L4D2] Ammo Pickup

Last edited by xZk; 02-02-2020 at 12:12.
xZk is offline
Silvers
AlliedModders Donor
Join Date: Aug 2010
Location: SpaceX
Old 02-02-2020 , 16:02   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #20

Quote:
Originally Posted by xZk View Post
another common mistake on my part that I also had is to use the wrong types of props, since in some entities there is only one of these: Prop_Send or Prop_Data.
Well, if you use the sm_dump* commands you can see which properties are Prop_Send or Prop_Data.

Quote:
Originally Posted by xZk View Post
I have a doubt with respect this point:

Would it be a good alternative to use a DispatchKeyValueVector(ent, "origin", pos) instead of TeleportEntity ?. In my case I always use this to SetParent entities when they are created.
I guess it's down to preference. But sometimes depending on entity type DispatchKeyValueVector origin might not teleport the entity to where you want and it remains at 0,0,0. This is just something you have to test when creating plugins.


Quote:
Originally Posted by Dragokas View Post
-
Quote:
Originally Posted by xZk View Post
-
Thanks, added links.
__________________
Silvers 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 13:30.


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