[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
#2

I'm surprised that no one has replied yet. This type of include could evolve into many other dynamic systems, and it would be great to see some more from you in the future. I'm going to replace the old vending machines with these so that they will support my anti-cheat.
Reply
#3

This is nice, it could replace the client sided vending machines and support linking with anti-cheats.
Reply
#4

Realy good job, thanks alot.

Here you can see actual machines pos: http://gta.wikia.com/Vending_Machines

Greetings

Ranslsad
Reply
#5

Thank you very much, this is pretty cool Great work.
Reply
#6

This is really amazing. SA-MP needed something like this.
Reply
#7

Thanks.

I got the coordinates of the single-player machines. Now the include replaces the single-player machines automatically, so no need to remove them manually.
Reply
#8

Awesome! I was thinking of making something like this; but never actually did anything more than think about it. Very well done from the looks of it.
Reply
#9

Thanks a lot, this is nice

Btw, why you dont use y_iterate and dynamics areas (streamer) to optimize this?
Reply
#10

Thanks.

I didn't want the user needed to download other includes to be able to use the include.
But i'm updating it to check if streamer is included, probably i'll do the same to y_iterate.
Reply
#11

I'd recommend adding the following:

pawn Код:
SetVendingMachineMaterial(...);
GetVendingMachineMaterial(...);
SetVendingMachineColor(vendingid, color);
GetVendingMachineColor(vendingid);
Reply
#12

Good suggestion.

Currently, only colors is supported.

On next updates, I'll insert object material changes.

Reply
#13

Nice: looks pretty damn cool!(especially how the silver is still apparent, suggesting maybe different sprunk flavors?).

And another suggestion(which judging by script organization is very easy):
pawn Код:
GetVendingMachineObjectID(vendingid);
And maybe(although since streamer would be included isn't really THAT needed):
pawn Код:
GetVendingMachineObjectType(vendingid);
And the types would be something like:

pawn Код:
VENDING_MACHINE_TYPE_OBJECT
VENDING_MACHINE_TYPE_DYNAMIC_OBJECT
(I have made a pull request on github if your intrested.)
Reply
#14

Quote:
Originally Posted by Abagail
Посмотреть сообщение
Nice: looks pretty damn cool!(especially how the silver is still apparent, suggesting maybe different sprunk flavors?).

And another suggestion(which judging by script organization is very easy):
pawn Код:
GetVendingMachineObjectID(vendingid);
Yeah, actually, this function already exist. Just wasn't documented. Thanks for reminding me.


Edit:
Quote:
Originally Posted by Abagail
Посмотреть сообщение
(I have made a pull request on github if your intrested.)
Ok.

Btw, thanks for your suggestions.
Reply
#15

This is pretty decent actually, I may use this, thanks.
Reply
#16

Quote:
Originally Posted by Luis-
Посмотреть сообщение
This is pretty decent actually, I may use this, thanks.
More than decent; it's a revolution. I may release a loading / saving vending machines script, I'll see how that goes. This is a good include indeed, especially for those looking to customize their SA:MP servers extensively(especially with the color functions).
Reply
#17

Omg amazing!!, Thanks for this work awesome.
Reply
#18

Very interesting !

nice job Larceny.
Reply
#19

I like the machine colour thing.
Reply
#20

Quote:
Originally Posted by Kar
Посмотреть сообщение
I like the machine colour thing.
My suggestion, <3. Anyways, I have a question: Does this properly replace the original vending machine objects to the point where it doesn't create a crash when someone times out?(due to RemoveBuildingForPlayer being called twice).
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)