AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Confusion With Array (https://forums.alliedmods.net/showthread.php?t=334643)

soumyadip77 10-10-2021 11:55

Confusion With Array
 
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??

jimaway 10-10-2021 12:00

Re: Confusion With Array
 
arrayset(Array, 0, sizeof(Array))

Cristian505 10-10-2021 12:22

Re: Confusion With Array
 
Why not Array = 0?

Bugsy 10-10-2021 12:49

Re: Confusion With Array
 
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.

Natsheh 10-10-2021 13:23

Re: Confusion With Array
 
Try this and tell me if it works.

new Array[2] = { 1, 2 };
Array = { 0, 0 };

fysiks 10-10-2021 18:32

Re: Confusion With Array
 
Quote:

Originally Posted by Natsheh (Post 2760209)
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.

soumyadip77 10-12-2021 14:29

Re: Confusion With Array
 
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 ?

Bugsy 10-12-2021 17:00

Re: Confusion With Array
 
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.


All times are GMT -4. The time now is 11:50.

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