SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 09/12/2019, 04:42 PM   #1
ImTobi
Big Clucker
 
ImTobi's Avatar
 
Join Date: Jun 2017
Posts: 144
Reputation: 3
Default Help with vehicleid

Code:
for(new i=0; i<sizeof(KraftstoffCars); i++)
		{
			if(vID == KraftstoffCars[i][kID])
			{
				if(GetVehicleModel(GetVehicleTrailer(vID)) == 584)
				{
					tInfo[tID[playerid]][tFuelStand] = 100;
					SendClientMessage(playerid, COLOR_YELLOW, "You filled the gas pump.");
					GameTextForPlayer(playerid, "~g~PAYDAY +1500 $", 2000, 6);
					pInfo[playerid][payday] += 1500;
					return 1;
				}
				return SendClientMessage(playerid, COLOR_RED, "Your Truck doesn't have the right Trailer.");
			}
		    return SendClientMessage(playerid, COLOR_RED, "You are not sitting in an Job-Truck");
		}

My question is, how do i make it, so when i am not in an Job Tuck, i am getting a message, that i am not in a job truck? For me it just says it for every other truck, but the first one ist working
ImTobi is offline   Reply With Quote
Old 09/12/2019, 04:58 PM   #2
NaS
High-roller
 
NaS's Avatar
 
Join Date: Mar 2008
Location: 🇩🇪
Posts: 1,774
Reputation: 619
Default Re: Help with vehicleid

Instead of putting the second message (and return) into the loop, you must move it outside of the loop, otherwise it will execute at the first iteration where the player is not in the correct truck (when you have for example 10 trucks, this might be the case for the first 9 iterations - this is why only the first truck works).

So only if the loop has finished completely and no truck was the one the player is driving, it should send the message saying the player isn't in any job truck.
NaS is offline   Reply With Quote
Old 09/12/2019, 05:03 PM   #3
ImTobi
Big Clucker
 
ImTobi's Avatar
 
Join Date: Jun 2017
Posts: 144
Reputation: 3
Default Re: Help with vehicleid

Quote:
Originally Posted by NaS View Post
Instead of putting the second message (and return) into the loop, you must move it outside of the loop, otherwise it will execute at the first iteration where the player is not in the correct truck (when you have for example 10 trucks, this might be the case for the first 9 iterations - this is why only the first truck works).

So only if the loop has finished completely and no truck was the one the player is driving, it should send the message saying the player isn't in any job truck.
can you give me an example?
ImTobi is offline   Reply With Quote
Old 09/12/2019, 05:13 PM   #4
NaS
High-roller
 
NaS's Avatar
 
Join Date: Mar 2008
Location: 🇩🇪
Posts: 1,774
Reputation: 619
Default Re: Help with vehicleid

Code:
for(new i=0; i<sizeof(KraftstoffCars); i++)
{
	if(vID == KraftstoffCars[i][kID])
	{
		if(GetVehicleModel(GetVehicleTrailer(vID)) == 584)
		{
			tInfo[tID[playerid]][tFuelStand] = 100;
			SendClientMessage(playerid, COLOR_YELLOW, "You filled the gas pump.");
			GameTextForPlayer(playerid, "~g~PAYDAY +1500 $", 2000, 6);
			pInfo[playerid][payday] += 1500;
			return 1;
		}
		return SendClientMessage(playerid, COLOR_RED, "Your Truck doesn't have the right Trailer.");
	}
}
return SendClientMessage(playerid, COLOR_RED, "You are not sitting in an Job-Truck");
Now the message will only be sent if none of the trucks are driven by the player, since you use return in any other case.
NaS is offline   Reply With Quote
Old 09/12/2019, 05:21 PM   #5
ImTobi
Big Clucker
 
ImTobi's Avatar
 
Join Date: Jun 2017
Posts: 144
Reputation: 3
Default Re: Help with vehicleid

Quote:
Originally Posted by NaS View Post
Code:
for(new i=0; i<sizeof(KraftstoffCars); i++)
{
	if(vID == KraftstoffCars[i][kID])
	{
		if(GetVehicleModel(GetVehicleTrailer(vID)) == 584)
		{
			tInfo[tID[playerid]][tFuelStand] = 100;
			SendClientMessage(playerid, COLOR_YELLOW, "You filled the gas pump.");
			GameTextForPlayer(playerid, "~g~PAYDAY +1500 $", 2000, 6);
			pInfo[playerid][payday] += 1500;
			return 1;
		}
		return SendClientMessage(playerid, COLOR_RED, "Your Truck doesn't have the right Trailer.");
	}
}
return SendClientMessage(playerid, COLOR_RED, "You are not sitting in an Job-Truck");
Now the message will only be sent if none of the trucks are driven by the player, since you use return in any other case.

Code:
if(tInfo[tID[playerid]][tFuelStand] < 100)
	{
		for(new i=0; i<sizeof(KraftstoffCars); i++)
		{
			if(vID == KraftstoffCars[i][kID])
			{
				if(GetVehicleModel(GetVehicleTrailer(vID)) == 584)
				{
					tInfo[tID[playerid]][tFuelStand] = 100;
					SendClientMessage(playerid, COLOR_YELLOW, "Du hast die Zapfsäule erfolgreich gefüllt.");
					GameTextForPlayer(playerid, "~g~PAYDAY +1500 $", 2000, 6);
					pInfo[playerid][payday] += 1500;
					return 1;
				}
				return SendClientMessage(playerid, COLOR_RED, "Dein LKW hat keinen oder nicht den richtigen Auflieger.");
			}
		}
		return SendClientMessage(playerid, COLOR_RED, "Du sitzt nicht in einem Job-LKW.");
	}
	return SendClientMessage(playerid, COLOR_RED, "Die Zapfsäule ist voll.");

so like that it should work everything?
ImTobi is offline   Reply With Quote
Old 09/12/2019, 06:01 PM   #6
ImTobi
Big Clucker
 
ImTobi's Avatar
 
Join Date: Jun 2017
Posts: 144
Reputation: 3
Default Re: Help with vehicleid

K its working, thank you, i now understand it why it is outside of the loop! Rep
ImTobi is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Vehicleid bug MRM Scripting Help 3 25/06/2017 12:21 PM
/v ([vehicleid]) kalanerik99 Scripting Help 6 22/01/2015 03:16 PM
Workaround vehicleid not matching MySQL vehicleid DrDoom151 Scripting Help 2 18/05/2013 11:49 PM
Vehicleid? Darekfred Help Archive 2 04/01/2010 01:00 AM
VehicleID Grex Help Archive 4 16/09/2009 06:06 PM


All times are GMT. The time now is 04:55 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.