SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 05/08/2017, 07:11 PM   #5641
TommyB
Big Clucker
 
TommyB's Avatar
 
Join Date: Sep 2010
Location: Texas, USA.
Posts: 102
Reputation: 72
Default Re: Streamer Plugin

Quote:
Originally Posted by Salik View Post
Dear Incognito, could you simplify the function 'Streamer_GetNearbyItems', I almost did not understand how it works, how to determine the number of Objects in a given position, could make it something to return a count of objects or to show an example.

https://github.com/samp-incognito/sa...GetNearbyItems
That has all the info you need. If you wish to grab the number of objects in that position after using the native, you can use 'strlen(yourarray)'.
__________________
TommyB is offline   Reply With Quote
Old 05/08/2017, 07:47 PM   #5642
Salik
Big Clucker
 
Salik's Avatar
 
Join Date: Aug 2015
Location: Russia
Posts: 66
Reputation: 0
Default Re: Streamer Plugin

Quote:
Originally Posted by TommyB View Post
https://github.com/samp-incognito/sa...GetNearbyItems
That has all the info you need. If you wish to grab the number of objects in that position after using the native, you can use 'strlen(yourarray)'.

Do you think I did not watch the wiki? If you can help me make this function, it will stupidly return 0 or 1 ...
Not just a return, to the array ...
Salik is offline   Reply With Quote
Old 06/08/2017, 01:42 PM   #5643
BeckzyBoi
High-roller
 
Join Date: Dec 2006
Posts: 1,593
Reputation: 76
Default Re: Streamer Plugin

22 commits since 2.9.1. When is 2.9.2 coming? I'm getting sick of the checkpoint bug where they don't show until you re-enter the area. I know that one of the commits fixes this. I'd have thought you'd released 2.9.2 by now so people can download it, use it, and not experience that horrific bug.
__________________
BeckzyBoi is offline   Reply With Quote
Old 07/08/2017, 01:24 PM   #5644
MrHarry
Little Clucker
 
Join Date: Jul 2013
Posts: 1
Reputation: 0
Default Re: Streamer Plugin

Quote:
Originally Posted by TommyB View Post
https://github.com/samp-incognito/sa...GetNearbyItems
That has all the info you need. If you wish to grab the number of objects in that position after using the native, you can use 'strlen(yourarray)'.
Woah, thanks!
MrHarry is offline   Reply With Quote
Old 07/08/2017, 01:28 PM   #5645
donsta3000
Little Clucker
 
Join Date: Aug 2012
Posts: 37
Reputation: 15
Default Re: Streamer Plugin

Very good plugin
__________________
Small County Roleplay

Feel free to ask me any questions however, I can't guarantee I'll answer!
donsta3000 is offline   Reply With Quote
Old 07/08/2017, 03:31 PM   #5646
IstuntmanI
High-roller
 
IstuntmanI's Avatar
 
Join Date: Mar 2009
Location: Romania
Posts: 1,875
Reputation: 354
Default Re: Streamer Plugin

Quote:
Originally Posted by TommyB View Post
https://github.com/samp-incognito/sa...GetNearbyItems
That has all the info you need. If you wish to grab the number of objects in that position after using the native, you can use 'strlen(yourarray)'.
strlen is recommended only for char arrays. I guess you could use it in that case too, but it isn't recommended.
That wiki page says that it returns 0 or 1. It actually returns the size of final items: https://github.com/samp-incognito/sa...eous.cpp#L1682 . I don't think it is limited by the "maxitems" parameter, so he could actually use
Code:
new items = Streamer_GetNearbyItems( ... );
Quote:
Originally Posted by BeckzyBoi View Post
22 commits since 2.9.1. When is 2.9.2 coming? I'm getting sick of the checkpoint bug where they don't show until you re-enter the area. I know that one of the commits fixes this. I'd have thought you'd released 2.9.2 by now so people can download it, use it, and not experience that horrific bug.
As you may know, Streamer Plugin has a crash bug probably since chunks were added:
https://github.com/samp-incognito/sa...gin/issues/205. I remember that Incognito said in one of those issues that he will release the next version when he will be sure that crash was fixed. He can't find the source of server crash. It acts weird. He made few commits to try to fix it, but with no result.
__________________


IstuntmanI is online now   Reply With Quote
Old 07/08/2017, 06:11 PM   #5647
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,690
Reputation: 1242
Default Re: Streamer Plugin

@Salik, @TommyB, @IstuntmanI - do not use strlen for non-strings under any circumstances! If you pass a brand new array, strlen will return 0 and I don't think it would do any harm, the maxlen param ends its life in this function: https://sourcegraph.com/github.com/s...oArray#L92-108 but it certainly wouldn't do anything useful at all.

Use sizeof, it's even the default. You can also limit the amount of work done by using some value lower than sizeof if for example you only want the closest 3 items.
__________________
Masterlist Alternative - Add your server today!

Contact me:
My discord: dc.southcla.ws

I have limited internet right now so expect periodic inactivity!
[HLF]Southclaw is offline   Reply With Quote
Old 07/08/2017, 07:34 PM   #5648
IstuntmanI
High-roller
 
IstuntmanI's Avatar
 
Join Date: Mar 2009
Location: Romania
Posts: 1,875
Reputation: 354
Default Re: Streamer Plugin

Quote:
Originally Posted by [HLF]Southclaw View Post
@Salik, @TommyB, @IstuntmanI - do not use strlen for non-strings under any circumstances! If you pass a brand new array, strlen will return 0 and I don't think it would do any harm, the maxlen param ends its life in this function: https://sourcegraph.com/github.com/s...oArray#L92-108 but it certainly wouldn't do anything useful at all.

Use sizeof, it's even the default. You can also limit the amount of work done by using some value lower than sizeof if for example you only want the closest 3 items.
Well, I told him that it isn't recommended. I wrote something about sizeof too, but I deleted it afterwards, because that's not what he wants. sizeof only gets an array dimension size at compile time, but he wanted the number of IDs that will be filled in at run time (or maybe even more than that, if the array isn't big enough, maybe he wants the total nearby IDs without any array limit, which is what that function actually returns).

The downside of using strlen: it can report a wrong size if the whole array is filled up with IDs different than 0, so it won't find the internal 0 correctly. It may check too much causing some kind of buffer overflow.
__________________


IstuntmanI is online now   Reply With Quote
Old 07/08/2017, 07:43 PM   #5649
TommyB
Big Clucker
 
TommyB's Avatar
 
Join Date: Sep 2010
Location: Texas, USA.
Posts: 102
Reputation: 72
Default Re: Streamer Plugin

Quote:
Originally Posted by [HLF]Southclaw View Post
@Salik, @TommyB, @IstuntmanI - do not use strlen for non-strings under any circumstances! If you pass a brand new array, strlen will return 0 and I don't think it would do any harm, the maxlen param ends its life in this function: https://sourcegraph.com/github.com/s...oArray#L92-108 but it certainly wouldn't do anything useful at all.

Use sizeof, it's even the default. You can also limit the amount of work done by using some value lower than sizeof if for example you only want the closest 3 items.
That's strange because the following code works flawlessly for me.

PHP Code:
new DynamicPickup:pickups[300], Float:xFloat:yFloat:zidpickuparray[2];
GetPlayerPos(playeridxyz);
Streamer_GetNearbyItems(xyzSTREAMER_TYPE_PICKUPpickups300dist);
for(new 
0strlen(_:pickups); p++)
{
    
Streamer_GetArrayData(STREAMER_TYPE_PICKUPpickups[p], E_STREAMER_EXTRA_IDpickuparray);

    
//...

In fact, running that code in an area that only has two pickups gives me these results with strlen and sizeof.

Code:
[14:28:02] strlen: 2 sizeof: 300
The loop works exactly as intended and only iterates twice where I tested it. Using sizeof would in my case would would cause 300 iterations, 298 of them being absolutely useless.
__________________
TommyB is offline   Reply With Quote
Old 07/08/2017, 08:46 PM   #5650
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,690
Reputation: 1242
Default Re: Streamer Plugin

Just because something works doesn't mean it's a good thing to do!

The strlen use in your loop isn't good practice at all, the only reason it stops at the right value is because strings end with a zero cell but there's no guarantee that output array would be filled with zeroes after the given length (this is usually referred to as "undefined behaviour" - relying on this isn't ever a good idea as an implementation change in the plugin code could render your check code useless).

As mentioned before, the correct result size is actually returned as a value from the function, so the best way to handle this would be:

Code:
new DynamicPickup:pickups[300], Float:x, Float:y, Float:z, id, pickuparray[2], resultLength;
GetPlayerPos(playerid, x, y, z); 
resultLength = Streamer_GetNearbyItems(x, y, z, STREAMER_TYPE_PICKUP, pickups, sizeof(pickups), dist); 
for(new p = 0; p < length; p++) 
{ 
    Streamer_GetArrayData(STREAMER_TYPE_PICKUP, pickups[p], E_STREAMER_EXTRA_ID, pickuparray); 

    //... 
}
__________________
Masterlist Alternative - Add your server today!

Contact me:
My discord: dc.southcla.ws

I have limited internet right now so expect periodic inactivity!
[HLF]Southclaw 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
[Include] Checkpoint / Area sub-streamer for incognito's streamer plugin Pottus Includes 11 21/03/2014 06:31 PM
Need 3dtextlabel Streamer And Gangzone Streamer !! Please Help . Not streamer plugin . jame42 Scripting Help 4 30/05/2012 07:33 AM
Streamer plugin 0.3d rt-2 Plugin Development 7 05/12/2011 06:17 PM
Streamer Plugin Help! ColdXX Everything and Nothing 2 21/08/2010 10:28 PM
Streamer Plugin! ColdXX Help Archive 10 18/07/2010 12:47 PM


All times are GMT. The time now is 11:45 PM.


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