Useful Functions
#41

GetVehicleDriver(vehicleid)
Returns the ID of the player driving in the vehicle. Returns '-1' if nobody is driving in the vehicle.
Код:
stock GetVehicleDriver(vehicleid)
{
  for(new i; i<MAX_PLAYERS; i++)
  {
    if (IsPlayerInVehicle(i, vehicleid))
    {
      if(GetPlayerState(i) == 2)
      {
   		return i;
      }
	}
  }
  return -1;
}
I see that the function I just came up with, was already posted
However, the one I made is a LITTLE bit faster and more server-friendly

pawn Код:
stock GetDriver(vehicleid)
{
    for(new playerid = 0; playerid<MAX_PLAYERS;playerid++)
    {
        if(IsPlayerConnected(playerid))
        {
            if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
            {
                if(IsPlayerInVehicle(playerid,vehicleid)) return playerid;
            }
        }
    }
    return INVALID_PLAYER_ID;
}
This one returns INVALID_PLAYER_ID if the vehicle has no driver, and the player id of a driver if it has.
Reply
#42

Quote:
Originally Posted by KANiS6111
GetVehicleDriver(vehicleid)
Returns the ID of the player driving in the vehicle. Returns '-1' if nobody is driving in the vehicle.
Код:
stock GetVehicleDriver(vehicleid)
{
  for(new i; i<MAX_PLAYERS; i++)
  {
    if (IsPlayerInVehicle(i, vehicleid))
    {
      if(GetPlayerState(i) == 2)
      {
   		return i;
      }
	}
  }
  return -1;
}
I see that the function I just came up with, was already posted
However, the one I made is a LITTLE bit faster and more server-friendly

pawn Код:
stock GetDriver(vehicleid)
{
    for(new playerid = 0; playerid<MAX_PLAYERS;playerid++)
    {
        if(IsPlayerConnected(playerid))
        {
            if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
            {
                if(IsPlayerInVehicle(playerid,vehicleid)) return playerid;
            }
        }
    }
    return INVALID_PLAYER_ID;
}
This one returns INVALID_PLAYER_ID if the vehicle has no driver, and the player id of a driver if it has.
i think sandra write it, and !damo!spiderman....
Reply
#43

Thank you , Andre. I couldn't get the identation right here on forums
Reply
#44

GetSkinGender(skinID);
This function returns the gender of a skin. It can be usefull for example RolePlay-gamemodes...
If a skin is unusable, this function will return '0'
If the skin is a male, this function will return '1'
and if the skin is a female, this function will return '2'

First you need to put this array, containing all skinID's on top of your gamemode/filterscript.
Код:
new SkinArray[] =
{
	3, 4, 5, 6, 7, 8, 42, 65, 74, 86, 119, 149, 208, 268, 273,
	0,1,2,7,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,32,33,34,35,36,37,
	38,40,43,44,45,46,47,48,49,50,51,52,57,58,59,60,61,62,66,67,68,70,71,72,73,78,
	79,80,81,82,83,84,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,110,112,
	113,114,115,116,117,118,120,121,122,123,124,125,126,127,128,131,132,133,134,135,
	136,137,142,143,144,146,147,153,154,155,156,158,159,160,161,162,163,164,165,166,
	167,168,170,171,173,174,175,176,177,179,180,181,182,183,184,185,186,187,188,189,
	200,202,203,204,206,209,210,212,213,217,220,221,222,223,227,228,229,230,234,235,
	236,239,240,241,242,247,248,249,250,252,253,254,255,258,259,260,261,262,264,265,
	266,267,269,270,271,272,274,275,276,277,278,279,280,281,282,283,284,285,286,287,
	288,289,290,291,292,293,294,295,296,297,299,
	9,10,11,12,13,31,39,41,42,53,54,55,56,63,64,69,75,76,77,85,87,88,89,90,91,92,93,
	109,111,129,130,131,138,139,140,141,145,148,150,151,152,157,169,172,178,190,191,
	192,193,194,195,196,197,198,199,201,205,207,211,214,215,216,218,219,224,225,226,
	231,232,233,237,238,243,244,245,246,251,256,257,263,298
};
IMPORTANT NOTE: Do NOT modify this array! Else this function won't work anymore!!


Next put this function somewhere in your script:
Код:
GetSkinGender(skinID)
{
  for(new i; i<sizeof(SkinArray); i++)
  {
    if(SkinArray[i] == skinID)
    {
	  switch(i)
	  {
	    case 0..14: return 0;
	    case 15..221: return 1;
		case 222..299: return 2;
	  }
	  break;
	}
  }
  return 0;
}
Now you can use this function

Example command:
Код:
if(strcmp(cmdtext, "/gender", true)==0)
{
  new gender = GetSkinGender(GetPlayerSkin(playerid));
  if(gender == 1)
  {
    SendClientMessage(playerid, 0x0000FFAA, "You're a male!");
  }
  else if(gender == 2)
  {
    SendClientMessage(playerid, 0xFF00FFAA, "You're a female!");
  }
  return 1;
}
Reply
#45

Does the function include gender benders? :P

WeeDarr
Reply
#46

Quote:
Originally Posted by WeeDarr
Does the function include gender benders? :P

WeeDarr
What's that?
Sorry, my english is not very good
Reply
#47

A transexual :P I was just kidding. Must've taken ages to go through all skin ids...

WeeDarr
Reply
#48

Quote:
Originally Posted by WeeDarr
A transexual :P I was just kidding. Must've taken ages to go through all skin ids...

WeeDarr
Oh lol :P
Yeah it took a while to type all those id's.
First i used http://gtam.info/sampid/skiny_samp.php, but i discovered not all available skins where listed. So i made in pawno a small function to check which id's i was missing. After that i went ingame trough those ID's to see it was a male of female skin.
At last i made a function to sort all ID's from low to high.
Totally it took me about 1,5 hours.
Reply
#49

heh, sandra was first =)

pawn Код:
stock IsSkinFemale(skinid)  
{  
  new Skins[] = {
  9, 10, 11, 12, 13, 31, 39, 40, 41, 54, 55,
  56, 63, 64, 69, 75, 76, 77, 85, 86, 87,
  88, 89, 90, 92, 93, 129, 130, 131, 138,
  140, 141, 145, 148, 150, 151, 152, 157,
  169, 172, 178, 190, 191, 192, 193, 194,
  195, 196, 197, 198, 199, 201, 205, 207,
  211, 214, 215, 216, 218, 219, 224, 225,
  226, 231, 232, 233, 237, 238, 243, 244,
  245, 246, 251, 256, 257, 263, 298
};  
  for(new i = 0; i < sizeof(Skins); i++)  
  {  
  if(skinid == i) return 1;  
  }  
return 0;  
}
Reply
#50

Vehicle Names

Note: Not by me, im not sure who did it, please tell me if you were the creator and I will add your name to this.

EDIT: By [K4L]Leopard
pawn Код:
new VehicleNames[212][] = {
"Landstalker", "Bravura", "Buffalo", "Linerunner", "Perennial", "Sentinel",
"Dumper", "Firetruck" , "Trashmaster" , "Stretch", "Manana", "Infernus",
"Voodoo", "Pony", "Mule", "Cheetah", "Ambulance", "Leviathan", "Moonbeam",
"Esperanto", "Taxi", "Washington", "Bobcat", "Mr Whoopee", "BF Injection",
"Hunter", "Premier", "Enforcer", "Securicar", "Banshee", "Predator", "Bus",
"Rhino", "Barracks", "Hotknife", "Trailer", "Previon", "Coach", "Cabbie",
"Stallion", "Rumpo", "RC Bandit", "Romero", "Packer", "Monster", "Admiral",
"Squalo", "Seasparrow", "Pizzaboy", "Tram", "Trailer", "Turismo", "Speeder",
"Reefer", "Tropic", "Flatbed","Yankee", "Caddy", "Solair","Berkley's RC Van",
"Skimmer", "PCJ-600", "Faggio", "Freeway", "RC Baron","RC Raider","Glendale",
"Oceanic", "Sanchez", "Sparrow", "Patriot", "Quad", "Coastguard", "Dinghy",
"Hermes", "Sabre", "Rustler", "ZR-350", "Walton", "Regina", "Comet", "BMX",
"Burrito", "Camper", "Marquis", "Baggage", "Dozer","Maverick","News Chopper",
"Rancher", "FBI Rancher", "Virgo", "Greenwood","Jetmax","Hotring","Sandking",
"Blista Compact", "Police Maverick", "Boxville", "Benson","Mesa","RC Goblin",
"Hotring Racer", "Hotring Racer", "Bloodring Banger", "Rancher", "Super GT",
"Elegant", "Journey", "Bike", "Mountain Bike", "Beagle", "Cropdust", "Stunt",
"Tanker", "RoadTrain", "Nebula", "Majestic", "Buccaneer", "Shamal", "Hydra",
"FCR-900","NRG-500","HPV1000","Cement Truck","Tow Truck","Fortune","Cadrona",
"FBI Truck", "Willard", "Forklift","Tractor","Combine","Feltzer","Remington",
"Slamvan", "Blade", "Freight", "Streak","Vortex","Vincent","Bullet","Clover",
"Sadler", "Firetruck", "Hustler", "Intruder", "Primo", "Cargobob", "Tampa",
"Sunrise", "Merit", "Utility Truck", "Nevada", "Yosemite", "Windsor", "Monster",
"Monster","Uranus","Jester","Sultan","Stratum","Elegy","Raindance","RCTiger",
"Flash","Tahoma","Savanna", "Bandito", "Freight", "Trailer", "Kart", "Mower",
"Dune", "Sweeper", "Broadway", "Tornado", "AT-400", "DFT-30", "Huntley",
"Stafford", "BF-400", "Newsvan","Tug","Trailer","Emperor","Wayfarer","Euros",
"Hotdog", "Club", "Trailer", "Trailer","Andromada","Dodo","RC Cam", "Launch",
"Police Car LSPD", "Police Car SFPD","Police Car LVPD","Police Ranger",
"Picador", "S.W.A.T. Van", "Alpha", "Phoenix", "Glendale", "Sadler",
"Luggage Trailer","Luggage Trailer","Stair Trailer", "Boxville", "Farm Plow",
"Utility Trailer"
};

Is very useful in scripts.

-Franjdea
Reply
#51

Quote:
Originally Posted by Franjdea
Vehicle Names

Note: Not by me, im not sure who did it, please tell me if you were the creator and I will add your name to this.
pawn Код:
new VehicleNames[212][] = {
"Landstalker", "Bravura", "Buffalo", "Linerunner", "Perennial", "Sentinel",
"Dumper", "Firetruck" , "Trashmaster" , "Stretch", "Manana", "Infernus",
"Voodoo", "Pony", "Mule", "Cheetah", "Ambulance", "Leviathan", "Moonbeam",
"Esperanto", "Taxi", "Washington", "Bobcat", "Mr Whoopee", "BF Injection",
"Hunter", "Premier", "Enforcer", "Securicar", "Banshee", "Predator", "Bus",
"Rhino", "Barracks", "Hotknife", "Trailer", "Previon", "Coach", "Cabbie",
"Stallion", "Rumpo", "RC Bandit", "Romero", "Packer", "Monster", "Admiral",
"Squalo", "Seasparrow", "Pizzaboy", "Tram", "Trailer", "Turismo", "Speeder",
"Reefer", "Tropic", "Flatbed","Yankee", "Caddy", "Solair","Berkley's RC Van",
"Skimmer", "PCJ-600", "Faggio", "Freeway", "RC Baron","RC Raider","Glendale",
"Oceanic", "Sanchez", "Sparrow", "Patriot", "Quad", "Coastguard", "Dinghy",
"Hermes", "Sabre", "Rustler", "ZR-350", "Walton", "Regina", "Comet", "BMX",
"Burrito", "Camper", "Marquis", "Baggage", "Dozer","Maverick","News Chopper",
"Rancher", "FBI Rancher", "Virgo", "Greenwood","Jetmax","Hotring","Sandking",
"Blista Compact", "Police Maverick", "Boxville", "Benson","Mesa","RC Goblin",
"Hotring Racer", "Hotring Racer", "Bloodring Banger", "Rancher", "Super GT",
"Elegant", "Journey", "Bike", "Mountain Bike", "Beagle", "Cropdust", "Stunt",
"Tanker", "RoadTrain", "Nebula", "Majestic", "Buccaneer", "Shamal", "Hydra",
"FCR-900","NRG-500","HPV1000","Cement Truck","Tow Truck","Fortune","Cadrona",
"FBI Truck", "Willard", "Forklift","Tractor","Combine","Feltzer","Remington",
"Slamvan", "Blade", "Freight", "Streak","Vortex","Vincent","Bullet","Clover",
"Sadler", "Firetruck", "Hustler", "Intruder", "Primo", "Cargobob", "Tampa",
"Sunrise", "Merit", "Utility Truck", "Nevada", "Yosemite", "Windsor", "Monster",
"Monster","Uranus","Jester","Sultan","Stratum","Elegy","Raindance","RCTiger",
"Flash","Tahoma","Savanna", "Bandito", "Freight", "Trailer", "Kart", "Mower",
"Dune", "Sweeper", "Broadway", "Tornado", "AT-400", "DFT-30", "Huntley",
"Stafford", "BF-400", "Newsvan","Tug","Trailer","Emperor","Wayfarer","Euros",
"Hotdog", "Club", "Trailer", "Trailer","Andromada","Dodo","RC Cam", "Launch",
"Police Car LSPD", "Police Car SFPD","Police Car LVPD","Police Ranger",
"Picador", "S.W.A.T. Van", "Alpha", "Phoenix", "Glendale", "Sadler",
"Luggage Trailer","Luggage Trailer","Stair Trailer", "Boxville", "Farm Plow",
"Utility Trailer"
};

Is very useful in scripts.

-Franjdea
My list real vehicle names:

pawn Код:
new RealName[][] =
{
  "Jeep Wagoneer","Mercury Cougar","Camaro with Scoop","Big Rig","Jeep Grand Wagoneer",        
  "BMW 7-Series","Dumptruck","SA Firetruck","Peterbuilt","Lincoln Towncar","Dodge Aries",            
  "Acura NSX '05","Chevy Biscayne","Ford Aerostar","Ford Box Van","Ferrari Testarosso",
  "Ford Econoline","Emergency Helicopter","Chevrolet Astrovan","Cadillac Eldorado",
  "Chevy Caprice","Lincoln Mark 7","Chevrolet S10","Chevy Ice Cream Truck",
  "Volkswagen Beach Buggy","AH-64A","Chevrolet Caprice", "International SWAT Van",
  "Securita Van","Dodge Viper","Preditor","Volvo Bus","M1A1 Abrams","Barracks",
  "Ford Hot Rod","Trailer","Nissan Pulsar","Old Coach","Caprice Classic Cab",        
  "Ford Mustang Mach 1","Mercedes Van","RC Bandit","Cadillac Hearse","Packer/Stunt Helper",        
  "Chevy S-10 Monster Truck","Mercedes-Benz S-Class","Chris Craft Stinger","Bell 47G",
  "Piaggio Vespa PX 200","Tram","Trailer","Ferrari F40", "Go-Fast Boat","Orca",
  "Sea Ray 270 Sedan Bridge","Flatbed","1992 Ford F800","Golf Car","Ford Taurus Wagon",        
  "Honda Life '74","Cessna 150 With Floats","Honda CBR 600 '92", "Piaggio Vespa PX 200 '86",
  "Harley Davidson Soft Tail", "RC Red Baron", "RC Raider","Dodge Dart","Plymouth Belverdere",
  "Yamaha DT 200 Dirt Bike","Bell 47G","Hummer H-1","Honda TRX250x '92","Coastguard Boat",          
  "Rescue Boat","Mercury '51","Chevy Chevelle","Curtiss P-40D Warhawk","Mazda RX-7",            
  "Chevy Farm Truck","Chevy Caprice Estate","Porsche 911","Schwinn BMX","Dodge Ramvan",          
  "Volkswagen Bus","Endeavour 42","Equitech M40 '85","Bulldozer","Bell 206L-4",
  "Bell 206B-3","Ford Bronco","Chevrolet Suburban '92","Lincoln Mark 7",
  "Dodge Diplomat","CMN Interceptor DV-15","Ford Mustang LX","Ford Bronco",
  "Honda CRX","Bell 206L-4","Chevy Cargo Van","Ford Moving Van","Jeep Wrangler",          
  "RC Heli","Ford Mustang LX '86","Ford Mustang LX '86","Customised Glendale",        
  "Ford Bronco '80","Mitsubishi 3000 GT","Buick Roadmaster","GMC R.V.","Old Bike",            
  "Schwinn Mesa Mountain Hardtail","C-2 Greyhound","Grumman G-164 AgCat",
  "Pitt's Special","Gas Tanker","International 9370 Truck","Lincoln Towncar",          
  "Chevy Monte Carlo","Chevrolet Monte Carlo","Bombardier Learjet 55",
  "AV-8 Harrier Jump-Jet","Honda CBR 900 RR Fireblade","Honda NSR 500 '01",
  "Kawasaki KZ1000-P21","Chevrolet Cement Truck","Tow Truck '91","Ford Thunderbird",
  "Ford Escort","CSI/FBI Investigation Truck","Dodge Dynasty","Forklift '89","Old Tractor",
  "Combine Harvester","Mercedes-Benz SL-Class","Lincoln Mark 5","Chevy CST '68",          
  "Chevrolet Caprice Droptop","1972 EMD SD40","Amtrak F40PH","Hovercraft","Mercedes Benz E120",
  "Ford GT-40","Dodge Challenger '70","Dodge 100 Series","SA Firetruck","Ford Hotrod",
  "Chevrolet Lumina","Oldsmobile Cutlass Ciera","Sikorsky CH-53","Dodge Roadrunner",        
  "Late 80's Honda Sedan","Mercury Grand Marquis","Chevy 2500","Douglas C-47",
  "GMC Sierra","Jaguar XKE '66","Chevy S-10 Monster Truck","Chevy S-10 Monster Truck",
  "Eagle Talon","Toyota Supra","Impreza 2.5RS '95","Honda Accord Wagon","Nissan R34 Skyline",        
  "Sikorsky UH-60 Black Hawk","RC Tiger","Honda Civic","Oldsmobile Cutlass","Chevy Impala",          
  "Half Life 2 Sand Rail","EMD SD40", "Trailer","Go Kart","Ride-On Lawn Mower",
  "Mercedes-Benz AK 4x4 '91","Elgin Pelican","Caddilac '54","Chevy Bel Air '57",        
  "Boeing 737","Flatbed","Range Rover","Rolls Royce","Honda VFR 400","Dodge Ramvan Newsvan",      
  "Baggage Tow Tractor HTAG-30/40","Trailer","Infinity J30 '92","Honda Goldwing GL1500 '04",
  "Nissan 350Z/240SX","Hotdog Van","Volkswagen Golf","Trailer","Trailer","Lockheed C-5 Galaxy",
  "Cessna 150", "Unknown","CMN Interceptor DV-15","Chevy Caprice LA", "Chevy Caprice SF",
  "Chevy Caprice LV","Chevy Blazer Desert","Chevrolet El Camino '68","S.W.A.T. Van",
  "Dodge Stealth '91","Pontiac Trans AM", "Dodge Dart", "Dodge 100 Series", "Luggage Trailer",
  "Luggage Trailer", "Stair Trailer", "Chevy Cargo Van","Farm Plow", "Chevy 2500 Trailer"
 
};
Reply
#52

Hey, i would like to share with you some of the functions i have created in the last time..
i hope it will help you and it will be useful for some of you

Checks if player is in Bicycle.
pawn Код:
stock IsABicycle(carid)
{

    if(GetVehicleModel(carid)==509||GetVehicleModel(carid)==510||GetVehicleModel(carid)==481)
    {
        return 1;
    }
    return 0;
}
Next function uses for servers with a factions system...
function checks how much players is online from the chosen faction.


pawn Код:
stock GetFactionPlayers(faction)
{
    new mem = 0;
    for(new i = 0; i < GetMaxPlayers(); i++)
    {
        if(IsPlayerConnected(i))
        {
            if(PLAYERLIST_authed[i])
            {
                if(PlayerInfo[i][pFaction] == faction)
                {
                    mem++;
                }
            }
        }
    }
    return mem;
}
Cleaning the chosen player chat..
pawn Код:
ChatCleanup(playerid, lines = 50)
{
  for (new i = 0; i < lines; i++)
  {
    SendClientMessage(playerid, 0, "\n");
  }
}
Example: ChatCleanup(playerid);


Checks if the car is in the Position you set
pawn Код:
stock IsCarInCircle(car,Float:x,Float:y,radius)
{
    if(GetCarDistanceToPoint(car,x,y) < radius)
    {
        return 1;
    }
    return 0;
}
Example: if(IsCarInCircle(140,1500.4252,200.5005,5)) { }

Works same as the last function, but this one uses the Z position too.
pawn Код:
stock IsCarInSphere(vehicleid,Float:x,Float:y,Float:z,radius)
{
    if(GetCarDistanceToPointEx(vehicleid,x,y,z) < radius)
    {
        return 1;
    }
    return 0;
}
This function checks if the icon you wrote is valid or not.
pawn Код:
stock IsValidMapIcon(IconID)
{
    if(IconID >= 0 && IconID <= 63)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

Sets the Player X,Y,Z and the facing angle, also sets the interior and virtualworld, Option to for camera behing player (use 0/1)
pawn Код:
stock SetPlayerArea(playerid,Float:x,Float:y,Float:z,Float:angle,Interior,World,Cameraback)
{
    SetPlayerPos(playerid,x,y,z);
    SetPlayerFacingAngle(playerid,angle);
    SetPlayerInterior(playerid,Interior);
    SetPlayerVirtualWorld(playerid,World);
    if(Cameraback == 1)
    {
        SetCameraBehindPlayer(playerid);
    }
}
Same but for vehicles:
pawn Код:
stock SetCarArea(vehicleid,Float:x,Float:y,Float:z,Float:angle,Interior,World)
{
    SetVehiclePos(vehicleid,x,y,z);
    SetVehicleZAngle(vehicleid,angle);
    LinkVehicleToInterior(vehicleid,Interior);
    SetVehicleVirtualWorld(vehicleid,World);
}

*** EDIT , new functions i made..

This one is not mine, but you'll have to use this for the one i made. ( that's the only one i didnt created here.)
pawn Код:
stock IsSkinValid(SkinID) return ((SkinID >= 0 && SkinID <= 1)||(SkinID == 2)||(SkinID == 7)||(SkinID >= 9 && SkinID <= 41)||(SkinID >= 43 && SkinID <= 85)||(SkinID >=87 && SkinID <= 118)||(SkinID >= 120 && SkinID <= 148)||(SkinID >= 150 && SkinID <= 207)||(SkinID >= 209 && SkinID <= 272)||(SkinID >= 274 && SkinID <= 288)||(SkinID >= 290 && SkinID <= 299)) ? true:false;
That's the function i made, it will avoid server crashes becouse of wrong skin id's.. so every time you use setplayerskin(playerid,skinid)
you will use SetSkin(playerid,skinid) and it will be like a safe function that checks if its valid skin..

pawn Код:
stock SetSkin(playerid,skinid)
{
    if(!IsSkinValid(skinid))
    {
        SendClientMessage(playerid,0xA9A9A9FF,"* This is not a valid Skin ID!");
        return 1;
    }
    SetPlayerSkin(playerid,skinid);
    return 1;
}

[b]Works same as the last functino i made... just with vehicle components.. it checks if the component you wanna add is valid, if it is it will work,
if you wont be valid it will return 1; and it won't work.[/b
]

pawn Код:
stock IsValidComponent(componentid)
{
    if(componentid >= 1000 && componentid <= 1193)
    {
      return 1;
    }
    else
    {
      return 0;
    }
}
pawn Код:
stock AddCarComponent(vehicleid,componentid)
{
    if(!IsValidComponent(componentid))
    {
        return 1;
    }
    AddVehicleComponent(vehicleid,componentid);
    return 1;
}
Reply
#53

Very nice functions.Also the SetPlayerArea and SetCarArea are perfect
Reply
#54

Thanks bro, i appreciate that

btw, i forgot to add the Camera Behind player in the SetCarAera...
so here's the new one if it will help some of you..

pawn Код:
stock SetCarArea(vehicleid,playerid,Float:x,Float:y,Float:z,Float:angle,Interior,World,Camera)
{
    SetVehiclePos(vehicleid,x,y,z);
    SetVehicleZAngle(vehicleid,angle);
    LinkVehicleToInterior(vehicleid,Interior);
    SetVehicleVirtualWorld(vehicleid,World);        
    if(Camera == 1)
    {
       SetCameraBehindPlayer(playerid);
    }
}
Reply
#55

Код:
add(a[],b[])
{
	new i;

	new a_str[256];
	new a_len;
	new a_digit[100];

	format(a_str,255,"%s",a);

	a_len = strlen(a_str);

	for(i = 1;i <= a_len;i++)
	{
	  strdel(a_str,a_len-i+1,a_len);
	  strdel(a_str,0,a_len-i);
	  a_digit[i] = strval(a_str);
		format(a_str,255,"%s",a);
	}

	new b_str[256];
	new b_len;
	new b_digit[100];


	format(b_str,255,"%s",b);
	b_len = strlen(b_str);

	for(i = 1;i <= b_len;i++)
	{
	  strdel(b_str,b_len-i+1,b_len);
	  strdel(b_str,0,b_len-i);
	  b_digit[i] = strval(b_str);
		format(b_str,255,"%s",b);
	}

	new c_digit[100] = 0;
	new c[256];
	c = "0";
	new e;

	for(i = 1;i <= 99;i++)
	{
	  new tmp[256];
		c_digit[i] = a_digit[i] + b_digit[i] + e;
		e = 0;
		if((c_digit[i] >= 10))
		{
			new e_str[256];
			valstr(e_str,c_digit[i]);
			new e_len;
			e_len = strlen(e_str);
			strdel(e_str,e_len-1,e_len);
			e = strval(e_str);
			c_digit[i] = c_digit[i] - e*10;
		}
		valstr(tmp,c_digit[i]);
		strins(c,tmp,1);
	}
	return c;
}
can add upto a sum of 99 digits.
Reply
#56

****** has a habbit of doing that
Reply
#57

StrGetTime
This functions returns the numeric time as string.
pawn Код:
StrGetTime( )
{
    new
      string[ 9 ],
      hours,
      minutes,
      seconds;
       
    gettime( hours , minutes , seconds );
    format( string , sizeof( string ) , "%d:%02d:%02d" , hours , minutes , seconds );
    return string;
}
StrGetDate
This functions can return the current date in different english styles as string.

StrGetDate( 1 ) will return "July 22, 2008" today.

I'd put the months array at the Global variables.
pawn Код:
new months[ 12 ] [ 10 ] = {
  { "January" }, { "February" }, { "March" }, { "April" }, { "May" }, { "June" },
  { "July" }, { "August" }, { "September" }, { "October" }, { "November" }, { "December" }
};
pawn Код:
StrGetDate( type )
{
    new
      string[ 16 ],
      year,
      stryear[ 4 ],
      month,
      day;

    getdate( year , month , day );
    switch( type )
    {
      case 0 : // 10 July 1994
        format( string , sizeof( string ) , "%02d %s %d" , day , months[ month -1 ] , year );

      case 1 : // July 10, 1994
        format( string , sizeof( string ) , "%s %02d, %d" , months[ month -1 ] , day , year );

      case 2 : // 10 07 1994
        format( string , sizeof( string ) , "%02d %02d %d" , day , month , year );

      case 3 : // 10.07.1994
        format( string , sizeof( string ) , "%02d.%02d.%d" , day , month , year );

      case 4 : // 10.7.1994
        format( string , sizeof( string ) , "%d.%d.%d" , day , month , year );

      case 5 : // 10 07 94
      {
        valstr( stryear , year );
        format( string , sizeof( string ) , "%02d %02d %2s" , day , month , stryear[ 2 ] );
      }

      case 6 : // 10.7.94
      {
        valstr( stryear , year );
        format( string , sizeof( string ) , "%d.%d.%2s" , day , month , stryear[ 2 ] );
      }
    }
    return string;
}
Reply
#58

Quote:
Originally Posted by Y_Leѕѕ
Let me introduce you to the wonderful world of formatting options and variables:

Same can be applied to your other function.
Thanks for informing me. I have edited my previous post with the better version. I even added some other types, the last 2 types had to be strings I thought, am I right? I guarantee it to work 7992 years from now!

Once again, thanks ******.
Reply
#59

That function is very nice, Westie. I may use it in the future.

I'll post a function that calculate time with an offset:
Код:
stock ShiftTime(&y=0,&mo=1,&d=1,&h=0,&m=0,&s=0,sy=0,smo=0,sd=0,sh=0,sm=0,ss=0){
	new days[12]={31,28,31,30,31,30,31,31,30,31,30,31};
	s+=ss;
	m+=sm+(s/60);
	h+=sh+(m/60);
	d+=-1+sd+(h/24);
	mo+=smo-1;y+=sy+mo/12;mo%=12;
	if((!(y%4)&&(y%100))||!(y%400))days[1]=29;
	for(new i=sign(d);d/days[mo];d-=i*days[mo]){
		mo+=i;
		if(mo>11||mo<0){
			y+=i;if((!(y%4)&&(y%100))||!(y%400))days[1]=29;else days[1]=28;
		}mo%=12;
	}s%=60;m%=60;h%=24;mo+=1;d+=1;
}stock sign({Float,_}:x){if(x>0)return 1;else if(x<0)return -1;return 0;}
First 6 values are simply integers to get time from. You can put them variables with stored date and time. The other are offset for the time (sy: year offset, smo: month offset, sd: day offset, sh: hour offset, ...)
Offset values can be any integer values including negative values.
That's all.
Reply
#60

Today I have found that
Код:
return "hi";
crashes pawno, so I came up with this:
Constant string return.
pawn Код:
stock csReturn(string[])
{
    return string;
}
Now you can return your string like this:

return csReturn("Hi");

and it won't give you an error.

UPDATE:

Or use this:
pawn Код:
#define Returns_%1; new tstr[128]; tstr=%1; return tstr;
on top of your script to make you able to return strings like this:
pawn Код:
Returns_"Hi";
Reply


Forum Jump:


Users browsing this thread: 16 Guest(s)