SA-MP Forums Archive
Client crush on Connect (Compiles without any error) - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Client crush on Connect (Compiles without any error) (/showthread.php?tid=86238)



Client crush on Connect (Compiles without any error) - Paranoja - 12.07.2009

Since i created a loop for my cars to make an unique id, when i connect to server my client crushes, there is the code:
the code which sets values for arrays:
Код:
	new ucarsquery[128];
	new usercar[11][128];
	new cars;
	format(ucarsquery, sizeof(ucarsquery), "SELECT owner,modelid,spawn_x,spawn_y,spawn_z,angle,color1,color2,tune,locked FROM `ucars`");
	samp_mysql_query(ucarsquery);
	samp_mysql_store_result();
	while(samp_mysql_fetch_row(ucarsquery)) {
		split(ucarsquery, usercar, '|');
		playercar[cars][car_owner] = strval(usercar[0]);
		playercar[cars][car_modelid] = strval(usercar[1]);
		playercar[cars][car_spawnX] = floatstr(usercar[2]);
		playercar[cars][car_spawnY] = floatstr(usercar[3]);
		playercar[cars][car_spawnZ] = floatstr(usercar[4]);
		playercar[cars][car_spawnA] = floatstr(usercar[5]);
		playercar[cars][car_color1] = strval(usercar[6]);
		playercar[cars][car_color2] = strval(usercar[7]);
		playercar[cars][car_tune] = strval(usercar[8]);
		playercar[cars][car_locked] = strval(usercar[9]);
		playercar[cars][car_id] = CreateVehicle(playercar[1][car_modelid],playercar[1][car_spawnX],playercar[1][car_spawnY],playercar[1][car_spawnZ],playercar[1][car_spawnA],playercar[1][car_color1],playercar[1][car_color2],-1);
		cars++;
	}
The code which uses them to check (OnPlayerConnect):
Код:
		for (new cars=0;cars<1000; cars++) {
			if (!strcmp(playercar[cars][car_owner], playerinfo[playerid][nickname])) {
				for (players=0;players<MAX_PLAYERS; players++) {
					SetVehicleParamsForPlayer(playercar[cars][car_id],players,0,1);
				}
			} else {
				SetVehicleParamsForPlayer(playercar[cars][car_id],playerid,1,0);
			}
		}
Where is the problem that causes my client to crush?

EDIT: Problem is in the first part of the script, because when i delete it, everything goes fine.
I think the problem is because of cars++; on the bottom of the while function, can't you do that in pawno like in php? so that each while cars value would increase by 1...? If so, how can i do that ?


Re: Client crush on Connect (Compiles without any error) - NeRoSiS - 12.07.2009

Try
Код:
cars += 1;



Re: Client crush on Connect (Compiles without any error) - Paranoja - 12.07.2009

Didin't solved the problem, i guess it somewhere else.
EDIT: Found the problem: createVehicle had playercar[1] instead of playercar[cars], everything is fine on creating cars, but now i have different thing, the car doesn't lock:
Код:
		for (new cars=0;cars<5; cars++) {
			if (!strcmp(playercar[cars][car_owner], playerinfo[playerid][nickname])) {
				SetVehicleParamsForPlayer(playercar[cars][car_id],playerid,0,1);
			} else {
				SetVehicleParamsForPlayer(playercar[cars][car_id],playerid,1,0);
			}
		}
Where is the problem? It should show an arrow above the car if the playername matches, but if it doesn't than it should lock that car for that player, but it doesn't do either one or other.
Tryied to add print(playercar[cars][car_owner]); in for loop, and it returned : <null> arrays, even know there should be a strings with names.
EDIT:
Код:
		print(usercar[0]);
		playercar[cars][car_owner] = strval(usercar[0]);
		print(playercar[cars][car_owner]);
Returns MyName and than after assigning <null> why?


Re: Client crush on Connect (Compiles without any error) - ledzep - 12.07.2009

pawn Код:
if(playercar[cars][car_locked]){
  vehicleLock(playercar[cars][car_id]);
}
pawn Код:
stock vehicleLock(vehicleid, lock=1)
{
    playercar[vehicleid][car_locked] = lock;
    for(new playerid; playerid < MAX_PLAYERS; playerid++)
    {
      SetVehicleParamsForPlayer(vehicleid, playerid, 0, lock);
    }
    return 1;
}
That's how I would go about it.


Re: Client crush on Connect (Compiles without any error) - Paranoja - 13.07.2009

There is a thing.. I don't want to lock the car for every single player in the server.. I want to do different thing for the owner, i want to use as it is, it's just there some kind of mistake i done.. the code should work, it's just my understanding about enum is wrong... I need some help about it. I want to keep the code as i done, because in my understanding everything is right, it's just the array problems and i don't know how to sort them out...


Re: Client crush on Connect (Compiles without any error) - ledzep - 13.07.2009

With your strcmp, you are basically saying "if the car's owner is the same as player's nickname, lock the car"
"otherwise, unlock the car, and set objective to 1 for player"

See: https://sampwiki.blast.hk/wiki/SetVehicleParamsForPlayer

You should also take a look at: https://sampwiki.blast.hk/wiki/Strcmp


Re: Client crush on Connect (Compiles without any error) - Paranoja - 13.07.2009

SOLVED all the problems with:
Код:
format(playercar[cars][car_owner],256,"%s",usercar[0]);
Thank you everyone for trying to help me