[Include] Campfire in SA-MP 'Object'
#1

[] Campfire in SA-MP 'Object' By OTACON
[] Information:
N/A

[] Function:
pawn Код:
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.
[] Example Usage:
pawn Код:
#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;
    }
[] Downloads:


[] Password:
Otacon

[] Credits:
OTACON
Reply
#2

Wow, nice man.

If i was to use:
pawn Код:
IsPlayerInRangeOfFire(playerid, &Float:distance);
You could slowly kill the player if they are right? that's pretty impressive. +rep.
Reply
#3

Just what I need Thanks
Reply
#4

:O noice!
Reply
#5

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;
}
Reply
#6

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
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!
LMAO.

Between, nice idea OTACON, finally... something different from you, you can be proud of yourself.
Reply
#7

He just needs to improve his dynamic system design then he'll be 100 percent boss
Reply
#8

Just a question, how is this better than checking for the object itself?
Reply
#9

The CreateCampfire() function should return the id of the campfire that was created.

When you release something for free, make it easy for people to view/download your code.
Don't use passworded archives and post a pastebin link with the code. In what situation would a passworded archive be useful?
Reply
#10

Hello nice Script but i cant do it this script for one person,i mean Player write /campfire and its 1 campfire cannot spawn 2 campfires how to make it? its for RolePlay server
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)