Doesn't detect vehicle as Ambulance
#1

Heya there SAMP scripters, I was wondering what's wrong in this code
This is a stretcher system im trying to script, although it detects every vehicle as Ambulance
(Command works even if im not near an ambulance)
Note: I am pretty sure the problem is in the for loop
Thanks in advice

PHP Code:
        new Float:XFloat:YFloat:ZFloat:A;
         
GetPlayerPos(playeridXYZ);
          
GetPlayerFacingAngle(playeridA);
        for(new 
i=0i<MAX_VEHICLESi++)
        {
            if(
IsPlayerNearVehicle(playeridi2) && IsLSFMDVehicle(i))
            {
                 
ambulance++;
                if(
ContainStretcher[i]) ambstretcher++;
            }
        }
        if(
ambulance 0) return SendClientMessage(playeridCOLOR_GREY"You are not near any ambulance.");
        if(
ambstretcher 0) return SendClientMessage(playeridCOLOR_GREY"This ambulance doesn't contain any stretcher.");
        if(
UsingStretcher[playerid]) return SendClientMessage(playeridCOLOR_GREY"You are already using a stretcher.");
         
UsingStretcher[playerid] = 1;
        
StretcherObj[playerid] = CreateObject(2146XYZ00A100.0);
         
MovingStretcher[playerid] = 1;
          
AttachObjectToPlayer(StretcherObj[playerid], playerid0.001.30, -0.500.00.00.0);
        
format(stringsizeof(string), "* %s opens the back of the ambulance and withdraws a stretcher."RPN(playerid));
        
SendNearbyMessage(playerid15stringCOLOR_PURPLECOLOR_PURPLECOLOR_PURPLECOLOR_PURPLECOLOR_PURPLE); 
Reply
#2

Can you post your code for this function?:
Code:
IsLSFMDVehicle(i)
Reply
#3

Quote:
Originally Posted by Godey
View Post
Can you post your code for this function?:
Code:
IsLSFMDVehicle(i)
Ofcourse
PHP Code:
stock IsLSFMDVehicle(vehicleid)
{
    for(new 
i=0i<21i++)
    {
        if(
vehicleid == FacInfo[5][fCars][i]) return 1;
    }
    return 
0;

CreateVehicles
PHP Code:
FacInfo[5][fCars][0] = CreateVehicle(416,1124.0000000,-1329.1999512,13.5000000,0.0000000,1,3,0); //Ambulance
    
FacInfo[5][fCars][1] = CreateVehicle(416,1110.5999756,-1328.9000244,13.3999996,0.0000000,1,3,0); //Ambulance
    
FacInfo[5][fCars][2] = CreateVehicle(416,1097.4000244,-1329.0999756,13.5000000,0.0000000,1,3,0); //Ambulance
    
FacInfo[5][fCars][3] = CreateVehicle(416,1147.6999512,-1314.0999756,13.8000002,0.0000000,1,3,0); //Ambulance
    
FacInfo[5][fCars][4] = CreateVehicle(416,1135.4000244,-1340.6999512,13.8999996,0.0000000,1,3,0); //Ambulance
    
FacInfo[5][fCars][5] = CreateVehicle(416,1147.5999756,-1347.0000000,13.6999998,180.0000000,1,3,0); //Ambulance
    
FacInfo[5][fCars][6] = CreateVehicle(487,1161.5999756,-1310.0999756,31.7999992,268.0000000,3,1,0); //Maverick
    
FacInfo[5][fCars][7] = CreateVehicle(487,1162.0999756,-1296.8000488,31.7999992,270.0000000,3,1,0); //Maverick
    
FacInfo[5][fCars][8] = CreateVehicle(487,1161.4000244,-1322.0999756,31.7999992,268.0000000,3,1,0); //Maverick
    
FacInfo[5][fCars][9] = CreateVehicle(407,1217.6999512,-1332.8000488,13.8000002,90.0000000,3,1,0); //Firetruck
    
FacInfo[5][fCars][10] = CreateVehicle(407,1218.0000000,-1341.5999756,13.8000002,90.0000000,3,1,0); //Firetruck
    
FacInfo[5][fCars][11] = CreateVehicle(407,1218.0000000,-1350.0999756,13.6999998,90.0000000,3,1,0); //Firetruck
    
FacInfo[5][fCars][12] = CreateVehicle(407,1246.6999512,-1332.5999756,13.8000002,270.0000000,3,1,0); //Firetruck
    
FacInfo[5][fCars][13] = CreateVehicle(407,1246.8000488,-1341.0999756,13.8000002,270.0000000,3,1,0); //Firetruck
    
FacInfo[5][fCars][14] = CreateVehicle(407,1247.0000000,-1349.9000244,13.8000002,270.0000000,3,1,0); //Firetruck
    
FacInfo[5][fCars][15] = CreateVehicle(407,1232.3000488,-1315.8000488,14.3999996,90.0000000,3,1,0); //Firetruck
    
FacInfo[5][fCars][16] = CreateVehicle(407,1231.3000488,-1360.6999512,14.5000000,270.0000000,3,1,0); //Firetruck
    
FacInfo[5][fCars][17] = CreateVehicle(416,1178.0000000,-1338.6999512,13.8999996,270.0000000,1,3,0); //Ambulance
    
FacInfo[5][fCars][18] = CreateVehicle(416,1178.0999756,-1308.5000000,13.8999996,272.0000000,1,3,0); //Ambulance
    
FacInfo[5][fCars][19] = CreateVehicle(487,1231.4000244,-1334.1999512,27.5000000,90.0000000,3,1,0); //Maverick
    
FacInfo[5][fCars][20] = CreateVehicle(487,1232.0000000,-1348.8000488,27.5000000,90.0000000,3,1,0); //Maverick
    
for(new i=0i<21i++)
    {
        
ContainStretcher[FacInfo[5][fCars][i]] = 1;
    } 
Reply
#4

Anyone?
Reply
#5

Code:
FacInfo[5][fCars][20]
Why 5?
Why not just use:
Code:
FacInfo[fCars][20]
Reply
#6

Quote:
Originally Posted by Godey
View Post
Code:
FacInfo[5][fCars][20]
Why 5?
Why not just use:
Code:
FacInfo[fCars][20]
I have 13 factions ...
Each faction has its own vehicles
Reply
#7

You could create an if statement to check if the Vehicle model is equal to that of an ambulance. You can do this using "getplayervehicleid" with a variable
Reply
#8

Quote:
Originally Posted by ConnorHunter
View Post
You could create an if statement to check if the Vehicle model is equal to that of an ambulance. You can do this using "getplayervehicleid" with a variable
I tried to do the code when Im not near ANY LSFMD vehicle, so it shouldn't work anyways
But it still works
I think the whole for loop is misused, do you have any clue ?
Reply
#9

Do you want to make it so it's only for ambulances or for the entire faction?
Reply
#10

Why are you using [5] for all factions?
Reply
#11

He's not, I'm assuming the LSFMD is using ID 5 for their faction
Reply
#12

pawn Code:
for(new i=0; i<MAX_VEHICLES; i++)
{
        if(IsPlayerNearVehicle(playerid, i, 2) && IsLSFMDVehicle(i))
        {
                ambulance++;
                if(ContainStretcher[i]) ambstretcher++;
        }
}
if(ambulance < 0) return SendClientMessage(playerid, COLOR_GREY, "You are not near any ambulance.");
I'm going to assume that you have

pawn Code:
new ambulance;
somewhere there too?
Reply
#13

Quote:
Originally Posted by Padevex
View Post
pawn Code:
for(new i=0; i<MAX_VEHICLES; i++)
{
        if(IsPlayerNearVehicle(playerid, i, 2) && IsLSFMDVehicle(i))
        {
                ambulance++;
                if(ContainStretcher[i]) ambstretcher++;
        }
}
if(ambulance < 0) return SendClientMessage(playerid, COLOR_GREY, "You are not near any ambulance.");
I'm going to assume that you have

pawn Code:
new ambulance;
somewhere there too?
Top of command, ofc.

PHP Code:
CMD:stretcher(playeridparams[])
{
    new 
string[128], ambulanceambstretcher;
    if(!
IsPlayerLoggedIn(playerid) || PlayerInfo[playerid][pAsshole] == 1) return SendClientMessage(playeridCOLOR_GREY"You are not allowed to use this command.");
    if(!
IsMedic(playerid)) return SendClientMessage(playeridCOLOR_GREY"You are not authorized to use this command."); 
Reply
#14

In your "IsLSFMDCar" function try setting the return value to 0 instead of 1.
Reply
#15

Quote:
Originally Posted by ConnorHunter
View Post
In your "IsLSFMDCar" function try setting the return value to 0 instead of 1.
EDIT- Fixed using this code:

PHP Code:
stock IsPlayerNearAmbulance(playeridFloat:range)
{
        new 
Float:XFloat:YFloat:Z;
        for(new 
ii<MAX_VEHICLESi++)
        {
                
GetVehiclePos(iXYZ);
                if(
IsPlayerInRangeOfPoint(playeridrangeXYZ) && IsLSFMDVehicle(i) && GetVehicleModel(i) == 416) return i;
        }
        return 
0;

Thanks for trying
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)