This repository has been archived by the owner on Dec 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
trade.pwn
218 lines (192 loc) · 6.28 KB
/
trade.pwn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#define FILTERSCRIPT
#include <a_samp>
#include <a_graphfunc>
#include <zcmd>
#include <sscanf2>
#define MAX_POINTS 230
new Text:TDEditor_PTD;
enum pdata
{
showing,
moneyput,
Float:put,
buy,
}
new pData[MAX_PLAYERS][pdata];
enum pdta
{
Float:val
}
new Graph:MY_GRAPH;
new pointData[MAX_POINTS][pdta];
new Float:IncDec[][1] = {
{1.045}, {2.042}, {-1.045}, {-2.042}, {1.234}, {-1.234}, {-0.124}, {0.124}
};
forward InitializeTD(str[]);
public InitializeTD(str[])
{
TDEditor_PTD = TextDrawCreate(315.768646, 246.101257, str);
TextDrawLetterSize( TDEditor_PTD, 0.398000, 1.590000);
TextDrawTextSize(TDEditor_PTD, 0.000000, 200.000000);
TextDrawAlignment(TDEditor_PTD, 2);
TextDrawColor(TDEditor_PTD, -1);
TextDrawUseBox(TDEditor_PTD, 1);
TextDrawBoxColor( TDEditor_PTD, 255);
TextDrawSetShadow(TDEditor_PTD, 0);
TextDrawSetOutline(TDEditor_PTD, 0);
TextDrawBackgroundColor(TDEditor_PTD, 255);
TextDrawFont( TDEditor_PTD, 1);
TextDrawSetProportional( TDEditor_PTD, 1);
TextDrawSetShadow(TDEditor_PTD, 0);
}
main()
{
}
forward CreditsEzpz();
public CreditsEzpz()
{
printf("");
printf(" ======================================================== ");
printf("| |");
printf("| Trade System By Milton (Ezpz / StevenLV) Loaded.. |");
printf("| |");
printf(" ======================================================== ");
printf("");
}
public OnFilterScriptInit() {
AddPlayerClass(0, 0, 0, 0, 0, 0, 0, 0 ,0 , 0 ,0);
InitializeTD("Nothing");
for(new i = 0; i < MAX_POINTS; i++)
{
if(i == 0) pointData[i][val] = 1.0;
else if(i == MAX_POINTS - 1) pointData[i][val] = pointData[i-1][val];
else if(i > 150) pointData[i][val] = pointData[i-1][val] + 0.01;
else pointData[i][val] = pointData[i-1][val] + 1.0;
}
MY_GRAPH = GRAPHIC::Create(200.0, 250.0, 0, 0, 230, 230);
GRAPHIC::XYAxisColor(MY_GRAPH, 0x000000FF, 0x000000FF);
GRAPHIC::UseBackground(MY_GRAPH, 1);
GRAPHIC::BackgroundColor(MY_GRAPH, 0x000000FF);
SetTimer("ChangeVals", 1500, true);
SetTimer("CreditsEzpz", 2000, false);
}
CMD:trade(playerid, params[])
{
new money, bbuy[24], mstr[256];
if(sscanf(params, "is[24]", money, bbuy)) return SendClientMessage(playerid, -1, "[USAGE] /trade [MONEY] [Buy/Sell]");
if(money < 0) return SendClientMessage(playerid, -1, "[ERROR] Money must be positive.");
if(!strcmp(bbuy, "buy", true, 3))
{
pData[playerid][moneyput] = money;
pData[playerid][put] = pointData[MAX_POINTS - 1][val];
GivePlayerMoney(playerid, -money);
pData[playerid][buy] = 1; // buy
format(mstr, 256, "You have put on buy at %f", pData[playerid][put]);
SendClientMessage(playerid, -1, mstr);
}
else if(!strcmp(bbuy, "sell", true, 4))
{
pData[playerid][moneyput] = money;
pData[playerid][put] = pointData[MAX_POINTS - 1][val];
GivePlayerMoney(playerid, -money);
pData[playerid][buy] = 2; // sell
format(mstr, 256, "You have put on sell at %f", pData[playerid][put]);
SendClientMessage(playerid, -1, mstr);
}
else SendClientMessage(playerid, -1, "ERROR");
return 1;
}
CMD:stoptrade(playerid, params[])
{
if(pData[playerid][moneyput] == 0) return SendClientMessage(playerid, -1, "ERROR");
new Float:diff;
if(pData[playerid][buy] == 1) diff = pointData[MAX_POINTS-1][val] - pData[playerid][put];
else if(pData[playerid][buy] == 2) diff = pData[playerid][put] - pointData[MAX_POINTS - 1][val];
new multi = floatround(diff);
GivePlayerMoney(playerid, multi*pData[playerid][moneyput]);
new mstr[256];
format(mstr, 256, "You have earned %i.", multi*pData[playerid][moneyput]);
SendClientMessage(playerid, -1, mstr);
pData[playerid][moneyput] = 0;
pData[playerid][put] = 0;
pData[playerid][buy] = 0;
return 1;
}
CMD:tradechart(playerid, params[])
{
if(pData[playerid][showing] == 0)
{
GRAPHIC::ShowForPlayer(playerid, MY_GRAPH);
TextDrawShowForPlayer(playerid, TDEditor_PTD);
pData[playerid][showing] = 1;
}
else
{
GRAPHIC::HideForPlayer(playerid, MY_GRAPH);
TextDrawHideForPlayer(playerid, TDEditor_PTD);
pData[playerid][showing] = 0;
}
return 1;
}
/*native Graph:GRAPHIC::Create(Float:x, Float:y, Float:x_min, Float:y_min, Float:x_max, Float:y_max);
native GRAPHIC::XYAxisColor(Graph:_id, _x_color, _y_color);
native GRAPHIC::UseBackground(Graph:_id, use);
native GRAPHIC::BackgroundColor(Graph:_id, color);
native GRAPHIC::GRAPHIC::AddPoint(Graph:_id, Float:x, Float:y, color);
native GRAPHIC::ShowForPlayer(playerid, Graph:_id);
native GRAPHIC::HideForPlayer(playerid, Graph:_id);
native GRAPHIC::ShowForAll(Graph:_id);
native GRAPHIC::HideForAll(Graph:_id);
native GRAPHIC::Update(Graph:_id, playerid = INVALID_PLAYER_ID);
native GRAPHIC::Destroy(Graph:_id);
native GRAPHIC::OtherXYAxis(oper, playerid, Graph:_id, xAxis, yAxis);*/
public
OnPlayerSpawn(playerid)
{
//GRAPHIC::ShowForPlayer(playerid, MY_GRAPH);
// InitializeTD(playerid, "Nothing");
return 1;
}
forward ChangeVals();
public ChangeVals()
{
GRAPHIC::RemoveTD(MAX_POINTS);
GRAPHIC::Destroy(MY_GRAPH);
MY_GRAPH = GRAPHIC::Create(200.0, 250.0, 0, 0, 230, 230);
GRAPHIC::XYAxisColor(MY_GRAPH, 0x000000FF, 0x000000FF);
GRAPHIC::UseBackground(MY_GRAPH, 1);
GRAPHIC::BackgroundColor(MY_GRAPH, 0x000000FF);
new Float:exps;
new Float:oldshit = pointData[MAX_POINTS-1][val];
for(new i = 0; i < MAX_POINTS; i++)
{
exps = IncDec[random(sizeof(IncDec))][0];
if(i == MAX_POINTS - 1) pointData[i][val] = pointData[i][val] + exps;
else pointData[i][val] = pointData[i+1][val];
if(pointData[i][val] < 0.0) pointData[i][val] = 0.0;
if(pointData[i][val] > 229.0) pointData[i][val] = 229.0;
if(i < 0 || i > MAX_POINTS-1) continue;
GRAPHIC::AddPoint(MY_GRAPH, i, pointData[i][val], 0xFFFFFFFF);
}
new Float:newshit = pointData[MAX_POINTS - 1][val];
new Float:diff = newshit - oldshit;
new mstr[256];
if(diff >= 0) format(mstr, 256, " New: %f Diff:~g~%f", newshit, diff);
else format(mstr, 256, " New: %f Diff:~r~%f", newshit, diff);
//TextDrawDestroy(TDEditor_PTD);
//InitializeTD(mstr);
TextDrawSetString(TDEditor_PTD, mstr);
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(pData[i][showing] == 1)
{
GRAPHIC::ShowForPlayer(i, MY_GRAPH);
//TextDrawHideForPlayer(i, TDEditor_PTD);
TextDrawShowForPlayer(i, TDEditor_PTD);
}
}
}
GRAPHIC::ResetTD();
}