SA-MP Forums Archive
little question - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: little question (/showthread.php?tid=64872)

Pages: 1 2


little question - nesty - 07.02.2009

hi i've just a little question
I know how to use a timer(ex) to call a function after some time ok
but i dont wanna that the function will be called directly after i started the server? just after 10 sec.?


Re: little question - Auto-Sized - 07.02.2009

https://sampwiki.blast.hk/wiki/SetTimerEx

Where it says 1000 = 1 sec so 10000 = 10secs


Re: little question - nesty - 07.02.2009

thanks but that wasnt my question i wanted to know how to delay a function after the server started


Re: little question - nesty - 07.02.2009

can someone help me? pls.



Re: little question - Nero_3D - 08.02.2009

You just need to look at the functions

SetTimer(funcname[], time_in_milliseconds, bool:repeat?);
SetTimerEx(funcname[], time_in_milliseconds, bool:repeat?, const format[], {Float,_}:...);

Than you only need to know what public gets called when the server start
If you use a GM its OnGameModeInit() and than main()
If its a filterscript that OnFilterScriptInit()


Re: little question - nesty - 09.02.2009

sry but ...
public Test() starts if I start the server and my timer would restart the function after a few minutes but i wanna that the function only start cause of the timer


Re: little question - nesty - 09.02.2009

can someone help me pls.?

public Test()
{
print("lol");
}


This function will start directly if i start the server but i wanna that the function will called after 1 minute? How can I do this


Re: little question - Eraz0r - 09.02.2009

Код:
OnGameModeInit()
{
 SetTimer("Test",6000,0);
 //CODE
}



Re: little question - nesty - 09.02.2009

Can u give an example? pls.


Re: little question - nesty - 09.02.2009

pawn Код:
OnGameModeInit()
{
 SetTimer("Test",6000,0);
 //CODE
}
pawn Код:
public Test(modelid)
{
print ("lol");
}
The function Test() is called immediately
what can i do?


Re: little question - ICECOLDKILLAK8 - 09.02.2009

6000 = 6 Seconds, Make that longer e.g. for 10 seconds it 10000, Also if you want the timer to repeat then change
this
pawn Код:
SetTimer("Test",6000,0);
to this
pawn Код:
SetTimer("Test",6000,1);
If you need more help on converting Seconds to Milliseconds then ****** it e.g. "How many milliseconds in 1 minute" and that will give you a straight answer


Re: little question - Eraz0r - 09.02.2009

@nesty: Also be sure that you only call the function with the timer and not with Test(); in OnGameModeInit()


Re: little question - nesty - 09.02.2009

ty
it doesnt work here was my idea

pawn Код:
public OnGameModeInit()
{

SetTimer("CreatePickupAtRandPos",6000,0);

}
pawn Код:
public CreatePickupAtRandPos(modelid)
{
    new rand = random(sizeof RandomSpawn);
    RandomPickupid = CreatePickup(modelid, 3, RandomSpawn[rand][0], RandomSpawn[rand][1], RandomSpawn[rand][2]);
}
So that function is called immediately but it should only start cause of the timer
hope u can help me



Re: little question - Eraz0r - 09.02.2009

Well then add the Timer in a command. Or set the time higher. ATM the pickup will be created 6 seconds after u launched the samp-server.exe


Re: little question - nesty - 09.02.2009

I changed the time to a higher one but no effect and when i put the timer in a command the timer has no effect
here my whole idea

pawn Код:
forward CreatePickupAtRandPos(modelid);

pawn Код:
new Float:RandomSpawn[][] =
{
    {2211.2908,2472.7927,10.8203},
    {2191.8694,2500.7825,10.8203},
    {2181.1367,2488.4922,10.8203},
    {2213.7810,2494.0610,10.8203},
    {2202.3906,2474.9817,10.8203},
    {2193.9182,2472.9346,10.8203}
   
}, RandomPickupid;

pawn Код:
//public OnGameModeInit()
SetTimer("CreatePickupAtRandPos", 60_000, false);
CreatePickupAtRandPos(1550);

pawn Код:
public CreatePickupAtRandPos(modelid)
{
    new rand = random(sizeof RandomSpawn);
    RandomPickupid = CreatePickup(modelid, 3, RandomSpawn[rand][0], RandomSpawn[rand][1], RandomSpawn[rand][2]);
}
pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
    if(pickupid == RandomPickupid)
        {
            DestroyPickup(RandomPickupid);
            GivePlayerMoney(playerid, 15_000);
            SetTimerEx("CreatePickupAtRandPos", 30_000, false, "i", 1550);
            // and some TextDraws

        }
  return 1;

}
timer dosent work


Re: little question - Auto-Sized - 10.02.2009

pawn Код:
forward CreateRandomPickup();

new RandomPickup;

new Float:RandomSpawn[4][3] =
{
  {2211.2908,2472.7927,10.8203},//Leave the same for testing purposes saves you running around.
  {2211.2908,2472.7927,10.8203},
  {2211.2908,2472.7927,10.8203},
  {2211.2908,2472.7927,10.8203}
};

new RandomModelType[2][2] =
{
  {1212,23},
  {1274,23}
};

new RandomMoney[3][1] =
{
  {5000},
  {10000},
  {15000}
};

public CreateRandomPickup()
{
  new modeltype= random(sizeof RandomModelType);
  new spawn = random(sizeof RandomSpawn);
  RandomPickup = CreatePickup(RandomModelType[modeltype][0], RandomModelType[modeltype][1], RandomSpawn[spawn][0], RandomSpawn[spawn][1], RandomSpawn[spawn][2]);
  return 1;
}

public OnGameModetInit()
{
  SetTimer("CreateRandomPickup", 60000, false);
  return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
  new RandomMoneyAmount = random(sizeof RandomMoney);
  if(pickupid == RandomPickup)
    {
      DestroyPickup(RandomPickup);
      GivePlayerMoney(playerid, RandomMoney[RandomMoneyAmount][0]);
      SetTimer("CreateRandomPickup", 20000, false);
    }
  return 1;
}
1550 seems to be a object. Just an example. I did test it.


Re: little question - nesty - 11.02.2009

hey thanks a lot it works
(1550 is the moneybag pickup)
later i actually wanted to add random money but u just already have done it
really cool thanks



Re: little question - Auto-Sized - 11.02.2009

NP. I was editing my script so I though I would edit some of it and post as I thought it was relevant.


Re: little question - nesty - 13.02.2009

I have just one last question on this topic...
How can I show the player who pick up the moneybag the amount of the money?


Textdraw3 = TextDrawCreate(112.000000,118.000000,"You found the moneybag");
Textdraw4 = TextDrawCreate(174.000000,79.000000,"Congratulatio ns!!!");
Textdraw5 = TextDrawCreate(254.000000,146.000000,"%d"); <-----// I thought of something like this
Textdraw6 = TextDrawCreate(304.000000,146.000000," $");

(Problem is the random money) hope some1 can help me


Re: little question - Nero_3D - 13.02.2009

for that we only need to change the OnPlayerPickupPickup
pawn Код:
new RandomMoney[5] = { 5_000, 10_000, 15_000, ... };
pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
    if(pickupid == RandomPickup)
    {
        DestroyPickup(RandomPickup);
        SetTimer("CreateRandomPickup", 20000, false);
        new RandomMoneyAmount = random(sizeof RandomMoney), string[10];
        GivePlayerMoney(playerid, RandomMoney[RandomMoneyAmount]);
        Textdraw3 = TextDrawCreate(112.000000,118.000000,"You found the moneybag");
        Textdraw4 = TextDrawCreate(174.000000,79.000000, "Congratulations!!!");
        format(string, sizeof string, "$%d", RandomMoney[RandomMoneyAmount]);
        Textdraw5 = TextDrawCreate(254.000000,146.000000, string);
    }
    return 1;
}
Destroy / Hiding / Changing the textdraw you need to do by yourself