Little question about y_iterate
#1

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.
Reply
#2

B U M P
Reply
#3

What are you trying to achieve?
Reply
#4

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, ...
Reply
#5

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

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

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.
Reply
#8

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;
}
Reply
#9

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.
Reply
#10

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;

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)