Traffic Lights

Započeo devster, Jul 27, 2023, 20:43:00 POSLE PODNE

prethodna tema - sledeća tema

0 članova i 3 gostiju pregledaju ovu temu.

Tip: Include
Slike ili Video: //
Opis i dodatne informacije: //
Download link: //
Scan link: //
Credits: realnaith

[pawn]
/*
* Traffic Lights Control Include
* Author: [realnaith]
* Version: 1.0
*/

#define MAX_TRAFFIC_LIGHTS 10

#define TL_RED      0
#define TL_YELLOW   1
#define TL_GREEN    2

new TrafficLight[MAX_TRAFFIC_LIGHTS][3]; //
  • = Red, [1] = Yellow, [2] = Green

    stock CreateTrafficLight(Float:x, Float:y, Float:z)
    {
        static LightIndex = 0;

        if (LightIndex >= MAX_TRAFFIC_LIGHTS) return -1;

        TrafficLight[LightIndex][TL_RED] = CreateObject(19377, x, y, z);
        TrafficLight[LightIndex][TL_YELLOW] = CreateObject(19377, x, y, z);
        TrafficLight[LightIndex][TL_GREEN] = CreateObject(19377, x, y, z);

        SetObjectMaterial(TrafficLight[LightIndex][TL_RED], 0, 131, "models/txd/traffic1.txd");
        SetObjectMaterial(TrafficLight[LightIndex][TL_YELLOW], 0, 130, "models/txd/traffic1.txd");
        SetObjectMaterial(TrafficLight[LightIndex][TL_GREEN], 0, 132, "models/txd/traffic1.txd");

        LightIndex++;
        return LightIndex - 1;
    }

    stock SetTrafficLightState(lightID, trafficlightstate)
    {
        if (lightID < 0 || lightID >= MAX_TRAFFIC_LIGHTS) return false;
        if (trafficlightstate < TL_RED || trafficlightstate > TL_GREEN) return false;

        for (new i = 0; i < 3; i++)
        {
            SetObjectMaterial(TrafficLight[lightID], 0, 129, "models/txd/traffic1.txd");
        }

        SetObjectMaterial(TrafficLight[lightID][trafficlightstate], 0, 131 + trafficlightstate, "models/txd/traffic1.txd");

        return true;
    }

    stock ToggleTrafficLight(lightID)
    {
        if (lightID < 0 || lightID >= MAX_TRAFFIC_LIGHTS) return false;

        new currentState = GetObjectMaterial(TrafficLight[lightID][TL_RED], 0);

        if (currentState == 131)
        {
            SetTrafficLightState(lightID, TL_GREEN);
        }
        else
        {
            SetTrafficLightState(lightID, TL_RED);
        }

        return true;
    }
    [/pawn]


Citat: realnaith poslato Jul 27, 2023, 20:43:00 POSLE PODNE
Tip: Include
Slike ili Video: //
Opis i dodatne informacije: //
Download link: //
Scan link: //
Credits: realnaith

[pawn]
/*
* Traffic Lights Control Include
* Author: [realnaith]
* Version: 1.0
*/

#define MAX_TRAFFIC_LIGHTS 10

#define TL_RED      0
#define TL_YELLOW   1
#define TL_GREEN    2

new TrafficLight[MAX_TRAFFIC_LIGHTS][3]; //
  • = Red, [1] = Yellow, [2] = Green

    stock CreateTrafficLight(Float:x, Float:y, Float:z)
    {
        static LightIndex = 0;

        if (LightIndex >= MAX_TRAFFIC_LIGHTS) return -1;

        TrafficLight[LightIndex][TL_RED] = CreateObject(19377, x, y, z);
        TrafficLight[LightIndex][TL_YELLOW] = CreateObject(19377, x, y, z);
        TrafficLight[LightIndex][TL_GREEN] = CreateObject(19377, x, y, z);

        SetObjectMaterial(TrafficLight[LightIndex][TL_RED], 0, 131, "models/txd/traffic1.txd");
        SetObjectMaterial(TrafficLight[LightIndex][TL_YELLOW], 0, 130, "models/txd/traffic1.txd");
        SetObjectMaterial(TrafficLight[LightIndex][TL_GREEN], 0, 132, "models/txd/traffic1.txd");

        LightIndex++;
        return LightIndex - 1;
    }

    stock SetTrafficLightState(lightID, trafficlightstate)
    {
        if (lightID < 0 || lightID >= MAX_TRAFFIC_LIGHTS) return false;
        if (trafficlightstate < TL_RED || trafficlightstate > TL_GREEN) return false;

        for (new i = 0; i < 3; i++)
        {
            SetObjectMaterial(TrafficLight[lightID], 0, 129, "models/txd/traffic1.txd");
        }

        SetObjectMaterial(TrafficLight[lightID][trafficlightstate], 0, 131 + trafficlightstate, "models/txd/traffic1.txd");

        return true;
    }

    stock ToggleTrafficLight(lightID)
    {
        if (lightID < 0 || lightID >= MAX_TRAFFIC_LIGHTS) return false;

        new currentState = GetObjectMaterial(TrafficLight[lightID][TL_RED], 0);

        if (currentState == 131)
        {
            SetTrafficLightState(lightID, TL_GREEN);
        }
        else
        {
            SetTrafficLightState(lightID, TL_RED);
        }

        return true;
    }
    [/pawn]
nepotrebno


Prvo, meni nista nije jasno... A i cini mi se da postoji vec krsteni library za ovo...
Drugo, jel ovo za 0.3DL ili WTF? Ako je za 0.3DL gde su potrebni modeli?
Trece, semafori su sinhronizirani u sampu, to znam 300%, bio sam tu kad je Kye pizdio oko toga i morali smo da test jedno 30x

Citat: SpArTa1 poslato Jul 27, 2023, 21:18:33 POSLE PODNE
nepotrebno

jer si nesposoban da iskoristis ??

Citat: Sniffie White poslato Jul 27, 2023, 21:40:07 POSLE PODNE
Prvo, meni nista nije jasno... A i cini mi se da postoji vec krsteni library za ovo...
Drugo, jel ovo za 0.3DL ili WTF? Ako je za 0.3DL gde su potrebni modeli?
Trece, semafori su sinhronizirani u sampu, to znam 300%, bio sam tu kad je Kye pizdio oko toga i morali smo da test jedno 30x

Msm da nema lib za ovo ?
0.3.7 / 0.3DL moze se oba koristit...
Jesu, obvo je base code gde ako neko malo promucka mozak moze iskoristiti da na semoforima preko objekta menja boje na semaforu. Korisno za svasta nesto, sta znam mozda nekome bude zatrebalo.
Tacno je da ne mozes menjati boje kao kontrolisanje semafora, sto je tuzno, MTA to ima...