More efficient way?
#1

I am making a system so players in my server can do "Mini-Missions". Currently it's set up so when the enter a checkpoint it increases a variable, and sets the next checkpoint. Is there a better way I can go about doing this? Heres an example of what I have:

Код:
		if(GetPVarInt(playerid, "Progress") == 1)
		{
			SetPVarInt(playerid, "Progress", pProgress);
			SetPlayerCheckpoint(playerid, 1399.4467, 1901.4362, 10.6995, 3);
			SetTimerEx("Unfreeze", 2500, false, "i", playerid);
			TogglePlayerControllable(playerid, 0);
			GameTextForPlayer(playerid, "Unloading...", 3000, 5);
		}
Reply
#2

I don't know what you mean, it's good at is it (unless you've it under OnPlayerUpdate or a very repetitive timer).
Reply
#3

There is only one timer, I guess it's efficient. The code just looks messy :P
Reply
#4

Quote:
Originally Posted by ScottCFR
Посмотреть сообщение
There is only one timer, I guess it's efficient. The code just looks messy :P
People code different ways. For example, me i code with LOTS of comments marking places etc, so i can just Crtl + F and search "//vehicles" and boom it takes me to the vehicles section. So keep in mind, if your the only one coding, then just do it the way you like. And if your apart of a team, leave comments on your work explaining how to read/do things.
Reply
#5

Yeah, it's just me. I also use a ton of comments :P I just thought an array or something could make it look cleaner, but I'm not good with arrays and the use of them.
Reply
#6

using a switch statment is more efficent then lots of if's like so
pawn Код:
switch(GetPVarInt(playerid, "Progress")) {
        case: 1 {
            SetPVarInt(playerid, "Progress", pProgress);
            SetPlayerCheckpoint(playerid, 1399.4467, 1901.4362, 10.6995, 3);
            SetTimerEx("Unfreeze", 2500, false, "i", playerid);
            TogglePlayerControllable(playerid, 0);
            GameTextForPlayer(playerid, "Unloading...", 3000, 5);
        }
    }
Reply
#7

Quote:
Originally Posted by ScottCFR
Посмотреть сообщение
There is only one timer, I guess it's efficient. The code just looks messy :P
So you say you use a timer to check if the players have entered a checkpoint?
Why don't use callback(OnPlayerEnterCheckpoint)?
It's more efficient then using a timer, because it is only called when a player enters a checkpoint.
If you use a timer, it will still run the code even if the player haven't entered any checkpoints.

Using switch would be more efficient, but only when you check the value of the same thing for more than or equal to 3 times.
Reply
#8

Quote:
Originally Posted by leong124
Посмотреть сообщение
So you say you use a timer to check if the players have entered a checkpoint?
Why don't use callback(OnPlayerEnterCheckpoint)?
It's more efficient then using a timer, because it is only called when a player enters a checkpoint.
If you use a timer, it will still run the code even if the player haven't entered any checkpoints.

Using switch would be more efficient, but only when you check the value of the same thing for more than or equal to 3 times.
Agree

Quote:
Originally Posted by ScottCFR
Посмотреть сообщение
Yeah, it's just me. I also use a ton of comments :P I just thought an array or something could make it look cleaner, but I'm not good with arrays and the use of them.
pawn Код:
enum JobInfo
{
     Float: Pos,
}
new JobPos[][JobInfo] = {
     {x, y, z},
     {x, y, z};
};
Now to fetch the positions from the array you do like this :

pawn Код:
SetPlayerCheckpoint(playerid, JobPos[GetPVarInt(playerid, "Progress") -1][Pos][0], JobPos[GetPVarInt(playerid, "Progress") -1][Pos][1], JobPos[GetPVarInt(playerid, "Progress") -1][Pos][2], 3);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)