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

optimize string array


Post New Thread Reply   
 
Thread Tools Display Modes
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-13-2021 , 11:12   Re: optimize string array
Reply With Quote #11

Are you attempting to assign a random weapon from this array, and the weapon can only be applicable to the players current team?

What does this mean? "but because number of weapon each round is different"
__________________
Bugsy is offline
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 02-17-2021 , 03:57   Re: optimize string array
Reply With Quote #12

Quote:
Originally Posted by Bugsy View Post
Are you attempting to assign a random weapon from this array, and the weapon can only be applicable to the players current team?

What does this mean? "but because number of weapon each round is different"
Ex:
- First Round only USP (CT) / Glock (T)
- Second round have P228 (Both), DE (Both) and Five Seven (CT) / Dual Elite (T)

So my plan was doing something like this (after reading previous post)
PHP Code:
new WeaponList_CT[][] = 
{
    { 
CSW_USP },
    { 
CSW_USPCSW_P228CSW_DEAGLECSW_FIVESEVEN }
}

new 
WeaponList_T[][] =
{
    { 
CSW_GLOCK18 },
    { 
CSW_GLOCK18CSW_P228CSW_DEAGLECSW_ELITE }
}


...

new 
radnum random(sizeof(WeaponList_CT[round][]))

new 
wpname[32]; get_weaponname(WeaponList_CT[round][radnum], wpnamecharsmax(wpname))

give_item(idwpname
P/S: I think I do something wrong with sizeof...
__________________
My plugin:

Last edited by Celena Luna; 02-17-2021 at 04:11.
Celena Luna is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-17-2021 , 16:54   Re: optimize string array
Reply With Quote #13

The way you have that array setup will not work: WeaponList_X[ Round# ][ GunIndex ]

You will get an index out of bounds error when you get to round 2 how you have it setup now, unless you did ( round - 1), you would then instead get the error at round 3.

Can you instead have a certain set of weapons for say rounds 1-2, and then rounds 3-9999 have a defined set?
__________________
Bugsy is offline
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 02-17-2021 , 20:53   Re: optimize string array
Reply With Quote #14

Quote:
Originally Posted by Bugsy View Post
The way you have that array setup will not work: WeaponList_X[ Round# ][ GunIndex ]

You will get an index out of bounds error when you get to round 2 how you have it setup now, unless you did ( round - 1), you would then instead get the error at round 3.

Can you instead have a certain set of weapons for say rounds 1-2, and then rounds 3-9999 have a defined set?
ah, I wrote it quickly so I got an oversight on that part.
Yes, it should be "round-1", not "round".
I only plan to max up to round 7 have different pool of weapons each round and there will be defined one set of weapons for the rest of remaining rounds.
__________________
My plugin:

Last edited by Celena Luna; 02-17-2021 at 20:55.
Celena Luna is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-17-2021 , 21:49   Re: optimize string array
Reply With Quote #15

This should work. Just be careful when indexing the array so you don't go out of bounds (eg use round-1, team-1 and 0 to max-1 for weapon slots).

PHP Code:
WeaponListminiRound ) ][ iTeam ][ ]

new const 
WeaponList[][][] = 
{
    { 
//Round 1
        
CSW_USP CSW_GLOCK18 } , //T
        
CSW_P228 CSW_DEAGLE }   //CT
    
},
    { 
//Round 2
        
CSW_USPCSW_P228CSW_DEAGLECSW_FIVESEVEN }, //T
        
CSW_USPCSW_P228CSW_DEAGLECSW_FIVESEVEN }  //CT
    
},
    { 
//Round 3
        
CSW_USPCSW_P228CSW_DEAGLECSW_FIVESEVEN }, //T
        
CSW_USPCSW_P228CSW_DEAGLECSW_FIVESEVEN }  //CT
    
},
    { 
//Round 4
        
CSW_USPCSW_P228CSW_DEAGLECSW_FIVESEVEN }, //T
        
CSW_USPCSW_P228CSW_DEAGLECSW_FIVESEVEN }  //CT
    
},
    { 
//Round 5
        
CSW_USPCSW_P228CSW_DEAGLECSW_FIVESEVEN }, //T
        
CSW_USPCSW_P228CSW_DEAGLECSW_FIVESEVEN }  //CT
    
},
    { 
//Round 6
        
CSW_USPCSW_P228CSW_DEAGLECSW_FIVESEVEN }, //T
        
CSW_USPCSW_P228CSW_DEAGLECSW_FIVESEVEN }  //CT
    
},
    { 
//Round 7
        
CSW_USPCSW_P228CSW_DEAGLECSW_FIVESEVEN }, //T
        
CSW_USPCSW_P228CSW_DEAGLECSW_FIVESEVEN }  //CT
    
},
    { 
//Round 8-9999
        
CSW_USPCSW_P228CSW_DEAGLECSW_FIVESEVEN }, //T
        
CSW_USPCSW_P228CSW_DEAGLECSW_FIVESEVEN }  //CT
    
}
}; 
__________________

Last edited by Bugsy; 02-18-2021 at 21:07.
Bugsy is offline
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 02-18-2021 , 02:44   Re: optimize string array
Reply With Quote #16

@Bugsy Thank you so much.
__________________
My plugin:
Celena Luna is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-18-2021 , 21:08   Re: optimize string array
Reply With Quote #17

Added code for handling rounds 8-9999
__________________
Bugsy is offline
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 02-28-2021 , 00:44   Re: optimize string array
Reply With Quote #18

PHP Code:
new const WeaponList[][][] = 
{
    { 
//Round 1
        
CSW_GLOCK18 } , //T
        
CSW_USP }   //CT
    
},
    { 
//Round 2
        
CSW_P228CSW_GLOCK18CSW_ELITE}, //T
        
CSW_P228CSW_USPCSW_FIVESEVEN}  //CT
    
},
    { 
//Round 3
        
CSW_SCOUTCSW_XM1014CSW_M3 }, //T
        
CSW_SCOUTCSW_XM1014CSW_M3 }  //CT
    
},
    { 
//Round 4
        
CSW_MAC10CSW_MP5NAVYCSW_SCOUT}, //T
        
CSW_TMPCSW_MP5NAVYCSW_SCOUT}  //CT
    
},
    { 
//Round 5
        
CSW_MP5NAVYCSW_UMP45CSW_P90 }, //T
        
CSW_MP5NAVYCSW_UMP45CSW_P90 }  //CT
    
},
    { 
//Round 6
        
CSW_GALILCSW_MP5NAVYCSW_P90 }, //T
        
CSW_FAMASCSW_MP5NAVYCSW_P90 }, //T
    
},
    { 
//Round 7
        
CSW_GALILCSW_AK47CSW_SG552 },
        { 
CSW_FAMASCSW_M4A1CSW_AUG },  //CT
    
},
    { 
//Round 8
        
CSW_SG550CSW_AK47CSW_AWP },
        { 
CSW_G3SG1CSW_M4A1CSW_AWP },  //CT
    
}, 
    { 
//Round 9-9999
        
CSW_GALILCSW_SG552CSW_AK47CSW_AWP },
        { 
CSW_FAMASCSW_AUGCSW_M4A1CSW_AWP },  //CT
    
},
    { 
//Pistol after round 6 
        
CSW_DEAGLE }, //T
        
CSW_DEAGLE }, //CT
    
}
}; 


    new 
iTeam get_user_team(id)
    new 
iRound Rounds();
    new 
iSizeof sizeofWeaponList[min(iRound 18)][iTeam]) 
Is This line is wrong?
PHP Code:
new iSizeof sizeofWeaponList[min(iRound 18)][iTeam])
GiveWeapons(idWeaponList[min(iRound 18)][iTeam][ranom(iSizeof)] 
__________________
My plugin:
Celena Luna is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 02-28-2021 , 01:07   Re: optimize string array
Reply With Quote #19

Yes. Try defining max weapons in the array for each round.

For example.
PHP Code:

{
    { 
//Round 1
        
1CSW_GLOCK18 } , //T
        
1CSW_USP }   //CT
    
},
    { 
//Round 2
        
3CSW_P228CSW_GLOCK18CSW_ELITE}, //T
        
3CSW_P228CSW_USPCSW_FIVESEVEN}  //CT
    
},
    { 
//Round 3
        
3CSW_SCOUTCSW_XM1014CSW_M3 }, //T
        
3CSW_SCOUTCSW_XM1014CSW_M3 }  //CT
    
}

WeaponList[][][ 0 ] will hold the max weapons count.


And the proper way to select a random weapon will be.

PHP Code:

new iMaxWpnsCount WeaponList[min(iRound 18)][max(iTeam 10)][ ]
GiveWeapons(idWeaponList[min(iRound 18)][max(iTeam -10)][random_num(1iMaxWpnsCount)] ) 
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 02-28-2021 at 01:11.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
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 15:36.


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