Quantcast
Channel: SA-MP Forums - Screenshots and Videos
Viewing all articles
Browse latest Browse all 1373

Having fun with water level

$
0
0

(Click on the image for the video)

As you probably noticed from the video, this isn't the default San Andreas map, but copied one far at the sea location. In fact, water level isn't moving, but copied San Andreas map, but it's still fun to play with it.

Here's the main code if anyone is interested:
Code:

#include "a_samp"
#include "foreach"
#include "sscanf"
#include "streamer"
#include "zcmd"
#include "allobjects"
#include "modelsizes"

Code:

#define X_OFF (6000.0)
#define Y_OFF (6000.0)
#define WATER_LEVEL (-1.5)
#define MAX_WATER_OBJECTS (15000)

Code:

enum DataWater
{
        Object,
        Float:Location[3]
}

new
                g_Count, WaterData[MAX_WATER_OBJECTS][DataWater], Float:g_Level;

Code:

command(map, playerid, params[])
{
        new
                        Float:min_obj_model_size, Float:w_level, Float:distance;
        if(sscanf(params, "F(15.0)F(10.0)F(400.0)", min_obj_model_size, w_level, distance))
                return SendClientMessage(playerid, -1, "Correct usage: \"/map [object model size] [water level] [object stream distance]\"");
        CreateMap(min_obj_model_size, w_level, distance);
        return true;
}

Code:

command(level, playerid, params[])
{
        new
                        Float:w_level, Float:speed;
        if(sscanf(params, "ff", w_level, speed))
                return SendClientMessage(playerid, -1, "Correct usage: \"/level [water level rise] [rising speed]\"");
        ChangeWaterLevel(w_level, speed);
        return true;
}

Code:

command(setlevel, playerid, params[])
{
        new
                        Float:w_level;
        if(sscanf(params, "f", w_level))
                return SendClientMessage(playerid, -1, "Correct usage: \"/setlevel [water level]\"");
        SetWaterLevel(w_level);
        return true;
}

Code:

command(getlevel, playerid, params[])
{
        new
                        string[24];
        format(string, 24, "Water level: %0.1f", GetWaterLevel());
        SendClientMessage(playerid, -1, string);
        return true;
}

Code:

stock CreateMap(Float:min_obj_model_size = 15.0, Float:w_level = WATER_LEVEL, Float:distance = 400.0)
{
        new
                        a;
        for(a = 0; a < g_Count; a++)
        {
                if(IsValidDynamicObject(WaterData[a][Object]))
                        DestroyDynamicObject(WaterData[a][Object]);
        }
        g_Count = 0;
        for(a = 0; a < SEARCH_DATA_SIZE; a++)
        {
                if(g_Count >= MAX_WATER_OBJECTS)
                        return printf("Error: Increase \"MAX_WATER_OBJECTS\" definition.");
                if(GetColSphereRadius(SearchData[a][Search_Model]) < min_obj_model_size)
                        continue;
                WaterData[g_Count][Object] = CreateDynamicObject(
                        SearchData[a][Search_Model],
                        (SearchData[a][SearchX] + X_OFF),
                        (SearchData[a][SearchY] + Y_OFF),
                        (SearchData[a][SearchZ] - w_level),
                        SearchData[a][SearchRX],
                        SearchData[a][SearchRY],
                        SearchData[a][SearchRZ],
                        .streamdistance        =        (distance + GetColSphereRadius(SearchData[a][Search_Model])),
                        .drawdistance        =        (distance + GetColSphereRadius(SearchData[a][Search_Model]))
                );
                WaterData[g_Count][Location][0] = (SearchData[a][SearchX] + X_OFF);
                WaterData[g_Count][Location][1] = (SearchData[a][SearchY] + Y_OFF);
                WaterData[g_Count][Location][2] = SearchData[a][SearchZ];
                g_Count++;
        }
        g_Level = w_level;
        printf("Total objects: %i", g_Count);
        return true;
}

Code:

stock ChangeWaterLevel(Float:w_level, Float:speed)
{
        for(new a = 0; a < g_Count; a++)
                MoveDynamicObject(WaterData[a][Object],
                        WaterData[a][Location][0],
                        WaterData[a][Location][1],
                        (WaterData[a][Location][2] - w_level),
                        speed
                )
        ;
        g_Level = w_level;
        return true;
}

Code:

stock SetWaterLevel(Float:w_level)
{
        for(new a = 0; a < g_Count; a++)
                SetDynamicObjectPos(WaterData[a][Object],
                        WaterData[a][Location][0],
                        WaterData[a][Location][1],
                        (WaterData[a][Location][2] - w_level)
                )
        ;
        g_Level = w_level;
        return true;
}

Code:

forward Float:GetWaterLevel();
stock Float:GetWaterLevel()
        return g_Level;

Code:

public OnGameModeInit()
{
        SetGameModeText("Blank Script");

        AddPlayerClass(59, (0.0 + X_OFF), (0.0 + Y_OFF), (3.5 - WATER_LEVEL), 0.0, 0, 0, 0, 0, 0, 0);

        CreateMap(15.0, WATER_LEVEL, 400.0);
        return true;
}

Code:

public OnPlayerConnect(playerid)
{
        RemoveBuildingForPlayer(playerid, -1, 0.0, 0.0, 0.0, 6000.0);
        return true;
}

Required files:

Viewing all articles
Browse latest Browse all 1373

Trending Articles