SA-MP Forums Archive
Little question about y_iterate - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Little question about y_iterate (/showthread.php?tid=624025)



Little question about y_iterate - knuckleduster5 - 09.12.2016

Well..

I'm using y_iterate.inc for dynamic systems but I have a problem with id value.

You know y_iterate integer value starting with "0" value.

I want to start this with "1" value.

How can I do this? Thanks for help.


Re: Little question about y_iterate - knuckleduster5 - 09.12.2016

B U M P


Re: Little question about y_iterate - SickAttack - 09.12.2016

What are you trying to achieve?


Re: Little question about y_iterate - knuckleduster5 - 09.12.2016

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
What are you trying to achieve?
For example:
/createcar
Car is created. ID: 1 (not starting with 0)

System does: 0, 1, 2, 3, ....
I want: 1, 2, 3, 4, ...


Re: Little question about y_iterate - SickAttack - 09.12.2016

I still don't know what you want to achieve with that.


Re: Little question about y_iterate - knuckleduster5 - 09.12.2016

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
I still don't know what you want to achieve with that.
Because I want to use vehicleid directly.


Re: Little question about y_iterate - Konstantinos - 09.12.2016

You need to provide more information or a sample of code of what you're trying to do. I'm saying this because there are "Vehicle" and "LocalVehicle" iterators already in y_iterate. Even if you still want to make your own iterator for something else, then use Iter_Add with 2nd parameter the vehicleid. The only way you'd get 0 added would be Iter_Free which we don't know whether you used or not.


Re: Little question about y_iterate - knuckleduster5 - 09.12.2016

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
You need to provide more information or a sample of code of what you're trying to do. I'm saying this because there are "Vehicle" and "LocalVehicle" iterators already in y_iterate. Even if you still want to make your own iterator for something else, then use Iter_Add with 2nd parameter the vehicleid. The only way you'd get 0 added would be Iter_Free which we don't know whether you used or not.
Sorry, it's my bad.

Here is an example code:

Код:
#include <a_samp>
#include <YSI/y_iterate>
#include <izcmd>
#include <sscanf2>

#define MAX_VEH 1000

enum DynamicVehicle
{
	v_id,
	v_lock,
	v_engine,
	v_cost
};
new VehicleInfo[MAX_VEH][DynamicVehicle],
	Iterator: Vehicles<MAX_VEH>;
	

CMD:createvehicle(playerid, params[])
{
	new id = Iter_Free(Vehicles); /*My problem is there. Iterator starting with "0". I want to start this with "1".*/
	if(id == -1) return SendClientMessage(playerid, -1, "You can't creating more.");

	new lock, engine, cost;

	if(sscanf(params, "iii", lock, engine, cost))
	    return SendClientMessage(playerid, -1, "SYNTAX: /createvehicle [lock] [engine] [cost]");

	VehicleInfo[id][v_id] = id;
	VehicleInfo[id][v_lock] = lock;
	VehicleInfo[id][v_engine] = engine;
	VehicleInfo[id][v_cost] = cost;

	Iter_Add(Vehicles, id);
	return true;
}



Re: Little question about y_iterate - Konstantinos - 09.12.2016

You don't need any of this, just use "LocalVehicle" iterator to loop through the vehicles created for that script only. Functions are hooked so the vehicle ID is inserted by the include.


Re: Little question about y_iterate - AlexBlack - 09.12.2016

Or just block the ID 0 by creating it and removing it after create the vehicle.
For example:

PHP код:
CMD:createvehicle(playeridparams[])
{
    
Iter_Add(Vehicles0);
    new 
id Iter_Free(Vehicles); /*My problem is there. Iterator starting with "0". I want to start this with "1".*/
    
Iter_Remove(Vehicles0);
    if(
id == -1) return SendClientMessage(playerid, -1"You can't creating more.");
    new 
lockenginecost;
    if(
sscanf(params"iii"lockenginecost))
        return 
SendClientMessage(playerid, -1"SYNTAX: /createvehicle [lock] [engine] [cost]");
    
VehicleInfo[id][v_id] = id;
    
VehicleInfo[id][v_lock] = lock;
    
VehicleInfo[id][v_engine] = engine;
    
VehicleInfo[id][v_cost] = cost;
    
Iter_Add(Vehiclesid);
    return 
true;