Weird problem with Streamer include. (Dynamic CPs)
#1

Well, I was making a Farming system in which the user has to enter 10 different CPs. After entering one, the one should disappear and the other one should come. But the Checkpoint stays at the same place and reappears again and again.

Preview of problem -> http://imgur.com/a/gslKO

The whole code:
PHP код:
#include <a_samp>
#include <zcmd>
#include <streamer>
enum FarmerJ
{
    
TMoney,
    
Onfarming,
    
Finished,
    
EFTimer,
    
tstamp,
    
CP1,
    
CP2,
    
CP3,
    
CP4,
    
CP5,
    
CP6,
    
CP7,
    
CP8,
    
CP9,
    
CP10,
    
M1,
    
M2,
    
M3,
    
M4,
    
M5,
    
M6,
    
M7,
    
M8,
    
M9,
    
M10
};
/*new Float: CheckpointsC[][10] =
{
    {699.7277, 1286.4685, 11.2983, 5.0}, // pos2
    {763.6042, 1271.3716, 19.6916, 5.0},//pos 3
    {741.0443, 1166.6055, 19.4455, 5.0}, //pos 4
    {575.7811, 1157.2560, 12.2097, 5.0}, // pos 5
    {466.3000, 1159.3514, 7.5807, 5.0}, // pos 6
    {645.4191, 1213.5051, 11.2806, 5.0}, // pos1
    {388.5491, 1086.0913, 15.7358, 5.0}, //pos 7
    {271.6047, 1139.2432, 9.7194, 5.0}, //pos 8
    {354.0098, 1134.9053, 9.2518, 5.0}, //pos 9
    {520.6189, 1182.1271, 10.0533, 5.0} //pos 10
};*/
new Farmer[MAX_PLAYERS][FarmerJ];
new 
Harvester;
// new vid;
new CountDownFromAmount;
forward CountDownTimer(playerid);
public 
OnFilterScriptInit()
{
    print(
"\n--------------------------------------");
    print(
" Farmer Job test by VisionX");
    print(
"--------------------------------------\n");
    
Harvester CreateVehicle(532573.20311218.154812.7604206.1154110);
    new 
enginelightsalarmdoorsbonnetbootobjective;
    
GetVehicleParamsEx(Harvesterenginelightsalarmdoorsbonnetbootobjective);
    
SetVehicleParamsEx(Harvester0lightsalarmdoorsbonnetbootobjective);
    return 
1;
}
public 
OnFilterScriptExit()
{
    return 
1;
}
CMD:gofarming(playeridparmas[])
{
    
Farmer[playerid][Onfarming] = 1;
    
SendClientMessage(playerid, -1"You're all set to go on farming now. You can turn your harvester's engine now.");
    
Farmer[playerid][CP1] = CreateDynamicCP645.41911213.505111.28065.000playerid);
    return 
1;
}
public 
OnPlayerEnterVehicle(playeridvehicleidispassenger)
{
    if(
GetVehicleModel(vehicleid) == 532 && Farmer[playerid][Onfarming] == 0)
    {
        
SendClientMessage(playerid, -1"To go farming and earn cash do /gofarming");
    }
    return 
1;
}
public 
OnPlayerConnect(playerid)
{
    
Farmer[playerid][Onfarming] = 0;
}
CMD:engine(playeridvehicleidparmas[])
{
    if(
Farmer[playerid][Onfarming] == 1)
    {
        
CountDownFromAmount 120;
        
Farmer[playerid][tstamp] = SetTimerEx("CountDownTimer"999true"i"playerid);
        new 
enginelightsalarmdoorsbonnetbootobjective;
        
GetVehicleParamsEx(Harvesterenginelightsalarmdoorsbonnetbootobjective);
        
SetVehicleParamsEx(Harvester1lightsalarmdoorsbonnetbootobjective);
        
SendClientMessage(playerid, -1"You've got 120 secs to complete your route!");
        
Farmer[playerid][EFTimer] = SetTimerEx("FTimer"120000false"i"playerid);
    }
    if(
Farmer[playerid][Onfarming] == && GetVehicleModel(vehicleid) == 532) return SendClientMessage(playerid, -1"You have to /gofarming to engine this vehicle! (You can't use this vehicle for public use!)");
    return 
1;
}
public 
CountDownTimer(playerid)
{
    
CountDownFromAmount--;
    if(
CountDownFromAmount == 0)
    {
        
GameTextForPlayer(playerid,"~b~Time's up!"50003);
    }
}
public 
OnPlayerEnterDynamicCP(playeridcheckpointid)
{
    if(
checkpointid == Farmer[playerid][CP1])
    {
        
SendClientMessage(playerid, -1"1st");
        new 
Cash RandomEx(1050);
        
Farmer[playerid][M1] = GivePlayerMoney(playeridCash);
        
DestroyDynamicCP(Farmer[playerid][CP1]);
        
Farmer[playerid][CP2] = CreateDynamicCP(699.72771286.468511.29835.0playerid);
    }
    if(
checkpointid == Farmer[playerid][CP2])
    {
        
SendClientMessage(playerid, -1"2nd");
        new 
Cash RandomEx(1050);
        
Farmer[playerid][M2] = GivePlayerMoney(playeridCash);
        
DestroyDynamicCP(Farmer[playerid][CP2]);
        
Farmer[playerid][CP3] = CreateDynamicCP(763.60421271.371619.69165.0playerid);
    }
    if(
checkpointid == Farmer[playerid][CP3])
    {
        
SendClientMessage(playerid, -1"3rd");
        new 
Cash RandomEx(1050);
        
Farmer[playerid][M3] = GivePlayerMoney(playeridCash);
        
DestroyDynamicCP(Farmer[playerid][CP3]);
        
Farmer[playerid][CP4] = CreateDynamicCP(741.04431166.605519.44555.0playerid);
    }
    if(
checkpointid == Farmer[playerid][CP4])
    {
        
SendClientMessage(playerid, -1"4th");
        new 
Cash RandomEx(1050);
        
Farmer[playerid][M4] = GivePlayerMoney(playeridCash);
        
DestroyDynamicCP(Farmer[playerid][CP4]);
        
Farmer[playerid][CP5] = CreateDynamicCP(575.78111157.256012.20975.0playerid);
    }
    if(
checkpointid == Farmer[playerid][CP5])
    {
        
SendClientMessage(playerid, -1"5th");
        new 
Cash RandomEx(1050);
        
Farmer[playerid][M5] = GivePlayerMoney(playeridCash);
        
DestroyDynamicCP(Farmer[playerid][CP5]);
        
Farmer[playerid][CP6] = CreateDynamicCP(466.30001159.35147.58075.0playerid);
    }
    if(
checkpointid == Farmer[playerid][CP6])
    {
        
SendClientMessage(playerid, -1"6th");
        new 
Cash RandomEx(1050);
        
Farmer[playerid][M6] = GivePlayerMoney(playeridCash);
        
DestroyDynamicCP(Farmer[playerid][CP6]);
        
Farmer[playerid][CP6] = CreateDynamicCP(645.41911213.505111.28065.0playerid);
    }
    if(
checkpointid == Farmer[playerid][CP7])
    {
        
SendClientMessage(playerid, -1"7th");
        new 
Cash RandomEx(1050);
        
Farmer[playerid][M7] = GivePlayerMoney(playeridCash);
        
DestroyDynamicCP(Farmer[playerid][CP7]);
        
Farmer[playerid][CP7] = CreateDynamicCP(388.54911086.091315.73585.0playerid);
    }
    if(
checkpointid == Farmer[playerid][CP8])
    {
        
SendClientMessage(playerid, -1"8th");
        new 
Cash RandomEx(1050);
        
Farmer[playerid][M8] = GivePlayerMoney(playeridCash);
        
DestroyDynamicCP(Farmer[playerid][CP8]);
        
Farmer[playerid][CP8] = CreateDynamicCP(354.00981134.90539.25185.0playerid);
    }
    if(
checkpointid == Farmer[playerid][CP9])
    {
        
SendClientMessage(playerid, -1"9th");
        new 
Cash RandomEx(1050);
        
Farmer[playerid][M9] = GivePlayerMoney(playeridCash);
        
DestroyDynamicCP(Farmer[playerid][CP9]);
        
Farmer[playerid][CP4] = CreateDynamicCP(520.61891182.127110.05335.0playerid);
    }
    if(
checkpointid == Farmer[playerid][CP10])
    {
        
SendClientMessage(playerid, -1"10th");
        new 
Cash RandomEx(1050);
        
Farmer[playerid][M10] = GivePlayerMoney(playeridCash);
        
DestroyDynamicCP(Farmer[playerid][CP10]);
    }
    return 
1;
}
RandomEx(minmax// By ******
{
    return 
random(max min) + min;
}
// 
I can't really understand what's the error. A help would be appriciated!
Reply
#2

Код:
    if(checkpointid == Farmer[playerid][CP9]) 
    { 
        SendClientMessage(playerid, -1, "9th"); 
        new Cash = RandomEx(10, 50); 
        Farmer[playerid][M9] = GivePlayerMoney(playerid, Cash); 
        DestroyDynamicCP(Farmer[playerid][CP9]); 
        Farmer[playerid][CP4] = CreateDynamicCP(520.6189, 1182.1271, 10.0533, 5.0, playerid); 
    }
Not sure if this is intentional, but it seems you've accidentally used 'CP4' for the CP being created here. This might not be the source of your issue, but it seems to be a mistake nonetheless.

You've also used 'CP6' two times in the script.
Reply
#3

If the problem starts at the first CP, then I must say it's weird as the code looks fine. But for the latter, as @Sebz pointed there seems to be a logic bug in your code.
Reply
#4

This is what happens now; When I enter one CP, it now goes upto 10 at the same place, no other CP is created at different location, it's just 1 CP occuring again and again at 1 place.

--> http://imgur.com/a/3pCW7
Reply
#5

The best thing to do is make your code into arrays, which will not just make your code correct but faster and easier to write and MANAGE.
Reply
#6

I think I found the culprit.

Quote:

DestroyDynamicCP(Farmer[playerid][CP1]);
Farmer[playerid][CP2] = CreateDynamicCP(699.7277, 1286.4685, 11.2983, 5.0, playerid);

As you could see above, you were destroying the previous CP before creating another CP.

So just assume, the ID you've got from the first CreatDynamicCP was 1, and you'd assign that ID 1 to Farmer[playerid][CP1].

When the player enters the first CP, your code would destroy the previous CP by grabbing ID from Farmer[playerid][CP1] that is 1.

After that you tried to create another CP which is then being assigned to Farmer[playerid][CP2], here comes the culprit, as we know the ID 1 that we destroyed was still in Farmer[playerid][CP1], and the new CreateDynamicCP will also return 1 as the ID 1 slot is free.

That causes the CP to be created always in the same first place as in CP1.

You just had to reset the Farmer[playerid][CP1 to 10] to -1 in each OnPlayerEnterDynamicCP.

A modified code snippet below


Quote:

public OnPlayerEnterDynamicCP(playerid, checkpointid)
{

if(checkpointid == Farmer[playerid][CP1])
{
SendClientMessage(playerid, -1, "1st");
new Cash = RandomEx(10, 50);
Farmer[playerid][M1] = GivePlayerMoney(playerid, Cash);
DestroyDynamicCP(Farmer[playerid][CP1]);
Farmer[playerid][CP1] = -1; //ADDED CODE
Farmer[playerid][CP2] = CreateDynamicCP(699.7277, 1286.4685, 11.2983, 5.0, playerid);
}
if(checkpointid == Farmer[playerid][CP2])
{
SendClientMessage(playerid, -1, "2nd");
new Cash = RandomEx(10, 50);
Farmer[playerid][M2] = GivePlayerMoney(playerid, Cash);
DestroyDynamicCP(Farmer[playerid][CP2]);
Farmer[playerid][CP2] = -1; //ADDED CODE
Farmer[playerid][CP3] = CreateDynamicCP(763.6042, 1271.3716, 19.6916, 5.0, playerid);
}
if(checkpointid == Farmer[playerid][CP3])
{
SendClientMessage(playerid, -1, "3rd");
new Cash = RandomEx(10, 50);
Farmer[playerid][M3] = GivePlayerMoney(playerid, Cash);
DestroyDynamicCP(Farmer[playerid][CP3]);
Farmer[playerid][CP3] = -1; //ADDED CODE
Farmer[playerid][CP4] = CreateDynamicCP(741.0443, 1166.6055, 19.4455, 5.0, playerid);
}
if(checkpointid == Farmer[playerid][CP4])
{
SendClientMessage(playerid, -1, "4th");
new Cash = RandomEx(10, 50);
Farmer[playerid][M4] = GivePlayerMoney(playerid, Cash);
DestroyDynamicCP(Farmer[playerid][CP4]);
Farmer[playerid][CP4] = -1; //ADDED CODE
Farmer[playerid][CP5] = CreateDynamicCP(575.7811, 1157.2560, 12.2097, 5.0, playerid);
}

Just do the same for the rest. Hope it helped you out
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)