AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   hamsandwich (https://forums.alliedmods.net/showthread.php?t=183424)

Liverwiz 04-21-2012 15:47

hamsandwich
 
is it worth the overhead of the hamdsandwich include file if i'm just going to use a single function out of it?

Code:

RegisterHam(Ham_Spawn, "player", ham_atSpawn", 1)
as opposed to....

Code:

register_event("start", "atSpawn", "a", "1=Round_Start")
using the for-loop traversal in atSpawn()
is this really worth it? (other than simply lines of code)
i feel like Ham_Spawn does something quite similar, but i'm not so familiar with hamsandwich.

i'd like some expert opinions.

claudiuhks 04-21-2012 16:42

Re: hamsandwich
 
Round Start is a log event which is executed when freeze time ends.
Spawn forward taken from HamSandwich is executed when server's engine is spawning a client.

For example, if you want to reset some variables for each player at the begin of the round, you should hook Round Start.

Of course, Round Start is a forward which is executed once so it should be more faster than HamSandwich's Spawn forwards for each client.

Liverwiz 04-21-2012 19:05

Re: hamsandwich
 
but Round Start executes the function at the start, rather than per client. while Ham_Spawn does it per client, as they spawn. yes?

Thus....Round Start would best be used for a server-wide change at spawn. And you'd use Ham_Spawn as the best use for changes to individual clients.

i.e. Round Start: use to do like a server-wide, client separate command
Code:

clinet_print(0, print_chat, "HamSandwiches for all!")
and you'd use Ham_Spawn for client specific events. such as changing internal states for the client or executing a command on the specific client as they spawn.
Code:

public Ham_onSpawn(id)
    client_cmd(id, "say TUNA!")

is my understanding correct?

which also leads me to the question.....is the overhead of hamsandwich worth the performance increase?

i know hamsandwich is a large headerfile, and not all administrators have HS enabled. Or am i just asking pointless questions that really don't matter.....i've noticed you guys put a high value on efficiency, so i'm looking for the best methods here....


Also, when HLTV is placed into the world, does it go through Ham_Spawn? Should i make it a point to exclude HLTV from code being executed on it?

claudiuhks 04-21-2012 19:21

Re: hamsandwich
 
Your explanation seems to be alright. Round Start is executed after freeze time ends.
HamSandwich is creating custom forwards which will interract with the game engine. And I could give you an example.

PHP Code:

void DoSpawnedict_t *ePlayer )
{
  
// This is an engine function created by Valve Software.
  // This is executed to spawn the specified target.
}

void DoRoundStartvoid )
{
  
// This is an engine function created by Valve Software.
  // This is executed with a purpose made by Valve Software.


Now HamSandwich will hook DoSpawn and will create a custom forward which will interract with DoSpawn. Or, Amx Mod X in DoRoundStart.
When DoSpawn is executed, your forward registered into your plugin is also executed. If your forward is registered as post, it will be executed after the game forward will be executed. Else, if your forward is registered as pre, it will be executed before the game forward will be executed.

And of course, game will execute forward DoSpawn 32 times, and your Ham_OnSpawn forward too.
Game will execute forward DoRoundStart once, and your LogEvent_RoundStart forward once.

No, HamSandwich and FakeMeta are good extensions to use.
Engine is a forging machine for server.

Is your choice: HamSandwich with 32 executions or RoundStart with one execution.

Liverwiz 04-21-2012 19:34

Re: hamsandwich
 
Thanks so much!

another one....sorry to ask so many questions, but does HLTV go through these spawn functions? or do they just get placed into the world and left to do what they need to do.

claudiuhks 04-21-2012 19:40

Re: hamsandwich
 
Now I'm testing difference between HLTV message and Ham Spawn forward, I'm also curious. In three minutes I'll be here editing my post.

HLTV is executed before player spawn post.

But, after map change, in first round HLTV is not executed.

Liverwiz 04-21-2012 20:51

Re: hamsandwich
 
NEAT! Thanks, man! I really appreciate your help. Learned a few things from you.

+karma

fysiks 04-21-2012 22:19

Re: hamsandwich
 
TLDR

Round_Start is not an alternative to Ham_Spawn. They are very very different. If you want when a player actually spawns then you should always use Ham_Spawn, no excuses.

You should only avoid additional modules if and only if you can already achieve the same exact thing with engine or fun. For spawn, ham sandwich is the only way to do it correctly.

Liverwiz 04-21-2012 22:21

Re: hamsandwich
 
Well THAT is a clear cut answer i was looking for. Dually noted.

On another note.....what does "TLDR" mean?

[EDIT] Google says Too Long Didn't Read. I assume as much and accept it as such.


All times are GMT -4. The time now is 07:41.

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