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

Solved Replace in a String that Contains Repeated Chars


Post New Thread Reply   
 
Thread Tools Display Modes
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-20-2022 , 20:55   Re: Replace in a String that Contains Repeated Chars
Reply With Quote #11

Agreed, this isn't ideal but it can work.

I personally would do something more organized, like below. OP, if you can provide some use-cases for how your plugin will be utilizing costumes, I can make adjustments.
PHP Code:

#include <amxmodx>

enum CostumeTypes
{
    
Male1,
    
Male2,
    
Female1
}

enum CostumeGender
{
    
Male,
    
Female
}

enum CostumeModels
{
    
CostumeGender:Gender,
    
Hat50 ],
    
Shirt50 ],
    
Pants50 ],
    
Shoes50 ]
}

new 
CostumeDataCostumeTypes ][ CostumeModels ] = 
{
    { 
Male "models/costume/male1_hat.mdl" "models/costume/male1_shirt.mdl" "models/costume/male1_pants.mdl" "models/costume/male1_shoes.mdl" },
    { 
Male "models/costume/male2_hat.mdl" "models/costume/male2_shirt.mdl" "models/costume/male2_pants.mdl" "models/costume/male2_shoes.mdl" },
    { 
Female "models/costume/female1_hat.mdl" "models/costume/female1_shirt.mdl" "models/costume/female1_pants.mdl" "models/costume/female1_shoes.mdl" }
}
    
public 
plugin_init() 
{
    
server_print"%s %s %s %s" CostumeDataMale1 ][ Hat ] , CostumeDataMale1 ][ Shirt ] , CostumeDataMale1 ][ Pants ] , CostumeDataMale1 ][ Shoes ] );
    
server_print"%s %s %s %s" CostumeDataMale2 ][ Hat ] , CostumeDataMale2 ][ Shirt ] , CostumeDataMale2 ][ Pants ] , CostumeDataMale2 ][ Shoes ] );
    
server_print"%s %s %s %s" CostumeDataFemale1 ][ Hat ] , CostumeDataFemale1 ][ Shirt ] , CostumeDataFemale1 ][ Pants ] , CostumeDataFemale1 ][ Shoes ] );

__________________
Bugsy is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 07-21-2022 , 03:16   Re: Replace in a String that Contains Repeated Chars
Reply With Quote #12

You probably need to follow a certain file name format, it will be much better such as costume_m_hats.mdl

PHP Code:
new const szFile[] = "costume_X"

new charGender szFileName[strlen(szFile) - 1];

switch( 
charGender )
{
     case 
'm'charGender'M';
     case 
'f'charGender'F';

__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 07-21-2022 at 03:22.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
asdian
Member
Join Date: Sep 2016
Location: Indonesia
Old 07-21-2022 , 06:34   Re: Replace in a String that Contains Repeated Chars
Reply With Quote #13

thanks for your answer guys, it all works as i need now.

one last question, is it possible to get 2 chars or more like :
Code:
szCos[strlen(szCos)-4] == "this"
without using equal/equali in amxx ?
asdian is offline
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 07-21-2022 , 08:03   Re: Replace in a String that Contains Repeated Chars
Reply With Quote #14

Quote:
Originally Posted by asdian View Post
thanks for your answer guys, it all works as i need now.

one last question, is it possible to get 2 chars or more like :
Code:
szCos[strlen(szCos)-4] == "this"
without using equal/equali in amxx ?
Yes, by using the logical operator "&&" ( AND )

Code:
// By defining a new variable which stores the string lenght, you avoid multiple function calls ( improving the performance ) new iLen = strlen(szCos) if(szCos[iLen - 4] == 't' && szCos[iLen - 3] == 'h' && szCos[iLen - 2] == 'i' && szCos[iLen - 1] == 's') {     // meets the criterias, execute }
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]
Shadows Adi is offline
asdian
Member
Join Date: Sep 2016
Location: Indonesia
Old 07-24-2022 , 12:09   Re: Replace in a String that Contains Repeated Chars
Reply With Quote #15

Quote:
Originally Posted by Shadows Adi View Post
Code:
// By defining a new variable which stores the string lenght, you avoid multiple function calls ( improving the performance ) new iLen = strlen(szCos) if(szCos[iLen - 4] == 't' && szCos[iLen - 3] == 'h' && szCos[iLen - 2] == 'i' && szCos[iLen - 1] == 's') {     // meets the criterias, execute }
now after i did that, it gives me index out of bounds error. previously it works fine. this is driving me nuts !

*edit
nvm, fixed now. just forgot to modify some data

Last edited by asdian; 07-24-2022 at 12:24.
asdian is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-24-2022 , 12:13   Re: Replace in a String that Contains Repeated Chars
Reply With Quote #16

What is the total length of the string and size of the szCos variable?

Also, you may be better off hard-coding all of this information instead of swapping characters (see my example above). We aren't using computers from the 1970's anymore where memory is a limitation.
__________________

Last edited by Bugsy; 07-24-2022 at 12:14.
Bugsy is offline
asdian
Member
Join Date: Sep 2016
Location: Indonesia
Old 07-24-2022 , 16:06   Re: Replace in a String that Contains Repeated Chars
Reply With Quote #17

Quote:
Originally Posted by Bugsy View Post
What is the total length of the string and size of the szCos variable?

Also, you may be better off hard-coding all of this information instead of swapping characters (see my example above). We aren't using computers from the 1970's anymore where memory is a limitation.
it is already correct, just my .ini file that is wrong. somehow if it is only contains semicolon it won't skip
asdian 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:27.


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