SA-MP Forums

SA-MP Forums (https://forum.sa-mp.com/index.php)
-   Scripting Help (https://forum.sa-mp.com/forumdisplay.php?f=12)
-   -   Little coding questions - For general minor queries 5 (https://forum.sa-mp.com/showthread.php?t=30938)

Nero_3D 23/04/2020 01:59 AM

Re: Little coding questions - For general minor queries 5
 
Quote:

Originally Posted by Electrifying (Post 4141419)
What _: Means? Why and when should I use it?

It is somewhat explained here -> https://wiki.sa-mp.com/wiki/Scripting:tags
But to make it short it is usually used to overwrite tags
pawn Code:
new MyTag: myvar;

if(_: myvar == 0) {
    print("yay");
}

Electrifying 27/04/2020 11:28 PM

Re: Little coding questions - For general minor queries 5
 
Does anyone here can send me the link of ps-format?
Is it still useful to this day?

Nero_3D 27/04/2020 11:53 PM

Re: Little coding questions - For general minor queries 5
 
Quote:

Originally Posted by Electrifying (Post 4142381)
Does anyone here can send me the link of ps-format?
Is it still useful to this day?

Took me literally one search to find it, on the second last page of the main thread attached to this reply
Quote:

Originally Posted by RogueDrifter (Post 3975078)
There you go guys enjoy it ^^

If it is useful, depends, packed strings are only useful if you plan to save a lot of long string globally and you want to save a bit of memory otherwise not

Calinut200 23/05/2020 04:22 PM

Re: Little coding questions - For general minor queries 5
 
how to rezolve?
PHP Code:

if(PlayerText:linia11 == strcmp("PLD_SLOT:r_69","LD_SLOT:r_69"))
 
warning 213tag mismatchexpected tag "PlayerText"but found none ("_"


SkyFlare 24/06/2020 04:46 AM

Re: Little coding questions - For general minor queries 5
 
How to make unbreakable atm machines/objects?, this example isnt working below
Code:

DynamicAtms[atmid][ObjectID] = CreateDynamicObject(DynamicAtms[atmid][ModelID], DynamicAtms[atmid][PosX], DynamicAtms[atmid][PosY], DynamicAtms[atmid][PosZ], 0.0, 0.0, 0.0, 0, 0, -1, 100.0);
        SetDynamicObjectMaterialText(DynamicAtms[atmid][ObjectID],0,"None",50," Arial",24,0,0,0,1);

would be nice to know how this works, thanks in advance.

Alpays 21/07/2020 03:20 PM

Re: Little coding questions - For general minor queries 5
 
what is the difference between

new Float:TDMSpawn[][] =
{
{1,1,1,1},
{1,1,1,1)
}

and

new Float:TDMSpawn[2][4] =
{
{1,1,1,1},
{1,1,1,1)
}

RoboN1X 21/07/2020 05:45 PM

Re: Little coding questions - For general minor queries 5
 
Quote:

Originally Posted by Alpays (Post 4156064)
what is the difference between

new Float:TDMSpawn[][] =
{
{1,1,1,1},
{1,1,1,1)
}

and

new Float:TDMSpawn[2][4] =
{
{1,1,1,1},
{1,1,1,1)
}

The first one will have the compiler calculate the array size based on the initializer, thus it will technically becomes [2][4]. It is only possible if the initial values are declared, so you cant just have:
Code:

new Float:TDMSpawn[][];
The second will have fixed amount array size as you specified, which is [2][4]... giving [1][3] will result error because the array size mismatch and giving more like [3][5] will result a warning because the array must be fully initialized.
Since the array size is explicit, you can declare without initial value, so you can have:
Code:

new Float:TDMSpawn[2][4];
which will have all 0 for initial values.

Note that it is possible to have
Code:

new Float:TDMSpawn[][4] =
{
{1,1,1,1},
{1,1,1,1}
}

In case you will be adding more tdm spawn rows in the initializer but dont want to accidentally change the column size
Code:

new Float:TDMSpawn[][4] =
{
{1,1,1,1},
{1,1,1,1},
{1,1,1,1} // ok
}

Code:

new Float:TDMSpawn[][4] =
{
{1,1,1,1},
{1,1,1,1},
{1,1,1} // error
}


Check out the pawn-lang.pdf documentation

Dignity 22/07/2020 08:44 PM

Re: Little coding questions - For general minor queries 5
 
What would be the most efficient way of removing dynamic objects attached to a vehicle, for ANY vehicle?


I've got more than 10,000 objects easily in my server, so a loop is not ideal...

The only "true" way to consider all objects is by hooking CreateObject, storing the value in a variable and then looping through it, using Streamer_GetIntData to match the vehicle ID and then remove it however considering the amount of objects I have this would end up being very laggy and bad for server performance...


Any alternatives?

coool 25/07/2020 02:49 PM

Re: Little coding questions - For general minor queries 5
 
Quote:

Originally Posted by Dignity (Post 4156216)
What would be the most efficient way of removing dynamic objects attached to a vehicle, for ANY vehicle?


I've got more than 10,000 objects easily in my server, so a loop is not ideal...

The only "true" way to consider all objects is by hooking CreateObject, storing the value in a variable and then looping through it, using Streamer_GetIntData to match the vehicle ID and then remove it however considering the amount of objects I have this would end up being very laggy and bad for server performance...


Any alternatives?

PHP Code:

new AttachedObjects[MAX_VEHICLES][100];
hook AttachObjectToVehicle()
{
    new 
free_slot;
    for (
free_slot 0free_slot sizeof AttachedObjects[vehicled]; free_slot++)
        if (
AttachedObjects[vehicled][free_slot] == 0) break; 
    
AttachedObjects[vehicleid][free_slot] = objectid;
}

DestroyObjectsAttachedToVehicle(vehicleid)
{
    for (new 
isizeof AttachedObjects[vehicleid]; i++)
        
DestroyObject(AttachedObjects[vehicleid][i])


What do you think about this alternative? This loops over only the objects attached to a vehicle.

Dignity 02/08/2020 01:49 PM

Re: Little coding questions - For general minor queries 5
 
Quote:

Originally Posted by coool (Post 4156531)
PHP Code:

new AttachedObjects[MAX_VEHICLES][100];
hook AttachObjectToVehicle()
{
    new 
free_slot;
    for (
free_slot 0free_slot sizeof AttachedObjects[vehicled]; free_slot++)
        if (
AttachedObjects[vehicled][free_slot] == 0) break; 
    
AttachedObjects[vehicleid][free_slot] = objectid;
}

DestroyObjectsAttachedToVehicle(vehicleid)
{
    for (new 
isizeof AttachedObjects[vehicleid]; i++)
        
DestroyObject(AttachedObjects[vehicleid][i])


What do you think about this alternative? This loops over only the objects attached to a vehicle.

Looks good. I thought of doing it in a similar fashion but not using the same loop... this saved me some headache thanks a lot.


All times are GMT. The time now is 07:04 AM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.