Checkpoint Management -
Ash. - 27.04.2011
Checkpoint Management (v2)
Manage checkpoints with ease!
Good Morning all,
I'd like to present you with "Checkpoint Management".
The Brief
It allows you to manage your checkpoints accordingly with their position, size, whether a player is in someone else's checkpoint, and allows you to make a player checkpoint the same as someone else's. I made it after reading
this thread. And thought it would be good to make it. However, i'm not sure it would be good for much else!
The Functions
Okay, so there's eight functions, all using the same data, as otherwise they could just be any old function. Anyway, here i will explain what they are and do.
pawn Код:
SetPlayerCheckpoint(playerid, Float:x, Float:y, Float:z, Float:size)
/*
Returns 1, always.
The original function, documented on the SAMP Wiki, stated that the original returned no specific value.
*/
This function is pretty obvious, create the player checkpoint. It's usage is the same as the original function, however the return values have changed. This function creates 5 PVars, 3 for the x, y, z co-ordinates, 1 for the size, and one to tell the script/functions that feed off the data, that the checkpoint has been created.
pawn Код:
DisablePlayerCheckpoint(playerid)
/*
Returns 1, always.
The original document information, states that the original function did not return any specific value.
*/
This function simply disables the players checkpoint, it also removes the PVars that are created when making a checkpoint, and turns the initiation variable to 0 (off, checkpoint doesn't exist)
pawn Код:
GetPlayerCheckpointPos(playerid, &Float:__x, &Float:__y, &Float:__z)
/*
Returns
0 if the players checkpoint is disabled / non-existant.
1 otherwise.
This is a new function.
*/
This function, allows you to get a players checkpoint co-ordinates. It works in the same way as GetPlayerPos, with 3 variables needing to be created for the data to get put in them. This function will only work if the checkpoint is active (otherwise it will return 0).
pawn Код:
GetPlayerCheckpointSize(playerid, &Float:__size)
/*
Returns
0 if the players checkpoint is disabled / non-existant.
1 otherwise
This is a new function.
*/
This function, returns the size of the checkpoint. I'm not too sure what this could be used for unless you wanted to use it to get a decent radius for the function following this.
pawn Код:
IsPlayerInRangeOfCheckpoint(playerid, Float:range)
/*
Returns
-1 if the players checkpoint does not exist
0 if they are not in range of their checkpoint
1 if they are in range of their checkpoint
This is a new function
*/
This function is alot like IsPlayerInRangeOfPoint, however only needs to arguments. It simply runs a check to see if a player is in range of they checkpoint, but checks it on a range you give it.
pawn Код:
IsPlayerInOthersCheckpoint(playerid, playerid2)
/*
Returns
-1 if playerid2's checkpoint does not exist
1 if playerid is in playerid2's checkpoint
0 if they are not
This is a new function
*/
This function is pretty simple, it just checks to see if playerid, is in playerid2's checkpoint. I'm not too sure what this could be used for, but i thought i'd add it in anyway, i'm sure someone will find a use.
pawn Код:
SetPlayerCPAsPlayerCP(playerid, setplayerid)
/*
Returns
0 if playerid's checkpoint does not exist
1 otherwise.
This is a new function
*/
This function simply puts setplayerid's checkpoint in the same place, with the same size, as playerid's checkpoint. Again i'm not too sure what this could be used for, but i'm sure it'll be useful for someone.
pawn Код:
CreateCheckpointHere(playerid, Float:size)
/*
Returns
1, always.
This is a new function
*/
All this function does, is creates the checkpoint where the player is standing, again i'm not sure what this could be used for, and i'm not sure if a use will be found for it. But it could have a use, i suppose. (Note: If a player is already stood in the checkpoint when it is created, OnPlayerEnterCheckpoint will not be called)
pawn Код:
Float:GetDistanceToPlayerCheckpoint(playerid)
/*
Returns:
-1 if the checkpoint is inactive.
otherwise, the distance to the checkpoint.
*/
This function returns the distance to the checkpoint from their current position. It will return -1(.0) if the checkpoint is not enabled.
The Download Link
http://pastebin.com/iKhkhE2k
You can download the include from the download link above. (This is the updated version).
The old version: http://solidfiles.com/d/fff55/
Installation
It's simple, to begin using it just put CP.inc (or whatever you called it) in your include directory (folder), and include CP at the top of your script (but BELOW a_samp), like so:
pawn Код:
#include <a_samp>
#include <cp>
Please please please ensure that you have the CP.inc file in the include folder of your "PAWN Directory".
Bugs?
If you find a bug, which is highly unlikely due to this includes simplicity, post it in this thread! I'll keep checking! When i have my website set up, i will setting up a bug report section, for both my server and anything i release here - and so you will be able to post any bugs about any scripts there too soon.
Closing Message
Well, after my failure when i began to right this topic (as in, pressing post instead of preview) i think my typing skills are finally paying off. If i couldn't type as fast as i can, you'd be waiting in suspense for a lot longer than this. As i said many times above, i still have no clue what this could be used for, or if it's useful at all.
Also, i'm sorry if there are any errors in this post at all, I've been typing rather quickly in order to get this post out to you, as my failure before was rather embarrassing, shall we say?
Thank You to whichever moderator / beta tester / administrator who deleted my first post, it was most appreciated
I will consider updating this script with some more functions, as i have just thought of a few.
Oh, and a quick
NOTE: (Big note) - This include will not work with a checkpoint streamer, all it will do is create the checkpoint using the native system UNLESS you are using a checkpoint streamer with the same function name. In which case it may still not work due to the fact it has not been setup for use with a streamer. If you would like me to ATTEMPT to make it work with a streamer, tell me, and tell me which streamer too.
Enjoy!
Thanks, Ash.
(Also, i think that was my longest ever post!)
Re: Checkpoint Management -
Ash. - 27.04.2011
Change Log
Код:
25/05/11 - Fixed the unknown directive error (however unsure why that appeared)
Код:
27/05/11 - Fixed the #endif error (Had a space) and so 'refixed' the unknown directive error
Код:
24/12/11 - Added the GetDistanceToPlayerCheckpoint function!
Reserved for news and updates.
Re: Checkpoint Management -
anantanni - 24.05.2011
Woot no reply to an awesome topic..?
Re: Checkpoint Management -
Meinstad - 24.05.2011
Nice release, I'll test it now. Finnaly I can create my parkour easly
Got one problem:
pawn Код:
\Server\pawno\include\../include/CP.inc(3) : error 031: unknown directive
gamemodes\parkour.pwn(17) : warning 202: number of arguments does not match definition
gamemodes\parkour.pwn(191) : error 017: undefined symbol "CreateCheckpointHere"
gamemodes\parkour.pwn(201) : error 017: undefined symbol "GetPlayerCheckpointPos"
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase
3 Errors.
help...
Re: Checkpoint Management -
[KSF]WARLOCK - 24.05.2011
Uh.. can somebody explain me why am I getting this error after I've done EVERYTHING correctly. Please I really need ur include. Reply.
I've copied the file in the include folder of pawno folder and still I am not able to use it.
Код:
F:\GTA SAN ANDREAS\GTA San Andreas\Server tools\pawno\include\cp.inc(3) : error 031: unknown directive
Re: Checkpoint Management -
Ash. - 25.05.2011
Message Removed.
Re: Checkpoint Management -
Ash. - 25.05.2011
Quote:
Originally Posted by ******
Nice simple release with useful functions, but I have two questions:
1) Why PVars? Your system does not stream checkpoints so there is a finite number of checkpoints, bounded by the number of players which is known at compile time. PVars are useful for instances where the memory requirements can't be known in advance, which is not the case here.
|
PVars: simply because there can only be only one single checkpoint location at any given time. However i see your point now; I may modify it. However, with PVars; the user could request the information at any point in any script without necessarily including the "CP" include (however it would be needed somewhere, obviously)
Quote:
Originally Posted by ******
2) Why "__x" and "__size" etc, not "x" and "size"? It is not a rule, but symbols starting with underscores are often reserved for framework internal code and symbols starting with double underscores for symbols defined by the compiler itself. This is not the case here but you may want to bear it in mind for the future - the idea is to try and reduce the chance of a symbol name collision.
|
I actually didn't know that; I thought by using underscores I was reducing the chance of clashing names! There are no name clashes here though, and so i won't worry about it too much. I'll look out for that in the future though.
Thanks,
Ash
Re: Checkpoint Management -
Ash. - 25.05.2011
Quote:
Originally Posted by ******
Beside the PVar point, that's actually quite a bad argument (in a nice way) for anything. The point of a library like this is to abstract away details and hide them from the end-user. Honestly they shouldn't need to know that you store the data in PVars, it could be sent via HTTP to a remote server for all they care (though I wouldn't recommend that). Anything like that is internal to your code and where possible shouldn't be seen from the outside, as doing so can cause problems in the future. For example "foreach" creates a number of variables for each iterator created, but I don't document them and I don't explain them. People should only be accessing them through the interface provided so that if and when I choose to update the library and find that the internal representation needs to change, it doesn't matter. If, however, they have used the variables directly and I change something which they shouldn't have been interacting with, their code will break.
|
Hmm I see; however with something as simple as this I don't think that changing of the internals will happen; And changing a name wouldn't make much difference. However I can see where your points would be true in other scripts. But, to be fair: If they are interacting with the variables as they shouldn't, it's really there own problem.
Quote:
Originally Posted by ******
In "C++" "inline" functions are brilliant for this sort of thing as you can declare variables as private to one section of code, but still use them directly in other parts in a controlled manner. "C#" getters and setters also try and encapsulate this idea, but I'm less of a fan of them.
They're local variables - they can't clash with other local variables. The only thing they could clash with is globals, but frankly if people are using globals with names like that it's their own fault if it causes clashes! Having said that, I'm a little worried about the new version of YSI for this reason as a new technique I have for advanced macros dictates the use of short names to improve flexibility - I'll have to do something about that!
I hope you see this as useful instruction in the wider area of programming rather than critisism of this one library, it's not.
|
Yes, they're local but could clash with global variables; which is why I named them the way I have. I've played with C++ before, and I quite favour the way that works too, C# has and is always picky about the way things are done though. And yes, you may need to play with YSI if that is going to happen!
Everything you say is really helpful; and your criticism is always constructive anyway; I can see many ways what you have said can apply to PAWN and other languages, as well as single libraries.
Thanks,
Ash
Re: Checkpoint Management -
[KSF]WARLOCK - 26.05.2011
Quote:
Originally Posted by funky1234
It seems there was a missing "#" on line 2 (causing an error on line 3 because the compiler thought i was starting a new function (i guess?))
Anyway; New Download Link:
http://solidfiles.com/d/a268/
Simply redownload the file and copy it OVER the original one which is already in your includes file. You will not have to modify your script.
|
Haha! I removed the first four lines and it works now, but im just gonna use the new release. Thanks again.
Re: Checkpoint Management -
ylleron - 26.05.2011
ahh i need this for jobs, their lessons
Re: Checkpoint Management -
[KSF]WARLOCK - 26.05.2011
Uhh the new file still doesn't work. Same error. I removed the #IF DEFINED CP INCLUDED thing and it works well, but is it okay?
Re: Checkpoint Management -
Ash. - 27.05.2011
The script should still work without the "#if" section at the top. Just make sure you do NOT include the file twice, as it will cause function name clashes (in the same script) - the "#if" just stops the compiler and gives an error if you have included it twice; the script will be fine without it.
Re: Checkpoint Management -
Ash. - 27.05.2011
The script has been
fixed.
Here is the new download link:
http://solidfiles.com/d/fff55/
Simply overwrite the current include (cp.inc) in your includes folder and compile your script(s)! - No other changes needed.
Re: Checkpoint Management -
cs_master - 27.05.2011
wow man keep it up!
Re: Checkpoint Management -
Ash. - 27.05.2011
Quote:
Originally Posted by cs_master
wow man keep it up!
|
I intend to.
Just as another update: I'm getting closer to getting my "Distance To Checkpoint" thing to work, it will appear soon.
Re: Checkpoint Management -
Iphone1234g - 15.06.2011
nice work and nice include! KISS U!
Re: Checkpoint Management -
Ash. - 24.12.2011
Quote:
Originally Posted by funky1234
pawn Код:
Float:GetDistanceToPlayerCheckpoint(playerid) /* Returns: -1 if the checkpoint is inactive. otherwise, the distance to the checkpoint. */
This function returns the distance to the checkpoint from their current position. It will return -1(.0) if the checkpoint is not enabled.
|
Quote:
Originally Posted by funky1234
Код:
24/12/11 - Added the GetDistanceToPlayerCheckpoint function!
|
Updated the include (with something I could've done a long long long time ago using a simple native function...)
Re: Checkpoint Management -
Rizard - 17.02.2012
pawn Код:
stock CreateCheckpointHere(playerid, Float:size) //Not sure what this'd be used for though
{
new Float:x_, Float:y_, Float:z_;
GetPlayerPos(playerid, x_, y_, z_);
SetPlayerCheckpoint(playerid, x_, y_, x_, size);
return 1;
}
tried to use this function earlier but noticed a typing err in here: @SetPlayerCheckpoint ... the z value is x_
Good job, all the way.
[EDIT] include updated, problem solved.
Re: Checkpoint Management -
Dude_Lebowski - 15.03.2012
Cannot read from the file cp im sure i downloaded latest version and put all fine its simply doesent work for me.
Re: Checkpoint Management -
Ash. - 10.04.2012
Quote:
Originally Posted by Dude_Lebowski
Cannot read from the file cp im sure i downloaded latest version and put all fine its simply doesent work for me.
|
The cannot read from file error is not an issue with my include, it's an issue with the way you're including it. Are you sure you're putting it in the correct pawno/include directory? Perhaps you have multiple versions of the pawno package.
Ash