Help me with Random Pos
#1

Done
Reply
#2

try
pawn Код:
new Float:RandomMats[][]
Quote:

The first [] left blank so that we don't have to change the number when we add more spawns
The second [] left blank so that we don't have to change the number when we want to add more data to a spawn.

Cr.FunExtreme
Reply
#3

Read clearly my post, I also use
pawn Код:
new Float:RandomMats[][]
Reply
#4

Quote:
Originally Posted by Kenxxx
Посмотреть сообщение
pawn Код:
new Float:RandomMats[4][3] =
{
        {-2221.0332,-116.0993,34.8923},
    {-2532.7168,-17.1955,15.9828}, // Random
    {-2311.2241,-58.7478,34.8691},
    {-2233.0249,160.2346,34.8879} // Random
};

CMD:getmats(playerid, params[])
{
    new Random = random(sizeof(RandomMats));
    if(!IsAMats(GetPlayerVehicleID(playerid)))
    {
        SendClientMessage(playerid, COLOR_WHITE, "Ban phai can co mot chiec Bobcat/Sadler de tien hanh lam viec");
        return 1;
    }
    if (IsPlayerInRangeOfPoint(playerid, 4.0, -1816.528686, -179.502624, 9.398437)) // Matrun 4
    {
        if(GetPVarInt(playerid, "VL") >= 10) return SendClientMessage(playerid, COLOR_GRAD2, "Ban phai chuyen goi vat lieu cua ban truoc.");
        if(PlayerInfo[playerid][pVIP] == 1)
        {
            if(GetPlayerCash(playerid) < 900)
            {
                SendClientMessage(playerid, COLOR_GREY,"Ban khong co du 900 SAD de chi tra!");
                return 1;
            }
            GivePlayerCash(playerid, -900);
            SetPVarInt(playerid, "VL", 18);
            SendClientMessage(playerid, COLOR_WHITE,"{FF8000}[-]: {FFFFFF}Ban da mua 18 goi vat lieu voi gia 900 SAD.");
            SendClientMessage(playerid, COLOR_WHITE,"{FF8000}Bronze VIP: {FFFFFF}Ban nhan duoc hon 1.5x lan/tui, se hon duoc 1.5x lan vat lieu.");
           
        }
        else if(PlayerInfo[playerid][pVIP] == 2 || PlayerInfo[playerid][pVIP] == 3)
        {
            if(GetPlayerCash(playerid) < 1200)
            {
                SendClientMessage(playerid, COLOR_GREY,"Ban khong co du 1200 SAD de chi tra!");
                return 1;
            }
            GivePlayerCash(playerid, -1200);
            SetPVarInt(playerid, "VL", 24);
            SendClientMessage(playerid, COLOR_WHITE,"{FF8000}[-]: {FFFFFF}Ban da mua 24 goi vat lieu voi gia 1200 SAD.");
            SendClientMessage(playerid, COLOR_WHITE,"{EE9A4D} Silver & Gold VIP: {FFFFFF}Ban nhan duoc hon 2x lan/tui, se hon duoc 2x lan vat lieu.");
        }
        else if(PlayerInfo[playerid][pVIP] >= 4)
        {
            if(GetPlayerCash(playerid) < 1500)
            {
                SendClientMessage(playerid, COLOR_GREY," Ban khong co du 1500 SAD de chi tra!");
                return 1;
            }
            GivePlayerCash(playerid, -1500);
            SetPVarInt(playerid, "VL", 30);
            SendClientMessage(playerid, COLOR_WHITE,"{FF8000}[-]: {FFFFFF}Ban da mua 30 goi vat lieu voi gia 1500 SAD .");
            SendClientMessage(playerid, COLOR_WHITE,"{298EFF} Platinum VIP: {FFFFFF}Ban nhan duoc hon 2.5x lan/tui, se hon duoc 2.5x lan vat lieu.");
        }
        else
        {
            if(GetPlayerCash(playerid) < 600)
            {
                SendClientMessage(playerid, COLOR_WHITE," Ban khong co du 600 SAD de chi tra!");
                return 1;
            }
            SendClientMessage(playerid, COLOR_WHITE,"{FF8000}[-]: {FFFFFF}Ban da mua 12 goi vat lieu voi gia 600 SAD.");
            GivePlayerCash(playerid, -600);
            SetPVarInt(playerid, "VL", 12);
        }

        SetPVarInt(playerid, "tpMatRunTimer", 12);
        SetPVarInt(playerid, "Mats",Random);
        SetPVarInt(playerid, "XuongXeLayMat", 0);
        SetTimerEx("OtherTimerEx", 1000, false, "ii", playerid, TYPE_TPMATRUNTIMER);
        SetPlayerCheckpoint(playerid, RandomMats[Random][0], RandomMats[Random][1], RandomMats[Random][2], 5);
        return 1;
    }
    else    {
        SendClientMessage(playerid, COLOR_WHITE, "Ban khong o diem lay vat lieu");
    }
    return 1;
}


stock IsAMats(carid)    {
    if(GetVehicleModel(carid) == 422 || GetVehicleModel(carid) == 543) {
        return 1;
    }
    return 0;
}

public OnPlayerUpdate(playerid)
{
    if(GetPVarInt(playerid, "Mats") > 0 && IsPlayerInRangeOfPoint(playerid, 18, RandomMats[GetPVarInt(playerid, "Mats")][0], RandomMats[GetPVarInt(playerid, "Mats")][1], RandomMats[GetPVarInt(playerid, "Mats")][2]))
    {
        if(IsPlayerInAnyVehicle(playerid) && GetPVarInt(playerid, "XuongXeLayMat") == 0)
    {
        new vehicleid = GetPlayerVehicleID(playerid);
        new Float:vehx, Float:vehy, Float:vehz;
           
        XeMats[playerid] = vehicleid;
            GetVehiclePos(vehicleid, vehx, vehy, vehz);
            SetVehiclePos(vehicleid, vehx, vehy, vehz);
            RemovePlayerFromVehicle(playerid);
            SendClientMessage(playerid, COLOR_WHITE, "{FF8000}[-]: {FFFFFF}Ban can phai di lai diem do de lay thung vat lieu chat len xe");
            SetPVarInt(playerid, "XuongXeLayMat", 1);
            return 1;
         }
    }
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & KEY_YES && GetPVarInt(playerid, "MATSCR") == 1)
    {
        new Float:vx, Float:vy, Float:vz;
        for(new i = 0; i < MAX_VEHICLES; i++)
        {
            GetVehiclePos(XeMats[playerid],vx,vy,vz);
            if(IsPlayerInRangeOfPoint(playerid, 3, vx, vy, vz))
            {
                if(IsAMats(i))
                {
                    if(PlayerInfo[playerid][pDonateRank] == 1)
                    {
                        MInfo[i][Slot1] = GetPVarInt(playerid, "MMT");
                        MInfo[i][Object1] = CreateObject(1271,0,0,0,0,0,0,0);
                        AttachObjectToVehicle(MInfo[i][Object1],i,  0.324999, -1.619998, 0.019999, 0.000000, 0.000000, 0.000000); //Object Model: 1271 |
                        SetPVarInt(playerid,"MATSCR",2);
                        SetPVarInt(playerid, "TransVL", 444);

                        SetPlayerCheckpoint(playerid,-1816.528686, -179.502624, 9.398437, 5);
                        RemovePlayerAttachedObject(playerid,9);
                        ApplyAnimation(playerid,"CARRY","putdwn",1,0,0,0,0,0);
                        SetPVarInt(playerid,"MMT",1);
                    }
                    else if(PlayerInfo[playerid][pDonateRank] == 2 || PlayerInfo[playerid][pDonateRank] == 3)
                    {
                        MInfo[i][Slot1] = GetPVarInt(playerid, "MMT");
                        MInfo[i][Object1] = CreateObject(1271,0,0,0,0,0,0,0);
                        AttachObjectToVehicle(MInfo[i][Object1],i,  0.324999, -1.619998, 0.019999, 0.000000, 0.000000, 0.000000); //Object Model: 1271 |
                        SetPVarInt(playerid,"MATSCR", 2);
                        SetPVarInt(playerid, "TransVL", 444);

                        SetPlayerCheckpoint(playerid,-1816.528686, -179.502624, 9.398437, 5);
                        RemovePlayerAttachedObject(playerid,9);
                        ApplyAnimation(playerid,"CARRY","putdwn",1,0,0,0,0,0);
                        SetPVarInt(playerid,"MMT",1);
                    }
                    else if(PlayerInfo[playerid][pDonateRank] >= 4)
                    {
                        MInfo[i][Slot1] = GetPVarInt(playerid, "MMT");
                        MInfo[i][Object1] = CreateObject(1271,0,0,0,0,0,0,0);
                        AttachObjectToVehicle(MInfo[i][Object1],i,  0.324999, -1.619998, 0.019999, 0.000000, 0.000000, 0.000000); //Object Model: 1271 |
                        SetPVarInt(playerid,"MATSCR",2);
                        SetPVarInt(playerid, "TransVL", 444);

                        SetPlayerCheckpoint(playerid,-1816.528686, -179.502624, 9.398437, 5);
                        RemovePlayerAttachedObject(playerid,9);
                        ApplyAnimation(playerid,"CARRY","putdwn",1,0,0,0,0,0);
                        SetPVarInt(playerid,"MMT",1);
                    }
                    else
                    {
                        MInfo[i][Slot1] = GetPVarInt(playerid, "MMT");
                        MInfo[i][Object1] = CreateObject(1271,0,0,0,0,0,0,0);
                        AttachObjectToVehicle(MInfo[i][Object1],i,  0.324999, -1.619998, 0.019999, 0.000000, 0.000000, 0.000000); //Object Model: 1271 |
                        SetPVarInt(playerid,"MATSCR",2);
                        SetPVarInt(playerid, "TransVL", 444);

                        SetPlayerCheckpoint(playerid,-1816.528686, -179.502624, 9.398437, 5);
                        RemovePlayerAttachedObject(playerid,9);
                        ApplyAnimation(playerid,"CARRY","putdwn",1,0,0,0,0,0);
                        SetPVarInt(playerid,"MMT",1);
                    }
                }
            }
            else    {
                SendClientMessage(playerid, COLOR_WHITE, "{FF8000}[-]: {FFFFFF}Ban can phai o gan xe Bobcat/Sadler cua ban");
                return 1;
            }
        }
    }
    return 1;
}

if(GetPVarInt(playerid, "Mats") > 0 && IsPlayerInRangeOfPoint(playerid, 5.0, RandomMats[GetPVarInt(playerid, "Mats")][0], RandomMats[GetPVarInt(playerid, "Mats")][1], RandomMats[GetPVarInt(playerid, "Mats")][2]))
    {
        if(GetPVarInt(playerid,"MMT") == 1) return SendClientMessage(playerid,COLOR_WHITE,"Ban da co mot thung hang tren tay");
        if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_WHITE, "Ban can phai xuong xe truoc");
        if(PlayerInfo[playerid][pDonateRank] == 1)
        {
            SetPlayerAttachedObject(playerid, 9, 1271,1, 0.356999, 0.371999, 0.000000, 0.000000, 0.000000, 0.000000, 0.861000, 0.633999, 1.000000, 0, 0);
            ApplyAnimation(playerid,"CARRY","crry_prtial",4.0,1,0,0,1,1,1);
            SendClientMessage(playerid, COLOR_WHITE, "{FF8000}[-]: {FFFFFF}Ban con mot thung hang nua");
            SendClientMessage(playerid, COLOR_WHITE, "{FF8000}[-]: {FFFFFF}Lai gan xe nhan Y de cho vao thung xe");
            SetPVarInt(playerid,"MATSCR",1);
            SetPVarInt(playerid,"MMT", 1);
        }
        else if(PlayerInfo[playerid][pDonateRank] == 2 || PlayerInfo[playerid][pDonateRank] == 3)
        {
            SetPlayerAttachedObject(playerid, 9, 1271,1, 0.356999, 0.371999, 0.000000, 0.000000, 0.000000, 0.000000, 0.861000, 0.633999, 1.000000, 0, 0);
            ApplyAnimation(playerid,"CARRY","crry_prtial",4.0,1,0,0,1,1,1);
            SendClientMessage(playerid, COLOR_WHITE, "{FF8000}[-]: {FFFFFF}Ban con mot thung hang nua");
            SendClientMessage(playerid, COLOR_WHITE, "{FF8000}[-]: {FFFFFF}Lai gan xe nhan Y de cho vao thung xe");
            SetPVarInt(playerid,"MATSCR",1);
            SetPVarInt(playerid,"MMT", 1);

        }
        else if(PlayerInfo[playerid][pDonateRank] >= 4)
        {
            SetPlayerAttachedObject(playerid, 9, 1271,1, 0.356999, 0.371999, 0.000000, 0.000000, 0.000000, 0.000000, 0.861000, 0.633999, 1.000000, 0, 0);
            ApplyAnimation(playerid,"CARRY","crry_prtial",4.0,1,0,0,1,1,1);
            SendClientMessage(playerid, COLOR_WHITE, "{FF8000}[-]: {FFFFFF}Ban con mot thung hang nua");
            SendClientMessage(playerid, COLOR_WHITE, "{FF8000}[-]: {FFFFFF}Lai gan xe nhan Y de cho vao thung xe");
            SetPVarInt(playerid,"MATSCR",1);
            SetPVarInt(playerid,"MMT", 1);

        }
        else
        {
            SetPlayerAttachedObject(playerid, 9, 1271,1, 0.356999, 0.371999, 0.000000, 0.000000, 0.000000, 0.000000, 0.861000, 0.633999, 1.000000, 0, 0);
            ApplyAnimation(playerid,"CARRY","crry_prtial",4.0,1,0,0,1,1,1);
            SendClientMessage(playerid, COLOR_WHITE, "{FF8000}[-]: {FFFFFF}Lai gan xe nhan Y de cho vao thung xe");
            DisablePlayerCheckpoint(playerid);
            SetPVarInt(playerid,"MATSCR",1);
            SetPVarInt(playerid,"MMT", 1);
        }
    }
    if(GetPVarInt(playerid, "TransVL") == 444 && IsPlayerInRangeOfPoint(playerid, 6.0, -1816.528686, -179.502624, 9.398437))
    {
        if(PlayerInfo[playerid][pDonateRank] == 1)
        {
            PlayerInfo[playerid][pMats] += 450;
            SendClientMessage(playerid, COLOR_LIGHTBLUE, "{FF8000}[-]: {FFFFFF}Nha may da dua 450 vat lieu va cho ban 18 goi vat lieu.");
            SendClientMessage(playerid, COLOR_YELLOW,"{FF8000}Bronze VIP: {FFFFFF}Ban nhan duoc 1.5x vat lieu.");

        }
        else if(PlayerInfo[playerid][pDonateRank] == 2 || PlayerInfo[playerid][pDonateRank] == 3)
        {
            PlayerInfo[playerid][pMats] += 600;
            SendClientMessage(playerid, COLOR_LIGHTBLUE, "{FF8000}[-]: {FFFFFF}Nha may da dua 600 vat lieu va cho ban 24 goi vat lieu.");
            SendClientMessage(playerid, COLOR_YELLOW,"{EE9A4D} Silver & Gold VIP: {FFFFFF}Ban nhan duoc 2x vat lieu.");

        }
        else if(PlayerInfo[playerid][pDonateRank] >= 4)
        {
            PlayerInfo[playerid][pMats] += 750;
            SendClientMessage(playerid, COLOR_LIGHTBLUE, "{FF8000}[-]: {FFFFFF}Nha may da dua 750 vat lieu va cho ban 30 goi vat lieu.");
            SendClientMessage(playerid, COLOR_YELLOW,"{298EFF} Platinum VIP: {FFFFFF}Ban nhan duoc 2.5x vat lieu.");

        }
        else
        {
            PlayerInfo[playerid][pMats] += 300;
            SendClientMessage(playerid, COLOR_LIGHTBLUE, "{FF8000}[-]: {FFFFFF}Nha may da dua 300 vat lieu va cho ban 12 goi vat lieu.");
        }
        DestroyObject(GetPVarInt(playerid, "MMT"));
        ApplyAnimation(playerid,"CARRY","putdwn",1,0,0,0,0,0);

        DeletePVar(playerid, "Packages");
        DeletePVar(playerid, "TransVL");
        DeletePVar(playerid, "MATSCR");
        DeletePVar(playerid, "Mats");
        DeletePVar(playerid, "MMT");
        DisablePlayerCheckpoint(playerid);
    }
    return 1;
}

I use 4 random pos, but when I use it as RandomMats[GetPVarInt(playerid, "Mats")][]
(Mats was defined at random from 1 to 4)
But when I use cmd:getmats. There are only 3 place worked, and another one didnt. I tried to decrease to 3 pos, then there are only 2 place worked. What can I do ?
PHP код:
new Float:RandomMats[4][3
pawn Код:
new Float:RandomMats[][]

Quote:
Originally Posted by Kenxxx
Посмотреть сообщение
Read clearly my post, I also use
pawn Код:
new Float:RandomMats[][]
PHP код:
new Float:RandomMats[4][3] =
{
        {-
2221.0332,-116.0993,34.8923},
    {-
2532.7168,-17.1955,15.9828}, // Random
    
{-2311.2241,-58.7478,34.8691},
    {-
2233.0249,160.2346,34.8879// Random
}; 
Quote:
Originally Posted by colonel-top
Посмотреть сообщение
try
pawn Код:
new Float:RandomMats[][]
Cr.FunExtreme
PHP код:
new Float:RandomMats[][] 
made it Unlimited for adding for fix it
Reply
#5

Indexes in arrays start from 0. Declaring RandomMats with size of 4 means 0-3 are its valid indexes.
If "Random" is 0 you are ignoring it so reset it to -1 and check if "Mats" is not -1 so you can check in IsPlayerInRangeOfPoint.

If you don't use PVars for communication with other scripts, arrays are recommended then (they're much faster).
Reply
#6

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Indexes in arrays start from 0. Declaring RandomMats with size of 4 means 0-3 are its valid indexes.
If "Random" is 0 you are ignoring it so reset it to -1 and check if "Mats" is not -1 so you can check in IsPlayerInRangeOfPoint.

If you don't use PVars for communication with other scripts, arrays are recommended then (they're much faster).
Give me code please, I dont clearly understand what you mean ?
Reply
#7

pawn Код:
SetPVarInt(playerid, "Mats",Random);
"Mats" will be a number between 0 and 3.
pawn Код:
if(GetPVarInt(playerid, "Mats") > 0 && IsPlayerInRangeOfPoint(playerid, 18, RandomMats[GetPVarInt(playerid, "Mats")][0], RandomMats[GetPVarInt(playerid, "Mats")][1], RandomMats[GetPVarInt(playerid, "Mats")][2]))
If "Mats" is 0, the above code will fail.

That's why I'm also telling you to use arrays.
pawn Код:
new Player_Mats[MAX_PLAYERS];

// on connect and when you used DeletePVar:
Player_Mats[playerid] = -1;
pawn Код:
Player_Mats[playerid] = Random;
pawn Код:
if(Player_Mats[playerid] != -1 && IsPlayerInRangeOfPoint(playerid, 18, RandomMats[Player_Mats[playerid]][0], RandomMats[Player_Mats[playerid]][1], RandomMats[Player_Mats[playerid]][2]))
and replace the rest.
Reply
#8

Still have one place not working
Reply
#9

Oh thats my bad, its working. Thanks you very muchh bro
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)