Variable from - to - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Variable from - to (
/showthread.php?tid=474940)
Variable from - to -
_NosiK_ - 10.11.2013
Hello everybody,
I have a problem. I'm making a system and I need variable for 50 objects. But I have a lot of objects, so I would have to do about 500 variables. I need "only" 50 variables but from objectid 440 to 489. I make objects via a command, so I can't put them up.. I hope you understand

(I'm Czech)
Re: Variable from - to -
Sinner - 10.11.2013
You don't need to make 500 variables just so you can use array[440] to array[489]. Just subtract every object id with 440 to get the array index.
Example:
pawn Код:
// your variable to store all the object ids
static ObjectIDs[50];
stock StoreObjectId(objectid) // objectid ranges from 440 to 489
{
new arrayIndex = objectid - 440; // index ranged from 0 to 49
ObjectIDs[arrayIndex] = objectid;
}
stock GetObjectId(objectid)
{
new arrayIndex = objectid - 440; // index ranged from 0 to 49
return ObjectIDs[arrayIndex];
}
EDIT: Tell me if I misunderstood, because you didn't explain too well.
Re: Variable from - to -
Misiur - 10.11.2013
You can use an array:
pawn Код:
new objarray[50];
//then later
for(new i = 0; i != 50; ++i) {
objarray[i] = CreateDynamicObject(...);
}
Re: Variable from - to -
_NosiK_ - 10.11.2013
Eh.. I don't understand that

.. I made clear script for now. So I'll put the command
Код:
if(StavCmd >= 50 ) return SendClientMessage(...);
ObjCmd[StavCmd] = CreateDynamicObject(id, X, Y, 2039.14160, 0.00000, 0.00000, 0.00000, 0, 1);
SetTimerEx("ObjectStatus", 1000, false, "d", ObjCmd[StavCmd]); //1000 - just for now
StatusCmd[ObjCmd[StavCmd]] = 0;
StavCmd ++;
Код:
public ObjectStatus(objectid)
{
if(StatusCmd[objectid] < 120)
{
StatusCmd[objectid] ++;
SetTimerEx("ObjectStatus", 1000, false, "i", objectid);
new Float:x, Float:y, Float:z;
GetDynamicObjectPos(objectid, Float:x, Float:y, Float:z);
SetDynamicObjectPos(objectid, x, y, z+0.01);
}
return 1;
}
If StavCmd is 0, objectID is 103
And I want to make variable only for objectid 103 and more (from 103 to 153).
I hope it's better now