SA-MP Forums Archive
Lil help with this. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Lil help with this. (/showthread.php?tid=188468)



Lil help with this. - ihatetn931 - 07.11.2010

Ok, I cannot get this working at all. It worked before (on the previous sa-mp). If i manually set playerids where [playerid] is it works fine

pawn Код:
new TimeLeft[MAX_PLAYERS];
new Trailer[MAX_PLAYERS];
new Trucking[MAX_PLAYERS];
Ongamemodeinit
pawn Код:
SetTimer("CheckTrailer", 1000, true);
pawn Код:
forward CheckTrailer(playerid);
public CheckTrailer(playerid)
{
    printf("%d",IsTrailerAttachedToVehicle(GetPlayerVehicleID(playerid)));
    printf("%d",Trucking[playerid]);
    printf("%d",TimeLeft[playerid]);
    new vehicleid = GetPlayerVehicleID(playerid);
    if(Trucking[playerid] > 1 && !IsTrailerAttachedToVehicle(vehicleid))
    {
        if(TimeLeft[playerid] == 0)
        {
            TimeLeft[playerid] = 60;
            Trucking[playerid] = 0;
            PlayerInfo[playerid][pJob] = 0;
            InfoBoxForPlayer(1, "~g~Fired~n~~n~~w~You were supposed to keep it together. The Boss has ~r~fired ~w~you");
            return 0;
        }
        TimeLeft[playerid] --;
        new string[128];
        format(string, sizeof(string), "You have ~g~%d ~w~seconds left to attach the trailer", TimeLeft[playerid]);
        GameTextForPlayer(1,string, 1000, 5);
    }
    else
    {
        TimeLeft[playerid] = 60;
    }
    return 1;
}
OnPlayerExitVehicle
pawn Код:
if(Trucking[playerid] > 0)
    {
        TimeLeft[playerid] = 60;
        Trucking[playerid] = 0;
        TogglePlayerControllable(playerid, 1);
        DisablePlayerCheckpoint(playerid);
    }
OnPlayerEnterCheckPoint
pawn Код:
if(Trucking[playerid] == 2)
    {
        if(IsALSTrucker(veh))
        {
            if(IsTrailerAttachedToVehicle(veh))
            {
                new randmoney = 150 + random(700);
                //GivePlayerCash(playerid, randmoney);
                PlayerInfo[playerid][pPaycheck] += randmoney;
                format(string, sizeof(string), "~g~Money Earned~n~~n~You earned $%d for delivering products", randmoney );
                InfoBoxForPlayer(playerid, string);
                new rand = random(sizeof(checkpoints));
                SetPlayerCheckpoint(playerid, checkpoints[rand][0], checkpoints[rand][1], checkpoints[rand][2], 3.0);
            }
            else
            {
                SendClientMessage(playerid, COLOR_RED, "Where is your truck trailer?");
            }
        }
    }
    if(Trucking[playerid] == 1)
    {
        new Float:x, Float:y, Float:z;
        GetPlayerPos(playerid, x, y, z);
        Trucking[playerid] = 2;
        Trailer[playerid] = CreateVehicle(435, -76.7316,-1118.6506,0.8108,159.7473, -1, -1, 9960);
        AttachTrailerToVehicle(Trailer[playerid], veh); //this dosen't work cause i'm not to sure how to stream them
        new rand = random(sizeof(checkpoints));
        SetPlayerCheckpoint(playerid, checkpoints[rand][0], checkpoints[rand][1], checkpoints[rand][2], 3.0);
    }
Anyone mind giving me a hand? I added the prints to try and figure it out


Re: Lil help with this. - (SF)Noobanatior - 08.11.2010

cant pass player id like that try this

pawn Код:
forward CheckTrailer();
public CheckTrailer(){
    for(new i=0;i<MAX_PLAYERS;i++){
        printf("%d",IsTrailerAttachedToVehicle(GetPlayerVehicleID(i)));
        printf("%d",Trucking[i]);
        printf("%d",TimeLeft[i]);
        new vehicleid = GetPlayerVehicleID(i);
        if(Trucking[i] > 1 && !IsTrailerAttachedToVehicle(i)){
            if(TimeLeft[i] == 0) {
                TimeLeft[i] = 60;
                Trucking[i] = 0;
                PlayerInfo[i][pJob] = 0;
                InfoBoxForPlayer(i, "~g~Fired~n~~n~~w~You were supposed to keep it together. The Boss has ~r~fired ~w~you");
                return 0;
            }
            TimeLeft[i] --;
            new string[128];
            format(string, sizeof(string), "You have ~g~%d ~w~seconds left to attach the trailer", TimeLeft[i]);
            GameTextForPlayer(i,string, 1000, 5);
        }
        else {
            TimeLeft[i] = 60;
        }
    }
    return 1;
}



Re: Lil help with this. - ihatetn931 - 08.11.2010

Ya after i posted this i messed with a lil more and added

pawn Код:
for(new i=0;i<MAX_PLAYERS;i++){
And it worked fine. I dunno why i didn't think of that before. Maybe cause it worked fine on the previous sa-mp. Thank you for the help tho.


Re: Lil help with this. - ihatetn931 - 11.11.2010

I got a problem with this, When 1 player does the job it works fine. But when another player trys to do it as well. It shows the timer for the first player instead of the second player. It also dosen't create the trailer for the second player.

For example

Player 1 Gets in the truck and enters the check point, The trailer spawns and the timer counts down then he hooks the trailer up and does all the other checkpoints

Now if Player 2 gets in a truck the trailer dosen't spawn and Player 1 sees the timer, What would cause this?


Re: Lil help with this. - (SF)Noobanatior - 11.11.2010

can you post the code you got now coz that not the only thing i changed


Re: Lil help with this. - ihatetn931 - 11.11.2010

I've done some changes to the code and added more stuff to it
OnPlayerEnterCheckPoint
pawn Код:
if(Trucking[playerid] == 2)
    {
        if(IsALSTrucker(veh))
        {
            if(IsTrailerAttachedToVehicle(veh))
            {
           
                //SetVehicleVelocity(veh,0,0,0);
                TogglePlayerControllable(playerid,0);
                SetTimer("Unload",10000,false);
                GameTextForPlayer(playerid,"~r~ Please Wait while you're being unloaded....",5000,5);
            }
            else
            {
                SendClientMessage(playerid, COLOR_RED, "Where is your truck trailer?");
            }
        }
    }
    if(Trucking[playerid] == 1)
    {
        new Float:x, Float:y, Float:z;
        GetPlayerPos(playerid, x, y, z);
        Trucking[playerid] = 2;
        Trailer[playerid] = CreateVehicle(435, -76.7316,-1118.6506,0.8108,159.7473, -1, -1, 9960);
        AttachTrailerToVehicle(Trailer[playerid], veh);
        new rand = random(sizeof(checkpoints));
        SetPlayerCheckpoint(playerid, checkpoints[rand][0], checkpoints[rand][1], checkpoints[rand][2], 3.0);
        new location[MAX_ZONE_NAME];
        Get2DZone(location, MAX_ZONE_NAME, checkpoints[rand][0],checkpoints[rand][1],checkpoints[rand][2]);
        format(string, sizeof(string), "Your Load is In %s", location);
        SendClientMessage(playerid, COLOR_YELLOW2, string);
       
    }
pawn Код:
forward CheckTrailer();
public CheckTrailer()
{
    for(new i = 0; i < MAX_PLAYERS; i++){
//  printf("%d",IsTrailerAttachedToVehicle(GetPlayerVehicleID(i)));
//  printf("%d",Trucking[i]);
//  printf("%d",TimeLeft[i]);
    new vehicleid = GetPlayerVehicleID(i);
    if(Trucking[i] > 1 || TruckingConstruct[i] > 1 || TruckingFuel[i] > 1)
    {
    if(!IsTrailerAttachedToVehicle(vehicleid))
        {
        if(TimeLeft[i] == 0)
        {
            TimeLeft[i] = 60;
            Trucking[i] = 0;
            TruckingConstruct[i] = 0;
            TruckingFuel[i] = 0;
            PlayerInfo[i][pJob] = 0;
            //InfoBoxForPlayer(1, "~g~Fired~n~~n~~w~You were supposed to keep it together. The Boss has ~r~fired ~w~you");
            GameTextForPlayer(1,"~r~Fired~n~~n~~w~You were supposed to keep it together. The Boss has ~r~fired ~w~you", 10000, 5);
            SetVehicleToRespawn(vehicleid);
            DestroyVehicle(Trailer[i]);
            return 0;
        }
        TimeLeft[i] --;
        new string[128];
        format(string, sizeof(string), "You have ~g~%d ~w~seconds left to attach the trailer", TimeLeft[i]);
        GameTextForPlayer(1,string, 1000, 5);
    }
    else
    {
        TimeLeft[i] = 60;
    }
    }
    }
    return 1;
}
My callback to unfreeze them after a certian time
pawn Код:
forward Unload();
public Unload()
{

    new string[128];
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
    if(Trucking[i] == 2)
    {
    //  GameTextForPlayer(i,"~g~You have been Unloaded ~n~ You May Contiune Your Route",5000,5);
        new randmoney = 150 + random(700);
        //GivePlayerCash(playerid, randmoney);
        PlayerInfo[i][pPaycheck] += randmoney;
        format(string, sizeof(string), "~w~You have been unloaded.~n~~w~You Earned ~g~$%d~n~~w~For Dropping Off this Load", randmoney );
        //InfoBoxForPlayer(playerid, string);
        GameTextForPlayer(i, string, 10000, 5);
        TogglePlayerControllable(i,1);
        new rand = random(sizeof(checkpoints));
        SetPlayerCheckpoint(i, checkpoints[rand][0], checkpoints[rand][1], checkpoints[rand][2], 3.0);
        new location[MAX_ZONE_NAME];
        Get2DZone(location, MAX_ZONE_NAME, checkpoints[rand][0],checkpoints[rand][1],checkpoints[rand][2]);
        format(string, sizeof(string), "Your Load is In %s", location);
        SendClientMessage(i, COLOR_YELLOW2, string);
        return 1;
    }
    if(TruckingConstruct[i] == 2)
    {
        //  GameTextForPlayer(i,"~g~You have been Unloaded ~n~ You May Contiune Your Route",5000,5);
        new randmoney = 150 + random(700);
        //GivePlayerCash(playerid, randmoney);
        PlayerInfo[i][pPaycheck] += randmoney;
        format(string, sizeof(string), "~w~You have been unloaded.~n~~w~You Earned ~g~$%d~n~~w~For Dropping Off this Load", randmoney );
        //InfoBoxForPlayer(playerid, string);
        GameTextForPlayer(i, string, 10000, 5);
        TogglePlayerControllable(i,1);
        new rand = random(sizeof(constructpoints));
        SetPlayerCheckpoint(i, constructpoints[rand][0], constructpoints[rand][1], constructpoints[rand][2], 3.0);
        new location[MAX_ZONE_NAME];
        Get2DZone(location, MAX_ZONE_NAME, constructpoints[rand][0], constructpoints[rand][1], constructpoints[rand][2]);
        format(string, sizeof(string), "Your Load is In %s", location);
        SendClientMessage(i, COLOR_YELLOW2, string);
        return 1;
    }
    if(TruckingFuel[i] == 2)
    {
            //  GameTextForPlayer(i,"~g~You have been Unloaded ~n~ You May Contiune Your Route",5000,5);
        new randmoney = 150 + random(700);
        //GivePlayerCash(playerid, randmoney);
        PlayerInfo[i][pPaycheck] += randmoney;
        format(string, sizeof(string), "~w~You have been unloaded.~n~~w~You Earned ~g~$%d~n~~w~For Dropping Off this Load", randmoney );
        //InfoBoxForPlayer(playerid, string);
        GameTextForPlayer(i, string, 10000, 5);
        TogglePlayerControllable(i,1);
        new rand = random(sizeof(fuelpoints));
        SetPlayerCheckpoint(i, fuelpoints[rand][0], fuelpoints[rand][1], fuelpoints[rand][2], 3.0);
        new location[MAX_ZONE_NAME];
        Get2DZone(location, MAX_ZONE_NAME, fuelpoints[rand][0], fuelpoints[rand][1], fuelpoints[rand][2]);
        format(string, sizeof(string), "Your Load is In %s", location);
        SendClientMessage(i, COLOR_YELLOW2, string);
        return 1;
    }
    }
    return 1;
}
The rest is pretty much the same


Re: Lil help with this. - (SF)Noobanatior - 11.11.2010

ok so ill let you do this one read through the "Checktrailer" carfully checking all the "i" as some of them arnt "i" they are "1" hece the player 1 getting all the info


and as for the trailer not loading how do you set "veh"


Re: Lil help with this. - ihatetn931 - 11.11.2010

I must of missed those when i set the ids manually, What about the create trailer issue?


Re: Lil help with this. - (SF)Noobanatior - 11.11.2010

how do you set veh?


Re: Lil help with this. - ihatetn931 - 11.11.2010

Trailer[playerid] = CreateVehicle(435, -76.7316,-1118.6506,0.8108,159.7473, -1, -1, 9960);