SA-MP Forums Archive
Clickable textdraw CarEngine - 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)
+--- Thread: Clickable textdraw CarEngine (/showthread.php?tid=333688)



Clickable textdraw CarEngine - johannes95 - 12.04.2012

Does someone know how to make a Clickable textdraw for engine?
I did try but it wont work :/

If you step in the car it shows the textdraw then you click on start you drive away and when you stop it show the textdraw again and then you can click on stop to stop the engine?


Re: Clickable textdraw CarEngine - SomebodyAndMe - 12.04.2012

You will need a speedometer to do such thing so you can check every 500 mili seconds with a timer if the speed is below 5.


Re: Clickable textdraw CarEngine - johannes95 - 12.04.2012

I have a speedometer, and i check the speed, but when i stop the textdraw come back but then i can't move, and start/stop button doesnt work

http://pastebin.com/4n3ddGdC


Re: Clickable textdraw CarEngine - SomebodyAndMe - 12.04.2012

Could you show the code?


Re: Clickable textdraw CarEngine - johannes95 - 12.04.2012

http://pastebin.com/4n3ddGdC


Re: Clickable textdraw CarEngine - SomebodyAndMe - 12.04.2012

This should work:

pawn Код:
// Ongamemodeinit
for(new i = 0; i < MAX_PLAYERS; i++)
{
        TextDrawSetSelectable(EngineStart[i], true);
        TextDrawSetSelectable(EngineStop[i], true);
}

// OnPlayerStateChange
if(IsCar(vehiclemodel) || IsMotorCycle(vehiclemodel) || IsBoat(vehiclemodel))
{
        TextDrawShowForPlayer(playerid, EngineStart[playerid]);
        TextDrawShowForPlayer(playerid, EngineStop[playerid]);
        SelectTextDraw(playerid, RED);
}

public OnPlayerClickTextDraw(playerid, Text:clickedid)
{
    new vehicle = GetPlayerVehicleID(playerid);
        new lights, alarm, doors, bonnet, boot;

        if (clickedid != Text:INVALID_TEXT_DRAW)
    {
        if(clickedid == EngineStart[playerid])
            {
             SetVehicleParamsEx(vehicle, 1, lights, alarm, doors, bonnet, boot, 0);
                         TextDrawShowForPlayer(playerid,speed[playerid]);
        }
            else if(clickedid == EngineStop[playerid])
        {
                 SetVehicleParamsEx(vehicle, 0, lights, alarm, doors, bonnet, boot, 0);
        }
        CancelSelectTextDraw(playerid);
        }
    return 1;
}

public SpeedoUpdate()
{
        for(new i = 0;i<MAX_PLAYERS;i++)
        {
                if(IsPlayerConnected(i) && IsPlayerInAnyVehicle(i))
                {
                        new Float:x,Float:y,Float:z,string[24],vehicleid = GetPlayerVehicleID(i);
                        GetVehicleVelocity(vehicleid,x,y,z);
                        format(string,sizeof(string),"%d~w~km/h", GetPlayerSpeed(i, true));//floatround(floatsqroot(((x*x)+(y*y))+(z*z))*250.666667));
                        TextDrawSetString(speed[i],string);
                        if(GetPlayerSpeed(i, true) >= 2)
                        {
                            TextDrawHideForPlayer(i, EngineStop[i]);
                                                        SelectTextDraw(playerid, 0xFF0000FF);
                        }
                        else
                        {
                            TextDrawShowForPlayer(i, EngineStart[i]);
                            SelectTextDraw(playerid, 0xFF0000FF);
                        }
                }
                if(!IsPlayerInAnyVehicle(i))
                {
                        TextDrawHideForPlayer(i,speed[i]);
                }
        }
}



Re: Clickable textdraw CarEngine - sjvt - 12.04.2012

What you post is wrong sir
I did send him a PM but he don't answer


Re: Clickable textdraw CarEngine - SomebodyAndMe - 12.04.2012

Quote:
Originally Posted by sjvt
Посмотреть сообщение
What you post is wrong sir
I did send him a PM but he don't answer
Well explain what is wrong.


Re: Clickable textdraw CarEngine - johannes95 - 12.04.2012

Quote:
Originally Posted by SomebodyAndMe
Посмотреть сообщение
Well explain what is wrong.
I did test it, its not clickable

sjvt i have no message received


Re: Clickable textdraw CarEngine - SomebodyAndMe - 12.04.2012

This should work:

pawn Код:
// Ongamemodeinit
for(new i = 0; i < MAX_PLAYERS; i++)
{
        TextDrawSetSelectable(EngineStart[i], 1);
        TextDrawSetSelectable(EngineStop[i], 1);
}

// OnPlayerStateChange
if(IsCar(vehiclemodel) || IsMotorCycle(vehiclemodel) || IsBoat(vehiclemodel))
{
        TextDrawShowForPlayer(playerid, EngineStart[playerid]);
        TextDrawShowForPlayer(playerid, EngineStop[playerid]);
        SelectTextDraw(playerid, RED);
}

public OnPlayerClickTextDraw(playerid, Text:clickedid)
{
    new vehicle = GetPlayerVehicleID(playerid);
        new lights, alarm, doors, bonnet, boot;

        if (clickedid != Text:INVALID_TEXT_DRAW)
    {
        if(clickedid == EngineStart[playerid])
            {
             SetVehicleParamsEx(vehicle, 1, lights, alarm, doors, bonnet, boot, 0);
                         TextDrawShowForPlayer(playerid,speed[playerid]);
        }
            else if(clickedid == EngineStop[playerid])
        {
                 SetVehicleParamsEx(vehicle, 0, lights, alarm, doors, bonnet, boot, 0);
        }
        CancelSelectTextDraw(playerid);
        }
    return 1;
}

public SpeedoUpdate()
{
        for(new i = 0;i<MAX_PLAYERS;i++)
        {
                if(IsPlayerConnected(i) && IsPlayerInAnyVehicle(i))
                {
                        new Float:x,Float:y,Float:z,string[24],vehicleid = GetPlayerVehicleID(i);
                        GetVehicleVelocity(vehicleid,x,y,z);
                        format(string,sizeof(string),"%d~w~km/h", GetPlayerSpeed(i, true));//floatround(floatsqroot(((x*x)+(y*y))+(z*z))*250.666667));
                        TextDrawSetString(speed[i],string);
                        if(GetPlayerSpeed(i, true) >= 2)
                        {
                            TextDrawHideForPlayer(i, EngineStop[i]);
TextDrawSetSelectable(EngineStart[i], 1);
                                                        SelectTextDraw(playerid, 0xFF0000FF);
                        }
                        else
                        {
                            TextDrawShowForPlayer(i, EngineStop[i]);
                            SelectTextDraw(playerid, 0xFF0000FF);
 TextDrawSetSelectable(EngineStop[i], 1);
                        }
                }
                if(!IsPlayerInAnyVehicle(i))
                {
                        TextDrawHideForPlayer(i,speed[i]);
                }
        }
}
Not tested