[Мануал] Создание ограничителя скорости

Description: Уроки по скриптингу
Moderator: SJplayer

Invi_Sasha M
Topic author, Мл. сержант
Мл. сержант
Avatar
Invi_Sasha M
Topic author, Мл. сержант
Мл. сержант
Posts: 34
Joined: 20 May 2013
With us: 11 years 3 months

#1by Invi_Sasha » 22 May 2013, 22:16

Всем привет!
Вот выкладываю урок по созданию ограничителя скорости
И так мы начинаем

В начало мода добавляем

Code: Select all

#define MAX_SPEEDO 0.6 // Максимально допустимая скорость. 
#define SLOW_FACTOR 0.9 // На сколько будет сбавляться скорость при превышении порога. 
forward Timer(); 
new 
Limiter[MAX_PLAYERS]; 
new 
limtimer;  

В public OnPlayerConnect добавляем

Code: Select all

Limiter[playerid] = 0;   

В public OnPlayerCommandText добавляем

Code: Select all

if (strcmp("/limiter"cmdtexttrue) == 0
                            { 
                          for(new 
i=0;i<MAX_PLAYERS;i++) 
                         { 
                          if(
GetPlayerState(playerid) == PLAYER_STATE_DRIVER
                         { 
                         if(
Limiter[playerid] == 0
                          { 
                         
SendClientMessage(playerid,0xAA3333AA,"Ограничитель скорости включен."); 
                         
SendClientMessage(playerid,0xAA3333AA,"Что бы выключить используйте /offlimiter."); 
                         
limtimer SetTimer("Timer",1000,1); 
                         
Limiter[playerid] = 1
                          } 
                          else 
                          { 
                          
SendClientMessage(playerid ,COL OR_G REY"Огр анич ител ь скорости уже включен."); 
                           } 
                         return 
1
                         } 
                         
SendClientMessage(playeridCOLOR_GRAD2"  Вы не в машине!"); 
                         return 
1
                         } 
                         } 
                         if (
strcmp("/offlimiter"cmdtexttrue) == 0
                           { 
                           if(
GetPlayerState(playerid) == PLAYER_STATE_DRIVER
                         { 
                         if(
Limiter[playerid] == 1
                          { 
                         
KillTimer(limtimer); 
                           
SendClientMessage(playerid,0xAA3333AA,"Ограничитель скорости выключен."); 
                           
Limiter[playerid] = 0
                         return 
1
                         } 
                         else 
                         { 
                         
SendClientMessage(playerid,COL OR_G REY"Огр анич ител ь скорости не включен."); 
                         return 
1
                          } 
                           } 
                           
SendClientMessage(playeridCOLOR_GRAD2"Вы не в машине!"); 
                           return 
1
                           }   

В public OnPlayerStateChange добавляем

Code: Select all

if(newstate == PLAYER_STATE_ONFOOT
                         {   

Ниже добавляем

Code: Select all

KillTimer(limtimer); 
Limiter[playerid] = 0;   

Создаем новый паблик в конец мода

Code: Select all

public Timer() 

                          new 
Float:x,Float:y,Float:z,veh
                          for(new 
ii<MAX_PLAYERSi++) 
                          { 
                          
veh=GetPlayerVehicleID(i); 
                          
GetVehicleVelocity(veh,x,y,z); 
                          if((
MAX_SPEEDO || < -MAX_SPEEDO) || (MAX_SPEEDO || < -MAX_SPEEDO)) 
                          { 
                          
SetVehicleVelocity(veh,x*SLOW_FACTOR,y*SLOW_FACTOR,z); 
                          } 
                          } 
}   

На этом наш урок закончен
Всем спасибо за внимание
Автор урока: KaspeR


  • Similar Topics
    Replies
    Views
    Last post

Return to “Уроки”

Who is online (over the past 5 minutes)

Users browsing this forum: 1 guest