native CreateObjectCampfire(&slots, &Float:x, &Float:y, &Float:z, &Float:a); //to create the object of the campfire.
native DestroyObjectCampfire(&slots); //to destroy the object of the campfire.
native IsPlayerInRangeOfFire(playerid, &Float:distance); //to see if the player is close to the object of the campfire.
#include <a_samp>
#include <zcmd>
#include <a_Campfire>
public OnFilterScriptInit() {
print("\n**************************************");
print(" Campfire in SA-MP 'Object' ");
print(" Date: 16/07/2013 ");
print(" Author: OTACON ");
print(" --* Loaded with Success!!. *-- ");
print("***************************************\n");
CreateObjectCampfire(0, 664.4656,-1903.3425,3.1809,353.5751);
return true;
}
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;
}
COMMAND:fire(playerid, params[]) {
if(!IsPlayerConnected(playerid)) return true;
if(IsPlayerInRangeOfFire(playerid, 3.0)) SendClientMessage(playerid, -1, " [ ! ] you are near a campfire.!.");
else SendClientMessage(playerid, -1, " [ ! ] you are not near a campfire!.");
return true;
}
IsPlayerInRangeOfFire(playerid, &Float:distance);
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;
}
// 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;
}
pawn Код:
![]() |