Timers.

Started by FarisDon, Jan 29, 2016, 08:59 AM

Previous topic - Next topic

FarisDon

Well, I just want to ask that can't i add timers to the bump? like we do in Pickups?
I know obviously we can't, and i've only one function "NewTimer" which when i'll add, will probably lag since those same model objects are likely 10-11, and people will bump them, and many timers will be used probably causing the script/server lag, so is their any other way?
Edit : -
function onObjectBump( object, player )
{
local q = QuerySQL( db, "SELECT * FROM Objects WHERE rowid='" + object.ID + "'" );
if ( object.Model == 513 )
{
ClientMessage("[ " + GetSQLColumnData( q, 0 ) + " ],[ " + GetSQLColumnData( q, 1 ) + " ]
, [ " + GetSQLColumnData( q, 2 ) + " ]",player,255,255,0); 
object.World = 2;
NewTimer( "SetObject", 5000, 1,1 ,object.ID );
FreeSQLQuery( q );
}
}
function SetObject( world, ID )
{
 local Object = FindObject(ID.tointeger());
if ( Object)
{
     Object.World=1;   
}
}
As you can see, I guess, i've made my code far enough secure to not to lag, but i'm not really sure, I just want to ask that if it can lag, and how can i make it "NOT TO LAG"
P.S : - Sorry, for my bad English.

DizzasTeR

Your approach is horrible... What you are trying to implement is going to cause lags and without a proper algorithm you can't make it 'not lag' magically.

FarisDon

#2
Quote from: Doom_Kill3R on Jan 29, 2016, 10:13 AMYour approach is horrible... What you are trying to implement is going to cause lags and without a proper algorithm you can't make it 'not lag' magically.
Man, so what can, I do, for it :(? I mean how i can make it not lag, any idea : [ any advise? also, I want to create something that's why i've made SetObject, cause i don't want that to show, for a purpose, after being hitted by a person, for a pacific time! :( Please any advise.
Sorry, i'm not rude or something just my, English sounds like it.
I'm here just to take help with my buggy/laggy code.
It's not like others who are taking codes from somewhere else, i'm making them by my own, want to know logics, so i don't commit the mistakes million time, and then i would be fixing the whole script, a proper step can make my future better.
P.S: PLEASE HELP ME.

FarisDon

Eh, sorry don't really want to spam, but, i'm really curious to know whats wrong with this code, i mean how it will lag, and how to fix that lag thingy :( ?

EK.IceFlake

It'll lag because you edited the db every time you bumped an object. Instead save it in a table and onScriptUnload do it in db and also some 30 minute etc timers to save just so if your server crashes not much will disappear.

FarisDon

Quote from: NE.CrystalBlue on Jan 30, 2016, 03:50 AMIt'll lag because you edited the db every time you bumped an object. Instead save it in a table and onScriptUnload do it in db and also some 30 minute etc timers to save just so if your server crashes not much will disappear.
Well, I understood what you mean, but i'm not editing the "DB", i'm just querying the information from it, to send to the server, save which thing in the table lol ? and sorry, i'll avoid making such timers which will surely can crash my server as well, anyway my server is at, Direct Save Mode, it doesn't need any timer, for saving thou.

EK.IceFlake

Sorry I got a bit wrong.
What I mean is save your db stuff in a table
hMyUniversalTable <- {};
and read from that table instead of that select.

FarisDon

Quote from: NE.CrystalBlue on Jan 30, 2016, 07:39 AMSorry I got a bit wrong.
What I mean is save your db stuff in a table
hMyUniversalTable <- {};
and read from that table instead of that select.
Dude, Let me clear one thing, for you, If you are creating a whole Prop System, are you gonna store the DATA in the table? Who buys, it will not be SAVED! in that array when it will be restarted, also i don't know about this array very much anyway, i'll learn it surely, if you could tell it now, i'll appreciate it, but that's not the topic right now, can anybody clearly tell me how can I really fix this stuff, cause, for Saving  "Database" is the best, i'm not creating Objects in the DATABASE, i'm already saving them in the Array BLA < - BLA...... 

DizzasTeR

BLA <- BLA  is not considered an array but Global Variable.

myArray <- array( 10 ) // This is a Global Array myArray2 <- []; // Another Global array

FarisDon

Quote from: Doom_Kill3R on Jan 30, 2016, 10:51 AMBLA <- BLA  is not considered an array but Global Variable.

myArray <- array( 10 ) // This is a Global Array myArray2 <- []; // Another Global array
Thank you, Sir, for telling that, but I want to ask one more question, please don't get this as annoying, I'm kinda confused, so i've saved my objects in an Global variable, and enable bumping from it, and for a quite time, i don't want somebody to see it after bumping it, so as everybody said that timer can lag, my algorithm isn't good, and i've to save them in the array, I want to ask how? it's told to store in a table/Global variable, and i've just did that to store objects in them, so how it's still wrong, i'm kinda much confused, what's wrong with this code, and how can i store it in arrays mean except the Objects, if you mean to store world and stuff, and etc, please help me, I really trust, and respect you more then any one here, Sir.

DizzasTeR

Please do not call me Sir, we all have to start from somewhere and what I like about you is the enthusiasm to learn.

This is a simple method which you can use, I haven't given it much thought but I just wanted to give you an idea. You don't need to use a database for hiding an object.

function onScriptLoad()
{
CreateObject( 561, 1, Vector( 0, 0, 2 ), 255 ).TrackingBumps = true;
CreateObject( 561, 1, Vector( 2, 0, 2 ), 255 ).TrackingBumps = true;
CreateObject( 561, 1, Vector( 0, 1, 2 ), 255 ).TrackingBumps = true;
}

function onObjectBump( object, player )
{
object.World = 2;
NewTimer( "RestoreBumpedObjects", 6000, 1, object.ID );
}

function RestoreBumpedObjects( id_Object )
{
local object = FindObject( id_Object );
if( object )
object.World = 1;
}

FarisDon

Thank you, so much this gave me a wonderful idea :) locked

KAKAN

Quote from: [TBS]Destroyer on Jan 30, 2016, 02:39 PMThank you, so much this gave me a wonderful idea :) locked
You again forgot to lock :P
oh no

FarisDon

Quote from: KAKAN on Jan 30, 2016, 04:50 PM
Quote from: [TBS]Destroyer on Jan 30, 2016, 02:39 PMThank you, so much this gave me a wonderful idea :) locked
You again forgot to lock :P
I didn't forgot, actually, I did click the Lock Topic, but as I was using my Mobile, I didn't noticed that it didn't got locked -,-
Anyway Locked.