Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - reaper

#1
I have created two threads, one each for addition and subtraction. I want them to run simultaneously, what are the possible ways for achieving concurrency?
function onScriptLoad()
{
local coro1 = newthread(add);
local coro2 = newthread(sub);
local addition=coro1.call(0);
local subtraction=coro2.call(50);
local i=1;
do
 {
 print("suspend passed ("+addition+")\n");
 print("suspend passed ("+subtraction+")\n");
 if(coro1.getstatus()=="suspended")
 addition= coro1.wakeup("Addition started "+i);
 if(coro2.getstatus()=="suspended")
 subtraction= coro2.wakeup("Subtraction started "+i);
 ++i;
 }while(coro1.getstatus()=="suspended"||coro2.getstatus()=="suspended");
}
x <- 0;
y <- 50;
function add(x)
{
 while(x<50)
 {
 x=x+5;
 print(x);
 if(x==25)
 local ret = suspend("addition suspended");
 }
}

function sub(y)
{
while(y>0)
 {
 y=y-5;
 print(y);
 if(y==25)
 local ret = suspend("subtraction suspended");
 }
}
#2
Quote from: S.L.C on Mar 01, 2015, 09:48 AMI see that you're looking for a healing function.
No i am not looking for a healing function, that was just an example for the delay function which i created.  I ll look into what you have suggested S.L.C.
#3
I have finally figured out a way to solve this problem

time <- 0;
DelayElapsed <- "False";
function delay( time )
{
local checkpoint = GetTickCount();
local timetaken = checkpoint + time;
while( GetTickCount() <= timetaken ) {}
DelayElapsed = "True";
}

Usage:
delay(2000);
if(DelayElapsed == "True")
{
// Next Lines........
}

Example:
if(cmd == "heal")
{
MessagePlayer("Healing ",player);
delay(5000)
if(DelayElapsed == "True")
{
player.Health=100.0;
MessagePlayer("You have Healed successfully ",player);
}
}

If there is a better way of implementing this, then please leave your suggestions here.
#4
Thanks for the reply Kratos_

Quote from: Kratos_ on Feb 28, 2015, 01:42 PMThis is simple stuff. Do this way :-

function count_down_1( player ) MessagePlayer("3", player);
function count_down_2( player ) MessagePlayer("2", player);
function count_down_3( player ) MessagePlayer("1", player);
function count_down_final( player ) MessagePlayer(" GO GO GO ", player);

NewTimer("count_down_1", 1000, 1, player);   // Will execute after 1 sec of count_down startup
NewTimer("count_down_2", 2000, 1, player);   // 2 sec after the reference instant

You got it wrong pal. What i was trying to say was that i dont want anything to happen for that time period. Like pausing at line 10 for a while say ( 5 sec ) and then resume from line 11. More precisely i need something like On delay Timer i.e After the given time is elapsed it should trigger ON.

Quote from: Kratos_ on Feb 28, 2015, 01:42 PMHmm... Dealing with SQL queries & that too with a timer of short iterating index of 2 seconds ?  This will lag definitely .  Anyway , you can create an empty array first and then push your vectors into it & then take those array indices . Check out this :-

checkpoint_handler <- [];                 // Creating an empty global array without family

function checkpoint_store()
{
local query_handler = QuerySQL( database_handler, "SELECT Xaxis, Yaxis, Zaxis FROM Path" );
while( GetSQLColumnData( query_handler, 0 ) )             // Till the end of the table
{
local x = GetSQLColumnData( query_handler, 0 ), y = GetSQLColumnData( query_handler, 1 ), z = GetSQLColumnData( query_handler, 2 );
checkpoint_handler.push( x );  // 0, 3, 6, 9,    Memory locations of the co-ordinates in the array where they are pushed
checkpoint_handler.push( y );  // 1, 4, 7, 10,
checkpoint_handler.push( z );  // 2, 5, 8, 11. etc
GetSQLNextRow( query_handler );                     
}
FreeSQLQuery( query_handler );           // Freeing up the SQL query
}


Now, you can make an easy algorithm for getting those array indices in the form (x, y, z) = ( n, n+1, n+2 )  .  Where , n = multiple of 3 but less than the size of the array after complete parsing of SQL Table .  Create a timer for doing it after an interval of 2 secs .
Thanks for making things clear here. This changed the way i was looking at it. I thought that i cant get to the next row so came up with that serial no thing ;D

Quote from: Kratos_ on Feb 28, 2015, 01:42 PMI couldn't get it . If player will be given the chance to choose the delay time of heal process then who want to heal himself in 100 seconds ??  Everyone will start giving the value to 1 mili-second for the iteration index of timer .  Although , its possible following this syntax  :-
NewTimer("function_need_to_be_executed", text, 1);   // text should be an integer & in milliseconds.

Sorry this was again about the delay function and i wasnt talking about healing at all, that was an example.
#5
For now i am doing it this way which is not a generator.

sql <- ConnectSQL( "scripts/db.sqlite" );
sno <- array ( 5 , 0 );


if(cmd == "move")
{
NewTimer("move", 100, 200);
}

function move()
{

QuerySQL( sql, "BEGIN TRANSACTION" );
 
  sno[1] ++;
 
      local x = QuerySQL( sql, "SELECT Xaxis FROM  Path WHERE sno = " + sno[1] );
      local xa = GetSQLColumnData( x, 0 );   
local xaxi = xa;
      FreeSQLQuery( x );
 
  local y = QuerySQL( sql, "SELECT Yaxis FROM  Path WHERE sno = " + sno[1] );
      local ya = GetSQLColumnData( y, 0 );
local yaxi = ya;
      FreeSQLQuery( y );
 
  local z = QuerySQL( sql, "SELECT Zaxis FROM  Path WHERE sno = " + sno[1] );
      local za = GetSQLColumnData( z, 0 );
local zaxi = za;
      FreeSQLQuery( z );
 
  QuerySQL( sql, "END TRANSACTION" );
   
  FindVehicle( 114 ).Pos = Vector( xaxi, yaxi, zaxi );
  FindVehicle( 114 ).EulerRotation = Vector( xang, yang, zang );
}

What i am trying to accomplish is something like this

function move()
{

QuerySQL( sql, "BEGIN TRANSACTION" );
 
  sno[1] ++;
 
      local x = QuerySQL( sql, "SELECT Xaxis FROM  Path WHERE sno = " + sno[1] );
      local xa = GetSQLColumnData( x, 0 );   
local xaxi = xa;
      FreeSQLQuery( x );
 
  local y = QuerySQL( sql, "SELECT Yaxis FROM  Path WHERE sno = " + sno[1] );
      local ya = GetSQLColumnData( y, 0 );
local yaxi = ya;
      FreeSQLQuery( y );
 
  local z = QuerySQL( sql, "SELECT Zaxis FROM  Path WHERE sno = " + sno[1] );
      local za = GetSQLColumnData( z, 0 );
local zaxi = za;
      FreeSQLQuery( z );
 
  QuerySQL( sql, "END TRANSACTION" );
     
// i want to generate a vector after a delay for n number of times. even with a for loop i need a delay and how am i supposed to create one?
}

if(cmd == "move")
{
FindVehicle( 114 ).Pos = /* Here i want to call the generated vector */;
}

So can anybody guide me out how to accomplish this??
#6
Help me to figure out how to generate a number or a vector every few seconds.  For example

1
// 2 sec delay
2
// 2 sec delay
3
// 2 sec delay

or

Vector( x, y, z) from database row 1
// 2 sec delay
Vector( x, y, z) from row 2
// 2 sec delay
Vector( x, y, z) from row 3
// so on


And how to create a delay function where after the time given by user the rest of the lines should execute. For Example

delay(time)
{

}

player.Health = 100;
delay(1000) // it should wait for 1 sec and then execute the next lines
print( Healed );
...

I am just learning from other scripts and snippets so please make sure to give me some example so that i can understand properly.