SA-MP Forums

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

 
 
Thread Tools Display Modes
Old 17/01/2011, 06:25 PM   #1
shadowdog
Gangsta
 
shadowdog's Avatar
 
Join Date: Feb 2010
Location: The Netherlands, Limburg
Posts: 554
Reputation: 682
Default multiple ifs

How do i make the script check multiple ifs in one checkpoint, it has supposed to be like this:
-must check if theyre driving a roadtrain(515), linerunner(403) or a tanker(514)
-and check if theres a trailer attached
here's the code i used:
Code:
public OnPlayerEnterCheckpoint(playerid)
{
    if(IsPlayerInVehicle(playerid, 514))//how do i make multiple car ids to check...
    if(IsPlayerInVehicle(playerid, 515))//
    if(IsPlayerInVehicle(playerid, 403))//
    if(IsTrailerAttachedToVehicle(playerid))//... and check if there's a trailer attached...
	{                                   //...all at the same time?
		SendClientMessage(playerid, 0x33AA33AA, "Thank you! Here's $1.700!");
		GivePlayerMoney(playerid, 1700);
		DisablePlayerCheckpoint(playerid);
		}else{
		SendClientMessage(playerid, 0xAA3333AA, "Hey! Where's your truck?");
		return 1;
	}

    return 1;
}


please help me
__________________
shadowdog is offline  
Old 17/01/2011, 06:28 PM   #2
Not available
Big Clucker
 
Join Date: Jan 2011
Posts: 94
Reputation: 0
Default Re: multiple ifs

If you are checking this several places, it could be smart making an array. For now this should work just fine:
Code:
public OnPlayerEnterCheckpoint(playerid)
{
    if(IsPlayerInVehicle(playerid, 514) || IsPlayerInVehicle(playerid, 515) || IsPlayerInVehicle(playerid, 403) && IsTrailerAttachedToVehicle(GetPlayerVehicleID(playerid))
    {
        SendClientMessage(playerid, 0x33AA33AA, "Thank you! Here's $1.700!");
        GivePlayerMoney(playerid, 1700);
        DisablePlayerCheckpoint(playerid);
        return 1;
    }
    else SendClientMessage(playerid, 0xAA3333AA, "Hey! Where's your truck?");
    return 1;
}
__________________


http://peak-host.net Your #1 Multi-player Game hosting provider.
Not available is offline  
Old 17/01/2011, 06:29 PM   #3
WillyP
High-roller
 
WillyP's Avatar
 
Join Date: Jul 2010
Location: England
Posts: 2,216
Reputation: 63
Default Re: multiple ifs

What is IFS?
__________________
once average now terrible
WillyP is offline  
Old 17/01/2011, 06:30 PM   #4
jamesbond007
Gangsta
 
jamesbond007's Avatar
 
Join Date: Oct 2009
Location: Canadia
Posts: 857
Reputation: 50
Default Re: multiple ifs

Code:
public OnPlayerEnterCheckpoint(playerid)
{
	if(IsPlayerInVehicle(playerid, 514))
	{
		if(IsTrailerAttachedToVehicle(playerid))
		{
		SendClientMessage(playerid, 0x33AA33AA, "Thank you! Here's $1.700!");
		GivePlayerMoney(playerid, 1700);
		DisablePlayerCheckpoint(playerid);
		}
		else return SendClientMessage(playerid, 0xAA3333AA, "Hey! Where's your truck?");
	}
	else if(IsPlayerInVehicle(playerid, 515))
	{
		if(IsTrailerAttachedToVehicle(playerid))
		{
		SendClientMessage(playerid, 0x33AA33AA, "Thank you! Here's $1.700!");
		GivePlayerMoney(playerid, 1700);
		DisablePlayerCheckpoint(playerid);
		}
                  else return SendClientMessage(playerid, 0xAA3333AA, "Hey! Where's your truck?");
	}
	else if(IsPlayerInVehicle(playerid, 403))
	{
		if(IsTrailerAttachedToVehicle(playerid))
		{
		SendClientMessage(playerid, 0x33AA33AA, "Thank you! Here's $1.700!");
		GivePlayerMoney(playerid, 1700);
		DisablePlayerCheckpoint(playerid);
		}
		else return SendClientMessage(playerid, 0xAA3333AA, "Hey! Where's your truck?");
	}
	return 1;
}
jamesbond007 is offline  
Old 17/01/2011, 06:31 PM   #5
Mike_Peterson
Gangsta
 
Mike_Peterson's Avatar
 
Join Date: Apr 2009
Location: In a concrete(used to brick) house
Posts: 848
Reputation: 37
Default Re: multiple ifs

something like this
Code:
public OnPlayerEnterCheckpoint(playerid)
{
    new truckid;
    truckid = GetPlayerVehicleID(playerid);
    if(GetVehicleModel(truckid) == 403 || GetVehicleModel(truckid) == 514 || GetVehicleModel(truckid) == 515 && IsTrailerAttachedToVehicle(playerid))
    { 
        SendClientMessage(playerid, 0x33AA33AA, "Thank you! Here's $1.700!");
        GivePlayerMoney(playerid, 1700);
        DisablePlayerCheckpoint(playerid);
        }else{
        SendClientMessage(playerid, 0xAA3333AA, "Hey! Where's your truck?");
        return 1;
    }

    return 1;
}

@not available and jamesbond. IsPlayerInVehicle will check the Vehicle ID not the model id..
#victious he meant if's.
__________________
I'm looking for some small-time paid work, no MySQL preferably.
Search before you post!

Got a problem? Debug your script (add prints to it).
If that doesn't help, use ******!
Still having issues? Create a thread on the SA-MP Forums.
If nothing helps, send me a PM.
And I'll try to figure it out with you.
Mike_Peterson is offline  
Old 17/01/2011, 06:36 PM   #6
Not available
Big Clucker
 
Join Date: Jan 2011
Posts: 94
Reputation: 0
Default Re: multiple ifs

Oh. Didn't even consider it being models and not IDs. This should be the best solution then:
Code:
public OnPlayerEnterCheckpoint(playerid)
{
    new
    	truckid = GetPlayerVehicleID(playerid)
	;
    if(GetVehicleModel(truckid) == 403 || GetVehicleModel(truckid) == 514 || GetVehicleModel(truckid) == 515 && IsTrailerAttachedToVehicle(truckid))
    {
        SendClientMessage(playerid, 0x33AA33AA, "Thank you! Here's $1.700!");
        GivePlayerMoney(playerid, 1700);
        DisablePlayerCheckpoint(playerid);
        return 1;
    }
	else SendClientMessage(playerid, 0xAA3333AA, "Hey! Where's your truck?");
    return 1;
}
__________________


http://peak-host.net Your #1 Multi-player Game hosting provider.
Not available is offline  
Old 17/01/2011, 06:46 PM   #7
shadowdog
Gangsta
 
shadowdog's Avatar
 
Join Date: Feb 2010
Location: The Netherlands, Limburg
Posts: 554
Reputation: 682
Default Re: multiple ifs

all of those didnt work.. now trying not available's last one

EDIT: your last one didnt work,
the vehicle ids worked but i could enter the checkpoint without trailer and still get $1700
__________________
shadowdog is offline  
Old 17/01/2011, 06:59 PM   #8
Not available
Big Clucker
 
Join Date: Jan 2011
Posts: 94
Reputation: 0
Default Re: multiple ifs

Try this one:
Code:
 OnPlayerEnterCheckpoint(playerid)
{
    new
    	truckid = GetPlayerVehicleID(playerid)
	;
    if(GetVehicleModel(truckid) == 403 || GetVehicleModel(truckid) == 514 || GetVehicleModel(truckid) == 515 && IsTrailerAttachedToVehicle(truckid))
    {
        SendClientMessage(playerid, 0x33AA33AA, "Thank you! Here's $1.700!");
        GivePlayerMoney(playerid, 1700);
        DisablePlayerCheckpoint(playerid);
        return 1;
    }
	else SendClientMessage(playerid, 0xAA3333AA, "Hey! Where's your truck?");
    return 1;
}
__________________


http://peak-host.net Your #1 Multi-player Game hosting provider.
Not available is offline  
Old 17/01/2011, 07:06 PM   #9
Backwardsman97
High-roller
 
Backwardsman97's Avatar
 
Join Date: Nov 2007
Posts: 2,200
Reputation: 36
Default Re: multiple ifs

Code:
public OnPlayerEnterCheckpoint(playerid)
{
	new vehid = GetPlayerVehicleID(playerid),
	model = GetVehicleModel(vehid);

	switch(model)
	{
		case 514,515,403:
		{
			if(!IsTrailerAttachedToVehicle(vehid))
			{
				SendClientMessage(playerid, 0xAA3333AA, "Hey! Where's your truck?");
				return 1;
			}
			SendClientMessage(playerid, 0x33AA33AA, "Thank you! Here's $1.700!");
			GivePlayerMoney(playerid, 1700);
			DisablePlayerCheckpoint(playerid);
			return 1;
		}
		default:SendClientMessage(playerid, 0xAA3333AA, "That's the wrong vehicle.");
	}
	return 1;
}
Backwardsman97 is offline  
Old 18/01/2011, 01:25 PM   #10
shadowdog
Gangsta
 
shadowdog's Avatar
 
Join Date: Feb 2010
Location: The Netherlands, Limburg
Posts: 554
Reputation: 682
Default Re: multiple ifs

Quote:
Originally Posted by Backwardsman97 View Post
Code:
public OnPlayerEnterCheckpoint(playerid)
{
	new vehid = GetPlayerVehicleID(playerid),
	model = GetVehicleModel(vehid);

	switch(model)
	{
		case 514,515,403:
		{
			if(!IsTrailerAttachedToVehicle(vehid))
			{
				SendClientMessage(playerid, 0xAA3333AA, "Hey! Where's your truck?");
				return 1;
			}
			SendClientMessage(playerid, 0x33AA33AA, "Thank you! Here's $1.700!");
			GivePlayerMoney(playerid, 1700);
			DisablePlayerCheckpoint(playerid);
			return 1;
		}
		default:SendClientMessage(playerid, 0xAA3333AA, "That's the wrong vehicle.");
	}
	return 1;
}
its working thank you very much and everyone else for your effort though
__________________
shadowdog is offline  
 

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
multiple servers with multiple ips on linux yakuzza Server Support 2 09/10/2010 07:08 PM
multiple checkpoints [Lsrcr]Rafa Help Archive 19 05/09/2010 07:47 PM
Multiple Queries Dj_maryo1993 Help Archive 7 26/08/2010 04:46 PM


All times are GMT. The time now is 08:15 PM.


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