SA-MP Forums Archive
vehicle slap - 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: vehicle slap (/showthread.php?tid=607101)



vehicle slap - Digii - 14.05.2016

Hello everyone, I was thinking to make a command such as /slapcar but I didn't succed and I was thinking if anyone of you can help me to make this command, btw I'm using zcmd.

Sorry for my rubbish english.
Thank you very much boyz!!


Re: vehicle slap - Skimmer - 14.05.2016

First define SLAP_HEIGHT top of your code. You can change the value according to your taste.
pawn Код:
#define SLAP_HEIGHT 10
And here's the command.
pawn Код:
COMMAND:slapcar(playerid, params[])
{
    new vehicleid;

    if(sscanf(params, "i", vehicleid))
        return SendClientMessage(playerid, -1, "USAGE: /slapcar <vehicleid>");

    if(vehicleid == INVALID_VEHICLE_ID)
        return SendClientMessage(playerid, -1, "Invalid Vehicle ID!");

    new Float:x, Float:y, Float:z;
    GetVehiclePos(vehicleid, x, y, z);
    SetVehiclePos(vehicleid, x, y, z + SLAP_HEIGHT);
    return 1;
}



Re: vehicle slap - Dayrion - 14.05.2016

Or :
PHP код:
COMMAND:slapcar(playeridparams[])
{
    new 
vehicleidheight;

    if(
sscanf(params"ii"vehicleidheight))
        return 
SendClientMessage(playerid, -1"USAGE: /slapcar <vehicleid> <height>");

    if(
vehicleid == INVALID_VEHICLE_ID)
        return 
SendClientMessage(playerid, -1"Invalid Vehicle ID!");

    new 
Float:xFloat:yFloat:z;
    
GetVehiclePos(vehicleidxyz);
    
SetVehiclePos(vehicleidxyheight);
    return 
1;

No?


Re: vehicle slap - Digii - 14.05.2016

Danke Skimmer and Dayrion, you helped me alot, thank you again brothers!!

SOLVED!


Re: vehicle slap - Sjn - 14.05.2016

A small correction for the answers posted above, the height should be a Float value. If it's an integer, the compiler will convert it into a float value which may cause a slight of difference while compiling. (From what I read)


Re: vehicle slap - AndreT - 14.05.2016

From a long long time ago I remember that if you want to "slap" the vehicle higher into the air and have it continue moving in the direction that it was moving before, you should save the vehicle's velocity before calling SetVehiclePos and re-apply it after calling SetVehiclePos.

The functions for retrieving and setting the velocity of a vehicle are:
GetVehicleVelocity
SetVehicleVelocity


Re: vehicle slap - Digii - 14.05.2016

So how my command should look like?


Re: vehicle slap - Skimmer - 14.05.2016

@AndreT has right. But I wanted to give him a simple code.

@Digii. AndreT means with my code above, when a players drives a car and you slap the vehicle that he drives it gets stopped. But if you don't want to stop it, you can use this code.

pawn Код:
COMMAND:slapcar(playerid, params[])
{
    new vehicleid;

    if(sscanf(params, "i", vehicleid))
        return SendClientMessage(playerid, -1, "USAGE: /slapcar <vehicleid>");

    if(vehicleid == INVALID_VEHICLE_ID)
        return SendClientMessage(playerid, -1, "Invalid Vehicle ID!");

    new Float:x, Float:y, Float:z,
        Float:vx, Float:vy, Float:vz;

    GetVehiclePos(vehicleid, x, y, z);
    GetVehicleVelocity(vehicleid, vx, vy, vz);

    SetVehiclePos(vehicleid, x, y, z + SLAP_HEIGHT);
    SetVehicleVelocity(vehicleid, vx, vy, vz);
    return 1;
}



Re: vehicle slap - Digii - 14.05.2016

I'm actually very surprised because of your patience and help you guys are awesome, I can't actually believe that you brothers gave me the full command ( I'm emotional thank you again my brothers for helping me.
All of you are awesome boys!!


Re: vehicle slap - Sew_Sumi - 14.05.2016

Yea, I'd go for the velocity portion, imagine their faces when they get thrown up a few feet in one motion rather than being "put" up a few feet...

Not saying these portions of code aren't good, it's just all about aesthetics for me.


Re: vehicle slap - AndreT - 15.05.2016

Furthermore, my players were exceptionally pleased when I binded this under a key (NUM4 or NUM6). For this, use the OnPlayerKeyStateChange (https://sampwiki.blast.hk/wiki/OnPlayerKeyStateChange) event.

Slapping the vehicle has the effect of resetting its rotation on all axles as well, this was desired for "flipping" the vehicle on its right side while keeping the velocity.