Array must be indexed.
#1

Hey guys, today i was trying to make "Car wanted" system.. but i stuck.



pawn Код:
Error : proba.pwn(53) : error 033: array must be indexed (variable "wantedmodel")
pawn Код:
#include <a_samp>
#include <zcmd>
#include <streamer>

#define COLOR_YELLOW 0xFFFF00AA
#define COLOR_LIME 0x10F441AA
#define COLOR_RED 0xFF0000AA
#define COLOR_BLUE 0x0000BBAA
#define COLOR_WHITE 0xFFFFFFAA

#define MAX_CP 100
new CP[MAX_CP];
new randompick;//should it be global ?
new wantedmodel[3];//is this right ?
forward Time();
forward VehPick();
new wantedcars[][][]=
{
    {405, 10000, "Car"},
    {522,  5000, "Bike"}
    //model, price, name..
};
public VehPick()
{
        new msg[128];
    randompick = random(sizeof(wantedcars)); // should it remain new randompick = ...  ?
    //How can i let script know what model (wantedcars[randompick][0]) is picked ?
    format(wantedmodel,sizeof(wantedmodel),"%d",wantedcars[randompick][0]);//i have no idea where im going with this.. :D
    format(msg,sizeof(msg),"[WANTED CAR]: bla bla %s bla bla $%d!",wantedcars[randompick][2],wantedcars[randompick][1]); //we look for,we pay for..
    SendClientMessageToAll(COLOR_WHITE,msg);
    SetTimer("Time",15000,false);
}
public Time()
{
    VehPick();
}
public OnGameModeInit()
{
    AddPlayerClass(2,2261.3000000,-83.4000000,26.1000000,100.0000000,0,0,0,0,0,0);
    VehPick();
    AddStaticVehicleEx(410,405.2999900,2535.1001000,16.3000000,0.0000000,94,112,15); //Manana
    AddStaticVehicleEx(405,2276.5000000,-84.5000000,26.4000000,76.0000000,32,32,15); //Sentinel
    AddStaticVehicleEx(522,2261.3000000,-83.4000000,26.1000000,100.0000000,109,122,15); //NRG-500
    CP[0] = CreateDynamicCP(2263.6418,-131.5671,27.4688,10.0,-1,-1,-1,50.0); // Final destination :D
    return 1;
}
public OnPlayerEnterDynamicCP(playerid, checkpointid)
{
    if(checkpointid == CP[0])
    {
        new Veh = GetPlayerVehicleID(playerid);
        new VehModel = GetVehicleModel(Veh);
        if(VehModel == wantedmodel) >>>> [Error line]
        {
            //give player money ..
        }
    }
    return 1;
}
Reply
#2

Since you decleared wantedmodel as wantedmodel[3] it must be indexed like:

Код:
public OnPlayerEnterDynamicCP(playerid, checkpointid)
{
	if(checkpointid == CP[0])
	{
        new Veh = GetPlayerVehicleID(playerid); 
        new VehModel = GetVehicleModel(Veh);
		if(VehModel == wantedmodel[0])
		{
		    //give player money ..
		}
	}
	return 1;
}
You tryna make like a bonus vehicle system?
Reply
#3

Quote:
Originally Posted by ISmokezU
Посмотреть сообщение
Since you decleared wantedmodel as wantedmodel[3] it must be indexed like:

Код:
public OnPlayerEnterDynamicCP(playerid, checkpointid)
{
	if(checkpointid == CP[0])
	{
        new Veh = GetPlayerVehicleID(playerid); 
        new VehModel = GetVehicleModel(Veh);
		if(VehModel == wantedmodel[0])
		{
		    //give player money ..
		}
	}
	return 1;
}
You tryna make like a bonus vehicle system?
Hey,thank you ! There is no errors now but still not working.
Im trying to make car wanted sistem , server needs to pick random car on gamemode start,servers shows msg to all players with wanted car name. If player get in checkpoint with wanted car,he will get money and sell it.After that we call again random pick,msg,and thats it.
But i have problem , when i enter in checkpoint with wanted car,nothing happens, look :
pawn Код:
#define MAX_CP 100
new CP[MAX_CP];
new randompick;//should it be global ?
new wantedmodel[3];//is this right ?
forward Time();
forward VehPick();
new wantedcars[][][]=
{
    {405, 10000, "Car"},
    {522,  5000, "Bike"}
    //model, price, name..
};
public VehPick()
{
        new msg[128];
    randompick = random(sizeof(wantedcars)); // should it remain new randompick = ...  ?
    //How can i let script know what model (wantedcars[randompick][0]) is picked ?
    format(wantedmodel,sizeof(wantedmodel),"%d",wantedcars[randompick][0]);//i have no idea where im going with this.. :D
    format(msg,sizeof(msg),"[WANTED CAR]: bla bla %s bla bla $%d!",wantedcars[randompick][2],wantedcars[randompick][1]); //we look for,we pay for..
    SendClientMessageToAll(COLOR_WHITE,msg);
    SetTimer("Time",15000,false);
}
public Time()
{
    VehPick();
}
public OnGameModeInit()
{
    AddPlayerClass(2,2261.3000000,-83.4000000,26.1000000,100.0000000,0,0,0,0,0,0);
        VehPick();
    AddStaticVehicleEx(410,405.2999900,2535.1001000,16.3000000,0.0000000,94,112,15); //Manana
    AddStaticVehicleEx(405,2276.5000000,-84.5000000,26.4000000,76.0000000,32,32,15); //Sentinel
    AddStaticVehicleEx(522,2261.3000000,-83.4000000,26.1000000,100.0000000,109,122,15); //NRG-500
    CP[0] = CreateDynamicCP(2263.6418,-131.5671,27.4688,10.0,-1,-1,-1,50.0); // Final destination :D
    return 1;
}
public OnPlayerEnterDynamicCP(playerid, checkpointid)
{
    if(checkpointid == CP[0])
    {
        new Veh = GetPlayerVehicleID(playerid);
        //new VehModel = GetVehicleModel(Veh);
        if(Veh == wantedmodel[0])
        {
            GivePlayerMoney(playerid,10);
            SendClientMessage(playerid,-1,".");
        }
    }
    return 1;
}
Please let me know,is it right way to let script know what car id is wanted by using format ? I didn't know how should i make it,so i read some tutorials on forum with similar things like this.new wantedmodel[3] (i wrote 3 because veh id is always 3 digits number[Example , Infernus id 411),and i guess this dont have sense ?! Should i change it. Thank you very much !
Reply
#4

A variable holds an integer whatever digits it is that means you have to assign just new wantedmodel . Yes, you can make an array according to your needs.
And the " format " wantedmodel shouldn't be an string it is an integer so wantedmodel = wantedcars[Randompick][0];
Reply
#5

Quote:
Originally Posted by coool
Посмотреть сообщение
A variable holds an integer whatever digits it is that means you have to assign just new wantedmodel . Yes, you can make an array according to your needs.
And the " format " wantedmodel shouldn't be an string it is an integer so wantedmodel = wantedcars[Randompick][0];
Can u write me how should it look ?
I'm confused.
pawn Код:
format(wantedmodel,sizeof(wantedmodel),"%d",wantedcars[randompick][0]);
%d or %i stands for integer, whole number,right ?
so i changed : on the top ,
pawn Код:
new wantedmodel[3];
to
pawn Код:
new wantedmodel;
Now there is two errors on "format" line :
error 035: argument type mismatch (argument 1)
error 035: argument type mismatch (argument 1)
yeah,two same errors,same line.
Reply
#6

delete format line and put wantedmodel = wantedcars[Randompick][0];
Reply
#7

Quote:
Originally Posted by coool
Посмотреть сообщение
delete format line and put wantedmodel = wantedcars[Randompick][0];
Cool, one error :
pawn Код:
error 006: must be assigned to an array
Line:
wantedmodel = wantedcars[randompick][0];
Reply
#8

try this:
Quote:

new wantedcars[][]

Just two " [] "s

Or return to your old code everything same the format and the wantedmodel[3]
just change
PHP код:
if(Veh == wantedmodel
to
PHP код:
if(Veh == strval(wantedmode)) 
Reply
#9

Quote:
Originally Posted by coool
Посмотреть сообщение
try this:
Just two " [] "s

Or return to your old code everything same the format and the wantedmodel[3]
just change
PHP код:
if(Veh == wantedmodel
to
PHP код:
if(Veh == strval(wantedmode)) 
Both ways don't work , and both ways show no error in pawn. I enter in CP with wanted car and nothing happens.
Reply
#10

Код HTML:
new wantedcars[][][]=
{
	{405, 10000, "Car"},
	{522,  5000, "Bike"}
};
to

Код HTML:
new wantedcars[][]=
{
	{405, 10000, "Car"},
	{522,  5000, "Bike"}
};
Reply
#11

Quote:
Originally Posted by Feynman
Посмотреть сообщение
Код HTML:
new wantedcars[][][]=
{
	{405, 10000, "Car"},
	{522,  5000, "Bike"}
};
to

Код HTML:
new wantedcars[][]=
{
	{405, 10000, "Car"},
	{522,  5000, "Bike"}
};
Still nothing happens ! :<
Reply
#12

Anyone ?
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)