Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 15

/*==========================================================================

Dynamic Fast Food System


______________________

Credits:-
__________

1. Yashas for improved zcmd


2. Incognito for streamer plugin/include
3. Konstantinos for SQLite tutorial
4. adri1 for textdraw editor
5. Y_less for YSI library

** Created by: SilentSoul


===========================================================================*/
#include <a_samp>
#include <izcmd>
#include <streamer>
#include <mSelection>
#include <YSI\y_iterate>

#define MAX_FOOD (100) // Maximum to load from database, you may change
that.

//Prices
#define PIZZA_PRICE (10)
#define FRIES_PRICE (5)
#define COLA_PRICE (2)
#define BURGER_PRICE (10)
#define HOTDOG_PRICE (10)

enum FoodData
{
id,
fmodelid,
fcheckpointid,
text[32],
Text3D:textid,

Float:ObjPosX,
Float:ObjPosY,
Float:ObjPosZ,
Float:ObjRotX,
Float:ObjRotY,
Float:ObjRotZ,

ActorID,
ActorSkin,
Float:ActorX,
Float:ActorY,
Float:ActorZ,
Float:ActorRot
};

new
FoodInfo[ MAX_FOOD ][FoodData ],
DB:f_database,
Iterator:Foods<MAX_FOOD>,
Text:Foodobj[15],
bool:Isviewingobj[MAX_PLAYERS],
PlayerAttachedObject[MAX_PLAYERS];

public OnFilterScriptInit()
{
print("\n--------------------------------------");
print(" Dynamic fast food system loaded");
print("--------------------------------------\n");

if ((f_database = db_open("food.db")) == DB: 0)


{
print("[SQLite]: Failed to open a connection to food.db");
print("[SQLite]: Creating food.db database...");
}
else
{
db_query( f_database, "PRAGMA synchronous = OFF" );
db_query( f_database, "CREATE TABLE IF NOT EXISTS food (id INTEGER, modelid
INTEGER, text VARCHAR(32) COLLATE NOCASE, x FLOAT, y FLOAT, z FLOAT, rotx FLOAT,
roty FLOAT, rotz FLOAT, Actorskin INTEGER, ActorX FLOAT, ActorY FLOAT, ActorZ
FLOAT, ActorRot FLOAT)");
}

new
Query[ 23 ],
DBResult: Result,
str[ 64 ],
fid;
format( Query, sizeof( Query ) , "SELECT * FROM food" );
Result = db_query( f_database, Query );

if (db_num_rows(Result))
{

for ( new i = 0; i != db_num_rows(Result); i++ )


{
fid = db_get_field_assoc_int( Result, "id" );
Iter_Add(Foods, fid);

FoodInfo[ fid ] [ fmodelid ] = db_get_field_assoc_int( Result,


"modelid" );

db_get_field_assoc(Result, "text", FoodInfo[ fid ] [ text ], 32 );

FoodInfo[ fid ] [ ObjPosX ] = db_get_field_assoc_float( Result , "x" );


FoodInfo[ fid ] [ ObjPosY ] = db_get_field_assoc_float( Result , "y" );
FoodInfo[ fid ] [ ObjPosZ ] = db_get_field_assoc_float( Result , "z" );

FoodInfo[ fid ] [ ObjRotX ] = db_get_field_assoc_float( Result , "rotx"


);
FoodInfo[ fid ] [ ObjRotY ] = db_get_field_assoc_float( Result , "roty"
);
FoodInfo[ fid ] [ ObjRotZ ] = db_get_field_assoc_float( Result , "rotz"
);
FoodInfo[ fid ] [ ActorSkin ] = db_get_field_assoc_int( Result,
"Actorskin" );
FoodInfo[ fid ] [ ActorX ] = db_get_field_assoc_float( Result ,
"ActorX" );
FoodInfo[ fid ] [ ActorY ] = db_get_field_assoc_float( Result ,
"ActorY" );
FoodInfo[ fid ] [ ActorZ ] = db_get_field_assoc_float( Result ,
"ActorZ" );
FoodInfo[ fid ] [ ActorRot ] = db_get_field_assoc_float( Result ,
"ActorRot" );

format( str, sizeof( str ) , "%s\nID(%d)", FoodInfo[ fid ] [ text


], fid );
FoodInfo[ fid ] [ textid ] = CreateDynamic3DTextLabel( str, -1,
FoodInfo[ fid ] [ ObjPosX ], FoodInfo[ fid ] [ ObjPosY ], FoodInfo[ fid ] [ ObjPosZ
], 10.0 );

FoodInfo[ fid ] [ id ] = CreateDynamicObject( FoodInfo[ fid ]


[ fmodelid ], FoodInfo[ fid ] [ ObjPosX ], FoodInfo[ fid ] [ ObjPosY ],
FoodInfo[ fid ] [ ObjPosZ ], FoodInfo[ fid ] [ ObjRotX ], FoodInfo[ fid ] [ ObjRotY
], FoodInfo[ fid ] [ ObjRotZ ] );

FoodInfo[ fid ] [ ActorID ] = CreateActor( FoodInfo[ fid ]


[ ActorSkin ] , FoodInfo[ fid ] [ ActorX ], FoodInfo[ fid ] [ ActorY ],
FoodInfo[ fid ] [ ActorZ ], FoodInfo[ fid ] [ ActorRot ] );

GetXYInFrontOfActor( FoodInfo[ fid ] [ ActorID ], FoodInfo[ fid ]


[ ActorX ], FoodInfo[ fid ] [ ActorY ], 2.0 );
FoodInfo[ fid ] [ fcheckpointid ] =
CreateDynamicCP( FoodInfo[ fid ] [ ActorX ], FoodInfo[ fid ]
[ ActorY ],FoodInfo[ fid ] [ ActorZ ] , 1.0, -1, -1, -1, 10.0);

db_next_row(Result);

print("\n==========================================================================
=");
printf( "[FOOD SYSTEM]: Loaded (%i) from the
database.",db_num_rows(Result) );

print("============================================================================
=\n");

db_free_result(Result);

}
Foodobj[1] = TextDrawCreate(192.699951, 118.449996, "");
TextDrawLetterSize(Foodobj[1], 0.000000, 0.000000);
TextDrawTextSize(Foodobj[1], 248.000000, 209.000000);
TextDrawAlignment(Foodobj[1], 1);
TextDrawColor(Foodobj[1], 255);
TextDrawSetShadow(Foodobj[1], 0);
TextDrawSetOutline(Foodobj[1], 0);
TextDrawBackgroundColor(Foodobj[1], 0);
TextDrawFont(Foodobj[1], 5);
TextDrawSetProportional(Foodobj[1], 0);
TextDrawSetShadow(Foodobj[1], 0);
TextDrawSetPreviewModel(Foodobj[1], 1895);
TextDrawSetPreviewRot(Foodobj[1], 0.000000, 0.000000, 0.000000, 1.000000);

Foodobj[0] = TextDrawCreate(278.500000, 120.000000, "box");


TextDrawLetterSize(Foodobj[0], 0.000000, 15.299999);
TextDrawTextSize(Foodobj[0], 350.000000, 0.000000);
TextDrawAlignment(Foodobj[0], 1);
TextDrawColor(Foodobj[0], -1);
TextDrawUseBox(Foodobj[0], 1);
TextDrawBoxColor(Foodobj[0], -935582209);
TextDrawSetShadow(Foodobj[0], 0);
TextDrawSetOutline(Foodobj[0], 0);
TextDrawBackgroundColor(Foodobj[0], 255);
TextDrawFont(Foodobj[0], 1);
TextDrawSetProportional(Foodobj[0], 1);
TextDrawSetShadow(Foodobj[0], 0);

Foodobj[2] = TextDrawCreate(219.500000, 206.187500, "");


TextDrawLetterSize(Foodobj[2], 0.000000, 0.000000);
TextDrawTextSize(Foodobj[2], 186.000000, 81.000000);
TextDrawAlignment(Foodobj[2], 1);
TextDrawColor(Foodobj[2], 255);
TextDrawSetShadow(Foodobj[2], 0);
TextDrawSetOutline(Foodobj[2], 0);
TextDrawBackgroundColor(Foodobj[2], 0);
TextDrawFont(Foodobj[2], 5);
TextDrawSetProportional(Foodobj[2], 0);
TextDrawSetShadow(Foodobj[2], 0);
TextDrawSetPreviewModel(Foodobj[2], 19134);
TextDrawSetPreviewRot(Foodobj[2], 0.000000, 0.000000, 90.000000, 1.000000);

Foodobj[3] = TextDrawCreate(296.500000, 144.062500, "FAST~n~~n~~n~MENU");


TextDrawLetterSize(Foodobj[3], 0.400000, 1.600000);
TextDrawAlignment(Foodobj[3], 1);
TextDrawColor(Foodobj[3], -54630401);
TextDrawSetShadow(Foodobj[3], 0);
TextDrawSetOutline(Foodobj[3], 0);
TextDrawBackgroundColor(Foodobj[3], 255);
TextDrawFont(Foodobj[3], 1);
TextDrawSetProportional(Foodobj[3], 1);
TextDrawSetShadow(Foodobj[3], 0);

Foodobj[4] = TextDrawCreate(287.500000, 162.000000, "FOOD");


TextDrawLetterSize(Foodobj[4], 0.539499, 1.888749);
TextDrawAlignment(Foodobj[4], 1);
TextDrawColor(Foodobj[4], -1);
TextDrawSetShadow(Foodobj[4], 0);
TextDrawSetOutline(Foodobj[4], 0);
TextDrawBackgroundColor(Foodobj[4], 255);
TextDrawFont(Foodobj[4], 1);
TextDrawSetProportional(Foodobj[4], 1);
TextDrawSetShadow(Foodobj[4], 0);

Foodobj[5] = TextDrawCreate(183.500000, 120.000000, "");


TextDrawLetterSize(Foodobj[5], 0.000000, 0.000000);
TextDrawTextSize(Foodobj[5], 90.000000, 90.000000);
TextDrawAlignment(Foodobj[5], 1);
TextDrawColor(Foodobj[5], -1);
TextDrawSetShadow(Foodobj[5], 0);
TextDrawSetOutline(Foodobj[5], 0);
TextDrawBackgroundColor(Foodobj[5], 0);
TextDrawFont(Foodobj[5], 5);
TextDrawSetProportional(Foodobj[5], 0);
TextDrawSetShadow(Foodobj[5], 0);
TextDrawSetSelectable(Foodobj[5], true);
TextDrawSetPreviewModel(Foodobj[5], 2702);
TextDrawSetPreviewRot(Foodobj[5], 0.000000, -60.000000, 90.000000, 1.000000);

Foodobj[6] = TextDrawCreate(221.500000, 197.875000, "PIZZA~n~~g~$10");


TextDrawLetterSize(Foodobj[6], 0.282500, 0.865000);
TextDrawAlignment(Foodobj[6], 1);
TextDrawColor(Foodobj[6], -1);
TextDrawSetShadow(Foodobj[6], 0);
TextDrawSetOutline(Foodobj[6], 0);
TextDrawBackgroundColor(Foodobj[6], 255);
TextDrawFont(Foodobj[6], 2);
TextDrawSetProportional(Foodobj[6], 1);
TextDrawSetShadow(Foodobj[6], 0);

Foodobj[7] = TextDrawCreate(183.000000, 193.500000, "");


TextDrawLetterSize(Foodobj[7], 0.000000, 0.000000);
TextDrawTextSize(Foodobj[7], 83.000000, 101.000000);
TextDrawAlignment(Foodobj[7], 1);
TextDrawColor(Foodobj[7], -1);
TextDrawSetShadow(Foodobj[7], 0);
TextDrawSetOutline(Foodobj[7], 0);
TextDrawBackgroundColor(Foodobj[7], 0);
TextDrawFont(Foodobj[7], 5);
TextDrawSetProportional(Foodobj[7], 0);
TextDrawSetShadow(Foodobj[7], 0);
TextDrawSetSelectable(Foodobj[7], true);
TextDrawSetPreviewModel(Foodobj[7], 2858);
TextDrawSetPreviewRot(Foodobj[7], 0.000000, 0.000000, 270.000000, 1.000000);

Foodobj[8] = TextDrawCreate(227.500000, 260.875000, "FRIES~n~~g~$5");


TextDrawLetterSize(Foodobj[8], 0.282500, 0.865000);
TextDrawAlignment(Foodobj[8], 1);
TextDrawColor(Foodobj[8], -1);
TextDrawSetShadow(Foodobj[8], 0);
TextDrawSetOutline(Foodobj[8], 0);
TextDrawBackgroundColor(Foodobj[8], 255);
TextDrawFont(Foodobj[8], 2);
TextDrawSetProportional(Foodobj[8], 1);
TextDrawSetShadow(Foodobj[8], 0);

Foodobj[9] = TextDrawCreate(282.000000, 239.437500, "");


TextDrawLetterSize(Foodobj[9], 0.000000, 0.000000);
TextDrawTextSize(Foodobj[9], 58.000000, 66.000000);
TextDrawAlignment(Foodobj[9], 1);
TextDrawColor(Foodobj[9], -1);
TextDrawSetShadow(Foodobj[9], 0);
TextDrawSetOutline(Foodobj[9], 0);
TextDrawBackgroundColor(Foodobj[9], 0);
TextDrawFont(Foodobj[9], 5);
TextDrawSetProportional(Foodobj[9], 0);
TextDrawSetShadow(Foodobj[9], 0);
TextDrawSetSelectable(Foodobj[9], true);
TextDrawSetPreviewModel(Foodobj[9], 2647);
TextDrawSetPreviewRot(Foodobj[9], 0.000000, 0.000000, 270.000000, 1.000000);

Foodobj[10] = TextDrawCreate(300.000000, 294.562500, "COLA~n~~g~$2");


TextDrawLetterSize(Foodobj[10], 0.282500, 0.865000);
TextDrawAlignment(Foodobj[10], 1);
TextDrawColor(Foodobj[10], -1);
TextDrawSetShadow(Foodobj[10], 0);
TextDrawSetOutline(Foodobj[10], 0);
TextDrawBackgroundColor(Foodobj[10], 255);
TextDrawFont(Foodobj[10], 2);
TextDrawSetProportional(Foodobj[10], 1);
TextDrawSetShadow(Foodobj[10], 0);

Foodobj[11] = TextDrawCreate(360.000000, 213.625000, "");


TextDrawLetterSize(Foodobj[11], 0.000000, 0.000000);
TextDrawTextSize(Foodobj[11], 58.000000, 66.000000);
TextDrawAlignment(Foodobj[11], 1);
TextDrawColor(Foodobj[11], -1);
TextDrawSetShadow(Foodobj[11], 0);
TextDrawSetOutline(Foodobj[11], 0);
TextDrawBackgroundColor(Foodobj[11], 0);
TextDrawFont(Foodobj[11], 5);
TextDrawSetProportional(Foodobj[11], 0);
TextDrawSetShadow(Foodobj[11], 0);
TextDrawSetSelectable(Foodobj[11], true);
TextDrawSetPreviewModel(Foodobj[11], 2880);
TextDrawSetPreviewRot(Foodobj[11], 180.000000, 90.000000, 360.000000,
1.000000);

Foodobj[12] = TextDrawCreate(374.500000, 249.500000, "BURGER~n~~g~$10");


TextDrawLetterSize(Foodobj[12], 0.282500, 0.865000);
TextDrawAlignment(Foodobj[12], 1);
TextDrawColor(Foodobj[12], -1);
TextDrawSetShadow(Foodobj[12], 0);
TextDrawSetOutline(Foodobj[12], 0);
TextDrawBackgroundColor(Foodobj[12], 255);
TextDrawFont(Foodobj[12], 2);
TextDrawSetProportional(Foodobj[12], 1);
TextDrawSetShadow(Foodobj[12], 0);

Foodobj[13] = TextDrawCreate(292.500000, 95.500000, "");


TextDrawLetterSize(Foodobj[13], 0.000000, 0.000000);
TextDrawTextSize(Foodobj[13], 165.000000, 125.000000);
TextDrawAlignment(Foodobj[13], 1);
TextDrawColor(Foodobj[13], -1);
TextDrawSetShadow(Foodobj[13], 0);
TextDrawSetOutline(Foodobj[13], 0);
TextDrawBackgroundColor(Foodobj[13], 0);
TextDrawFont(Foodobj[13], 5);
TextDrawSetProportional(Foodobj[13], 0);
TextDrawSetShadow(Foodobj[13], 0);
TextDrawSetSelectable(Foodobj[13], true);
TextDrawSetPreviewModel(Foodobj[13], 2769);
TextDrawSetPreviewRot(Foodobj[13], 0.000000, 60.000000, 90.000000, 1.000000);

Foodobj[14] = TextDrawCreate(364.000000, 192.625000, "Hot-dog~n~~g~$15");


TextDrawLetterSize(Foodobj[14], 0.282500, 0.865000);
TextDrawAlignment(Foodobj[14], 1);
TextDrawColor(Foodobj[14], -1);
TextDrawSetShadow(Foodobj[14], 0);
TextDrawSetOutline(Foodobj[14], 0);
TextDrawBackgroundColor(Foodobj[14], 255);
TextDrawFont(Foodobj[14], 2);
TextDrawSetProportional(Foodobj[14], 1);
TextDrawSetShadow(Foodobj[14], 0);
return true;
}

public OnFilterScriptExit()
{
for( new o = 0; o < 15; o++ )
{
TextDrawDestroy( Foodobj[o] );
}
for( new p = 0; p < MAX_FOOD; p ++ )
{
if( IsValidDynamicObject( FoodInfo[ p ] [ id ] ) )
{ DestroyDynamicObject( FoodInfo[ p ] [ id ] ); }
if( IsValidDynamicCP( FoodInfo[ p ] [ fcheckpointid ] ) )
{ DestroyDynamicCP( FoodInfo[ p ] [ fcheckpointid ] ); }
if( IsValidDynamic3DTextLabel( FoodInfo[ p ] [ textid ] ) )
{ DestroyDynamic3DTextLabel( FoodInfo[ p ] [ textid ] ); }
DestroyActor( FoodInfo[ p ] [ ActorID ] );
}
return true;
}
public OnPlayerConnect(playerid)
{
EnablePlayerCameraTarget(playerid, true);

return true;
}
public OnPlayerSpawn(playerid)
{
PreloadAnimLib( playerid, "FOOD" );
PreloadAnimLib( playerid, "DEALER" );
PreloadAnimLib( playerid, "VENDING" );

return true;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == 122 )
{
if(response)
{
switch( listitem )
{
case 0:
{
new
objects[ 3 ];
objects [ 0 ] = 1340, objects[ 1 ] = 956,
objects[ 2 ] = 1776;//you may add all the objects you want
ShowModelSelectionMenuEx(playerid, objects, 3, "Select
object model", 124, 16.0, 0.0, 180.0, 1.0, 0x00000033, 0x00000066, 0xA1A1A133);
}
case 1:
{
new
str[ 256 ];
for( new i = 0; i < MAX_FOOD; i++ )
{
if( IsValidDynamicObject( FoodInfo[ i ]
[ id ] ) )
{
format( str, sizeof( str ), "%s %s [ID:%d]\n",
str, FoodInfo[ i ] [ text ], i );
}
}
ShowPlayerDialog( playerid, 0, DIALOG_STYLE_LIST,
"Information", str, "Ok","" );
}
case 2:
{
ShowPlayerDialog( playerid, 124, DIALOG_STYLE_INPUT,
"Type the ID", "Type the ID you would like to teleport there", "Ok","" );
}
case 3:
{
ShowPlayerDialog( playerid, 125, DIALOG_STYLE_INPUT, "Type
the ID","Please type the ID of the desired one to be deleted\nNOTE: its found on
the object", "Ok", "Back" );
}
}
}
}
if( dialogid == 123 )
{
if( ! response ) return ShowPlayerDialog( playerid, 123,
DIALOG_STYLE_INPUT, "Type text", "Type here the text you would like to attach to
the object\n{FF0000}You can't skip this! its obligatory", "Ok", "");
if( response )
{
new
str[ 64 ], query[ 520 ], f_id;
f_id = Iter_Free(Foods);
format( str, sizeof( str ) , "%s\nID(%d)", inputtext, f_id );
FoodInfo[ f_id] [ textid ] = CreateDynamic3DTextLabel( str, -1,
FoodInfo[ f_id ] [ ObjPosX ], FoodInfo[ f_id ] [ ObjPosY ], FoodInfo[ f_id ]
[ ObjPosZ ], 10.0 );
format(FoodInfo[ f_id ] [ text ], 32, "%s", inputtext);
format( query , sizeof( query ) , "INSERT INTO food (id, modelid,
text, x, y, z, rotx, roty, rotz, Actorskin, ActorX, ActorY, ActorZ , ActorRot)
VALUES (%d, %d, '%s', %f, %f, %f, %f, %f, %f, %d, %f, %f, %f, %f)",\
f_id,
FoodInfo[ f_id ] [ fmodelid ],
inputtext ,
FoodInfo[ f_id ] [ ObjPosX ] ,
FoodInfo[ f_id ] [ ObjPosY ],
FoodInfo[ f_id ] [ ObjPosZ ],
FoodInfo[ f_id ] [ ObjRotX ],
FoodInfo[ f_id ] [ ObjRotY ],
FoodInfo[ f_id ] [ ObjRotZ ],
FoodInfo[ f_id ] [ ActorSkin ] ,
FoodInfo[ f_id ] [ ActorX ],
FoodInfo[ f_id ] [ ActorY ],
FoodInfo[ f_id ] [ ActorZ ],
FoodInfo[ f_id ] [ ActorRot ] );

db_query( f_database, query );

GetXYInFrontOfActor( FoodInfo[ f_id ] [ ActorID ], FoodInfo[ f_id


] [ ActorX ], FoodInfo[ f_id ] [ ActorY ], 2.0 );
FoodInfo[ f_id ] [ fcheckpointid ] =
CreateDynamicCP( FoodInfo[ f_id ] [ ActorX ], FoodInfo[ f_id ] [ ActorY ],FoodInfo[
f_id ] [ ActorZ ] , 1.0, -1, -1, -1, 10.0);

Iter_Add(Foods, f_id);
}
}
if( dialogid == 124 )
{
if( response )
{
new
f_id = strval(inputtext);
if(! strval( inputtext ) ) return SendClientMessage( playerid,
0xFF0000FF, "[ERROR]{FFFFFF} You must enter numbers only" );
if( !IsValidDynamicObject( FoodInfo[ f_id ] [ id ] )) return
SendClientMessage( playerid, 0xFF0000FF, "[ERROR]{FFFFFF} That object does not
exist!" );

new
Float:x, Float:y, Float:z;
GetDynamicObjectPos( FoodInfo[ strval(inputtext) ] [ id ] , x, y, z
);
SetPlayerPos( playerid, x+2.0, y+1.0,z );
GameTextForPlayer( playerid, "~b~~h~Teleported!", 2000, 3 );
}
}
if( dialogid == 125 )
{
if(response)
{
new
f_id = strval(inputtext);
if(!Iter_Contains(Foods, f_id)) return SendClientMessage( playerid,
0x00B503FF, "[INFO]{FFFFFF} Please type the number only (0-99)" );
if( !IsValidDynamicObject( FoodInfo[ f_id ] [ id ] )) return
SendClientMessage( playerid, 0xFF0000FF, "[ERROR]{FFFFFF} That object does not
exist!" );

DestroyDynamicObject( FoodInfo[ f_id ] [ id ] );

DestroyDynamic3DTextLabel( FoodInfo[ f_id ] [ textid ] );


DestroyActor( FoodInfo[ f_id ] [ ActorID ] );
DestroyDynamicCP( FoodInfo[ f_id ] [ fcheckpointid ] );
new
query[ 64 ];
format( query, sizeof( query ) , "DELETE FROM `food` WHERE id =
%d", f_id );
db_query( f_database, query );
GameTextForPlayer( playerid, "~g~Object Deleted!", 3000, 3 );
Iter_Remove(Foods, f_id);
}
}
return false;
}

public OnPlayerClickTextDraw(playerid, Text:clickedid)


{
if( clickedid == Text:INVALID_TEXT_DRAW )//if escape button is pressed
{
if( Isviewingobj[ playerid ] == true )
{
HidefoodTD( playerid );
Isviewingobj[ playerid ] = false;
}
}
if( clickedid == Foodobj[5] )
{
if( GetPlayerMoney( playerid ) < PIZZA_PRICE ) return
SendClientMessage( playerid, 0xFF0000FF, "[ERROR]{FFFFFF} You don't have money to
buy that food" );
GivePlayerMoney( playerid, - PIZZA_PRICE );
SetPlayerArmedWeapon(playerid,0);
HidefoodTD( playerid );

new
actorid = GetPlayerCameraTargetActor(playerid);
ApplyActorAnimation( actorid , "DEALER" , "shop_pay" , 4.0 , 0 , 0 ,
0 , 0 , 0 );

PlayerAttachedObject[ playerid ] = FindFreeObjectSlot( playerid );


SetPlayerAttachedObject( playerid, PlayerAttachedObject[ playerid ], 2702,
6, 0.138999, 0.046999, 0.021999, 0.000000, -7.300000, -90.100006, 1.000000,
1.000000, 1.000000);
ApplyAnimation(playerid, "FOOD", "EAT_Pizza", 4.0, 0 ,0 ,0 ,1 ,0 );
SetTimerEx("RemoveObject", 3000, false, "i", playerid );

}
if ( clickedid == Foodobj[7] )
{
if( GetPlayerMoney( playerid ) < FRIES_PRICE ) return
SendClientMessage( playerid, 0xFF0000FF, "[ERROR]{FFFFFF} You don't have money to
buy that food" );
GivePlayerMoney( playerid, - FRIES_PRICE );
SetPlayerArmedWeapon(playerid,0);
HidefoodTD( playerid );

new
actorid = GetPlayerCameraTargetActor(playerid);
ApplyActorAnimation( actorid , "DEALER" , "shop_pay" , 4.0 , 0 , 0 ,
0 , 0 , 0 );

PlayerAttachedObject[ playerid ] = FindFreeObjectSlot( playerid );


SetPlayerAttachedObject( playerid, PlayerAttachedObject[ playerid ], 2858,
6, 0.127000, 0.005999, 0.019999, 0.000000, -97.199974, 0.000000, 0.243000,
0.248000, 0.934000);
ApplyAnimation(playerid, "FOOD", "EAT_Pizza", 4.0, 0 ,0 ,0 ,1 ,0 );
SetTimerEx("RemoveObject", 3000, false, "i", playerid );

}
if ( clickedid == Foodobj[9] )
{
if( GetPlayerMoney( playerid ) < COLA_PRICE ) return
SendClientMessage( playerid, 0xFF0000FF, "[ERROR]{FFFFFF} You don't have money to
buy that food" );
GivePlayerMoney( playerid, - COLA_PRICE );
SetPlayerArmedWeapon(playerid,0);
HidefoodTD( playerid );

new
actorid = GetPlayerCameraTargetActor(playerid);
ApplyActorAnimation( actorid , "DEALER" , "shop_pay" , 4.0 , 0 , 0 ,
0 , 0 , 0 );

PlayerAttachedObject[ playerid ] = FindFreeObjectSlot( playerid );


SetPlayerAttachedObject( playerid, PlayerAttachedObject[ playerid ], 2647,
5, 0.147000, 0.036000, -0.009999, -45.299995, -95.299987, 0.000000, 0.715999,
0.839999, 0.786000);
ApplyAnimation(playerid, "VENDING", "VEND_Drink_P", 4.0, 0 ,0 ,0 ,1 ,0 );
SetTimerEx("RemoveObject", 3000, false, "i", playerid );

}
if ( clickedid == Foodobj[11] )
{
if( GetPlayerMoney( playerid ) < BURGER_PRICE ) return SendClientMessage(
playerid, 0xFF0000FF, "[ERROR]{FFFFFF} You don't have money to buy that food" );
GivePlayerMoney( playerid, - BURGER_PRICE );
SetPlayerArmedWeapon(playerid,0);
HidefoodTD( playerid );

new
actorid = GetPlayerCameraTargetActor(playerid);
ApplyActorAnimation( actorid , "DEALER" , "shop_pay" , 4.0 , 0 , 0 ,
0 , 0 , 0 );

PlayerAttachedObject[ playerid ] = FindFreeObjectSlot( playerid );


SetPlayerAttachedObject( playerid, PlayerAttachedObject[ playerid ], 2880,
6, 0.111999, 0.178000, 0.007999, 0.000000, 0.000000, -157.000045, 1.000000,
1.000000, 1.000000);
ApplyAnimation(playerid, "FOOD", "EAT_Burger", 4.0, 0 ,0 ,0 ,1 ,0 );
SetTimerEx("RemoveObject", 3000, false, "i", playerid );

}
if ( clickedid == Foodobj[13] )
{
if( GetPlayerMoney( playerid ) < HOTDOG_PRICE ) return SendClientMessage(
playerid, 0xFF0000FF, "[ERROR]{FFFFFF} You don't have money to buy that food" );
GivePlayerMoney( playerid, - HOTDOG_PRICE );
HidefoodTD( playerid );

new
actorid = GetPlayerCameraTargetActor(playerid);
ApplyActorAnimation( actorid , "DEALER" , "shop_pay" , 4.0 , 0 , 0 ,
0 , 0 , 0 );

PlayerAttachedObject[ playerid ] = FindFreeObjectSlot( playerid );


SetPlayerAttachedObject( playerid, PlayerAttachedObject[ playerid ], 2769,
6, 0.109999, 0.034999, 0.009000, 11.599999, 0.000000, -12.899994, 1.000000,
1.000000, 1.000000);
ApplyAnimation(playerid, "FOOD", "EAT_Chicken", 4.0, 0 ,0 ,0 ,1 ,0 );
SetTimerEx("RemoveObject", 3000, false, "i", playerid );

}
return true;
}
forward RemoveObject( playerid );
public RemoveObject( playerid )
{
new
Float:h;
GetPlayerHealth( playerid, h );
printf("health %f", h);
RemovePlayerAttachedObject( playerid, PlayerAttachedObject[ playerid ] );
ClearAnimations( playerid );
if( h < 100 && h >= 89 )
{
SetPlayerHealth( playerid, 100 );
}
if( h < 89)
{
SetPlayerHealth( playerid, h+10 );
}
}
public OnPlayerEditDynamicObject(playerid, objectid, response, Float:x, Float:y,
Float:z, Float:rx, Float:ry, Float:rz)
{
new f_id;
f_id = Iter_Free(Foods);
if( objectid == FoodInfo[ f_id ] [ id ] )
{
if( response == EDIT_RESPONSE_UPDATE )
{
SetDynamicObjectPos( objectid, x, y, z );
SetDynamicObjectRot( objectid, rx, ry, rz );// to update it so others
may see it.
}
if ( response == EDIT_RESPONSE_FINAL )
{
FoodInfo[ f_id ] [ id ]= objectid;

FoodInfo[ f_id ] [ ObjPosX ] = x;


FoodInfo[ f_id ] [ ObjPosY ] = y;
FoodInfo[ f_id ] [ ObjPosZ ] = z;

FoodInfo[ f_id ] [ ObjRotX ] = rx;


FoodInfo[ f_id ] [ ObjRotY ] = ry;
FoodInfo[ f_id ] [ ObjRotZ ] = rz;
SetDynamicObjectPos( objectid, x, y, z );
SetDynamicObjectRot( objectid, rx, ry, rz );
new
skins[ 6 ];
skins [ 0 ] = 171, skins[ 1 ] = 172, skins[ 2 ] =
169, skins[ 3 ] = 167, skins[ 4 ] = 168, skins[ 5 ] = 161;
ShowModelSelectionMenuEx(playerid, skins, 6, "Select
actor skin", 123, 16.0, 0.0, -55.0, 1.0, 0x00000033, 0x00000066, 0xA1A1A133);
}
else if( response == EDIT_RESPONSE_CANCEL ) { print("not response
hahahahha"); DestroyDynamicObject( FoodInfo[ f_id ] [ id ]) ; }
}
return true;
}
public OnPlayerModelSelectionEx(playerid, response, extraid, modelid)
{
if(extraid == 123)
{
if(response)
{
new
f_id;
f_id = Iter_Free(Foods);
FoodInfo[ f_id ] [ ActorSkin ] = modelid;
SendClientMessage( playerid, 0x00B503FF, "[INFO]{FFFFFF} Now stand
where you want to add the actor and type /saveact" );
GameTextForPlayer( playerid, "~w~Stand somewhere near object and type
~g~/saveact", 6000, 3 );
}
}
if(extraid == 124)
{
new
Float:x, Float:y, Float:z, f_id;
f_id = Iter_Free(Foods);
if( f_id == -1 || f_id == MAX_FOOD ) return SendClientMessage( playerid
, 0xFF0000FF, "[ERROR]{FFFFFF}You have reached the maxium limit!" );
GetPlayerPos( playerid, x, y, z );
FoodInfo[ f_id ] [ id ] = CreateDynamicObject( modelid, x+2.0, y, z,
0.0, 0.0, 0,0 );
EditDynamicObject( playerid, FoodInfo[ f_id ] [ id ] );
FoodInfo[ f_id ] [ fmodelid ] = modelid;
}
return 1;
}
public OnPlayerEnterDynamicCP(playerid, checkpointid)
{
for( new i = 0; i <= MAX_FOOD; i++ )
{
if( checkpointid == FoodInfo[ i ] [ fcheckpointid ] )
{
if(Isviewingobj[ playerid ] == false)
{
ShowfoodTD( playerid );
Isviewingobj[ playerid ] = true;
}
}
}
return true;
}
/*==========================================================
Functions
============================================================*/
ShowfoodTD( playerid )
{
for ( new i = 0; i < 15; i ++ )
{
TextDrawShowForPlayer( playerid, Foodobj[ i ] );

}
SelectTextDraw(playerid, 0x00FF00FF);
}
HidefoodTD( playerid )
{
for ( new i = 0; i < 15; i ++ )
{
TextDrawHideForPlayer( playerid, Foodobj[ i ] );
}
CancelSelectTextDraw(playerid);
}

stock GetXYInFrontOfActor(actorid, &Float:x, &Float:y, Float:distance)


{
// Created by Y_Less, just modified by me

new Float:a;

GetActorPos(actorid, x, y, a);
GetActorFacingAngle(actorid, a);

x += (distance * floatsin(-a, degrees));


y += (distance * floatcos(-a, degrees));
}
FindFreeObjectSlot( playerid )
{
new
objid;
for( new i = 0; i < MAX_PLAYER_ATTACHED_OBJECTS; i++ )
{
if( IsPlayerAttachedObjectSlotUsed( playerid, i ) ) continue;
objid = i;
}
return objid;
}
PreloadAnimLib(playerid, animlib[]) // not by me
{
ApplyAnimation( playerid,animlib,"null",0.0,0,0,0,0,0 );
}
/*==========================================================
commands
============================================================*/
CMD:food( playerid )
{
ShowPlayerDialog( playerid, 122, DIALOG_STYLE_LIST, "Choose option", "Create
new food machine\nList of food machines\nTeleport to food machine\nDelete food
machine", "Select", "Cancel" );
return true;
}
CMD:saveact( playerid )
{
new
Float:x, Float:y, Float:z, Float:ang, f_id;
f_id = Iter_Free(Foods);
GetPlayerPos( playerid, x, y, z );
GetPlayerFacingAngle( playerid, ang );
if(! IsPlayerInRangeOfPoint( playerid, 3.0, FoodInfo[ f_id ] [ ObjPosX ],
FoodInfo[ f_id ] [ ObjPosY ], FoodInfo[ f_id ] [ ObjPosZ ] ) ) return
SendClientMessage( playerid, -1, "You're far from that object!" );
FoodInfo[ f_id ] [ ActorX ] = x;
FoodInfo[ f_id ] [ ActorY ] = y;
FoodInfo[ f_id ] [ ActorZ ] = z;
FoodInfo[ f_id ] [ ActorRot ] = ang;

FoodInfo[ f_id ] [ ActorID ] = CreateActor( FoodInfo[ f_id ] [ ActorSkin ] ,


FoodInfo[ f_id ] [ ActorX ], FoodInfo[ f_id ] [ ActorY ], FoodInfo[ f_id ] [ ActorZ
], FoodInfo[ f_id ] [ ActorRot ] );

SetPlayerPos( playerid, x+2.0, y, z );

ShowPlayerDialog( playerid, 123, DIALOG_STYLE_INPUT, "Type text", "Type here


the text you would like to attach to the object", "Ok", "");
return true;
}

You might also like