Raised This Month: $ Target: $400
 0% 

[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 02-02-2020 , 16:02   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #21

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
BHaType
Great Tester of Whatever
Join Date: Jun 2018
Location: Methamphetamine
Old 02-12-2020 , 00:28   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #22

I think it would be a good idea to attach this topic so that no one don't have to search for it in the future also a new sourcemod user will see this topic and maybe this will fix the problem of identical errors and requests for
help such as: no debug stringtable, Error parsing gameconfig file, Language phrase "..." not found and so on
__________________
Heart

Last edited by BHaType; 02-12-2020 at 00:37.
BHaType is offline
Send a message via AIM to BHaType
Desktop
AlliedModders Donor
Join Date: Sep 2009
Location: C:\Users\Default\
Old 02-20-2020 , 12:47   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #23

I think it would be nice to add the usage of RequestFrame instead of CreateTimer with 0.1 seconds to execution as a good practice.

For example:
PHP Code:
public Action EventOnPlayerConnectedFull(Event eventchar[] namebool dontBroadcast){

    
int client GetClientOfUserId(GetEventInt(event"userid"));
    
    
RequestFrame(view_as<RequestFrameCallback>(MoveToSpectator), client);
}
public 
Action MoveToSpectator(any data){
    
    
ChangeClientTeam(dataCS_TEAM_NONE);

__________________
Massive Infection:: Piu-Games
Desktop is offline
Maxximou5
AlliedModders Donor
Join Date: Feb 2013
Old 02-20-2020 , 16:36   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #24

Quote:
Originally Posted by Desktop View Post
I think it would be nice to add the usage of RequestFrame instead of CreateTimer with 0.1 seconds to execution as a good practice.
Spoiler
It would depend on the use case, you could be using a repeat timer. Though for the instance you are probably mentioning, it would be a one time with an immediate response. That would be a great use of RequestFrame as it's that's what it should be used for. Though, I would say it would better to have a complete example, along with the newest method of usage. Such as -

PHP Code:
#include <cstrike>

public void OnPluginStart()
{
    
HookEvent("player_connect_full"Event_PlayerConnectFull);
}

public 
void Event_PlayerConnectFull(Event event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(event.GetInt("userid"));
    
RequestFrame(Frame_ChangeTeamclient);
}

public 
void Frame_ChangeTeam(any client)
{
    
ChangeClientTeam(clientCS_TEAM_NONE)

It should be mentioned that there are scenarios were RequestFrame and using a timer delay are different enough that something such as when a player is spawning and not creating a delay will cause a function to not work. Case scenarios I believe exist, like equipping a weapon, dropping a weapon, or cycling and stripping certain weapons, are such examples.

Of course, correct me if I am wrong, but this was such issues I had awhile ago.
__________________
Maxximou5 is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine
Old 02-21-2020 , 04:47   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #25

// TODO:
Where is a good start for learning VScript system? Some links for novice...

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

Last edited by Dragokas; 03-29-2020 at 09:44.
Dragokas is offline
Desktop
AlliedModders Donor
Join Date: Sep 2009
Location: C:\Users\Default\
Old 02-26-2020 , 08:43   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #26

Quote:
Originally Posted by Maxximou5 View Post
It would depend on the use case, you could be using a repeat timer. Though for the instance you are probably mentioning, it would be a one time with an immediate response. That would be a great use of RequestFrame as it's that's what it should be used for. Though, I would say it would better to have a complete example, along with the newest method of usage. Such as -

PHP Code:
#include <cstrike>

public void OnPluginStart()
{
    
HookEvent("player_connect_full"Event_PlayerConnectFull);
}

public 
void Event_PlayerConnectFull(Event event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(event.GetInt("userid"));
    
RequestFrame(Frame_ChangeTeamclient);
}

public 
void Frame_ChangeTeam(any client)
{
    
ChangeClientTeam(clientCS_TEAM_NONE)

It should be mentioned that there are scenarios were RequestFrame and using a timer delay are different enough that something such as when a player is spawning and not creating a delay will cause a function to not work. Case scenarios I believe exist, like equipping a weapon, dropping a weapon, or cycling and stripping certain weapons, are such examples.

Of course, correct me if I am wrong, but this was such issues I had awhile ago.
Yes, you're right, that would be a correct case, as you said, sometimes you have to "let things happen" before calling a func to that, like the case when the player equips a weapon or while working with networked entities and you need them to exist first.

There are two ways of using this logic, one is firing a timer for example on a "Pre" event (Time) and the other is to request a frame in the "post" event (requestFrame), both should work similarly on most cases.
The difference is that on the "post" event, you can read/know all the data you need to work with the entity (because you are sure it already exists)
__________________
Massive Infection:: Piu-Games

Last edited by Desktop; 02-26-2020 at 08:50.
Desktop is offline
conglyvaness
New Member
Join Date: Mar 2020
Location: Việt Nam
Old 03-05-2020 , 23:27   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #27

Originally Posted by Silvers
ConVars Anomaly Fixer
__________________
conglyvaness is offline
Silvers
AlliedModders Donor
Join Date: Aug 2010
Location: SpaceX
Old 03-05-2020 , 23:48   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #28

lol what, not by me... I think you made error posting? I have been meaning to update 1st post for a while, soon eventually I will please bear with me.
__________________

Last edited by Silvers; 03-05-2020 at 23:48.
Silvers is offline
Silvers
AlliedModders Donor
Join Date: Aug 2010
Location: SpaceX
Old 03-14-2020 , 16:36   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #29

We're stickied! Thanks! @Mods I'll try to keep this updated over the foreseeable future also feel free to make any changes.

Updated with suggestions from above and added various details to "Information:" part of section 7. Thanks to "JoinedSenses" and "Lux" for some details.

Added the RequestFrame example and one from my own uses.

Dragokas has even more additions coming soon!

Huge thanks to "GAMMACASE" for compiling a list of CS:S and CS:GO fixes, now added to the section 6.
__________________

Last edited by Silvers; 03-14-2020 at 18:00.
Silvers is offline
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 #30

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).

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

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.


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

Last edited by Dragokas; 03-29-2020 at 10:56.
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 03:56.


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