Jujuv icon

[SA:MP | DROPED] Dynamic Vehicles

Jujuv | PRO | 05/22/12 07:38:10 PM UTC | 0 ⭐ | 294 👁️ | Never ⏰ | []
Pawn |

12.66 KB

|

None

|

0 👍

/

0 👎

// This is a comment
// uncomment the line below if you want to write a filterscript
//#define FILTERSCRIPT
 
 
/*[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[Message de l'auteur]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
 
Ce systeme se veux relativement simpliste.Il existe surement beaucoups de moyens d'optimiser la vitesse d'execution de celui-ci sans même passer par le moindre plugin.
Il existe surement des optimisations possibles sans même utiliser de bibliotheques supplémentaires.si vous désirez améliorer/modifier celui-ci, vous y êtes invités!
Ce script n'est soumis à AUCUNES licences et je renonce à mes droits de propriété intelectuele car il me semble que la lois française me donne des droits de propriétés à défaut de licence.
 
Partagez le, modifiez le, hackez le, vendsez le mais surtout apréciez le!
 
Concernant la vente, il n'y qu'une limite: votre moral !
 
J'ai choisie l'utilisation de JSON (by DracoBlue) pour ses performances et sa simplicité d'utilisation.
De même pour ZCMD.
 
//--------------------------------------------------------------------------For English Readers-------------------------------------------------------------------------//
 
For my english readers: This system is pretty simple and you may find many ways to improve the code without using more library(s) and/or plugin(s) and if you want to improve it by yourself: do it!
This script is FREE and you may do everything you want with!
 
Share it, Use it, sell it, hack it, but LOVE IT !
 
About selling: there is only one limit: your soul!
 
BTW, sorry for my bad english (^_^)
 
------------------------------------------------------------------------Message to sa:mp team--------------------------------------------------------------------//
 
@Sa:Mp admin team: if u read this message (i think you will never ...) please tell WHY THE HELL I GOT BANNED FROM UR FORUM ?
I have just asked about sa:mp major issues to tell my opinion and i got banned without any reason!
 
I'm Jujuv and i have done a new account wich will probably spot.
 
 
//-------------------------------------------------------------------------Anyway------------------------------------------------------------------------------//
 
Have fun and remember to play only for fun !
Jujuv.
 
 
 
 
 
 
*/
//--------------------------------------------------------------------------------Inclusion de bibliotheques--------------------------------------------------------------//
#include <a_samp>
#include <djson>
#include <zcmd>
 
 
//-------------------------------------------------------------------------------definitions de macros-------------------------------------------------------------------//
 
#define VEHFILE "vehicles.json"
 
/*Properties*/
#define VEH_RESPAWN_DELAY 60
 
/*Dialog IDs*/
#define DIALOG_CAR_COLOR_CHOOSE 1       /*Ces macro permetent de régler facilement les conflits d'IDs si vous utilisez d'autres boites de dialogue*/
#define DIALOG_CAR_COLOR_CHOOSE_SECOND 2
 
/*Colors*/
#define COLOR_RED 0xD70000FF
#define COLOR_YELLOW 0xFBEE04FF
 
//----------------------------------------------------------------------------------Structures d'enumerations----------------------------------------------------------------------------------//
enum E_VEH_DATA
{
    registered,
    colour1,
    colour2
}
 
//-----------------------------------------------------------------------------Variables & tableaux globaux-------------------------------------------------------------------//
new vehInfo[MAX_VEHICLES][E_VEH_DATA];
//----------------------------------------------------------------------------Debut des callbacks et fonctions----------------------------------------------------------------//
 
#if defined FILTERSCRIPT
 
public OnFilterScriptInit()
{
    print("\n--------------------------------------");
    print(" Blank Filterscript by your name here");
    print("--------------------------------------\n");
    return 1;
}
 
public OnFilterScriptExit()
{
    return 1;
}
 
#else
 
main()
{
    print("\n----------------------------------");
    print(" Simple Dynamic Vehicles System");
    print("----------------------------------\n");
}
 
#endif
 
public OnGameModeInit()
{
    djson_GameModeInit();//DO NOT REMOVE ! THIS IS NEEDED BY DJSON LIBRARY !
    if(!fexist(VEHFILE)) { djCreateFile(VEHFILE); print("Vehicle file created"); djSetInt(VEHFILE, "Total", 0);}
    else{ LoadRegisteredVehicles(); }
    return 1;
}
 
public OnGameModeExit()
{
    djson_GameModeExit();//DO NOT REMOVE ! THIS IS NEEDED BY DJSON LIBRARY !
    return 1;
}
 
public OnPlayerRequestClass(playerid, classid)
{
 
    //don't use theses lines if it's a filterscript
    SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
    return 1;
}
 
public OnPlayerConnect(playerid)
{
    return 1;
}
 
public OnPlayerDisconnect(playerid, reason)
{
    return 1;
}
 
public OnPlayerSpawn(playerid)
{
    return 1;
}
 
public OnPlayerDeath(playerid, killerid, reason)
{
    return 1;
}
 
public OnVehicleSpawn(vehicleid)
{
    return 1;
}
 
public OnVehicleDeath(vehicleid, killerid)
{
    return 1;
}
 
public OnPlayerText(playerid, text[])
{
    return 1;
}
 
/*Don't use OnPlayerCommandText callback ! ZCMD disalow use of this callback !*/
 
/*
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/mycommand", cmdtext, true, 10) == 0)
    {
        // Do something here
        return 1;
    }
    return 0;
}
*/
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    return 1;
}
 
public OnPlayerExitVehicle(playerid, vehicleid)
{
    return 1;
}
 
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    return 1;
}
 
public OnPlayerEnterCheckpoint(playerid)
{
    return 1;
}
 
public OnPlayerLeaveCheckpoint(playerid)
{
    return 1;
}
 
public OnPlayerEnterRaceCheckpoint(playerid)
{
    return 1;
}
 
public OnPlayerLeaveRaceCheckpoint(playerid)
{
    return 1;
}
 
public OnRconCommand(cmd[])
{
    return 1;
}
 
public OnPlayerRequestSpawn(playerid)
{
    return 1;
}
 
public OnObjectMoved(objectid)
{
    return 1;
}
 
public OnPlayerObjectMoved(playerid, objectid)
{
    return 1;
}
 
public OnPlayerPickUpPickup(playerid, pickupid)
{
    return 1;
}
 
public OnVehicleMod(playerid, vehicleid, componentid)
{
    return 1;
}
 
public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
    return 1;
}
 
public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
    return 1;
}
 
public OnPlayerSelectedMenuRow(playerid, row)
{
    return 1;
}
 
public OnPlayerExitedMenu(playerid)
{
    return 1;
}
 
public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
    return 1;
}
 
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    return 1;
}
 
public OnRconLoginAttempt(ip[], password[], success)
{
    return 1;
}
 
public OnPlayerUpdate(playerid)
{
    return 1;
}
 
public OnPlayerStreamIn(playerid, forplayerid)
{
    return 1;
}
 
public OnPlayerStreamOut(playerid, forplayerid)
{
    return 1;
}
 
public OnVehicleStreamIn(vehicleid, forplayerid)
{
    return 1;
}
 
public OnVehicleStreamOut(vehicleid, forplayerid)
{
    return 1;
}
public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
    return 1;
}
 
 
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case DIALOG_CAR_COLOR_CHOOSE:
        {
            new colorID = strval(inputtext);
            if(colorID >= 0 && colorID <= 126)
            {
                SetPVarInt(playerid, "firstCarColor", colorID);
                ShowPlayerDialog(playerid, DIALOG_CAR_COLOR_CHOOSE_SECOND, DIALOG_STYLE_INPUT, "Choose color ID", "Please enter a second color for your vehicle (color ID)", "Ok", "");
            }
            else { ShowPlayerDialog(playerid, DIALOG_CAR_COLOR_CHOOSE, DIALOG_STYLE_INPUT, "Wrong color ID", "Please enter a valid color ID (0-126)", "Ok", ""); }
        }
        case DIALOG_CAR_COLOR_CHOOSE_SECOND:
        {
            new colorID = strval(inputtext);
            if(colorID >= 0 && colorID <= 126)
            {
                new Float:x, Float:y, Float:z, Float:fA, vehID;
                GetPlayerPos(playerid, x, y, z);
                GetPlayerFacingAngle(playerid, fA);
                
                vehID = CreateVehicle(GetPVarInt(playerid, "carModelID"), x, y, z, fA, GetPVarInt(playerid, "firstCarColor"), colorID, VEH_RESPAWN_DELAY);
                PutPlayerInVehicle(playerid, vehID, 0);
            }
            else { ShowPlayerDialog(playerid, DIALOG_CAR_COLOR_CHOOSE_SECOND, DIALOG_STYLE_INPUT, "Wrong color ID", "Please enter a valid color ID (0-126)", "Ok", ""); }
        }
    }
    return 1;
}
 
 
stock LoadRegisteredVehicles()
{
    new str[20], model, Float:x, Float:y, Float:z, Float:a, vehID, color1, color2, total;
    
    print("function called and executed");
    total = djInt(VEHFILE, "Total");
    printf("Total vehicles : %i", total);
    for(new i = 0; i <= total; i++)
    {
        print("one more loop");
        printf("%i loop(s)", i);
        format(str, sizeof(str), "%i/model", i);
        model = djInt(VEHFILE, str);
        if(model != -1)
        {
            print("block is executed");
            format(str, sizeof(str), "%i/axes/x", i);
            x = djFloat(VEHFILE, str);
            print("1");
            format(str, sizeof(str), "%i/axes/y", i);
            y = djFloat(VEHFILE, str);
            print("2");
            format(str, sizeof(str), "%i/axes/z", i);
            z = djFloat(VEHFILE, str);
            print("3");
            format(str, sizeof(str), "%i/axes/facingAngle", i);
            a = djFloat(VEHFILE, str);
            print("4");
            format(str, sizeof(str), "%i/colors/1", i);
            color2 = djInt(VEHFILE, str);
            print("5");
            format(str, sizeof(str), "%i/colors/2", i);
            color1 = djInt(VEHFILE, str);
            print("6");
 
            vehID = CreateVehicle(model, x, y, z, a, color1, color2, VEH_RESPAWN_DELAY);
            print("7");
 
            vehInfo[vehID][registered] = true;
            print("8");
            vehInfo[vehID][colour1] = color1;
            print("9");
            vehInfo[vehID][colour2] = color2;
            print("10");
            
            print("Not realy end of block ...");
            printf("%i vehicles loaded", i);
            print("End of block is executed too");
 
            
        }
     }
}
stock IsVehicleRegistered(vehID)
{
    if(vehInfo[vehID][registered]) { return true; }
    else { return false; }
}
 
stock RegisterVehicle(vehID)
{
    if(!IsVehicleRegistered(vehID))
    {
        new model, Float:x, Float:y, Float:z, Float:fA, total, str[20], i;
        model = GetVehicleModel(vehID);
        GetVehiclePos(vehID, x, y, z);
        GetVehicleZAngle(vehID, fA);
        
        total = djInt(VEHFILE, "Total");
        for(i = total; i > 0; i--)
        {
            format(str, sizeof(str), "%i/model", i);
            
            if(djInt(VEHFILE, str) == -1) {break;}
        }
        
        if(i == 0)
          {
                i = total+1;
          }
        
        format(str, sizeof(str), "%i/model", i);
        djSetInt(VEHFILE, str, model);
        format(str, sizeof(str), "%i/axes/x", i);
        djSetFloat(VEHFILE, str, x);
        format(str, sizeof(str), "%i/axes/y", i);
        djSetFloat(VEHFILE, str, y);
        format(str, sizeof(str), "%i/axes/z", i);
        djSetFloat(VEHFILE, str, z);
        format(str, sizeof(str), "%i/axes/facingAngle", i);
        djSetFloat(VEHFILE, str, fA);
        format(str, sizeof(str), "%i/colors/1", i);
        djSetInt(VEHFILE, str, vehInfo[vehID][colour1]);
        format(str, sizeof(str), "%i/colors/2", i);
        djSetInt(VEHFILE, str, vehInfo[vehID][colour2]);
 
        vehInfo[vehID][registered] = true;
        
        djSetInt(VEHFILE, "Total", djInt(VEHFILE, "Total")+1 );
 
        
        return true;
    }
    else{ return false; }
}
 
COMMAND:v(playerid, params[])
{
    if(isnull(params)) { SendClientMessage(playerid, COLOR_YELLOW, "Usage: /v [modelID]");}
    else if(IsPlayerAdmin(playerid))//Adaptez cette condition à votre systeme d'admin'
    {
        new modelID = strval(params);
        if(modelID >= 400 && modelID <= 611)
        {
            SetPVarInt(playerid, "carModelID", modelID);
            ShowPlayerDialog(playerid, DIALOG_CAR_COLOR_CHOOSE, DIALOG_STYLE_INPUT, "Select a color", "Please enter a first color for your vehicle (color ID)", "Ok", "");
        }
        else { SendClientMessage(playerid, COLOR_YELLOW, "Please enter a valid vehicle model ID"); }
    }
    else { SendClientMessage(playerid, COLOR_RED, "You must e dmin to use this command"); }
    
    return 1;
}
 
COMMAND:register(playerid, params[])
{
    if(IsPlayerAdmin(playerid))//Adaptez cette condition à votre systeme d'admin'
    {
        if(IsPlayerInAnyVehicle(playerid))
        {
 
            new response =  RegisterVehicle(GetPlayerVehicleID(playerid));
            if(response) { SendClientMessage(playerid, COLOR_YELLOW, "Vehicle registered");}
            else { SendClientMessage(playerid, COLOR_RED, "This vehicle is allready registered"); }
        }
        else{ SendClientMessage(playerid, COLOR_RED, "You must be in any vehicle to do that !");}
    }
    else { SendClientMessage(playerid, COLOR_RED, "You must e dmin to use this command"); }
    
    return 1;
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎