Score according to the distance
#1

Basically my script is supposed to check how much money player gets after a mission (money is calculated per distance..)
Код:
stock GetDistance(Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2)
{
    return floatround(floatsqroot(((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2)) + ((z1 - z2) * (z1 - z2))));
}
stock T_NewJob(playerid)
{
        new vID = GetPlayerVehicleID(playerid); //gets called on the next line
	if(T_OnMission[playerid] == 1) return SendClientMessage(playerid, COLOR_RED,"You are already working.");
    if(GetVehicleModel(vID)== 403 || GetVehicleModel(vID)== 515 || GetVehicleModel(vID) == 514)//this checks wether the player is in a Roadtrain, Tanker or Linerunner
    {
        if(IsTrailerAttachedToVehicle(vID))// This checks wether the player has a trailer attached
        {
            new MisRand = random(sizeof(MisLocations));// this is the line that will call a random mission.
            new LoadText[128], Float:x, Float:y, Float:z,vagtext[128];// these are where we will store each co-ord and the text for the mission
            x = MisLocations[MisRand][LoadX];//this sets one of the above
            y = MisLocations[MisRand][LoadY];//this sets one of the above
            z = MisLocations[MisRand][LoadZ];//this sets one of the above
            unx[playerid] = MisLocations[MisRand][UnloadX];//these set what we made in step 10.
            uny[playerid] = MisLocations[MisRand][UnloadY];//these set what we made in step 10.
            unz[playerid] = MisLocations[MisRand][UnloadZ];//these set what we made in step 10.
			iPay[playerid] = GetDistance(x,y,z,unx[playerid],uny[playerid],unz[playerid]);
			SetPlayerCheckpoint(playerid, x, y, z, 7);
            format(LoadText, 128, "Deliver %s",MisLocations[MisRand][LoadName]);// this is formatting the text the player will see in the console
            format(vagtext,sizeof(vagtext),"       %s",LoadText);
            TextDrawSetString(Textdraw0[playerid],vagtext);
            SendClientMessage(playerid, 0xFFFFFF, "_____________________");//sends message in console
            SendClientMessage(playerid, 0xFFFFFF, "");//sends message in console
            SendClientMessage(playerid, 0x33CCFFAA, LoadText);//sends the text we formatted earlier in console
            SendClientMessage(playerid, 0xFFFFFF, "_____________________");//sends message in console
            T_OnMission[playerid] = 1;
        }
        else//if the player doesnt have a trailer attached
        {
            SendClientMessage(playerid, COLOR_WHITE, "You need a trailer!");//sends message in console
        }
    }
    else//if the player isnt in a truck
    {
        SendClientMessage(playerid, COLOR_WHITE, "You must be in a Truck in order to work!");//sends message in console
    }
    return 1;
}
//-------------------[Stop Work]---------------------------------------
stock StopWork(playerid)
{
	if(T_OnMission[playerid] == 0) return SendClientMessage(playerid, COLOR_RED, "You are not on mission.");
	TextDrawSetString(Textdraw0[playerid],"       You are currently not on mission. Use /work to start working.");
    T_OnMission[playerid] = 0;
    DisablePlayerCheckpoint(playerid);
    SendClientMessage(playerid, COLOR_WHITE, "You chose to cancel the mission and got fined $1000");
    GivePlayerMoney(playerid, -1000);
    return 1;
}
stock CheckpointEntered(playerid)
{
	new string[300];
    new vID = GetPlayerVehicleID(playerid);//Explained earlier
    if(!IsTrailerAttachedToVehicle(vID)) return SendClientMessage(playerid, COLOR_WHITE, "You need a trailer to unload!");//This line checks wether the player has a trailer attached to their truck.
    if(T_OnMission[playerid] == 1)//checks the players mission status
    {
        DisablePlayerCheckpoint(playerid);//disables the checkpoint
        SetPlayerCheckpoint(playerid, unx[playerid], uny[playerid], unz[playerid], 7);//creates the new checkpoint from the saved positions we made earlier
        SendClientMessage(playerid, COLOR_WHITE, "Loaded. Please head to the second checkpoint!");//sends message
        T_OnMission[playerid] = 2;//sets the players mission status
    }
    else if(T_OnMission[playerid] == 2)//checks the mission status of the player
    {
		if(iPay[playerid] < 10001){
		iScore[playerid] = 1;
		}
		else if(iPay[playerid] < 20001){
		iScore[playerid] = 2;
		}
		else if(iPay[playerid] > 20000){
		iScore[playerid] = 3;
		}
		format(string,sizeof(string),"Well done. You have completed your mission and earned %d$ and %d score.",iPay[playerid]*5,iScore[playerid]);
		TextDrawSetString(Textdraw0[playerid],"       You are currently not on mission. Use /work to start working.");
        GivePlayerMoney(playerid,iPay[playerid]*5);
        SendClientMessage(playerid, COLOR_YELLOW, string);
		new string2[256],name[30];
		GetPlayerName(playerid,name,sizeof(name));
		format(string2, sizeof(string2), "%s has delivered %s!", name, MisLocations[MisRand][LoadName]); //line 295
		SendClientMessageToAll(COLOR_YELLOW, string2);
        DisablePlayerCheckpoint(playerid);//disables the checkpoint
        T_OnMission[playerid] = 0;
        SetPlayerScore(playerid, GetPlayerScore(playerid)+iScore[playerid]);//gives the player 2 score
		new INI:File = INI_Open(UserPath(playerid));
    	INI_SetTag(File,"data");
  	  	INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
    	INI_WriteInt(File,"Level",PlayerInfo[playerid][pLevel]);
    	INI_WriteInt(File,"Score",GetPlayerScore(playerid));
    	INI_Close(File);
    }
    return 1;
}
However even when I get like 15k money i still only get 1 score, while i'm supposed to get 2.

iPay and iScore are both defined as new iExample[MAX_PLAYERS];
Reply
#2

Anyone got any idea?
Reply
#3

If I were designing this, I'd do it like:
pawn Код:
#define FLOAT_CONST 0.1

stock Complete_mission()
{
     SetPlayerScore(playerid, GetPlayerScore(playerid) + floatround(GetDistance(..) * FLOAT_CONST) );
}
Sorry to not suggest you on your actual code - but please pinpoint the area of problem and post the code! It is quite not so fun going through all the code.
Reply
#4

Quote:
Originally Posted by Rajat_Pawar
Посмотреть сообщение
If I were designing this, I'd do it like:
pawn Код:
#define FLOAT_CONST 0.1

stock Complete_mission()
{
     SetPlayerScore(playerid, GetPlayerScore(playerid) + floatround(GetDistance(..) * FLOAT_CONST) );
}
Sorry to not suggest you on your actual code - but please pinpoint the area of problem and post the code! It is quite not so fun going through all the code.
Basically this always gives me 1 score
Код:
		if(iPay[playerid] < 10001){
		iScore[playerid] = 1;
		}
		else if(iPay[playerid] < 20001){
		iScore[playerid] = 2;
		}
		else if(iPay[playerid] > 20000){
		iScore[playerid] = 3;
		}
even if I earn more money..
Reply
#5

pawn Код:
if( iPay[playerid] > 0 && iPay[playerid] < 10000)
{
       iScore[playerid] = 1;
}
else if(iPay[playerid] > 10000 && iPay[playerid] < 20000)
{
      iScore[playerid] = 2;
}
else { iScore[playerid] = 3; }
Reply
#6

Got it working with SetPVarInt
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)