Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- addCommandHandler( "car",
- function( playerid, vehicleid )
- {
- local mypos = getPlayerPosition(playerid);
- if( isPointInCircle2D( mypos[0], mypos[1], -575.114868, 1623.623169, 35.0 ))
- {
- sendPlayerMessage( playerid, "[Server]: No cars on the spawn area!", 239, 51, 64 );
- return 1;
- }
- if( isPlayerInVehicle( playerid ) )
- {
- sendPlayerMessage( playerid, "[Server]: For a spawn new car you must be on foot!", 239, 51, 64 );
- return 1;
- }
- // You might want to check if the timer is active in here, if it is then return 1.
- // Currently there is nothing stopping them, except for the above if statements to spawn new vehicles
- // And its better to block spawning rather than destroying the vehicle when spawned
- // This variable should be global, aka outside the functions and commands
- // Currently the function blockcarforplayer cant access this
- local myTimer;
- local pos = getPlayerPosition( playerid );
- local vehicle = createVehicle( vehicleid.tointeger(), pos[0] + 2.0, pos[1], pos[2] + 1.0, 0.0, 0.0, 0.0 );
- // You are calling a function with a timer and checking whether the same timer is active or not
- // That will always return true
- // Unless you call the function with another timer to check if a different timer is active or not
- myTimer = timer( blockcarforplayer, 100, 1, playerid);
- sendPlayerMessage( playerid, "[Server]: Car ID: (" +vehicleid.tointeger() + ") has been sucessfully spawned", 0, 255, 0 );
- }
- );
- function blockcarforplayer(playerid)
- {
- // You just created a variable which does not hold anything
- local myTimer;
- //local myTimer = timer( blockcarforplayer, 9000, 1, playerid);
- // Now you are checking whether that variable is active or not (returns error, IsActive does not exist)
- // And if you are checking if a timer is active in a function called by the same timer, it will always return true
- if( myTimer.IsActive() )
- {
- // You are using playerid, you need the vehicleid (getPlayerVehicle())
- destroyVehicle(playerid);
- sendPlayerMessage( playerid, "[Server]: Wait!", 239, 51, 64 );
- return 1;
- }
- }
- /*************** NEW VERSION, Not tested but should work ***********/
- // With this we check if CMD is blocked per player
- local vehCMDBlock = array(MAX_PLAYERS, 0);
- // How long it waits before it unblocks the CMD
- local vehCMDBlockTime = 5000; // 5 seconds currently
- addCommandHandler( "car",
- function( playerid, vehicleid )
- {
- local mypos = getPlayerPosition(playerid);
- if( isPointInCircle2D( mypos[0], mypos[1], -575.114868, 1623.623169, 35.0 ))
- {
- sendPlayerMessage( playerid, "[Server]: No cars on the spawn area!", 239, 51, 64 );
- return 1;
- }
- if( isPlayerInVehicle( playerid ) )
- {
- sendPlayerMessage( playerid, "[Server]: For a spawn new car you must be on foot!", 239, 51, 64 );
- return 1;
- }
- // If cmd block is still active
- if( vehCMDBlock[playerid] == 1 ) {
- sendPlayerMessage( playerid, "[Server]: No señior, you no car", 239, 51, 64 );
- return 1;
- }
- local pos = getPlayerPosition( playerid );
- local vehicle = createVehicle( vehicleid.tointeger(), pos[0] + 2.0, pos[1], pos[2] + 1.0, 0.0, 0.0, 0.0 );
- sendPlayerMessage( playerid, "[Server]: Car ID: (" +vehicleid.tointeger() + ") has been sucessfully spawned", 0, 255, 0 );
- // Block usage of this command
- vehCMDBlock[playerid] = 1;
- timer( function() {
- // Unblock usage
- vehCMDBlock[playerid] = 0;
- // In here you can also destroy the previous vehicle
- // You need to create another global variable for a player (lastVehicleID ?)
- // Store the id from created vehicle (found inside the vehicle variable above)
- // And destroy the vehicle with that ID
- }, vehCMDBlockTime, 1);
- }
- );
Add Comment
Please, Sign In to add comment