Raised This Month: $54 Target: $400
 13% 

Solved Confusion With Array


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
soumyadip77
Senior Member
Join Date: Jul 2017
Location: INDIA,KOLKATA
Old 10-10-2021 , 12:55   Confusion With Array
Reply With Quote #1

Hi Guys,

I have a bit confession.

Code:
new Array[2] //declared array

Array[0] = 2 //stored value 2 in Array[0]
Array[1] = 3 //stored value 3 in Array[1]
now i want to make value to 0 for the total array mean Array[0] and Array[1] values will be 0

so I do it this way

Code:
Array[0] = 0
Array[1] = 0

is there any other method to do this in 1 line??
__________________
Let's Help Each Other

Last edited by soumyadip77; 10-10-2021 at 13:09. Reason: Solved
soumyadip77 is offline
Send a message via Skype™ to soumyadip77
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 10-10-2021 , 13:00   Re: Confusion With Array
Reply With Quote #2

arrayset(Array, 0, sizeof(Array))
jimaway is offline
Cristian505
Senior Member
Join Date: Oct 2020
Old 10-10-2021 , 13:22   Re: Confusion With Array
Reply With Quote #3

Why not Array = 0?
Cristian505 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-10-2021 , 13:49   Re: Confusion With Array
Reply With Quote #4

Because the compiler will not know that you want to set the entire array to 0 and is going to expect an index. You can only do that for a regular variable.
__________________
Bugsy is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 10-10-2021 , 14:23   Re: Confusion With Array
Reply With Quote #5

Try this and tell me if it works.

new Array[2] = { 1, 2 };
Array = { 0, 0 };
__________________
@Jailbreak Main Mod v2.6.6 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-10-2021 , 19:32   Re: Confusion With Array
Reply With Quote #6

Quote:
Originally Posted by Natsheh View Post
Try this and tell me if it works.

new Array[2] = { 1, 2 };
Array = { 0, 0 };
It works but arrayset() should be used if setting all cells to the same number because it's more scalable and less likely to break when the array is changed in size in the future.
__________________
fysiks is offline
soumyadip77
Senior Member
Join Date: Jul 2017
Location: INDIA,KOLKATA
Old 10-12-2021 , 15:29   Re: Confusion With Array
Reply With Quote #7

Quote:
new Data[MAX_PLAYERS+1][5]; //Data[0][id] For Kill | Data[id][1] For Death | Data[2][id] For HS | Data[3][id] For Knife Kill
new BestPlayerId;
new BsestPlayerScore;
new BestPlayerName[MAX_NAME_LENGTH];
new CvKillNeed;

public plugin_init()
{

RegisterHookChain(RG_CBasePlayer_TakeDamage, "Damage", 1);
RegisterHookChain(RG_CBasePlayer_Killed, "Killed", 1);
CvKillNeed = register_cvar("amx_race", "2");

set_task(1.0, "check_score_loop", 456, _, _, "b");
}

public check_score_loop()
{
new Players[MAX_PLAYERS]
new pNum;
new TempId;
get_players(Players, pNum);

for(new i ; i < pNum ; i++)
{
TempId = Players[i];

if(Data[TempId][0] == get_pcvar_num(CvKillNeed))
{
BoolData[2] = 1;
break
}
}
BestPlayer();

public Killed(Vic, Att, WeaponID)
{

if(is_user_connected(Att) && is_user_connected(Vic) && Att != Vic)
{
if(get_member(Att, m_iTeam) != get_member(Vic, m_iTeam))
{
if(get_member(Vic, m_bHeadshotKilled))
{
Data[Att][2]++;
Data[Vic][1]++;
}
if(rg_get_weapon_info(Att) == WEAPON_KNIFE)
{
Data[Att][3]++;
Data[Vic][1]++;
}
}
}
}

public Damage(pevVic, pevInflictor, pevAttacker, Float:flDamage, bitsDamageType)
{
if(is_user_connected(pevVic) && is_user_connected(pevAttacker) && pevVic !=pevAttacker)
{
if(get_member(pevAttacker, m_iTeam) != get_member(pevVic, m_iTeam))
{
DamageStore[pevAttacker] += flDamage;
}
}
}

public BestPlayer()
{
new Players[MAX_PLAYERS]
new pNum;
new TempId;
get_players(Players, pNum);

for(new i ; i < pNum ; i++)
{
TempId = Players[i];

if(Data[TempId][0] > BsestPlayerScore)
{
BestPlayerId = TempId;
BsestPlayerScore = Data[TempId][0];
}
}
}
In this How to do 2d array "Data" to set 0. And wanna end the plugin if some one reach maximum kill which is set by the "CvKillNeed" cvar i tried but not working.

Can anyone tell ho to do that ?
__________________
Let's Help Each Other
soumyadip77 is offline
Send a message via Skype™ to soumyadip77
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-12-2021 , 18:00   Re: Confusion With Array
Reply With Quote #8

PHP Code:
for ( new sizeofarr ) ; i++ )
    
arraysetarr] , sizeofarr[] ) ); 
In your code where you do stuff, put a condition to not do things if kills >= the max. You can get more creative/efficient by unregistering forwards etc.
__________________
Bugsy 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 20:59.


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