[Include] vending - Server-side vending machines
#1

Introduction

An include to create server-side vending machines that gives you full control of the in-game vending machines.

It automatically replaces the single-player machines. (since 1.6)

Example

Code:
new gVending;

main()
{
    gVending = CreateVendingMachine(MACHINE_SPRUNK, 1755.348144, -2113.468750, 12.692808, 0.000000, 0.000000, 180.000000);
}

public OnPlayerUseVendingMachine(playerid, machineid)
{ // Called when the player use the machine.
    if(GetPlayerMoney(playerid) < 1)
    {// If the player has no money.
        SendClientMessage(playerid, COLOR_ERROR, "* You don't have enough money.");
        return 0;
    }

    // Restore 10% of player's health and takes 1$.
    new Float:health;
    GetPlayerHealth(playerid, health);

    // Avoid player having more than 100.0 health.
    if((health + 10.0) > 100.0) health = 100.0;
    else health += 10.0;

    // Give player stats
    SetPlayerHealth(playerid, health);
    GivePlayerMoney(playerid, -1);
    return 1;
}

public OnPlayerDrinkSprunk(playerid)
{// Called when the player drink from the can.
    new Float:health;
    GetPlayerHealth(playerid, health);

    if((health + 10.0) > 100.0) health = 100.0;
    else health += 10.0;

    SetPlayerHealth(playerid, health);
    SendClientMessage(playerid, COLOR_INFO, "* You drank the sprunk. (+10HP)");
    return 1;
}
Functions
  • pawn Code:
    CreateVendingMachine(objectid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz);
    Creates a vending machine. returns the machine ID.
  • pawn Code:
    GetVendingMachineRot(machineid, &Float:rx, &Float:ry, &Float:rz);
    Gets the vending machine rotation, passed by reference.
  • pawn Code:
    SetVendingMachineRot(machineid, Float:rx, Float:ry, Float:rz);
    Sets the vending machine rotation.
  • pawn Code:
    GetVendingMachinePos(machineid, &Float:x, &Float:y, &Float:z);
    Gets the vending machine position.
  • pawn Code:
    SetVendingMachinePos(machineid, Float:x, Float:y, Float:z);
    Sets the vending machine position.
  • pawn Code:
    DestroyVendingMachine(machineid);
    Destroy a vending machine.
  • pawn Code:
    GetVendingMachineType(machineid);
    Gets the vending machine type.
  • pawn Code:
    SetVendingMachineColor(machineid, color);
    Sets the a vending machine color. (ARGB)
  • pawn Code:
    GetVendingMachineColor(machineid);
    Gets the vending machine color. (ARGB)
  • pawn Code:
    IsValidVendingMachine(machineid);
    Checks if a vending machine exist.
  • pawn Code:
    GetVendingMachineObjectID(machineid);
    Gets the ID of the objectid.
  • pawn Code:
    GetVendingMachineObjectType(machineid);
    returns OBJECT_TYPE_DYNAMIC if the machine is a dynamic object(streamer).
    returns OBJECT_TYPE_NORMAL if not.

    Just for reference.
Vending types

Currently, there is 3 types of vending machines.
Streamer plugin

If streamer plugin is included before vending.inc it will use CreateDynamicObject instead of CreateObject.

Creating a vending

You can use the vendingcreator filterscript to help you creating vendings.



Special action

By default, when a player uses the sprunk machine they get a sprunk can and can drink from it. You can disable it by adding NO_SPRUNK_ACTION before the include.

Code:
#define NO_SPRUNK_ACTION
#include <vending>
Download

Github.
Reply


Messages In This Thread
vending - Server-side vending machines - by Larceny - 01.01.2015, 15:36
Re: vending - Server-side vending machines - by SydthTV - 02.01.2015, 04:33
Re: vending - Server-side vending machines - by Lordzy - 02.01.2015, 04:34
Respuesta: vending - Server-side vending machines - by ranslsad - 02.01.2015, 11:57
Re: vending - Server-side vending machines - by RayC - 02.01.2015, 13:12
Re: vending - Server-side vending machines - by Diabloa - 02.01.2015, 13:37
Re: vending - Server-side vending machines - by Larceny - 04.01.2015, 18:08
Re: vending - Server-side vending machines - by Abagail - 04.01.2015, 18:11
Respuesta: vending - Server-side vending machines - by Swedky - 05.01.2015, 05:01
Re: vending - Server-side vending machines - by Larceny - 05.01.2015, 11:08
Re: vending - Server-side vending machines - by Abagail - 05.01.2015, 20:58
Re: vending - Server-side vending machines - by Larceny - 05.01.2015, 22:29
Re: vending - Server-side vending machines - by Abagail - 06.01.2015, 20:19
Re: vending - Server-side vending machines - by Larceny - 06.01.2015, 20:33
Re: vending - Server-side vending machines - by Luis- - 06.01.2015, 21:19
Re: vending - Server-side vending machines - by Abagail - 06.01.2015, 21:22
Re: vending - Server-side vending machines - by Ke_NiReM - 06.01.2015, 21:58
Re: vending - Server-side vending machines - by WLSF - 15.01.2015, 10:57
Re: vending - Server-side vending machines - by Kar - 19.01.2015, 22:57
Re: vending - Server-side vending machines - by Abagail - 19.01.2015, 23:06
Re: vending - Server-side vending machines - by RedGun2015 - 19.09.2017, 17:34

Forum Jump:


Users browsing this thread: 3 Guest(s)