SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts

Reply
 
Thread Tools Display Modes
Old 03/07/2020, 04:59 PM   #11
NaS
High-roller
 
NaS's Avatar
 
Join Date: Mar 2008
Location: 🇩🇪
Posts: 1,774
Reputation: 619
Default Re: Kill Assist [killAssist.fs]

Quote:
Originally Posted by brauf View Post
Yeah, you're right i need to reset it if they log out- will do that now


if(killAssist[playerid][a] == issuerid)
{
break;
}

checks if issuerid is in any of those arrays, then break the whole loops for them
then:
if((killAssist[playerid][a] == INVALID_PLAYER_ID) checks if slot is free for a player, then adds them to it

However, I think another person mentioned to me "playerid being in the array twice or more", but I don't think that's possible, could you explain further?

Thanks for your feedback - ill add the damage each player did as well later.

New Update! 03-07-20
--------------------------------------------------------------------------------------------------------

Update: 1d
* Now kill asssist for playerid is reset under OnPlayerDisconnect
* No longer calling local function
* No longer looping through macros
--------------------------------------------------------------------------------------------------------
If a slot is empty (say slot 1) and the player is already in slot 2, the loop will stop at slot 1 and insert. This will lead to the player being in slot 1 and 2 since the loop never reached slot 2 to check it.

I think a good way of solving this would be using a variable to assign the free slot, and not using break; when a free slot was found so that the loop continues to search for the player, for example:

Code:
new slot = -1;

for(new a; a < killAssist@MAX_SLOTS; a++)
{
	if(killAssist[playerid][a] == issuerid)
	{
		slot = -1; // Reset slot in case a free slot has been found already
		break;
	}

	if(slot == -1 && killAssist[playerid][a] == INVALID_PLAYER_ID)
	{
		slot = a;
	}
}

if(slot != -1)
{
	killAssist[playerid][slot] = issuerid;
}
The slot == -1 check in the loop is important so that slot is only assigned once (so the lowest free ID will be selected).

This way the loop will always check the whole array for the player even if a free slot was found somewhere in the middle.
NaS is offline   Reply With Quote
Old 03/07/2020, 05:21 PM   #12
brauf
Little Clucker
 
brauf's Avatar
 
Join Date: Jul 2018
Location: i live in narnia city Savage: 100%
Posts: 37
Reputation: 20
Default Re: Kill Assist [killAssist.fs]

Quote:
Originally Posted by NaS View Post
If a slot is empty (say slot 1) and the player is already in slot 2, the loop will stop at slot 1 and insert. This will lead to the player being in slot 1 and 2 since the loop never reached slot 2 to check it.

I think a good way of solving this would be using a variable to assign the free slot, and not using break; when a free slot was found so that the loop continues to search for the player, for example:

Code:
new slot = -1;

for(new a; a < killAssist@MAX_SLOTS; a++)
{
	if(killAssist[playerid][a] == issuerid)
	{
		slot = -1; // Reset slot in case a free slot has been found already
		break;
	}

	if(slot == -1 && killAssist[playerid][a] == INVALID_PLAYER_ID)
	{
		slot = a;
	}
}

if(slot != -1)
{
	killAssist[playerid][slot] = issuerid;
}
The slot == -1 check in the loop is important so that slot is only assigned once (so the lowest free ID will be selected).

This way the loop will always check the whole array for the player even if a free slot was found somewhere in the middle.
Thanks, I have used your loop and I can see how it works.
However I don't undertand... how my loop doesn't do the same? , what part exactly makes it fail :/. anyways thanks for the help, i've used your method, you have more experience than me

you say it will add the player to the slot even though it might be in a later slot, however this is impossible because
if(killAssist[playerid][a] == issuerid) break; checks all slots if their ID in in the slot, then breaks it if it is?
brauf is offline   Reply With Quote
Old 03/07/2020, 05:57 PM   #13
NaS
High-roller
 
NaS's Avatar
 
Join Date: Mar 2008
Location: 🇩🇪
Posts: 1,774
Reputation: 619
Default Re: Kill Assist [killAssist.fs]

Quote:
Originally Posted by brauf View Post
You say it will add the player to the slot even though it might be in a later slot, however this is impossible because
if(killAssist[playerid][a] == issuerid) break; checks all slots if their ID in in the slot, then breaks it if it is?
Consider this array content for some player:

0: 20
1: 21
2: 25
3: INVALID_PLAYER_ID (free)
4: 22

If you run the old loop with issuerid = 22 you would expect it to do nothing, as 22 is already in the array. However, what actually happens is that 22 is inserted a second time in index 3.

That is because of the second if() in the loop, it sees a free slot (INVALID_PLAYER_ID) in index 3 and stops the loop (break;). This will prevent the loop from even reaching index 4.


What my loop changed is that it doesn't stop on a free slot.
When reaching index 3 it would store the free index in the "slot" variable. When it continues to index 4, it would find ID 22, reset the "slot" variable and stop the loop. As a result, ID 22 is not inserted a second time.

I hope that makes sense.
NaS is offline   Reply With Quote
Old 03/07/2020, 06:21 PM   #14
brauf
Little Clucker
 
brauf's Avatar
 
Join Date: Jul 2018
Location: i live in narnia city Savage: 100%
Posts: 37
Reputation: 20
Default Re: Kill Assist [killAssist.fs]

Quote:
Originally Posted by NaS View Post
Consider this array content for some player:

0: 20
1: 21
2: 25
3: INVALID_PLAYER_ID (free)
4: 22

If you run the old loop with issuerid = 22 you would expect it to do nothing, as 22 is already in the array. However, what actually happens is that 22 is inserted a second time in index 3.

That is because of the second if() in the loop, it sees a free slot (INVALID_PLAYER_ID) in index 3 and stops the loop (break. This will prevent the loop from even reaching index 4.


What my loop changed is that it doesn't stop on a free slot.
When reaching index 3 it would store the free index in the "slot" variable. When it continues to index 4, it would find ID 22, reset the "slot" variable and stop the loop. As a result, ID 22 is not inserted a second time.

I hope that makes sense.
That makes sense now, thanks for your help!

I also read https://forum.sa-mp.com/showthread.php?t=596781
brauf is offline   Reply With Quote
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Little help assist kill :# ReD_HunTeR Scripting Help 4 21/02/2015 10:00 AM
Kill assist help Nabster Scripting Help 2 20/02/2015 07:18 AM
Help in kill assist Virus. Scripting Help 15 08/02/2013 03:21 PM
Can someone assist me with this? Dokins Scripting Help 13 14/01/2012 05:54 PM
Can someone assist me with this? Dokins Scripting Help 2 10/12/2011 06:01 PM


All times are GMT. The time now is 04:18 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.