Raised This Month: $51 Target: $400
 12% 

[HELP] Enum (value) (string)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
CodingIsHard
Junior Member
Join Date: Jul 2015
Old 07-28-2015 , 14:13   [HELP] Enum (value) (string)
Reply With Quote #1

Hi everyone again!

Since lots of you guys as programmers are sometimes lazy but efficent by creating a loop to make the big work from you without having to type everything one-by-one.

I've been reading the Exolent[jNr]'s guide on enums but it seems not to fit into my head on how it exactly works it's shortly, confusing to me.

So i came to you with a question can i make a enum list with the model location and name-string like this:

PHP Code:
enum _:model&name {

"v_model.mdl""Model name!"
"v_model2.mdl"
"Model name 2!"


Is it possible to achieve that and make it loop into a menu with the name meanwhile using the "v_model.mdl" in a function?

If not can you point me to a direction which would be an efficent way to select a model since i have multiple models to use.

Is creating a new global int and giving it a value gCurrentModel[id] = 0..1..2 in a function efficent?

Last edited by CodingIsHard; 07-28-2015 at 14:17.
CodingIsHard is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 07-28-2015 , 15:41   Re: [HELP] Enum (value) (string)
Reply With Quote #2

You can't do such stuff with enumerations, but you can with arrays:
PHP Code:
new const g_szModelList[][] =
{
    {
"v_model.mdl""Model name!"},
    {
"v_model2.mdl""Model name 2!"}
}; 
Then you can use
PHP Code:
sizeof(g_szModelList
to get the list length (number of items in that array), and use
PHP Code:
g_szModelList[index][0]
g_szModelList[index][1
to get model path and model name, respectively.
klippy is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-28-2015 , 17:00   Re: [HELP] Enum (value) (string)
Reply With Quote #3

Can you give an example of what you're trying to do. This may be doable.

Does this help? An enum isn't necessary for this, but it keeps your code clean so you are not using array[#][#], instead you would do array[#][data item that you want].
PHP Code:
enum _:ModelInfo
{
    
ModelFile32 ],
    
ModelName32 ]
}

new const 
g_szModelList[][ ModelInfo ] =
{
    { 
"v_model1.mdl" "Model name 1" },
    { 
"v_model2.mdl" "Model name 2" }
};  

for ( new 
sizeofg_szModelList ) ; i++ )
    
//Access the models details (file/name) using the index of it, in this example 'i'
    
server_print"File=%s Name=%s" g_szModelList][ ModelFile ] , g_szModelList][ ModelName ] ) 
__________________
Bugsy is offline
CodingIsHard
Junior Member
Join Date: Jul 2015
Old 07-29-2015 , 09:32   Re: [HELP] Enum (value) (string)
Reply With Quote #4

Thank you for your help, especially Bugsy for giving a clear image on how to use enum and array together, this helps a lot i'm slightly getting a hang of the enum.

Basically i have a menu where i loop through the array where i get a name for the slot, then make a case statement with the help of a global array?
PHP Code:
szModel[33]; 
Which holds maximum possible players in it. So after i've done that i use
PHP Code:
case 0: { szModel[id] = 5; } 
and after the switch i run the CurWeapon event function.

CurWeapon event simply changes the model when the weapon is correct so i use if statement along with the global array
PHP Code:
if(szModel[id] == 5) { //change model } 
i may be wrong but to me it doesn't seem like a good thing to do. I like to keep my code optimized and it should have a good performance on servers, but sometimes i just get lost in the code and start doing dumb things.

I also am using 1 menu handler for multiple menus as i have thought of using the case as model changer it does not stay in place and returns the default model after switching a weapon again.

I am sorry if i left you, the reader confused but that's all what came into my mind at this moment, ask freely if anything left unclear.

The main problem right now stays as how would i identify the chosen model in the CurWeapon event or should i use external function to send data to CurWeapon?

Last edited by CodingIsHard; 07-29-2015 at 09:41.
CodingIsHard is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-29-2015 , 10:01   Re: [HELP] Enum (value) (string)
Reply With Quote #5

I think your idea will work, I'll post something when I can
__________________
Bugsy is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-29-2015 , 22:51   Re: [HELP] Enum (value) (string)
Reply With Quote #6

I don't fully understand, but it sounds like you are setting a model index on a player based on their current weapon. If you can post more code to explain better it would help.

You should be able to end up with something where a model index is set in the players array, and then that can be used directly in the models array.

See if this helps at all:
PHP Code:
enum _:Models
{
    
Model1,
    
Model2,
    
Model3,
    
Model4
}

enum _:ModelInfo
{
    
ModelFile32 ],
    
ModelName32 ]
}

new const 
g_szModelListModels ][ ModelInfo ] =
{
    { 
"v_model1.mdl" "Model name 1" },
    { 
"v_model2.mdl" "Model name 2" },
    { 
"v_model3.mdl" "Model name 3" },
    { 
"v_model4.mdl" "Model name 4" }
};  

new 
g_iPlayerModel33 ];

//Assign model index for player
g_iPlayerModelid ] = Model3;
    
//Access the model data like this
g_szModelListg_iPlayerModelid ] ][ ModelName 
g_szModelListg_iPlayerModelid ] ][ ModelFile 
__________________

Last edited by Bugsy; 07-29-2015 at 22:52.
Bugsy is offline
CodingIsHard
Junior Member
Join Date: Jul 2015
Old 10-15-2015 , 09:38   Re: [HELP] Enum (value) (string)
Reply With Quote #7

Forgot to thank you @Bugsy, +karma, thank you.
CodingIsHard is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-15-2015 , 19:53   Re: [HELP] Enum (value) (string)
Reply With Quote #8

No problem and thank you for the imaginary karma.
__________________
Bugsy 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 09:10.


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