I need script (Rep +)
#1

Hello.
I need script which will do following task:
When vehicle health changes to less than 251:
- the script sets it to 251
- turns off engine and lights
- flips the car (if it's currently flipped over)

And also I need WORKING function to start engine and lights after that.

I'll give you rep+ if the script will work.

Thanks in advance
Reply
#2

lol idea round here is to have a go at it yourself and then post here when/if you get stuck with the code you have so far. People will reply will full code for you but they shouldnt, have a go your self. i did. now i can write a full GM myself.
Reply
#3

under

pawn Код:
OnPlayerUpdate(...
add

pawn Код:
new Float:health;
new veh;
veh = GetPlayerVehicleID(playerid);
GetVehicleHealth(veh, health);
if(health < 251)
{
    SetVehicleHealth(veh,251);
}
and for flipping use
pawn Код:
new currentveh, Float:angle; currentveh = GetPlayerVehicleID(playerid);
    GetVehicleZAngle(currentveh, angle);
    SetVehicleZAngle(currentveh, angle);
Reply
#4

English-Conceptz, I want to learn too, but I need example - I can't understand all these vehicle functions using only wiki.

Speed, isn't it copycat?
Код:
return NisiAdmin(playerid);
And it doesn't turn engine and lights off
Reply
#5

****** SetVehicleParams for turning engine on/off same with lights, use 1 or 0 for each setting.

and if you cant code everything off the wiki then thats fine but at least post what you have done so far here so it at least looks like you dont intend to copy and paste and be spoon fed.
Reply
#6

I've got that:
pawn Код:
public OnVehicleDamageStatusUpdate(vehicleid, playerid) //Get called every time a vehicle health changes (I think)
{
    new Float:health; //Creating a variable for the car's health
   
    GetVehicleHealth(vehicleid,health); //Storing the actual health of the vehicle in the variable
    if(health < 250.0) //Checkin if the health is lower than 400.0 (1000.0 is the max, somewhere around 400.0, it catches fire)
    {
        new engine, lights, alarm, doors, bonnet, boot, objective; //Creating variable's for the vehicle's parameters (doors, bonnet, engine, etc)
        GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective); //Getting the vehicle's parameters)
        SetVehicleParamsEx(vehicleid, 0, 0, 0, doors, bonnet, boot, objective); //Turning off the engine
        SetVehicleHealth(vehicleid,251.0);
        SendClientMessage(playerid, 0xFF0000FF, "Your car is broken.");
        return 1;
    }
    return 1;
}
But it works only sometimes (not always when health goes under 250)
Reply
#7

pawn Код:
forward CarCheckTimer();

public OnGameModeInit()
{
    SetTimer(CarCheckTimer, 2000, true);
}

public CarCheckTimer();
{
    for(new i=0; i<MAX_VEHICLES; i++)
    {
        new Float:vhealth;
        GetVehicleHealth(v,vhealth);
        if(vhealth < 250.0)
        {
            new engine, lights, alarm, doors, bonnet, boot, objective;
            GetVehicleParamsEx(v, engine, lights, alarm, doors, bonnet, boot, objective);
            SetVehicleParamsEx(v, VEHICLE_PARAMS_OFF, lights, alarm, doors, bonnet, boot, objective);
            SetVehicleHealth(v,251.0);
            SendClientMessage(playerid, 0xFF0000FF, "Your car is broken.");
            return 1;
        }
        return 1;
    }
}
Reply
#8

Rob_Maate, lots of errors:
Reply
#9

It compiles without errors/warnings. I hope it works.
pawn Код:
#include <a_samp>

new
    engine, lights, alarm, doors, bonnet, boot, objective;
public OnGameModeInit()
{
    SetTimer("CarCheckTimer", 1000, true);
}
public OnVehicleDamageStatusUpdate(vehicleid, playerid)
{
    new
        Float:health;
    GetVehicleHealth(vehicleid, health);
    if(health < 250.0) {
        GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
        SetVehicleParamsEx(vehicleid, 0, 0, 0, doors, bonnet, boot, objective);
        SetVehicleHealth(vehicleid, 251.0);
        SendClientMessage(playerid, -1, "Your car is broken.");
        return 1;
    }
    return 1;
}
forward CarCheckTimer(playerid);
public CarCheckTimer(playerid)
{
    for(new i=0; i<MAX_VEHICLES; i++) {
        new
            Float:vhealth, veh;
        veh = GetPlayerVehicleID(playerid);
        GetVehicleHealth(veh, vhealth);
        if(vhealth < 250.0) {
            GetVehicleParamsEx(veh, engine, lights, alarm, doors, bonnet, boot, objective);
            SetVehicleParamsEx(veh, VEHICLE_PARAMS_OFF, lights, alarm, doors, bonnet, boot, objective);
            SetVehicleHealth(veh, 251.0);
            SendClientMessage(playerid, -1, "Your car is broken.");
            return 1;
        }
    }
    return 1;
}
Reply
#10

Kostas, same as above I'm using engine, lights, alarm, doors, bonnet, boot, objective also in includes, so maybe that's the problem?
Reply
#11

Try this one (Not tested yet):
pawn Код:
//..Some code
new PlayerTime[MAX_PLAYERS], PlayerState[MAX_PLAYERS], Float:PlayerVehicleHP[MAX_PLAYERS], bool:UsableVehicle[MAX_VEHICLES];

stock IsVehicleUsable(vehicleid) return ((vehicleid > 0 && vehicleid < MAX_VEHICLES+1) ? UsableVehicle[vehicleid-1] : false);
stock MakeVehicleUsable(vehicleid) if(vehicleid > 0 && vehicleid < MAX_VEHICLES+1) UsableVehicle[vehicleid-1] = true;
stock MakeVehicleUnusable(vehicleid) if(vehicleid > 0 && vehicleid < MAX_VEHICLES+1) UsableVehicle[vehicleid-1] = false;
public OnPlayerDisconnect(playerid, reason)
{
    //...
    PlayerTime[playerid] = 0;
    PlayerState[playerid] = 0;
    PlayerVehicleHP[playerid] = 0;
    //...
    return 1;
}

public OnPlayerUpdate(playerid)
{
    new tick = GetTickCount();
    if(PlayerTime[playerid] >= tick) return 1; //Prevents script overkill (will delay up to < 1ms)
    PlayerTime[playerid] = tick;
    //...
    new pvID = GetPlayerVehicleID(playerid);
    if(pvID != 0)
    {
        new Float:pvHP;
        GetVehicleHealth(pvID, pvHP);
        if(PlayerVehicleHP[playerid] != pvHP)
        {
            if(pvHP < 251.0 && IsVehicleUsable(pvID))
            {
                MakeVehicleUnusable(vehicleid);
                new Float:angle;
                GetVehicleZAngle(pvID, angle);
                SetVehicleZAngle(pvID, angle);
                SetVehicleAngularVelocity(pvID, 0.0, 0.0, 0.0);
                SetVehicleHealth(pvID, 251.0);
                new vParams[7];
                GetVehicleParamsEx(pvID, vParams[0], vParams[1], vParams[2], vParams[3], vParams[4], vParams[5], vParams[6]);
                SetVehicleParamsEx(pvID, 0, 0, vParams[2], vParams[3], vParams[4], vParams[5], vParams[6]);
            }
            else if(pvHP >= 251.0 && !IsVehicleUsable(pvID))
            {
                MakeVehicleUsable(vehicleid);
                new vParams[7];
                GetVehicleParamsEx(pvID, vParams[0], vParams[1], vParams[2], vParams[3], vParams[4], vParams[5], vParams[6]);
                SetVehicleParamsEx(pvID, 1, 1, vParams[2], vParams[3], vParams[4], vParams[5], vParams[6]);
            }
            PlayerVehicleHP[playerid] = pvHP;
        }
    }
    else if(PlayerVehicleHP[playerid] != 0.0) PlayerVehicleHP[playerid] = 0.0;
    return 1;
}
//..Some code
Reply
#12

Here mate. If you've defined the above variables before, you need to change the ones you use in this command.

pawn Код:
forward CarCheckTimer();

public OnGameModeInit()
{
    SetTimer(CarCheckTimer, 2000, true);
}

public CarCheckTimer();
{
    for(new i=0; i<MAX_VEHICLES; i++)
    {
        new Float:vhealth;
        GetVehicleHealth(v,vhealth);
        if(vhealth < 250.0)
        {
            new eng, lig, ala, doo, bon, boo, objt;
            GetVehicleParamsEx(v, eng, lig, ala, doo, bon, boo, objte);
            SetVehicleParamsEx(v, VEHICLE_PARAMS_OFF, lig, ala, doo, bon, boo, objt);
            SetVehicleHealth(v,251.0);
            SendClientMessage(playerid, 0xFF0000FF, "Your car is broken.");
            return 1;
        }
        return 1;
    }
}
Reply
#13

Quote:
Originally Posted by xGoldenx
Посмотреть сообщение
Kostas, same as above I'm using engine, lights, alarm, doors, bonnet, boot, objective also in includes, so maybe that's the problem?
That was the problem, because you have the variables already into the include and at your script too. I suggest you what Rob_Maate said. Change the names of the variables on your script to different and try it. It should work!
Reply
#14

Now it works, but when I leave and enter the car the engine starts again. I think adding other variable storing informations about breaking like that:

if car broken set Broken[vehicleid] to true
if Broken[vehicleid]==false start the engine

and I got something like that:
pawn Код:
new bool:Broken[9000];

(...)
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    // Setup local variables
    new engine, lights, alarm, doors, bonnet, boot, objective;
(...)
        if (Broken[vehicleid]==false){
        // Start the engine and turn on the lights
        GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
        SetVehicleParamsEx(vehicleid, 1, 1, alarm, doors, bonnet, boot, objective);
        }
(...)
    return 1;
}

(...)

public CarCheckTimer(playerid)
{
    for(new i=0; i<MAX_VEHICLES; i++) {
        new Float:vhealth, vehicleid, Float:x = 0.0, Float:y = 0.0, Float:z = 0.0;
        vehicleid = GetPlayerVehicleID(playerid);
(...)
                Broken[vehicleid] = true;
                SendClientMessage(playerid, -1, "Your car is broken.");
                return 1;
            }
   
    }
    return 1;
}
But it shows
Код:
error 033: array must be indexed (variable "Broken")
Reply
#15

Ok, I've done it. Thanks you very much for help, everyone!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)