31.03.2012, 11:20
Useful Snippets
31.03.2012, 13:11
30.04.2012, 18:26
How to get MaxVehicles on Sever
This snipped add function "GetMaxVehicles()", very easy to use.
You can make test..
This snipped add function "GetMaxVehicles()", very easy to use.
pawn Код:
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
You can make test..
pawn Код:
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;
}
30.04.2012, 19:01
Why so.. so.. different? Its very easy without configuring script that much:
pawn Код:
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;
}
30.04.2012, 19:15
"Max" in GetMaxPlayers means maximum, just FYI. So here's a correct version of your function:
pawn Код:
stock GetMaxVehicles() {
return MAX_VEHICLES;
}
30.04.2012, 19:16
Even easier:
pawn Код:
stock GetVehiclesCount() {
new
iCount
;
for(new i = 1; i < MAX_VEHICLES; ++i) {
if(GetVehicleModel(i)) {
iCount++;
}
}
return iCount;
}
30.04.2012, 21:52
pawn Код:
stock GetVehiclesCount() {
new car = CreateVehicle(522,0,0,0,0,0,0,-1);
DestroyVehicle(car);
car = car-1;
return car;
}
30.04.2012, 22:10
01.05.2012, 02:10
Quote:
pawn Код:
|
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
}
pawn Код:
#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
}
01.05.2012, 07:23
Why put the count code in the defines instead of the functions? And what about AddStaticVehicle? And filterscripts? RyDeR`'s code is the most robust yet.
Also, since when is that a good global variable name?
Also, since when is that a good global variable name?
01.05.2012, 17:00
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
_
-> https://sampwiki.blast.hk/wiki/GetVehicleModel
Quote:
The vehicle model ID, or 0 if the vehicle doesn't exist. |
02.05.2012, 01:24
For DM servers, a way to prevents "g abuse" without loops finding a driver.
Put into OnPlayerEnterVehicle or OnPlayerStateChange:
Put into OnPlayerEnterVehicle or OnPlayerStateChange:
pawn Код:
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)
02.05.2012, 09:15
Quote:
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 |
02.05.2012, 21:41
If you want to adapt it to your gamemode, make to AddStaticVehicle, AddStaticVehicleEx, etc.. If possible use global server variables (GVars !?) and includes with code. I'm SURE it is functional
02.05.2012, 21:48
OK, run these two modes together and look at the output:
I'm not even bothered about AddStaticVehicle/Ex at this point.
pawn Code:
#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());
}
pawn Code:
#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());
}
03.05.2012, 06:25
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.
What if Vehicle ID 100, 124, 156,175,201 is destroyed? Then it will replace id 100, and return 99.
03.05.2012, 11:16
Quote:
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. |
The only good way to do it by hooking CreateVehicle is by having a global counter variable that is incremented in Create* and decremented on Destroy*.
But then you obviously have the problem of multiple different scripts having individual vehicle counts, therefore the only good way is looping through them all and checking if the model is valid.
I had another idea but I think it's too much work for the results really:
- Create a variable that holds the highest id.
- Hook CreateV. function so when a vehicle is created it checks if the ID is higher than the last marked ID from CreateV.
- If it is assign the new highest ID to the variable.
- Loop up to that ID on the count function, this way the loop doesn't to unneeded work if you have a server with only 200 vehicles on (MAX_VEHICLES is 2000 right?)
I guess that would work across multiple scripts right?
05.05.2012, 14:54
Cant it be improved if we leave strcat out and pass the address directly to strfind ?
05.05.2012, 15:14
Quote:
Cant it be improved if we leave strcat out and pass the address directly to strfind ?
|
Btw, using pointers.inc, this function could be as simple as:
pawn Code:
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);
}
}
05.05.2012, 16:48
Could you make a strreplace that works in OnPlayerText properly? even RyDeR`'s has a bug in OnPlayerText ;'\
EDIT: LOL I just realized you made one.. gonna test thanks
----
Here's a function to find a free slot in a unique column
EDIT: LOL I just realized you made one.. gonna test thanks
----
Here's a function to find a free slot in a unique column
Code:
SELECT MIN(Table.Uniqueid + 1) AS freeID\ FROM Table\ LEFT JOIN Table tf1\ ON Table.Uniqueid + 1 = tf1.Uniqueid\ WHERE tf1.Uniqueid IS NULL
« Next Oldest | Next Newest »
Users browsing this thread: 2 Guest(s)