vehicle slap
#1

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!!
Reply
#2

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;
}
Reply
#3

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?
Reply
#4

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

SOLVED!
Reply
#5

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)
Reply
#6

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
Reply
#7

So how my command should look like?
Reply
#8

@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;
}
Reply
#9

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!!
Reply
#10

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.
Reply
#11

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)