19.11.2010, 20:47
Nvm. Don't response.
enum
V_Type
{
ENGINE,
LIGHTS,
ALARM,
DOORS,
BONNET,
BOOT,
OBJECTIVE
};
stock
GetVehicleParams(vehicleid, V_Type:type)
{
if(vehicleid < 1) return INVALID_VEHICLE_ID;
new
GetStatus,
None;
switch(type)
{
case ENGINE: GetVehicleParamsEx(vehicleid, GetStatus, None, None, None, None, None, None);
case LIGHTS: GetVehicleParamsEx(vehicleid, None, GetStatus, None, None, None, None, None);
case ALARM: GetVehicleParamsEx(vehicleid, None, None, GetStatus, None, None, None, None);
case DOORS: GetVehicleParamsEx(vehicleid, None, None, None, GetStatus, None, None, None);
case BONNET: GetVehicleParamsEx(vehicleid, None, None, None, None, GetStatus, None, None);
case BOOT: GetVehicleParamsEx(vehicleid, None, None, None, None, None, GetStatus, None);
case OBJECTIVE: GetVehicleParamsEx(vehicleid, None, None, None, None, None, None, GetStatus);
}
return GetStatus; // (-1 VEHICLE_PARAMS_UNSET) (0 VEHICLE_PARAMS_OFF) (1 VEHICLE_PARAMS_ON)
}
stock
GetVehicleParams(vehicleid, V_Type:type)
{
if(vehicleid < 1) return INVALID_VEHICLE_ID;
new
engine,
lights,
alarm,
doors,
bonnet,
boot,
objective;
GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
switch(type)
{
case P_ENGINE: return engine;
case P_LIGHTS: return lights;
case P_ALARM: return alarm;
case P_DOORS: return doors;
case P_BONNET: return bonnet;
case P_BOOT: return boot;
case P_OBJECTIVE: return objective;
}
return VEHICLE_PARAMS_UNSET;
}
if(GetVehicleParams(GetPlayerVehicleID(playerid), ENGINE) == VEHICLE_PARAMS_ON)
{
// etc...
stock NumberToMonth(number)
{
new month[24];
if (number < 1 || number > 12) month = "INVALID_MONTH";
if (number == 1) month = "January";
if (number == 2) month = "February";
if (number == 3) month = "March";
if (number == 4) month = "April";
if (number == 5) month = "May";
if (number == 6) month = "June";
if (number == 7) month = "July";
if (number == 8) month = "August";
if (number == 9) month = "September";
if (number == 10) month = "October";
if (number == 11) month = "November";
if (number == 12) month = "December";
return month;
}
static stock NumberToMonth(number)
{
new month[24];
switch(number)
{
case 1:month = "January";
case 2: month = "February";
case 3: month = "March";
case 4: month = "April";
case 5: month = "May";
case 6: month = "June";
case 7: month = "July";
case 8: month = "August";
case 9: month = "September";
case 10: month = "October";
case 11: month = "November";
case 12: month = "December";
case default:month = "INVALID_MONTH";
}
return month;
}
case default:month = "INVALID_MONTH";
default:month = "INVALID_MONTH";
stock FactionColor(factiune)
{
switch(factiune)
{
case 1..3: return COLOR_DBLUE;
case 4: return COLOR_LIGHTRED;
case 5: return COLOR_ORANGE;
case 6: return COLOR_GREEN;
case 7: return COLOR_LIGHTGREEN;
case 8: return COLOR_RED;
case 9: return COLOR_NEWS2;
case 10: return COLOR_YELLOW;
case 11: return COLOR_LICENSE;
case 12: return COLOR_GANGSTA;
case 13: return COLOR_BLOODS;
case 14: return COLOR_SURENOS;
case 15: return COLOR_NORTENOS;
case 16: return COLOR_FMA;
}
return COLOR_WHITE;
}
stock FactionColor2(factiune)
{
static const
sc_culoare[17] =
{
COLOR_WHITE,
COLOR_DBLUE,
COLOR_DBLUE,
COLOR_DBLUE,
COLOR_LIGHTRED,
COLOR_ORANGE,
COLOR_GREEN,
COLOR_LIGHTGREEN,
COLOR_RED,
COLOR_NEWS2,
COLOR_YELLOW,
COLOR_LICENSE,
COLOR_GANGSTA,
COLOR_BLOODS,
COLOR_SURENOS,
COLOR_NORTENOS,
COLOR_FMA
};
if (0 <= factiune <= 16)
{
return sc_culoare[factiune];
}
return sc_culoare[0];
}
[13:30:58] GetTickCount = 43912 [13:30:58] Time #1: 13 [13:31:01] GetTickCount = 46336 [13:31:01] Time #2: 19
[13:41:31] GetTickCount = 13094 [13:41:31] Time #1: 16 [13:41:33] GetTickCount = 15054 [13:41:33] Time #2: 19
If you think like that when making a gamemode, you'll end up with tons of unoptimized functions resulting in higher and cpu usage.
|
stock mktime(hour,minute,second,day,month,year) { new timestamp2 = second + (minute * 60) + (hour * 3600), days_of_month[12], days_this_year = day; if(((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) days_of_month = {31,29,31,30,31,30,31,31,30,31,30,31}; else days_of_month = {31,28,31,30,31,30,31,31,30,31,30,31}; if(month > 1) for(new i=0; i<month-1;i++) days_this_year += days_of_month[i]; timestamp2 += days_this_year * 86400; for(new j=1970;j<year;j++) { timestamp2 += 31536000; if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) timestamp2 += 86400; } return timestamp2; }
stock date(zeitpunkt, &hour, &minute, &second, &day, &month, &year) // by Steam { new h = 0, m = 0, s = 0, da = 1, mo = 1, ye = 1970; for(;;) { ye++; if(((zeitpunkt) - (mktime(h, m, s, da, mo, ye))) < 0) { ye--; break; } } for(;;) { mo++; if(((zeitpunkt) - (mktime(h, m, s, da, mo, ye))) < 0) { mo--; break; } } for(;;) { da++; if(((zeitpunkt) - (mktime(h, m, s, da, mo, ye))) < 0) { da--; break; } } for(;;) { h++; if(((zeitpunkt) - (mktime(h, m, s, da, mo, ye))) < 0) { h--; break; } } for(;;) { m++; if(((zeitpunkt) - (mktime(h, m, s, da, mo, ye))) < 0) { m--; break; } } for(;;) { s++; if(((zeitpunkt) - (mktime(h, m, s, da, mo, ye))) < 0) { s--; break; } } hour = h; minute = m; second = s; day = da; month = mo; year = ye; return 1; }
new h, mins, s, d, m, y; date(mktime(18, 32, 0, 16, 04, 2002), h, mins, s, d, m, y); printf("%d.%d.%d %d:%d:%d", d, m, y, h, mins, s);
stock bool:IsLicensePlate( vehicleid )
{
switch( GetVehicleModel(vehicleid) )
{
case 406, 417, 425, 430, 432, 435, 441, 444, 446, 447, 449, 450,
452, 453, 454, 457, 460, 464, 465, 468, 469, 471, 472, 473, 476,
481, 484, 485, 486, 487, 488, 493, 494, 497, 501, 502, 503, 509,
510, 511, 512, 513, 514, 515, 519, 520, 522, 528, 530, 531, 532,
537, 538, 539, 548, 553, 563, 564, 568, 569, 570, 571, 572, 573,
577, 583, 584, 590, 591, 592, 593, 594, 595, 601, 606, 607, 608,
610, 611: return false;
}
return true;
}
#define MAX_PING 1000
#define PING_CHECKS 5
new avgcount[MAX_PLAYERS];
new pping[MAX_PLAYERS];
SetTimer("Ping_Timer", 5000, true);
forward Ping_Timer();
public Ping_Timer()
{
foreach(Player, i)
{
avgcount[i]++;
new ping = pping[i];
pping[i] = GetPlayerPing(i);
pping[i] = ping + pping[i];
if((avgcount[i]%PING_CHECKS) == 0)
{
pping[i] = (pping[i]/avgcount[i]);
if(pping[i] > MAX_PING)
{
new name[24], string[128];
GetPlayerName(i, name, sizeof(name));
format(string, sizeof(string), "[PLUTO AC]: %s has been kicked for high ping (%d/%d)", name, pping[i], MAX_PING);
SendClientMessageToAll(COLOR_REDONLY, string);
Kick(i);
}
else pping[i] = 0;
}
}
}
stock GetVehicleSpeed(vehicleid)
{
new Float:v_vX, Float:v_vY, Float:v_vZ, Float:retres;
GetVehicleVelocity(vehicleid, v_vX, v_vY, v_vZ);
retres = floatsqroot(floatabs(floatpower(v_vX + v_vY + v_vZ, 2)));
return floatround(retres * 100, floatround_ceil);
}
#include <a_samp>
#define PRESSED(%0) (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
new bool: FirstTime[MAX_PLAYERS];
public OnPlayerDisconnect(playerid, reason)
{
FirstTime[playerid] = false;
return true;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(PRESSED(128) && GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
{
if(FirstTime[playerid])
{
SetPVarInt(playerid, "weaponActual", GetPlayerWeapon(playerid));
FirstTime[playerid] = false;
}
NextSlot(playerid, GetPVarInt(playerid, "weaponActual"));
}
return 1;
}
NextSlot(playerid, weaponinuse)
{
static weapons[13][2], i, j;
for (i = 2; i < 13; ++i)
{
GetPlayerWeaponData(playerid, i, weapons[i][0], weapons[i][1]);
if(weapons[i][0] == weaponinuse) j=i;
}
while(j < 7)
{
j++;
if(weapons[j][0])
{
SetPlayerArmedWeapon(playerid, weapons[j][0]);
SetPVarInt(playerid, "weaponActual", weapons[j][0]);
return true;
}
}
SetPlayerArmedWeapon(playerid, weapons[2][0]);
SetPVarInt(playerid, "weaponActual", weapons[2][0]);
return true;
}
// You will need to change the IDs in the array to match with the weapons
// you do not want used inside of the script
/*
Function:
AdjustWeapons
Params:
playerid - The ID of the player
Usage:
Checks for certain weapons, if that weapon is armed
then it will replace it with a sub-machine gun if
the player has one. If not, it will set to fist.
Returns:
N/A
*/
stock AdjustWeapons( playerid )
{
new
ForbiddenWeapons[ ] = { 24, 27 }
;
for( new i = 0; i < sizeof( ForbiddenWeapons ); i ++ )
{
if( GetPlayerWeapon( playerid ) == ForbiddenWeapons[ i ] )
{
new
weapon,
ammo
;
GetPlayerWeaponData( playerid, 4, weapon, ammo );
if( ammo > 0 )
SetPlayerArmedWeapon( playerid, weapon );
else
SetPlayerArmedWeapon( playerid, 0 );
}
}
}
/*
Function:
AdjustWeaponsEx
Params:
playerid - The ID of the player
slot - The ID of the slot to replace the forbidden weapon with
weapon = 0 - The ID of the weapon to replace with (if the slot specified is unoccupied)
Usage:
Checks for certain weapons, if that weapon is armed
it will replace it with a weapon in the specified
slot. If there are no weapons in that slot, it will
replace it with the specified weapon ID (default = 0)
If that weapon is not found either, it will default
back to fist.
Returns:
N/A
*/
stock AdjustWeaponsEx( playerid, slot, weapon = 0 )
{
new
ForbiddenWeapons[ ] = { 24, 27 }
;
for( new i = 0; i < sizeof( ForbiddenWeapons ); i ++ )
{
if( GetPlayerWeapon( playerid ) == ForbiddenWeapons[ i ] )
{
new
weapon_s,
ammo
;
GetPlayerWeaponData( playerid, slot, weapon_s, ammo );
if( ammo <= 0 )
{
GetPlayerWeaponData( playerid, GetWeaponSlot( weapon ), weapon_s, ammo );
if( ammo <= 0 )
SetPlayerArmedWeapon( playerid, 0 );
else
SetPlayerArmedWeapon( playerid, weapon );
}
else
SetPlayerArmedWeapon( playerid, weapon_s );
}
}
}
/*
Function:
GetWeaponSlot
Params:
weaponid - The ID of the weapon
Usage:
Gets the slot ID for the specified weapon
Returns:
The returned slot ID. (Default = -1)
*/
stock GetWeaponSlot( weaponid )
{
switch( weaponid )
{
case 0, 1: return 0;
case 2..9: return 1;
case 10..15: return 10;
case 16..18, 39: return 8;
case 22..24: return 2;
case 25..27: return 3;
case 28, 29, 32: return 4;
case 30, 31: return 5;
case 33, 34: return 6;
case 35..38: return 7;
case 40: return 12;
case 41..43: return 9;
case 44..46: return 11;
default: return -1;
}
return -1;
}
// Will check if the player has a weapon in slot 5 and put that weapon
// If not, it will switch the player to weapon ID 16
// If none of the above are possible (meaning the player has no weapons in slot 5 and no weapon ID 16), it will default to fist
// That is all considering the player entered the vehicle with a weapon that corresponds to the IDs in the array
public OnPlayerStateChange( playerid, newstate, oldstate )
{
if( newstate == PLAYER_STATE_PASSENGER )
AdjustWeaponsEx( playerid, 5, 16 );
return 1;
}