/engine
#1

Hello, I want to make /engine cmd that doesn't need ZCMD , Y_CMD or any include for cmds.
Example of my commands,
pawn Код:
if(strcmp(cmd, "/findcar", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            if(gPlayerHasCar[playerid] == 1)
            {
                new Float:vx, Float:vy, Float:vz;
                GetVehiclePos(Vehicle[playerid], vx, vy, vz);
                SetPlayerCheckpoint(playerid, vx, vy, vz, 10.0);
                Checkpoint[playerid] = 1;
                SendClientMessage(playerid, 0xFFFFFFAA, "Go to the checkpoint to find your car!");
                return 1;
            }
            else {
                SendClientMessage(playerid, 0xAFAFAFAA, "You don't own a vehicle.");
                return 1;
                    }
        }
I hope someone help me.
Don't forget i will +REP you for that.
Reply
#2

Are you sure you posted the correct code?

What should this /engine command do?

You should really reconsider not using ZCMD or Y_CMD or any other command processor. Using strcmp under OnPlayerCommandText is slow.
Reply
#3

GetVehicleParamsEx
SetVehicleParamsEx
Reply
#4

Quote:
Originally Posted by dusk
Посмотреть сообщение
Are you sure you posted the correct code?

What should this /engine command do?

You should really reconsider not using ZCMD or Y_CMD or any other command processor. Using strcmp under OnPlayerCommandText is slow.
I just gave an example of my cmds, how they are and that they don't need ZCMD / Y_CMD. That is the code i gave was just an example. And I want to know and learn on how to make the /engine cmd.
Reply
#5

straight off; not gonna support this string comparison stuff...
really, its stunning that this crappy method survived until today
pawn Код:
YCMD:engine(playerid,params[],help)
{
    if(!IsPlayerInAnyVehicle(playerid)) return GameTextForPlayer(playerid,"error",3000,3);
    new bool:stmt[7];
    GetVehicleParamsEx(GetPlayerVehicleID(playerid),stmt[0],stmt[1],stmt[2],stmt[3],stmt[4],stmt[5],stmt[6]);
    SetVehicleParamsEx(GetPlayerVehicleID(playerid),stmt[0]=stmt[0]?false:true,stmt[1],stmt[2],stmt[3],stmt[4],stmt[5],stmt[6]);
    return 1;
}
does what it's supposed to do. engine on/off just by retyping the cmd.
now just customize it... put it in that creepy strcmp format :P

also, you could use rbits to shorten the size of that array a bit... since bool doesen't really need 32 bits for 0 or 1...
but that's just a sidenote!!
Quote:
Originally Posted by RyDeR`
Посмотреть сообщение
The .amx size after compile is 726 bytes. Nothing much, but as you can see we're using 32-bit variables for only 0 and 1, so that's a waste of a lot memory. The most relevant bit type in this case would be 1-bit
Reply
#6

Well if you're sure about using strcmp....
pawn Код:
if(!strcmp(cmdtext,"/engine",true,7))
{
    new vehicleid = GetPlayerVehicleID(playerid);
    if(!vehicleid) return SendClientMessage(playerid,0xFF0000FF,"You must be in a vehicle!");
    // You might want to add an exception to vehicles without an engine, for example bikes.
    new engine, lights, alarm, doors, bonnet, boot, objective;
    GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
    if(engine != VEHICLE_PARAMS_ON)
    {
         SetVehicleParamsEx(vehicleid, VEHICLE_PARAMS_ON,lights,alarm,doors,bonnet,boot,objective);
         SendClientMessage(playerid,0x00FF00FF,"The engine is now running");
    }
    else
    {
         SetVehicleParamsEx(vehicleid, VEHICLE_PARAMS_OFF,lights,alarm,doors,bonnet,boot,objective);
         SendClientMessage(playerid,0x00FF00FF,"The engine is stopped");
     }
}
Note that before using SetVehicleParamsEx function all values will be VEHICLE_PARAMS_UNSET(-1).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)