Advertisement
PlayerX

VSE beta

Dec 2nd, 2011
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.16 KB | None | 0 0
  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // Vice-city Squirrel Extension 0.1b //
  4. // By: [R3V]PlayerX //
  5. // //
  6. // 0.1b VSE-Main: //
  7. // Added Events //
  8. // VSE_CallEventInExtension() //
  9. // VSE_LoadModules() //
  10. // VSE_LoadFiles() //
  11. // VSE_IsNum() //
  12. // VSE_Value() //
  13. // VSE_AddEvent() //
  14. // VSE_CallFunction() //
  15. ///////////////////////////////////////////////////////////////////////////////////////////////////
  16.  
  17. local VSE_Modules_Loades = 0;
  18. local VSE_Files_Loades = 0;
  19. local VSE_Event = {};
  20.  
  21. for(local v = 0; v < 42; v++)
  22. {
  23. VSE_Event[v] <- {};
  24. }
  25.  
  26. VSE_Events <- ["onServerStart", "onTimeChange", "onWeatherChange", "onScriptLoad", "onScriptUnload", "onConsoleInput", "onPlayerJoin", "onPlayerPart" , "onPlayerSpawn", "onPlayerDeath", "onPlayerKill", "onPlayerTeamKill", "onPlayerChat", "onPlayerAction", "onPlayerPM", "onPlayerFailedPM", "onPlayerTeamChat", "onPlayerCommand", "onPlayerHealthChange", "onPlayerArmourChange", "onPlayerWeaponChange", "onPlayerCashChange", "onPlayerScoreChange", "onPlayerKeyStateChange", "onPlayerMove", "onPlayerRequestClass", "onPlayerRequestAmmunation", "onPlayerRequestAmmuWeapon", "onPlayerStartSpectating", "onPlayerExitSpectating", "onPlayerRconLogin", "onPlayerRconLoginAttempt", "onPlayerFall", "onPlayerVersion", "onPlayerEnterVehicle", "onPlayerExitVehicle", "onVehicleHealthChange", "onVehicleRespawn", "onVehicleMove", "onPickupPickedUp", "onPickupDestroy", "onPickupRespawn"];
  27.  
  28. ///////////////////////////////////////////////////////////////////////////////////
  29.  
  30. function onServerStart()
  31. {
  32. print("[VSE] Loading Files...");
  33. VSE_CallEventInExtension(VSE_Events[0]);
  34. return 1;
  35. }
  36.  
  37. function onScriptLoad()
  38. {
  39. print(">>==============================================<<");
  40. print(">>========// VLE 0.1b by [R3V]PlayerX //========<<");
  41. print(">>==============// Loading... //================<<");
  42. VSE_Modules_Loades = VSE_LoadModules();
  43. VSE_Files_Loades = VSE_LoadFiles();
  44. print(">>===============|| Finished ||=================<<");
  45. print(">>======|| Modules Loades: " + VSE_Modules_Loades.tostring() + " ||==========<<");
  46. print(">>======|| Files Loades: " + VSE_Files_Loades.tostring() + " ||=========<<");
  47. print(">>==============================================<<");
  48. VSE_CallEventInExtension(VSE_Events[3]);
  49. return 1;
  50. }
  51.  
  52. function onTimeChange(hour, minute)
  53. {
  54. VSE_CallEventInExtension(VSE_Events[1], hour, minute );
  55. return 1;
  56. }
  57.  
  58. function onWeatherChange(oldw, neww)
  59. {
  60. VSE_CallEventInExtension(VSE_Events[2], oldw, neww );
  61. return 1;
  62. }
  63.  
  64. function onScriptUnload()
  65. {
  66. VSE_CallEventInExtension(VSE_Events[4]);
  67. return 1;
  68. }
  69.  
  70. function onConsoleInput(cmd, text)
  71. {
  72. VSE_CallEventInExtension(VSE_Events[5], cmd, text);
  73. return 1;
  74. }
  75.  
  76. function onPlayerJoin(player)
  77. {
  78. VSE_CallEventInExtension(VSE_Events[6], player);
  79. return 1;
  80. }
  81.  
  82. function onPlayerPart(player, reason)
  83. {
  84. VSE_CallEventInExtension(VSE_Events[7], player, reason);
  85. return 1;
  86. }
  87.  
  88. function onPlayerSpawn(player)
  89. {
  90. VSE_CallEventInExtension(VSE_Events[8], player);
  91. return 1;
  92. }
  93. function onPlayerDeath(player, reason)
  94. {
  95. VSE_CallEventInExtension(VSE_Events[9], player, reason);
  96. return 1;
  97. }
  98.  
  99. function onPlayerKill(killer, player, reason, bodypart)
  100. {
  101. VSE_CallEventInExtension(VSE_Events[10], killer, player, reason, bodypart);
  102. return 1;
  103. }
  104.  
  105. function onPlayerTeamKill(killer, player, reason, bodypart)
  106. {
  107. VSE_CallEventInExtension(VSE_Events[11], killer, player, reason, bodypart);
  108. return 1;
  109. }
  110.  
  111. function onPlayerChat(player, text)
  112. {
  113. VSE_CallEventInExtension(VSE_Events[12], player, text);
  114. return 1;
  115. }
  116.  
  117. function onPlayerAction(player, text)
  118. {
  119. VSE_CallEventInExtension(VSE_Events[13], player, text);
  120. return 1;
  121. }
  122.  
  123. function onPlayerPM(player1, player2, text)
  124. {
  125. VSE_CallEventInExtension(VSE_Events[14], player1, player2, text);
  126. return 1;
  127. }
  128.  
  129. function onPlayerFailedPM(player1, player2, text)
  130. {
  131. VSE_CallEventInExtension(VSE_Events[15], player1, player2, text);
  132. return 1;
  133. }
  134.  
  135. function onPlayerTeamChat(player1, player2, text)
  136. {
  137. VSE_CallEventInExtension(VSE_Events[16], player1, player2, text);
  138. return 1;
  139. }
  140.  
  141. function onPlayerCommand(player, cmd, text)
  142. {
  143. VSE_CallEventInExtension(VSE_Events[17], player, cmd, text);
  144. return 1;
  145. }
  146.  
  147. function onPlayerHealthChange(player, oldhp, newhp)
  148. {
  149. VSE_CallEventInExtension(VSE_Events[18], player, oldhp, newhp);
  150. return 1;
  151. }
  152.  
  153. function onPlayerArmourChange(player, oldarm, newarm)
  154. {
  155. VSE_CallEventInExtension(VSE_Events[19], player, oldarm, newarm);
  156. return 1;
  157. }
  158.  
  159. function onPlayerWeaponChange(player, oldwep, newwep)
  160. {
  161. VSE_CallEventInExtension(VSE_Events[20], player, oldwep, newwep);
  162. return 1;
  163. }
  164.  
  165. function onPlayerCashChange(player, oldcash, newcash)
  166. {
  167. VSE_CallEventInExtension(VSE_Events[21], player, oldcash, newcash);
  168. return 1;
  169. }
  170.  
  171. function onPlayerScoreChange(player, oldscore, newscore)
  172. {
  173. VSE_CallEventInExtension(VSE_Events[22], player, oldscore, newscore);
  174. return 1;
  175. }
  176.  
  177. function onPlayerKeyStateChange(player, key, down)
  178. {
  179. VSE_CallEventInExtension(VSE_Events[23], player, key, down);
  180. return 1;
  181. }
  182.  
  183. function onPlayerMove(player, x1, y1, z1, x2, y2, z2)
  184. {
  185. VSE_CallEventInExtension(VSE_Events[24], player, x1, y1, z1, x2, y2, z2);
  186. return 1;
  187. }
  188.  
  189. function onPlayerRequestClass(player, id, team, skin)
  190. {
  191. VSE_CallEventInExtension(VSE_Events[25], player, id, team, skin);
  192. return 1;
  193. }
  194.  
  195. function onPlayerRequestAmmunation(player, ammunationid)
  196. {
  197. VSE_CallEventInExtension(VSE_Events[26], player, ammunationid);
  198. return 1;
  199. }
  200.  
  201. function onPlayerRequestAmmuWeapon(player, ammunationid, weaponid)
  202. {
  203. VSE_CallEventInExtension(VSE_Events[27], player, ammunationid, weaponid);
  204. return 1;
  205. }
  206.  
  207. function onPlayerStartSpectating(player1, player2)
  208. {
  209. VSE_CallEventInExtension(VSE_Events[28], player1, player2);
  210. return 1;
  211. }
  212.  
  213. function onPlayerExitSpectating(player)
  214. {
  215. VSE_CallEventInExtension(VSE_Events[29], player);
  216. return 1;
  217. }
  218.  
  219. function onPlayerRconLogin(player)
  220. {
  221. VSE_CallEventInExtension(VSE_Events[30], player);
  222. return 1;
  223. }
  224.  
  225. function onPlayerRconLoginAttempt(player, pass)
  226. {
  227. VSE_CallEventInExtension(VSE_Events[31], player, pass);
  228. return 1;
  229. }
  230.  
  231. function onPlayerFall(player)
  232. {
  233. VSE_CallEventInExtension(VSE_Events[32], player);
  234. return 1;
  235. }
  236.  
  237. function onPlayerVersion(player, version)
  238. {
  239. VSE_CallEventInExtension(VSE_Events[33], player, version);
  240. return 1;
  241. }
  242.  
  243. function onPlayerEnterVehicle(player, vehicle, passenger)
  244. {
  245. VSE_CallEventInExtension(VSE_Events[34], player, vehicle, passenger);
  246. return 1;
  247. }
  248.  
  249. function onPlayerExitVehicle(player, vehicle, passenger)
  250. {
  251. VSE_CallEventInExtension(VSE_Events[35], player, vehicle, passenger);
  252. return 1;
  253. }
  254.  
  255. function onVehicleHealthChange(vehicle, oldhp, newhp)
  256. {
  257. VSE_CallEventInExtension(VSE_Events[36], vehicle, oldhp, newhp);
  258. return 1;
  259. }
  260.  
  261. function onVehicleRespawn(vehicle)
  262. {
  263. VSE_CallEventInExtension(VSE_Events[37], vehicle);
  264. return 1;
  265. }
  266.  
  267. function onVehicleMove(player, vehicle, x1, y1, z1, x2, y2, z2)
  268. {
  269. VSE_CallEventInExtension(VSE_Events[38], player, vehicle, x1, y1, z1, x2, y2, z2);
  270. return 1;
  271. }
  272.  
  273. function onPickupPickedUp(player, pickup)
  274. {
  275. VSE_CallEventInExtension(VSE_Events[39], player, pickup);
  276. return 1;
  277. }
  278.  
  279. function onPickupDestroy(pickup)
  280. {
  281. VSE_CallEventInExtension(VSE_Events[40], pickup);
  282. return 1;
  283. }
  284.  
  285. function onPickupRespawn(pickup)
  286. {
  287. VSE_CallEventInExtension(VSE_Events[41], pickup);
  288. return 1;
  289. }
  290.  
  291.  
  292. /////////////////////////////////////////////////////////////////////////////////////////////
  293.  
  294. function VSE_LoadModules()
  295. {
  296. local total = 0;
  297. if(!VSE_FileExists("Modules.ini")) return 0;
  298. local FileHandle = file("Modules.ini", "r");
  299. if(FileHandle)
  300. {
  301. local result = "";
  302. while(!FileHandle.eos())
  303. {
  304. local c = FileHandle.readn('c');
  305. result = "" + result + "" + c.tochar();
  306. }
  307. if(result.len() > 0)
  308. {
  309. local m = split(result, "\r\n");
  310. foreach(i, instance in m)
  311. {
  312. local s = split(m[i], " ");
  313. if(s[1].tostring() == "1")
  314. {
  315. LoadModule(s[0]);
  316. total++;
  317. }
  318. }
  319. return total;
  320. }
  321. }
  322. return 0;
  323. }
  324.  
  325. function VSE_FileExists(FilePath)
  326. {
  327. try
  328. {
  329. file(FilePath, "r");
  330. }
  331. catch(E) return 0;
  332. return 1;
  333. }
  334.  
  335. function VSE_LoadFiles()
  336. {
  337. local total = 0;
  338. if(!VSE_FileExists("Files.ini")) return 0;
  339. local FileHandle = file("Files.ini", "r");
  340. if(FileHandle)
  341. {
  342. local result = "";
  343. while(!FileHandle.eos())
  344. {
  345. local c = FileHandle.readn('c');
  346. result = "" + result + "" + c.tochar();
  347. }
  348. local s = split(result, "\r\n");
  349. foreach(i, instance in s)
  350. {
  351. local f = split(s[i], " ");
  352. if(f[1].tostring() == "1")
  353. {
  354. dofile("" + f[0] + ".nut");
  355. total++;
  356. }
  357. }
  358. return total;
  359. }
  360. return 0;
  361. }
  362.  
  363. function VSE_CallEventInExtension(EventName, ...)
  364. {
  365. foreach(p, event in VSE_Events)
  366. {
  367. if(EventName == event)
  368. {
  369. foreach(i, func in VSE_Event[p])
  370. {
  371. local line;
  372. local moo;
  373. if(!vargv.len()) moo = compilestring(VSE_Event[p][i] + "()");
  374. else
  375. {
  376. for(local i = 0; i< vargv.len(); i++)
  377. {
  378. if(!line) line = VSE_Value(vargv[i].tostring());
  379. else line = line + "," + VSE_Value(vargv[i].tostring());
  380. }
  381. moo = compilestring(VSE_Event[p][i] + "(" + line + ")");
  382. }
  383. moo();
  384. }
  385. }
  386. }
  387. }
  388.  
  389. function VSE_CallFunction(string,...)
  390. {
  391. local line;
  392. local moo;
  393. if(!vargv.len()) moo = compilestring(string + "()");
  394. else
  395. {
  396. for(local i = 0; i< vargv.len(); i++)
  397. {
  398. if(!line) line = VSE_Value(vargv[i].tostring());
  399. else line = line + "," + VSE_Value(vargv[i].tostring());
  400. }
  401. moo = compilestring(string + "(" + line + ")");
  402. }
  403. moo();
  404. }
  405.  
  406. function VSE_AddEvent(EventName, f)
  407. {
  408. foreach(i, event in VSE_Events)
  409. {
  410. if(EventName == event)
  411. {
  412. foreach(i2, func in VSE_Event[i])
  413. {
  414. if(f == VSE_Event[i][i2]) return print("[VSE] Error: function already exists.");
  415. else
  416. {
  417. VSE_Event[i][VSE_Event[i].len()] <- f;
  418. return 1;
  419. }
  420. }
  421. VSE_Event[i][VSE_Event[i].len()] <- f;
  422. return 1;
  423. }
  424. }
  425. return print("[VSE] Invalid Event Name: " + EventName)
  426. }
  427.  
  428. function VSE_DelEvent(EventName, f)
  429. {
  430. foreach(i, event in VSE_Events)
  431. {
  432. if(EventName == event)
  433. {
  434. VSE_Event[i][VSE_Event[i].len()] <- f;
  435. return 1;
  436. }
  437. }
  438. }
  439.  
  440. function VSE_Value(data)
  441. {
  442. local d = VSE_IsNum(data);
  443. if(d == 0) return format("\"%s\"", data);
  444. else if(d == 1) return data.tointeger();
  445. else if(d == 2) return data.tofloat();
  446. else return data;
  447. }
  448.  
  449. function VSE_IsNum(data)
  450. {
  451. local _a = 1;
  452. foreach(i, char in data)
  453. {
  454. if(char > 47 && char < 58) continue;
  455. else if(char == 46) _a = 2;
  456. else _a = 0;
  457. }
  458. return _a;
  459. }
  460.  
  461. VSE_AddEvent("onTimeChange", "x");
  462. VSE_AddEvent("onTimeChange", "y");
  463.  
  464. function x(hour, minute)
  465. {
  466. print(">> " + hour + ":" + minute);
  467. return 1;
  468. }
  469.  
  470. function y(hour, minute)
  471. {
  472. print(">> " + hour + ":" + minute);
  473. return 1;
  474. }
  475.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement