vending - Server-side vending machines -
Larceny - 01.01.2015
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.
Re: vending - Server-side vending machines -
SydthTV - 02.01.2015
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.
Re: vending - Server-side vending machines -
Lordzy - 02.01.2015
This is nice, it could replace the client sided vending machines and support linking with anti-cheats.
Respuesta: vending - Server-side vending machines -
ranslsad - 02.01.2015
Realy good job, thanks alot.
Here you can see actual machines pos:
http://gta.wikia.com/Vending_Machines
Greetings
Ranslsad
Re: vending - Server-side vending machines -
RayC - 02.01.2015
Thank you very much, this is pretty cool
Great work.
Re: vending - Server-side vending machines -
Diabloa - 02.01.2015
This is really amazing. SA-MP needed something like this.
Re: vending - Server-side vending machines -
Larceny - 04.01.2015
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.
Re: vending - Server-side vending machines -
Abagail - 04.01.2015
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.
Respuesta: vending - Server-side vending machines -
Swedky - 05.01.2015
Thanks a lot, this is nice
Btw, why you dont use
y_iterate and dynamics areas (streamer) to optimize this?
Re: vending - Server-side vending machines -
Larceny - 05.01.2015
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.
Re: vending - Server-side vending machines -
Abagail - 05.01.2015
I'd recommend adding the following:
pawn Код:
SetVendingMachineMaterial(...);
GetVendingMachineMaterial(...);
SetVendingMachineColor(vendingid, color);
GetVendingMachineColor(vendingid);
Re: vending - Server-side vending machines -
Larceny - 05.01.2015
Good suggestion.
Currently, only colors is supported.
On next updates, I'll insert object material changes.
Re: vending - Server-side vending machines -
Abagail - 06.01.2015
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.)
Re: vending - Server-side vending machines -
Larceny - 06.01.2015
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.
Re: vending - Server-side vending machines -
Luis- - 06.01.2015
This is pretty decent actually, I may use this, thanks.
Re: vending - Server-side vending machines -
Abagail - 06.01.2015
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).
Re: vending - Server-side vending machines -
Ke_NiReM - 06.01.2015
Omg amazing!!, Thanks for this work awesome.
Re: vending - Server-side vending machines -
WLSF - 15.01.2015
Very interesting !
nice job Larceny.
Re: vending - Server-side vending machines -
Kar - 19.01.2015
I like the machine colour thing.
Re: vending - Server-side vending machines -
Abagail - 19.01.2015
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).