Jump to content
  • 0

Cum pot face sa seteze automat random vremea (weather) pe server cu ID-urile alese de mine


Question

Posted (edited)

Cum pot face sa seteze automat random vremea pe server cu ID-urile (weather) alese de mine

Exemplu: Vreau sa seteze automat weather cu ID-urile 1,2,3,5,9,12,15

Edited by cstef4n

1 answer to this question

Recommended Posts

  • 0
Posted
#include <a_samp>

// Intervalul de timp în milisecunde (Ex: 30 de minute = 30 * 60 * 1000)
#define WEATHER_TIMER_DELAY  (30 * 60 * 1000) 

// Lista cu ID-urile de vreme alese de tine
new const ValidWeathers[] = {1, 2, 3, 5, 9, 12, 15};

public OnGameModeInit()
{
    // Pornim timerul care va apela funcția "ChangeRandomWeather" periodic
    SetTimer("ChangeRandomWeather", WEATHER_TIMER_DELAY, true);
    
    // Opțional: Setăm o vreme random chiar și când se deschide serverul
    ChangeRandomWeather(); 
    return 1;
}

forward ChangeRandomWeather();
public ChangeRandomWeather()
{
    // random(sizeof(ValidWeathers)) alege un index la întâmplare din vector
    new randomIndex = random(sizeof(ValidWeathers));
    new newWeather = ValidWeathers[randomIndex];
    
    // Setăm vremea globală pe server
    SetWeather(newWeather);
    
    // Trimitem un mesaj informativ tuturor jucătorilor (opțional)
    new string[64];
    format(string, sizeof(string), "{FF9900}[Server]{FFFFFF} Vremea a fost schimbată (ID: %d).", newWeather);
    SendClientMessageToAll(-1, string);
    
    return 1;
}
/*
sizeof(ValidWeathers): Află automat câte ID-uri ai pus în listă (în cazul tău, 7 ID-uri). Dacă pe viitor vrei să adaugi și ID-ul 7, doar îl treci în array {1, 2, 3, 5, 9, 12, 15, 7} și codul se va adapta singur.

random(...): Extrage o poziție din listă (de la 0 la 6).

SetWeather(newWeather): Schimbă vremea pentru toți jucătorii care se conectează sau sunt deja pe server.*/

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more details you can also review our Terms of Use and Privacy Policy.