if(playername == x) do this..
#1

How can I check if the player name is 'Noone', I tried this..

Код:
if(newstate == PLAYER_STATE_DRIVER)
	{
	    for(new i = 0; i < MAX_PVEHICLES; i++)
	    {
	        new string[24], Name[24];
	        format(string, sizeof(string), "%s", VehicleInfo[i][vOwner]);
	        if(VehicleInfo[i][vType] == 1)
			{
			    if(!strcmp(Name,string, true) == "Noone")
			    {
		    		SendClientMessage(playerid, -1, "| This vehicle is owned by x |");
				}
				else
				{
				    SendClientMessage(playerid, -1, "| This vehicle is for sale |");
				}
			}
	    }
	}
ERRORS
Код:
C:\Users\andrei\Desktop\Scripting SA-MP\Basic RP Script Scratch FIX\gamemodes\U1.pwn(1325) : error 033: array must be indexed (variable "-unknown-")
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
Reply
#2

Quote:

if(!strcmp(Name,string, true) == "Noone")

That's not how you check for the name.

you need to do this:

Quote:

if(!strcmp(VehicleInfo[i][vOwner],"Noone", true))

Also what line is 1325?
Reply
#3

It doesn't work... this is the code:

The whole code:
Код:
if(newstate == PLAYER_STATE_DRIVER)
	{
	    for(new i = 0; i < MAX_PVEHICLES; i++)
	    {
	        if(VehicleInfo[i][vType] == 2)
			{
		    	SendClientMessage(playerid, -1, "| This is a Spawn Vehicle | Respawn time: 200 seconds |");
			}
	    }
	}
	if(newstate == PLAYER_STATE_DRIVER)
	{
	    for(new i = 0; i < MAX_PVEHICLES; i++)
	    {
	        if(VehicleInfo[i][vType] == 1)
			{
			    if(!strcmp(VehicleInfo[i][vOwner],"Noone", true))
			    {
		    		SendClientMessage(playerid, -1, "| This vehicle is owned by x |");
				}
				else
				{
				    SendClientMessage(playerid, -1, "| This vehicle is for sale |");
				}
			}
	    }
	}
No matter what vehicle I enter, I get those messages:
This once:
Код:
SendClientMessage(playerid, -1, "| This is a Spawn Vehicle | Respawn time: 200 seconds |");
And this twice:
Код:
SendClientMessage(playerid, -1, "| This vehicle is owned by x |");
It looks like it doesn't get the vehicle type right and I am not sure why, this is how I load vehicles:
Код:
stock LoadVehicleStats()
{

    new DB_Query[1024];

    for(new i = 0; i < MAX_PVEHICLES; i++)
	{
	    mysql_format(Database, DB_Query, sizeof(DB_Query), "SELECT * FROM `Vehicles` WHERE `ID` = '%d'", i);
     	mysql_query(Database, DB_Query);
		
    	cache_get_value_int(0, "ID", VehicleInfo[i][ID]);

		cache_get_value(0, "Owner", VehicleInfo[i][vOwner]);
		cache_get_value_int(0, "vModel", VehicleInfo[i][vModel]);

		cache_get_value_float(0, "Pos_x", VehicleInfo[i][vPos_x]);
		cache_get_value_float(0, "Pos_y", VehicleInfo[i][vPos_y]);
		cache_get_value_float(0, "Pos_z", VehicleInfo[i][vPos_z]);
		cache_get_value_float(0, "Rot", VehicleInfo[i][vRot]);
		
		cache_get_value_int(0, "Fuel", VehicleInfo[i][vFuel]);
		cache_get_value_int(0, "Type", VehicleInfo[i][vType]);
		cache_get_value(0, "Plate", VehicleInfo[i][vPlate]);
		cache_get_value_int(0, "vLock", VehicleInfo[i][vLock]);

		cache_get_value_int(0, "Color1", VehicleInfo[i][vColor1]);
		cache_get_value_int(0, "Color2", VehicleInfo[i][vColor2]);
		cache_get_value_int(0, "RespawnDelay", VehicleInfo[i][vRespawnDelay]);
		cache_get_value_int(0, "Price", VehicleInfo[i][vPrice]);
		/*VehicleInfo[i][Vehicle_Cache] = cache_save();*/
	
		pvehicle[VehicleInfo[i][ID]] = CreateVehicle(VehicleInfo[i][vModel], VehicleInfo[i][vPos_x], VehicleInfo[i][vPos_y], VehicleInfo[i][vPos_z], VehicleInfo[i][vRot], VehicleInfo[i][vColor1], VehicleInfo[i][vColor2], VehicleInfo[i][vRespawnDelay]);
	}
	return 1;
}
The vehicle is spawning in the right place so the coords are loading fine but others
Reply
#4

read documentation before posting.

strcmp return number of difference between two strings, if that number is 0 that means strings are equal.

so just remove exclamation sign (!) before strcmp
Reply
#5

Alright so my code is this
PHP код:
if(VehicleInfo[vehicle][vType] == 1)
    {
        if(
newstate == PLAYER_STATE_DRIVER)
        {
            if(
strcmp(VehicleInfo[vehicle][vOwner],"Noone"true))
            {
                
SendClientMessage(playerid, -1"| This vehicle is owned by x |");
            }
            else
            {
                
SendClientMessage(playerid, -1"| This vehicle is for sale |");
            }
        }
    } 
No matter if the vehicle is owned or not, it tells me that the vehicle is for Sale so it doesn't detect the name..


EDIT#

I did a debug and noticed that the owner name is not loading
PHP код:
cache_get_value(0"Owner"VehicleInfo[i][vOwner]); 
Why isn't this loading?
Reply
#6

Quote:
Originally Posted by AndreiWow
Посмотреть сообщение
Alright so my code is this
PHP код:
if(VehicleInfo[vehicle][vType] == 1)
    {
        if(
newstate == PLAYER_STATE_DRIVER)
        {
            if(
strcmp(VehicleInfo[vehicle][vOwner],"Noone"true))
            {
                
SendClientMessage(playerid, -1"| This vehicle is owned by x |");
            }
            else
            {
                
SendClientMessage(playerid, -1"| This vehicle is for sale |");
            }
        }
    } 
No matter if the vehicle is owned or not, it tells me that the vehicle is for Sale so it doesn't detect the name..
Is the unowned vehicle has "Noone" value ? or is it null is it null then use isnull(your_string) to check the value is null or not
Reply
#7

Quote:
Originally Posted by Sreyas
Посмотреть сообщение
Is the unowned vehicle has "Noone" value ? or is it null is it null then use isnull(your_string)
I have a field in the table called Owner and vOwner in the enum, I did a debug and noticed that it is not loading, not sure why.
Here is how I load it:
PHP код:
cache_get_value(0"Owner"VehicleInfo[i][vOwner]); 
#EDIT

And again.. I'm so dumb that I forgot this

cache_get_value(0, "Owner", VehicleInfo[i][vOwner], 24);

FIXED EVERYTHING, THANKS GUYS, RAINING WITH REP
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)