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

Structs in SourceMod


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Timon5022
Junior Member
Join Date: Jun 2005
Old 02-21-2016 , 13:43   Structs in SourceMod
Reply With Quote #1

Hi, I am new to SourceMod, and I am trying to make a simple plugin where I store damage information (a log) for each player.

Thus I have the following global variable (amongst many others):
Code:
int g_DmgDealt[MAXPLAYERS+1][MAXPLAYERS+1];
For each hit taken I then increment the stored value with the damage dealth. However, I would instead like to store an "object" that contains information about damage dealt, hitbox hit, timestamp, damage source (maybe also ref to client/player hit). For now I have created a different array for each of these scenarios, but is it not possible to store a struct in the array instead?

So my idea is to define the following struct in my include file:

Code:
struct Damage {
	public const int timestamp;
	public const int dmg;
	public const int dmgSource;
	public const Hitbox hitbox;	
};

// Code for hitbox
enum Hitbox{
	HITBOX_HEAD = 0,
	HITBOX_BODY,
	HITBOX_TORSO,
	HITBOX_STOMACH,
	HITBOX_ARM_LEFT,
	HITBOX_ARM_RIGHT,
	HITBOX_LEG_LEFT,
	HITBOX_LEG_RIGHT
};
and then simply have:
Code:
Damage g_damageDealth[MAXPLAYERS + 1][MAXPLAYERS + 1]
Can someone explain to me how I can declare a struct and then create an array of structs? Also I have been trying to get my own enum as part of the struct, however, I could not get that to compile when I define the struct, as it is unable to find the type Hitbox.

With the above mentioned definition the following code does not compile:
Code:
// Dummy construction of struct to test.
Damage dmgInfo = {
	timestamp = 01234,
	dmg = 1,
	dmgSource = 2,
	Hitbox = HITBOX_HEAD
}
Also I have read various threads about enums and structs and it seems that they are discouraged with the new syntax?
In any case, I would like to know if I should totally drop this notion of using enums and structs and arrays together and go with lots of different array declarations instead?

Last edited by Timon5022; 02-21-2016 at 13:49. Reason: Added code tags and elaborated on my intentions.
Timon5022 is offline
Send a message via MSN to Timon5022
Miu
Veteran Member
Join Date: Nov 2013
Old 02-21-2016 , 14:09   Re: Structs in SourceMod
Reply With Quote #2

Structs aren't supported
Miu is offline
Timon5022
Junior Member
Join Date: Jun 2005
Old 02-22-2016 , 09:18   Re: Structs in SourceMod
Reply With Quote #3

Quote:
Originally Posted by Miu View Post
Structs aren't supported
Can you explain to me then, how structs are used in terms of the plugin info? That is a struct, is it not?

Last edited by Timon5022; 02-22-2016 at 09:19.
Timon5022 is offline
Send a message via MSN to Timon5022
Santi.
Member
Join Date: Oct 2010
Location: Cordoba(Argentina)
Old 11-18-2017 , 01:51   Re: Structs in SourceMod
Reply With Quote #4

Quote:
Originally Posted by Timon5022 View Post
Can you explain to me then, how structs are used in terms of the plugin info? That is a struct, is it not?

I have the same question... I've seen structs in include files, but searching in the forum realized that everyone says sourcepawn does not support it
Santi. is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 11-18-2017 , 02:09   Re: Structs in SourceMod
Reply With Quote #5

Maybe you are looking for methodmap? Or "dynamic" by neurotoxin
__________________
8guawong is offline
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 11-18-2017 , 02:43   Re: Structs in SourceMod
Reply With Quote #6

You can use enum structs instead

EDIT: see "Data Structures" in here https://forums.alliedmods.net/showthread.php?t=140103

Last edited by hmmmmm; 11-19-2017 at 00:43.
hmmmmm is offline
Bobakanoosh
Senior Member
Join Date: Sep 2015
Location: United States
Old 11-18-2017 , 12:22   Re: Structs in SourceMod
Reply With Quote #7

Are objects planned for sourcepawn?
Bobakanoosh is offline
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 11-19-2017 , 05:47   Re: Structs in SourceMod
Reply With Quote #8

Quote:
Originally Posted by Bobakanoosh View Post
Are objects planned for sourcepawn?
As far as I know - nope.
You could write a methodmap to wrap around StringMap (or use SMObjects) to feel object-oriented programming even though it isn't.
__________________
retired
shavit is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 11-19-2017 , 13:01   Re: Structs in SourceMod
Reply With Quote #9

Quote:
Originally Posted by hmmmmm View Post
You can use enum structs instead

EDIT: see "Data Structures" in here https://forums.alliedmods.net/showthread.php?t=140103
That's amxx, please don't do this in your plugins, if it gets too big it'll be harder to control later on and end up being more confusing when you get an error.
Mitchell is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 11-19-2017 , 15:45   Re: Structs in SourceMod
Reply With Quote #10

Quote:
Originally Posted by Mitchell View Post
That's amxx, please don't do this in your plugins, if it gets too big it'll be harder to control later on and end up being more confusing when you get an error.
enum structs also work in SourceMod, although you do have to use the older style code.

Having said that, #pragma newdecls required allows enum structs for exactly this reason.
__________________
Not currently working on SourceMod plugin development.
Powerlord 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 09:58.


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