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

What is offsets?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mikka
Member
Join Date: Dec 2018
Old 02-05-2023 , 09:56   What is offsets?
Reply With Quote #1

Hi, I have a question with offsets.
What are offsets?
What does it use offsets for?

Ex:

//
Quote:
const OFFSET_SMOKE_AMMO=389
or

Quote:
set_pdata_int(id, 235, get_pdata_int(id, 235) & ~(1<<0));
set_pdata_int(id, 116, 0)
or

Quote:
#define OFFSET_CSTEAMS 114
set_pdata_int(id, OFFSET_CSTEAMS, _:team)

2) What is the difference between a forward and a regular function?

Quote:
register_forward(FM_ClientDisconnect, "fw_ClientDisconnect_Post", 1)
but it is the same?

Quote:
public client_disconnect(id)

Last edited by Mikka; 02-05-2023 at 10:00.
Mikka is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-05-2023 , 14:24   Re: What is offsets?
Reply With Quote #2

In layman's terms, an offset in your example tells the function what piece of data to use (it's kind of like a pointer in C). The value is often assigned to a constant or variable to explain what data is pointed to by the offset.

Again, in layman's terms, a regular function is simply a collection of actions called by other functions in your plugin. A forward is a special type of function that can be executed from outside the place that it is defined. In your example, both "client_disconnected" and "fw_ClientDisconnect_Post" are forwards. They both get called by AMX Mod X when a particular event happens. "client_disconnected" just happens to be so common that it was defined as part of AMX Mod X's core code. "fw_ClientDisconnect_Post" is a dynamically registered forward that gets called after (hence the "post") the FM_ClientDisconnect event occurs. I don't know the specifics but the difference will lie in how AMX Mod X decided to define client_disconnect.

One thing that you might note is that client_disconnect() actually has a rare bug in it forcing the developers to create a new forward called client_disconnected() that has that bug fixed.
__________________
fysiks is offline
Reply



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:10.


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