Raised This Month: $32 Target: $400
 8% 

[TUT] SourcePawn Scripting - Tips, Basics to Advanced


Post New Thread Reply   
 
Thread Tools Display Modes
MAGNAT2645
Senior Member
Join Date: Nov 2015
Location: AlliedMods.net
Old 08-20-2021 , 19:00   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #51

Quote:
Originally Posted by Dragokas View Post
MAGNAT2645, interesting ability, but IMHO, useless sample =) Can't find where it could be useful. The same can be written by manual string enquoting.
As i said, it's not that useful. You can use it in a macro to join text (and put it without quotes).
Code:
#define ERROR(%0) PrintToServer( "ERROR: " ... #%0 )

int a = 5;
int b = 0;
int c;
if ( b == 0 ) ERROR(Division by zero!);
else          c = a / b;
But, it's better to use quotes for better readability
Code:
#define ERROR(%0) PrintToServer( "ERROR: " ... %0 )
if ( b == 0 ) ERROR( "Division by zero!" );
__________________

Last edited by MAGNAT2645; 08-20-2021 at 19:01.
MAGNAT2645 is offline
zomexf
Junior Member
Join Date: Jul 2019
Old 09-20-2021 , 13:12   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #52

Use OnClientPostAdminCheck or OnClientPutInServer : SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage);

Whether it is necessary to use "SDKUnhook(client, SDKHook_OnTakeDamage, OnTakeDamage)" in OnClientDisconnect;

I want to know.
__________________
Sorry, My English is bad

Last edited by zomexf; 09-20-2021 at 13:14.
zomexf is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 09-20-2021 , 13:20   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #53

Quote:
Originally Posted by zomexf View Post
Use OnClientPostAdminCheck or OnClientPutInServer : SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage);

Whether it is necessary to use "SDKUnhook(client, SDKHook_OnTakeDamage, OnTakeDamage)" in OnClientDisconnect;

I want to know.
Hook inside OnClientPutInServer since that's when players join the server. I would only hook inside OnClientPostAdminCheck if you plan on checking admin flags to determine if they should be hooked.

Entities are automatically unhooked by SDKHooks when they leave (if they are player entities) or are deleted.
__________________
Psyk0tik is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 09-20-2021 , 13:38   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #54

Using OnClientPostAdminCheck is bad for anything other than when checking for admin flags, since if Steam goes offline they are not verified and the forward will not trigger.
__________________
Silvers is offline
zomexf
Junior Member
Join Date: Jul 2019
Old 09-20-2021 , 14:48   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #55

Thanks.
__________________
Sorry, My English is bad

Last edited by zomexf; 09-20-2021 at 14:53.
zomexf is offline
NoroHime
Veteran Member
Join Date: Aug 2016
Location: bed
Old 03-15-2022 , 06:24   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #56

I'm some confuses using entity reference, when I check for validate entities before using each entity does that mean I don't need entity references?
__________________
NoroHime is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 03-15-2022 , 07:08   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #57

Quote:
Originally Posted by NoroHime View Post
I'm some confuses using entity reference, when I check for validate entities before using each entity does that mean I don't need entity references?
I'll make it clearer in the post.

You want to use entity references and userid's for anything asynchronous such as CreateTimer, RequestFrame or when you're storing an entity index in an array. Anything that will be accessed later and not immediately in the same frame/functions where you have the entity index.
__________________
Silvers is offline
NoroHime
Veteran Member
Join Date: Aug 2016
Location: bed
Old 03-15-2022 , 07:58   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #58

Quote:
Originally Posted by Silvers View Post
I'll make it clearer in the post.

You want to use entity references and userid's for anything asynchronous such as CreateTimer, RequestFrame or when you're storing an entity index in an array. Anything that will be accessed later and not immediately in the same frame/functions where you have the entity index.
yeah, for this point wiki is explain clearly
but my confuses is what merit to use entity references? does OnEntityDestoyed cant handle all of the entity status change situations? or ent ref just double check here
or conversely, if enf ref check passed, that mean we dont have to use IsValidEntity or IsValidEdict
a digression, under which scene we should use Edict operation rather than Entity Operation?
very thanks silvers patiently anser
----
for the edict i found from main thread, sorry im reading slowly
__________________

Last edited by NoroHime; 03-15-2022 at 08:03.
NoroHime is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 03-16-2022 , 06:36   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #59

Follow this events order as example:

OnEntityCreated -> PostSpawn -> RequestFrame -> CreateTimer(timerReadEnt) -> EntityDestroyed > timerReadEnt

in timerReadEnt you will get an exception if you use the entity index cause it's gone (or replaced by another entity with the same index).

Storing the entity as EntRef allow you to post-check if that entityRef has an INVALID_REFERENCE (with EntRefToEntIndex) before using it.

The logic is the same as what happens to the player. (GetClientUserId)
__________________

Last edited by Marttt; 03-16-2022 at 06:37.
Marttt is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 03-16-2022 , 08:50   Re: [TUT] SourcePawn Scripting - Tips, Basics to Advanced
Reply With Quote #60

Quote:
Originally Posted by NoroHime View Post
but my confuses is what merit to use entity references?
NoroHime, the merit of using entity ref -> they are much more unique (higher range of values, like == index + time). There is a high chance the entity with index e.g. 123 will be destroyed and the new entity will be created with the same 123 index during asynhronous operation. The the next time when you chech this entity and expect it to be the same as it was at creation time, that will not be true: IsValidEntity will return true, but the entity is replaced.

Quote:
Originally Posted by NoroHime View Post
does OnEntityDestoyed cant handle all of the entity status change situations?
You could use OnEntityDestoyed with your entities array. However, usually a single IsValidEntity operation is more efficient.

Quote:
Originally Posted by NoroHime View Post
... or conversely, if enf ref check passed, that mean we dont have to use IsValidEntity or IsValidEdict
Well, personally I always check validity after dereference, like so:
PHP Code:
int soul EntRefToEntIndex(g_iGlowRef[client]);
        
if (
soul && soul != INVALID_ENT_REFERENCE && IsValidEntity(soul)) 
I think it's required. However, you can try remove entity and experiment with dereference on your own to see if error persist.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
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 20:38.


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