pawn Код:
public OnFilterScriptExit() {
print("\n**************************************");
print(" Campfire in SA-MP 'Object' ");
print(" Date: 16/07/2013 ");
print(" Author: OTACON ");
print(" --* Downloaded with Success!!. *-- ");
print("***************************************\n");
DestroyObjectCampfire(0);
return true;
}
Downloaded with success ? Splendid!
Anyways, I looked over the code and there is some problems with this include being that it is not really a well designed dynamic system it could be done much better. Fortunately I've written a very basic dynamic system for you to study if you apply this structure to your include it will improve functionality greatly.
Here is a simple system I made as a demo you will observe.
- Dynamic adding function style (This is the same for any dynamic system)
- Removing dynamic objects
- Bounds checking
- Implementation
It is all well commented and very very easy to understand pretty much any dynamic system you design will follow this structure that is why it is so important to learn and understand.
pawn Код:
// Hearts - simple dynamic system concept
#include <a_samp>
// We'll use ZCMD
#include <zcmd>
// We always need to define how many elements a dynamic system contains
#define MAX_HEARTS 1000
// Heart object for this dynamic system
#define HEART_OBJECT 1240
// The drawdistance for hearts
#define HEART_DRAW_DIST 150.0
// This is a bounds checking macro to make sure that referenced array elements are not out of bounds
#define HeartBounds(%0,%1); \
if(%0 < 0 || %0 > MAX_HEARTS) \
{ \
print(%1); \
return 0; \
}
// We need to define an enum which is basically the structure of the values that will be saved in the dynamic system
enum HEARTINFO
{
HeartObject,
Float:xPos,
Float:yPos,
Float:zPos,
}
// Create a new variable to store the heart information
new HeartData[MAX_HEARTS][HEARTINFO];
// When any dynamic system initializes we need to set any required default values in this case it is the heartobject which
// determines if the dynamic element exists
public OnFilterScriptInit()
{
// Loop through each element
for(new i = 0; i < MAX_HEARTS; i++)
{
// This marks the element as unused
HeartData[i][HeartObject] = INVALID_OBJECT_ID;
}
return 1;
}
// Destroy any created hearts
public OnFilterScriptExit()
{
for(new i = 0; i < MAX_HEARTS; i++)
{
if(HeartData[i][HeartObject] != INVALID_OBJECT_ID) DestroyObject(HeartData[i][HeartObject]);
}
return 1;
}
// Add a new heart
stock AddHeart(Float:x, Float:y, Float:z)
{
// Loop through hearts for a free slot
for(new i = 0; i < MAX_HEARTS; i++)
{
// Slot was not free continue
if(HeartData[i][HeartObject] != INVALID_OBJECT_ID) continue;
// We have a free slot create the new heart element
HeartData[i][HeartObject] = CreateObject(HEART_OBJECT, x, y, z, 0.0, 0.0, 0.0, HEART_DRAW_DIST);
// Set any additional data
HeartData[i][xPos] = x;
HeartData[i][yPos] = y;
HeartData[i][zPos] = z;
// Return the id of the heart element that was created
return i;
}
// There are too many hearts
print("ERROR: Tried to add too many hearts");
return INVALID_OBJECT_ID;
}
// Remove a heart
stock RemoveHeart(hid)
{
// Check the bounds to make sure they are valid
HeartBounds(hid, "Bounds error: RemoveHeart");
// Does the heart exist?
if(HeartData[hid][HeartObject] != INVALID_OBJECT_ID)
{
// Destroy heart
DestroyObject(HeartData[hid][HeartObject]);
// We only need to reset the heart objectid this element can now be re-used
HeartData[hid][HeartObject] = INVALID_OBJECT_ID;
return 1;
}
// Return 0 heart did not exist
return 0;
}
// Command for adding a heart
CMD:addheart(playerid, arg[])
{
// Get the players position
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
z += 1.0;
// Adding the heart was not success
if(AddHeart(x, y, z) == -1) return SendClientMessage(playerid, 0xFF0000FF, "There are too many hearts");
// Successfully added!
SendClientMessage(playerid, -1, "Added a new heart!");
return 1;
}
// Remove heart
CMD:removeheart(playerid, arg[])
{
// Remove was successful
if(RemoveHeart(strval(arg))) return SendClientMessage(playerid, -1, "Heart Removed");
// That heart does not exist!
SendClientMessage(playerid, -1, "Heart does not exist");
return 1;
}
// Checks if the player is near a heart
CMD:nearheart(playerid, arg[])
{
// Count how many hearts the player is near
new heartcount;
// Loop throuugh hearts
for(new i = 0; i < MAX_HEARTS; i++)
{
// Heart does not exist
if(HeartData[i][HeartObject] == INVALID_OBJECT_ID) continue;
// Player was in range of a heart increment the heart count
if(IsPlayerInRangeOfPoint(playerid, 5.0, HeartData[i][xPos], HeartData[i][yPos], HeartData[i][zPos])) heartcount++;
}
// There were hearts found show the player how many
if(heartcount)
{
new line[128];
format(line, sizeof(line), "You are near %i hearts!", heartcount);
SendClientMessage(playerid, -1, line);
}
else SendClientMessage(playerid, 0xFF0000FF, "You are not near any hearts!");
return 1;
}