What are you on about? Saying something is the best you've ever seen is a complement, not an insult!
|
Who you talking to?
If your talking to me: This is a topic where you post snippets, not insult people. |
new
Veiculos = -1
;
stock sDestroyVehicle(vehicleid)
{
if(GetVehicleModel(vehicleid)) return false;
Veiculos--;
return CallRemoteFunction("DestroyVehicle", "i", vehicleid);
}
stock sAddStaticVehicle(modelid, Float:spawn_x, Float:spawn_y, Float:spawn_z, Float:angle, color1, color2)
{
Veiculos++;
return CallRemoteFunction("AddStaticVehicle", "ifffffii", modelid, Float:spawn_x, Float:spawn_y, Float:spawn_z, Float:angle, color1, color2);
}
stock sAddStaticVehicleEx(modelid, Float:spawn_x, Float:spawn_y, Float:spawn_z, Float:angle, color1, color2, respawn_delay)
{
Veiculos++;
return CallRemoteFunction("AddStaticVehicleEx", "ifffffiii", modelid, Float:spawn_x, Float:spawn_y, Float:spawn_z, Float:angle, color1, color2, respawn_delay);
}
stock sCreateVehicle(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawn_delay)
{
Veiculos++;
return CallRemoteFunction("CreateVehicle", "iffffiii", modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawn_delay);
}
#define DestroyVehicle sDestroyVehicle
#define AddStaticVehicle sAddStaticVehicle
#define AddStaticVehicleEx sAddStaticVehicleEx
#define CreateVehicle sCreateVehicle
#define GetMaxVehicles() Veiculos
public OnFilterScriptInit()
{
AddStaticVehicle(411, 0.0,0.0,0.0, 0.0, 0,0);
AddStaticVehicle(411, 0.0,0.0,0.0, 0.0, 0,0);
AddStaticVehicle(411, 0.0,0.0,0.0, 0.0, 0,0);
AddStaticVehicle(411, 0.0,0.0,0.0, 0.0, 0,0);
AddStaticVehicle(411, 0.0,0.0,0.0, 0.0, 0,0);
AddStaticVehicle(411, 0.0,0.0,0.0, 0.0, 0,0);
AddStaticVehicle(411, 0.0,0.0,0.0, 0.0, 0,0);
AddStaticVehicle(411, 0.0,0.0,0.0, 0.0, 0,0);
AddStaticVehicle(411, 0.0,0.0,0.0, 0.0, 0,0);
AddStaticVehicle(411, 0.0,0.0,0.0, 0.0, 0,0);
printf("Have: %d vehicles", GetMaxVehicles());
DestroyVehicle(0);
printf("Now, Have: %d Veнvehicles", GetMaxVehicles());
return 1;
}
stock GetTotalVehicles()
{
new VehicleCount = 0;
for(new vehicle = 1; vehicle < MAX_VEHICLES; vehicle++)
{
new Float:Pos[3];
GetVehiclePos(vehicle, Pos[0], Pos[1], Pos[2]);
if(Pos[0] != 0.0 && Pos[1] != 0.0) VehicleCount++
}
return VehicleCount;
}
stock GetMaxVehicles() {
return MAX_VEHICLES;
}
stock GetVehiclesCount() {
new
iCount
;
for(new i = 1; i < MAX_VEHICLES; ++i) {
if(GetVehicleModel(i)) {
iCount++;
}
}
return iCount;
}
stock GetVehiclesCount() {
new car = CreateVehicle(522,0,0,0,0,0,0,-1);
DestroyVehicle(car);
car = car-1;
return car;
}
pawn Code:
|
pawn Код:
|
#include <a_samp>
stock GetTotalVehicles()
{
new vehc = 0;
for(new x; x != MAX_VEHICLES; ++x) {
if(GetVehicleModel(x)) vehc++;
}
return vehc;
}
main () {
CreateVehicle(520, 2109.1763, 1503.0453, 32.2887, 82.2873, 0, 1, 60); // 1
CreateVehicle(520, 2109.1763, 1503.0453, 32.2887, 82.2873, 0, 1, 60); // 2
CreateVehicle(520, 2109.1763, 1503.0453, 32.2887, 82.2873, 0, 1, 60); // 3
CreateVehicle(520, 2109.1763, 1503.0453, 32.2887, 82.2873, 0, 1, 60); // 4
CreateVehicle(520, 2109.1763, 1503.0453, 32.2887, 82.2873, 0, 1, 60); // 5
CreateVehicle(520, 2109.1763, 1503.0453, 32.2887, 82.2873, 0, 1, 60); // 6
CreateVehicle(520, 2109.1763, 1503.0453, 32.2887, 82.2873, 0, 1, 60); // 7
DestroyVehicle(4); // 6
DestroyVehicle(6); // 5
DestroyVehicle(2); // 4
printf("have %d vehicles on server", GetTotalVehicles()); // = 4 vehicles
DestroyVehicle(1); //
printf("have %d vehicles on server", GetTotalVehicles()); // = 3 vehicles
quit(); // http://slice-vps.nl/ppg/ :p
}
#include <a_samp>
new totalVeh = 0;
#define GetTotalVehicles() totalVeh
forward InternalCVeh(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawn_delay);
public InternalCVeh(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawn_delay) {
return CreateVehicle(modelid, x, y, z, angle, color1, color2, respawn_delay);
}
forward InternalDVeh(id);
public InternalDVeh(id) {
return DestroyVehicle(id);
}
#define CreateVehicle totalVeh ++, InternalCVeh
#define DestroyVehicle(%0) totalVeh = GetVehicleModel(%0) ? totalVeh - 1 :totalVeh , InternalDVeh(%0)
main () {
CreateVehicle(520, 2109.1763, 1503.0453, 32.2887, 82.2873, 0, 1, 60); // 1
CreateVehicle(520, 2109.1763, 1503.0453, 32.2887, 82.2873, 0, 1, 60); // 2
CreateVehicle(520, 2109.1763, 1503.0453, 32.2887, 82.2873, 0, 1, 60); // 3
CreateVehicle(520, 2109.1763, 1503.0453, 32.2887, 82.2873, 0, 1, 60); // 4
CreateVehicle(520, 2109.1763, 1503.0453, 32.2887, 82.2873, 0, 1, 60); // 5
CreateVehicle(520, 2109.1763, 1503.0453, 32.2887, 82.2873, 0, 1, 60); // 6
CreateVehicle(520, 2109.1763, 1503.0453, 32.2887, 82.2873, 0, 1, 60); // 7
DestroyVehicle(4); // 6
DestroyVehicle(6); // 5
DestroyVehicle(2); // 4
printf("have %d vehicles on server", GetTotalVehicles()); // = 4 vehicles
DestroyVehicle(1); //
printf("have %d vehicles on server", GetTotalVehicles()); // = 3 vehicles
quit(); // http://slice-vps.nl/ppg/ :p
}
The vehicle model ID, or 0 if the vehicle doesn't exist. |
new pVehicle = GetPlayerVehicleID(playerid), engine, invalidparam;
GetVehicleParamsEx(pVehicle, engine, invalidparam, invalidparam, invalidparam, invalidparam, invalidparam, invalidparam);
if(engine == -1) ClearAnimations(playerid);//Or RemovePlayerFromVehicle(OnPlayerStateChange&passenger newstate)
There is a problem in the code? Here it worked perfectly. Only do now to AddStaticVehicle and others. You know it.
_ -> https://sampwiki.blast.hk/wiki/GetVehicleModel But you need to create loops in all vehicles ids (slower). It is better to use redefine functions |
The main problem with your code is that it doesn't work if you add vehicles inside gamemodes and filterscripts, they will be counted separately. Next to that the issue of where to put the addition, and the fact that you don't use ALS are minor.
|
#include <a_samp>
new totalVeh = 0;
#define GetTotalVehicles1() totalVeh
stock GetTotalVehicles2()
{
new vehc = 0;
for(new x; x != MAX_VEHICLES; ++x) {
if(GetVehicleModel(x)) vehc++;
}
return vehc;
}
forward InternalCVeh(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawn_delay);
public InternalCVeh(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawn_delay) {
return CreateVehicle(modelid, x, y, z, angle, color1, color2, respawn_delay);
}
forward InternalDVeh(id);
public InternalDVeh(id) {
return DestroyVehicle(id);
}
#define CreateVehicle totalVeh ++, InternalCVeh
#define DestroyVehicle(%0) totalVeh = GetVehicleModel(%0) ? totalVeh - 1 :totalVeh , InternalDVeh(%0)
main()
{
}
public OnGameModeInit()
{
CreateVehicle(520, 2109.1763, 1503.0453, 32.2887, 82.2873, 0, 1, 60);
printf("You have %d or %d vehicles on server", GetTotalVehicles1(), GetTotalVehicles2());
}
#define FILTERSCRIPT
#include <a_samp>
new totalVeh = 0;
#define GetTotalVehicles1() totalVeh
stock GetTotalVehicles2()
{
new vehc = 0;
for(new x; x != MAX_VEHICLES; ++x) {
if(GetVehicleModel(x)) vehc++;
}
return vehc;
}
forward InternalCVeh(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawn_delay);
public InternalCVeh(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawn_delay) {
return CreateVehicle(modelid, x, y, z, angle, color1, color2, respawn_delay);
}
forward InternalDVeh(id);
public InternalDVeh(id) {
return DestroyVehicle(id);
}
#define CreateVehicle totalVeh ++, InternalCVeh
#define DestroyVehicle(%0) totalVeh = GetVehicleModel(%0) ? totalVeh - 1 :totalVeh , InternalDVeh(%0)
public OnFilterScriptInit()
{
CreateVehicle(520, 2109.1763, 1503.0453, 32.2887, 82.2873, 0, 1, 60);
printf("You have %d or %d vehicles on server", GetTotalVehicles1(), GetTotalVehicles2());
}
Well, you cannot just get last ID of car.
What if Vehicle ID 100, 124, 156,175,201 is destroyed? Then it will replace id 100, and return 99. |
Cant it be improved if we leave strcat out and pass the address directly to strfind ?
|
stock strdel_words(string[], ...) {
new pos = 0, len;
for (new i = numargs() - 1; i > 0; i--) {
len = strlen(@A[i]);
while (-1 != (pos = strfind(string, @A[i], true)))
strdel(string, pos, pos + len);
}
}
SELECT MIN(Table.Uniqueid + 1) AS freeID\ FROM Table\ LEFT JOIN Table tf1\ ON Table.Uniqueid + 1 = tf1.Uniqueid\ WHERE tf1.Uniqueid IS NULL