SHOW:
|
|
- or go back to the newest paste.
1 | /*========================================================================= | |
2 | ------------------------------------------------------------------------- | |
3 | *************Off-Line Message/Cash Sender By Zeus aka. BroZeus************* | |
4 | ||
5 | Current Version:- v1.0 | |
6 | ||
7 | Credits-- | |
8 | YSI aka Cole Miner :For y_ini include and isnumeric stock and for sscanf2 [<--He is always there :D] | |
9 | Zeex :For ZCMD | |
10 | David Weston :For strlib.inc | |
11 | Whole SAMP Team :For SAMP and PAWNO compiler [ofc This credit would be alwasy there] | |
12 | Zeus aka BroZeus :For scripting of this FS | |
13 | ||
14 | Avalable commands:-- | |
15 | /sendcash ---For sending offline message/cash | |
16 | /sendmes ---Same as /sendcash | |
17 | /trans ---For seeing received messages [Read messages=Green in color and UNREAD messages = orange in color] | |
18 | ||
19 | *******************DO NOT REMOVE CREDITS OR REDISTRUBATE******************* | |
20 | ---------------------------------------------------------------------------- | |
21 | ===========================================================================*/ | |
22 | ||
23 | #include <a_samp> | |
24 | #include <YSI\y_ini> | |
25 | #include <zcmd> | |
26 | #include <sscanf2> | |
27 | #include <strlib> | |
28 | /*======================*/ | |
29 | #define USER_PATH "/Users/%s.ini"//specifies the user path which your server uses | |
30 | /*======================*/ | |
31 | #define D_SendCash1 500//the dialogs and there id edit thier id's as per as your use DONT CHANGE THERE NAMES ONLY EDIT ID's | |
32 | #define D_MainMes 501 | |
33 | #define D_ConfirmMes 502 | |
34 | #define D_Transfers 503 | |
35 | #define D_InputBox 504 | |
36 | /*======================*/ | |
37 | #define MESP "/Transfers/%s.ini" | |
38 | /*======================*/ | |
39 | enum mInfo | |
40 | { | |
41 | Sender[MAX_PLAYER_NAME], | |
42 | Reciver[MAX_PLAYER_NAME], | |
43 | Subject[50], | |
44 | Amount, | |
45 | line1[100], | |
46 | line2[100], | |
47 | IsRead, | |
48 | msgn, | |
49 | newmsg | |
50 | } | |
51 | new MesInfo[MAX_PLAYERS][mInfo]; | |
52 | new Inpu[MAX_PLAYERS],tg[10]; | |
53 | /*=================================================================*/ | |
54 | forward LoadMNO_MNO(playerid,name[],value[]); | |
55 | public LoadMNO_MNO(playerid,name[],value[]) | |
56 | { | |
57 | INI_Int("msg_numbers", MesInfo[playerid][msgn]); | |
58 | INI_Int("NewMsg", MesInfo[playerid][newmsg]); | |
59 | return 1; | |
60 | } | |
61 | /*==================================================================*/ | |
62 | ||
63 | stock ReadWithTag(playerid,path[],tag[])//this stock made by me [ZEUS} ;-) | |
64 | { | |
65 | new line[50],sqtag[12],sr=0,ide[15],val[21],lir=0; | |
66 | format(sqtag,12,"[%s]",tag); | |
67 | new File:Fi=fopen(path,io_read); | |
68 | while(fread(Fi,line)) | |
69 | { | |
70 | ||
71 | if(!strfind(line, sqtag, true))sr=1; | |
72 | if(sr==1) | |
73 | { | |
74 | lir++; | |
75 | sscanf(line,"p<=>s[15]s[21]",ide,val); | |
76 | if(lir==2)format(MesInfo[playerid][Reciver],MAX_PLAYER_NAME,"%s",str_replace("\n","",val)); | |
77 | if(lir==3)format(MesInfo[playerid][Sender],MAX_PLAYER_NAME,"%s",str_replace("\n","",val)); | |
78 | if(lir==4)format(MesInfo[playerid][Subject],MAX_PLAYER_NAME,"%s",str_replace("\n","",val)); | |
79 | if(lir==5)MesInfo[playerid][Amount]=strval(str_replace("\n","",val)); | |
80 | if(lir==6)format(MesInfo[playerid][line1],MAX_PLAYER_NAME,"%s",str_replace("\n","",val)); | |
81 | if(lir==7)format(MesInfo[playerid][line2],MAX_PLAYER_NAME,"%s",str_replace("\n","",val)); | |
82 | if(lir==8)MesInfo[playerid][IsRead]=strval(str_replace("\n","",val)); | |
83 | } | |
84 | if(lir==8)break; | |
85 | } | |
86 | fclose(Fi); | |
87 | sr = 0;lir=0; | |
88 | return 1; | |
89 | } | |
90 | ||
91 | ||
92 | ||
93 | stock UserPath(Reciverr[]) | |
94 | { | |
95 | new string[MAX_PLAYER_NAME+20]; | |
96 | format(string,sizeof(string),USER_PATH,Reciverr); | |
97 | return string; | |
98 | } | |
99 | ||
100 | stock MesPath(Reciverm[]) | |
101 | { | |
102 | new string[MAX_PLAYER_NAME+20]; | |
103 | format(string,sizeof(string),MESP,Reciverm); | |
104 | return string; | |
105 | } | |
106 | ||
107 | stock isnum(str[])//by YSI taken from y_utils | |
108 | { | |
109 | new ch,i; | |
110 | while ((ch = str[i++])) if (!('0' <= ch <= '9')) return 0; | |
111 | return 1; | |
112 | } | |
113 | ||
114 | stock ShowMes(playerid) | |
115 | { | |
116 | new str[250]; | |
117 | format(str,sizeof(str),"{00FFFF}Reciver:\t\t{54C571}%s\n{00FFFF}Subject:\t\t{54C571}%s\n{00FFFF}Amount:\t\t{4E9258}$%i\n{00FFFF}Detail[Line1]:\t\t{54C571}%s\n{00FFFF}Detail[Line2]:\t\t{54C571}%s\n{E3E4FA}Send!", | |
118 | MesInfo[playerid][Reciver], | |
119 | MesInfo[playerid][Subject], | |
120 | MesInfo[playerid][Amount], | |
121 | MesInfo[playerid][line1], | |
122 | MesInfo[playerid][line2]); | |
123 | ShowPlayerDialog(playerid,D_SendCash1,DIALOG_STYLE_LIST,"{842DCE}Send Message",str,"Select","Cancel"); | |
124 | } | |
125 | /*================================================================*/ | |
126 | public OnPlayerSpawn(playerid) | |
127 | { | |
128 | new named[MAX_PLAYER_NAME]; | |
129 | GetPlayerName(playerid,named,MAX_PLAYER_NAME); | |
130 | INI_ParseFile(MesPath(named), "LoadMNO_%s", .bExtra = true, .extra = playerid); | |
131 | if(MesInfo[playerid][newmsg]>=1) | |
132 | { | |
133 | - | new st[30]; |
133 | + | new st[300]; |
134 | format(st,sizeof(st),"{00FFFF}You have received {ff0000}%i {00FFFF}new offline messages. Please do {ff0000}/trans {00FFFF}to see it/them.",MesInfo[playerid][newmsg]); | |
135 | SendClientMessage(playerid,-1,st); | |
136 | } | |
137 | return 1; | |
138 | } | |
139 | ||
140 | public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) | |
141 | { | |
142 | ||
143 | switch(dialogid) | |
144 | { | |
145 | case D_SendCash1: | |
146 | { | |
147 | if(response){ | |
148 | switch(listitem) | |
149 | { | |
150 | case 0:{ShowPlayerDialog(playerid,D_InputBox,DIALOG_STYLE_INPUT,"{842DCE}Reciver","{B93B8F}Enter the name of player whihc you want to send the message to.","OK","Back");Inpu[playerid]=1;} | |
151 | case 1:{ShowPlayerDialog(playerid,D_InputBox,DIALOG_STYLE_INPUT,"{842DCE}Subject","{B93B8F}Enter the subject of the transfer message.","OK","Back");Inpu[playerid]=2;} | |
152 | case 2:{ShowPlayerDialog(playerid,D_InputBox,DIALOG_STYLE_INPUT,"{842DCE}Amount","{B93B8F}Enter the amount you want to send.","OK","Back");Inpu[playerid]=3;} | |
153 | case 3:{ShowPlayerDialog(playerid,D_InputBox,DIALOG_STYLE_INPUT,"{842DCE}Details[Line 1/2]","{B93B8F}Enter some description about the message.\n\nNOTE:Maximum characters 20.","OK","Back");Inpu[playerid]=4;} | |
154 | case 4:{ShowPlayerDialog(playerid,D_InputBox,DIALOG_STYLE_INPUT,"{842DCE}Details[Line 2/2]","{B93B8F}Enter some description about the message.\n\nNOTE:Maximum characters 20.","OK","Back");Inpu[playerid]=5;} | |
155 | case 5:{new str[250]; | |
156 | format(str,sizeof(str),"{00FFFF}Reciver:\t\t{54C571}%s\n{00FFFF}Subject:\t\t{54C571}%s\n{00FFFF}Amount:\t\t{4E9258}$%i\n{00FFFF}Detail[Line1]:\t\t{54C571}%s\n{00FFFF}Detail[Line2]:\t\t{54C571}%s\n\n{ff0000}NOTE:Clicking on confirmation will send the message.", | |
157 | MesInfo[playerid][Reciver], | |
158 | MesInfo[playerid][Subject], | |
159 | MesInfo[playerid][Amount], | |
160 | MesInfo[playerid][line1], | |
161 | MesInfo[playerid][line2]); | |
162 | ShowPlayerDialog(playerid,D_ConfirmMes,DIALOG_STYLE_MSGBOX,"{842DCE}Confirmation",str,"Confirm","Back"); | |
163 | } | |
164 | } | |
165 | } | |
166 | } | |
167 | ||
168 | /*..............*/ | |
169 | case D_InputBox: | |
170 | { | |
171 | if(response) | |
172 | { | |
173 | switch(Inpu[playerid]) | |
174 | { | |
175 | case 1:{ | |
176 | if(!fexist(UserPath(inputtext))) | |
177 | {SendClientMessage(playerid,-1,"{ff0000}There is no such user");ShowMes(playerid);} | |
178 | else | |
179 | {format(MesInfo[playerid][Reciver],MAX_PLAYER_NAME,"%s",inputtext);ShowMes(playerid);} | |
180 | } | |
181 | case 2:{ | |
182 | if(strlen(inputtext)>10) | |
183 | {SendClientMessage(playerid,-1,"{ff0000}Subject should not be more than 10 characters.");ShowMes(playerid);} | |
184 | else | |
185 | {format(MesInfo[playerid][Subject],MAX_PLAYER_NAME,"%s",inputtext);ShowMes(playerid);} | |
186 | } | |
187 | case 3:{ | |
188 | if(!isnum(inputtext)){SendClientMessage(playerid,-1,"{ff0000}Enter a numerical value.");ShowMes(playerid);} | |
189 | else if(strval(inputtext)>GetPlayerMoney(playerid)){SendClientMessage(playerid,-1,"{ff0000}Not enough money.");ShowMes(playerid);} | |
190 | else {MesInfo[playerid][Amount]=strval(inputtext);ShowMes(playerid);} | |
191 | } | |
192 | case 4:{ | |
193 | if(strlen(inputtext)>20) | |
194 | {SendClientMessage(playerid,-1,"{ff0000}Description should not be more than 20 characters.");ShowMes(playerid);} | |
195 | else | |
196 | {format(MesInfo[playerid][line1],20,"%s",inputtext);ShowMes(playerid);} | |
197 | } | |
198 | case 5:{ | |
199 | if(strlen(inputtext)>20) | |
200 | {SendClientMessage(playerid,-1,"{ff0000}Description should not be more than 20 characters.");ShowMes(playerid);} | |
201 | else | |
202 | {format(MesInfo[playerid][line2],20,"%s",inputtext);ShowMes(playerid);} | |
203 | } | |
204 | } | |
205 | } | |
206 | else ShowMes(playerid); | |
207 | } | |
208 | /*......................*/ | |
209 | case D_ConfirmMes: | |
210 | { | |
211 | if(response) | |
212 | { | |
213 | if(!strcmp(MesInfo[playerid][Reciver],"{ff0000}---",false) || !strcmp(MesInfo[playerid][Subject],"{ff0000}---",false)) | |
214 | { | |
215 | SendClientMessage(playerid,-1,"{ff0000}The field of either Reciver or Subject is missing please fill them up."); | |
216 | ShowMes(playerid); | |
217 | } | |
218 | else | |
219 | { | |
220 | new pname[MAX_PLAYER_NAME]; | |
221 | GetPlayerName(playerid,pname,MAX_PLAYER_NAME); | |
222 | GivePlayerMoney(playerid,-MesInfo[playerid][Amount]); | |
223 | if(!fexist(MesPath(MesInfo[playerid][Reciver])))//that is if its recivers first message | |
224 | { | |
225 | new INI:iFile = INI_Open(MesPath(MesInfo[playerid][Reciver])); | |
226 | INI_SetTag(iFile,"MNO");//contain the varable to store number of messages received by player :) | |
227 | INI_WriteInt(iFile,"msg_numbers",1);//the varaible storing the no. of messages | |
228 | INI_WriteInt(iFile,"NewMsg",1); | |
229 | INI_SetTag(iFile,"msg1"); | |
230 | INI_WriteString(iFile,"Reciver",MesInfo[playerid][Reciver]); | |
231 | INI_WriteString(iFile,"Sender",pname); | |
232 | INI_WriteString(iFile,"Subject",MesInfo[playerid][Subject]); | |
233 | INI_WriteInt(iFile,"Amount",MesInfo[playerid][Amount]); | |
234 | INI_WriteString(iFile,"line1",MesInfo[playerid][line1]); | |
235 | INI_WriteString(iFile,"line2",MesInfo[playerid][line2]); | |
236 | INI_WriteInt(iFile,"IsRead",0); | |
237 | INI_Close(iFile); | |
238 | } | |
239 | else | |
240 | { | |
241 | INI_ParseFile(MesPath(MesInfo[playerid][Reciver]), "LoadMNO_%s", .bExtra = true, .extra = playerid); | |
242 | new Xtag[10]; | |
243 | format(Xtag,10,"msg%i",MesInfo[playerid][msgn]+1); | |
244 | new INI:iFile = INI_Open(MesPath(MesInfo[playerid][Reciver])); | |
245 | INI_SetTag(iFile,"MNO"); | |
246 | INI_WriteInt(iFile,"msg_numbers",MesInfo[playerid][msgn]+1); | |
247 | INI_WriteInt(iFile,"NewMsg",MesInfo[playerid][newmsg]+1); | |
248 | INI_SetTag(iFile,Xtag); | |
249 | INI_WriteString(iFile,"Reciver",MesInfo[playerid][Reciver]); | |
250 | INI_WriteString(iFile,"Sender",pname); | |
251 | INI_WriteString(iFile,"Subject",MesInfo[playerid][Subject]); | |
252 | INI_WriteInt(iFile,"Amount",MesInfo[playerid][Amount]); | |
253 | INI_WriteString(iFile,"line1",MesInfo[playerid][line1]); | |
254 | INI_WriteString(iFile,"line2",MesInfo[playerid][line2]); | |
255 | INI_WriteInt(iFile,"IsRead",0); | |
256 | INI_Close(iFile); | |
257 | } | |
258 | SendClientMessage(playerid,-1,"{00FF00}Message sent!!"); | |
259 | } | |
260 | } | |
261 | else ShowMes(playerid); | |
262 | } | |
263 | /*..............................*/ | |
264 | case D_Transfers: | |
265 | { | |
266 | if(response) | |
267 | { | |
268 | new tag[10],name[MAX_PLAYER_NAME],str[300]; | |
269 | GetPlayerName(playerid,name,MAX_PLAYER_NAME); | |
270 | format(tag,sizeof(tag),"msg%i",listitem+1); | |
271 | ReadWithTag(playerid,MesPath(name),tag); | |
272 | if(MesInfo[playerid][IsRead]==0) | |
273 | { | |
274 | GivePlayerMoney(playerid,MesInfo[playerid][Amount]); | |
275 | if(MesInfo[playerid][Amount]>0)SendClientMessage(playerid,-1,"{00cc00}Money received from message."); | |
276 | new INI:File=INI_Open(MesPath(name)); | |
277 | INI_SetTag(File,"MNO"); | |
278 | INI_WriteInt(File,"NewMsg",MesInfo[playerid][Amount]-1); | |
279 | INI_SetTag(File,tag); | |
280 | INI_WriteInt(File,"IsRead",1); | |
281 | INI_Close(File); | |
282 | } | |
283 | format(str,sizeof(str),"{00FFFF}Sender:\t\t{54C571}%s\n{00FFFF}Subject:\t\t{54C571}%s\n{00FFFF}Amount:\t\t{4E9258}$%i\n{00FFFF}Detail[Line1]:\t\t{54C571}%s\n{00FFFF}Detail[Line2]:\t\t{54C571}%s\n\n{ff0000}===================================", | |
284 | MesInfo[playerid][Sender], | |
285 | MesInfo[playerid][Subject], | |
286 | MesInfo[playerid][Amount], | |
287 | MesInfo[playerid][line1], | |
288 | MesInfo[playerid][line2]); | |
289 | ShowPlayerDialog(playerid,D_MainMes,DIALOG_STYLE_MSGBOX,"{842DCE}Message",str,"Cool","Cancel"); | |
290 | } | |
291 | } | |
292 | } | |
293 | } | |
294 | ||
295 | ||
296 | ||
297 | ||
298 | ||
299 | /*=============================COMMANDS========================COMMANDS=========================COMMANDS=============================*/ | |
300 | CMD:sendcash(playerid,params[]) | |
301 | { | |
302 | format(MesInfo[playerid][Reciver],MAX_PLAYER_NAME,"{ff0000}---"); | |
303 | format(MesInfo[playerid][Subject],MAX_PLAYER_NAME,"{ff0000}---"); | |
304 | MesInfo[playerid][Amount]=0; | |
305 | format(MesInfo[playerid][line1],MAX_PLAYER_NAME,"{ff0000}---"); | |
306 | format(MesInfo[playerid][line2],MAX_PLAYER_NAME,"{ff0000}---"); | |
307 | ShowMes(playerid); | |
308 | return 1; | |
309 | } | |
310 | ||
311 | CMD:sendmes(playerid,params[]) | |
312 | { | |
313 | cmd_sendcash(playerid,params); | |
314 | return 1; | |
315 | } | |
316 | ||
317 | ||
318 | CMD:trans(playerid,params[]) | |
319 | { | |
320 | ||
321 | new named[MAX_PLAYER_NAME]; | |
322 | GetPlayerName(playerid,named,sizeof(named)); | |
323 | if(!fexist(MesPath(named)))return SendClientMessage(playerid,-1,"{C58917}No Off-Line Messages currently recieved."); | |
324 | INI_ParseFile(MesPath(named), "LoadMNO_%s", .bExtra = true, .extra = playerid); | |
325 | SendClientMessage(playerid,-1,"{00FFFF}NOTE : {F87217}ORANGE{00FFFF} messages = Unread messages & {00cc00}GREEN {00FFFF}messages = Read Messages"); | |
326 | new sho[500],i,col[50]; | |
327 | format(sho,500,""); | |
328 | for(i=1;i<=MesInfo[playerid][msgn];i++) | |
329 | { | |
330 | format(tg,10,"msg%i",i); | |
331 | ReadWithTag(playerid,MesPath(named),tg); | |
332 | if(MesInfo[playerid][IsRead]==0)format(col,sizeof(col),"{F87217}%s: %s\n",MesInfo[playerid][Sender],MesInfo[playerid][Subject]); | |
333 | else format(col,sizeof(col),"{00cc00}%s: %s\n",MesInfo[playerid][Sender],MesInfo[playerid][Subject]); | |
334 | strcat(sho,col,sizeof(sho)); | |
335 | } | |
336 | ShowPlayerDialog(playerid,D_Transfers,DIALOG_STYLE_LIST,"{842DCE}Offline Transfers",sho,"Read","Cancel"); | |
337 | return 1; | |
338 | } |