Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.12 KB | None | 0 0
  1. Shop.Functions = {};
  2.  
  3. /*
  4. * Please read this file carefully!
  5. * Any invalid settings will result in the addon not working.
  6. * If you need help, you can add me on Steam:
  7. * www.steamcommunity.com/id/busan1/
  8. */
  9.  
  10. /*
  11.  
  12. /*
  13. * This file isn't necessary to edit, but if you want to add your own
  14. * functions to the shop, then you can do it here.
  15. * Remember that money is subtracted in wss_buy.lua.
  16. * These functions are only called once the player has enough money.
  17. * If function returns true, subtracts money.
  18. * If function returns false, Notify Shop.Messages.Unable to player.
  19. *
  20. * Every function is provided with three arguments:
  21. * _p = player entity
  22. * _e = string name of what was bought
  23. * _s = shop entity
  24.  
  25. You can change the NAME but do not change the index( like Shop.Functions.GiveWeapon ).
  26. */
  27.  
  28. // Generate ammo
  29. for i, v in pairs( Shop.Settings.AmmoTypes ) do
  30. Shop.Functions[ v ] = {};
  31. Shop.Functions[ v ].name = "Give ammo: " .. v;
  32. local _a = Shop.Functions[ v ];
  33. function _a:func( _p, _e, _s )
  34. print( v );
  35. _p:GiveAmmo( _e, v, true );
  36.  
  37. return true;
  38. end
  39. end
  40.  
  41.  
  42. // This is the function that is called to give players a weapon.
  43. // Simply done with the Give function.
  44. Shop.Functions.GiveWeapon = {};
  45. Shop.Functions.GiveWeapon.CreatesEntity = true;
  46. Shop.Functions.GiveWeapon.name = "Give a weapon";
  47. function Shop.Functions.GiveWeapon:func( _p, _e, _s )
  48.  
  49. if( _p:HasWeapon( _e ) ) then
  50. DarkRP.notify( _p, 0, 4, Shop.Messages.PlayerHasWeapon );
  51. return false;
  52. end
  53. _p:Give( _e );
  54. _p:SetActiveWeapon( _e );
  55. return true;
  56.  
  57. end
  58.  
  59. // This function gives a player health; if > 100 then it's set to 100.
  60. Shop.Functions.GiveHealth = {};
  61. Shop.Functions.GiveHealth.name = "Give health";
  62. function Shop.Functions.GiveHealth:func( _p, _e, _s )
  63.  
  64. if( _p:Health() + _e > 100 ) then
  65. _p:SetHealth( 100 );
  66. else
  67. _p:SetHealth( _p:Health() + _e );
  68. end
  69.  
  70. return true;
  71.  
  72. end
  73.  
  74. // This function gives a player armor; if > 100 then it's set to 100.
  75. Shop.Functions.GiveArmor = {};
  76. Shop.Functions.GiveArmor.name = "Give armor";
  77. function Shop.Functions.GiveArmor:func( _p, _e, _s )
  78.  
  79. if( _p:Armor() + _e > 100 ) then
  80. _p:SetArmor( 100 );
  81. else
  82. _p:SetArmor( _p:Armor() + _e );
  83. end
  84.  
  85. return true;
  86.  
  87. end
  88.  
  89.  
  90. // This function spawns an entity infront of the shop.
  91. Shop.Functions.SpawnEnt = {};
  92. Shop.Functions.SpawnEnt.CreatesEntity = true;
  93. Shop.Functions.SpawnEnt.name = "Spawn an entity";
  94. function Shop.Functions.SpawnEnt:func( _p, _e, _s )
  95.  
  96. local _e = ents.Create( _e );
  97. _e:SetPos( _s._spawnpos );
  98. _e:SetAngles( _s._spawnang );
  99. _e:Spawn();
  100.  
  101. if( !IsValid( _e ) ) then
  102. return false;
  103. end
  104.  
  105. return true;
  106.  
  107. end
  108.  
  109. // This is for PointShop points.
  110. Shop.Functions.PSPoints = {};
  111. Shop.Functions.PSPoints.name = "Pointshop points";
  112. function Shop.Functions.PSPoints:func( _p, _e, _s )
  113.  
  114. _p:PS_GivePoints( _e );
  115. return true;
  116.  
  117. end
  118.  
  119. // This functions spawns food from the food in config.
  120. // Uses default DarkRP spawn food code.
  121. Shop.Functions.SpawnFood = {};
  122. Shop.Functions.SpawnFood.name = "Spawn food";
  123. function Shop.Functions.SpawnFood:func( _p, _e, _s )
  124.  
  125. local onlyEnt = nil;
  126. Shop.Functions.SpawnEntOne = {};
  127. Shop.Functions.SpawnEntOne.CreatesEntity = true;
  128. Shop.Functions.SpawnEntOne.name = "Spawn only one entity";
  129. function Shop.Functions.SpawnEntOne:func( _p, _e, _s )
  130.  
  131. if( onlyEnt && IsValid( onlyEntr ) ) then
  132. _p:ChatPrint( "Cannot spawn right now" );
  133. return false;
  134. end
  135.  
  136. local _e = ents.Create( _e );
  137. _e:SetPos( _s._spawnpos );
  138. _e:SetAngles( _s._spawnang );
  139. _e:Spawn();
  140. onlyEnt = _e;
  141.  
  142. if( !IsValid( _e ) ) then
  143. return false;
  144. end
  145.  
  146. return true;
  147.  
  148. end
  149. local _foodData = false;
  150.  
  151. for i, v in pairs( FoodItems ) do
  152. if( v.name == _e ) then
  153. _foodData = FoodItems[ i ];
  154. end
  155. end
  156.  
  157. if( !_foodData ) then
  158. return false;
  159. end
  160.  
  161. local _c = 0;
  162. for i, v in pairs( ents.FindByClass( "spawned_food" ) ) do
  163. if( v.bought && v.bought == _p ) then
  164. _c = _c + 1;
  165. end
  166. end
  167.  
  168. if( _c > Shop.Settings.MaxFoodItems ) then
  169. DarkRP.notify( _p, 1, 5, Shop.Messages.TooManyFoods );
  170. return false;
  171. end
  172.  
  173. local _e = ents.Create( "spawned_food" );
  174. _e:SetPos( _s._spawnpos );
  175. _e:SetAngles( _s._spawnang );
  176. _e:Setowning_ent( _p );
  177. _e.ShareGravgun = true;
  178. _e.bought = _p;
  179. _e:SetPos( _s._spawnpos );
  180. _e:SetAngles( _s._spawnang );
  181. _e.onlyremover = true;
  182. _e.SID = _p.SID;
  183. _e:SetModel( _foodData.model );
  184. _e.FoodName = _foodData.name;
  185. _e.FoodEnergy = _foodData.energy;
  186. _e.FoodPrice = _foodData.price;
  187. _e:Spawn();
  188.  
  189. return true;
  190.  
  191. end
  192. Shop.Functions.ToCoffeInv = {};
  193. Shop.Functions.ToCoffeInv.name = "Put in CoffeeInventory";
  194. function Shop.Functions.ToCoffeInv:func( _p, _e, _s )
  195.  
  196. local _e = ents.Create( _e );
  197. _e:Spawn();
  198. if( !IsValid( _e ) ) then
  199. return false;
  200. else
  201. coffeeInventory.storeItem( _p, _e );
  202. _p:ChatPrint( "Placed in your inventory! (Access with F1)" );
  203. end
  204.  
  205. end
  206.  
  207. Shop.Functions.ItemStore = {};
  208. Shop.Functions.ItemStore.name = "Put in ItemStore";
  209. function Shop.Functions.ItemStore:func( _p, _e, _s )
  210.  
  211. local _e = ents.Create( _e );
  212. _e:Spawn();
  213. if( !IsValid( _e ) ) then
  214. return false;
  215. else
  216. if ( IsValid( _e ) and not _e.__Deleted ) then
  217. _p:PickupItem( _e );
  218. return true;
  219. end
  220. end
  221. return false;
  222.  
  223. end
  224.  
  225. // What checks player needs to pass to buy stuff
  226. function Shop:CanBuy( _p, _s )
  227.  
  228. // Player and shop needs to exist
  229. if( !IsValid( _p ) || !IsValid( _s ) ) then
  230. if( self.Settings.FullInfo ) then
  231. self:Message( "Invalid player or shop!", 1 );
  232. end
  233. return false;
  234. end
  235.  
  236. // Player needs to be alive, and not arrested
  237. if( !_p:Alive() || _p:isArrested() ) then
  238. if( self.Settings.FullInfo ) then
  239. self:Message( "Player tried to buy when dead/arrested!", 1 );
  240. end
  241. return false;
  242. end
  243.  
  244. // Player needs to be in range of the shop
  245. if( _s:GetPos():Distance( _p:GetPos() ) > 140 ) then
  246. if( self.Settings.FullInfo ) then
  247. self:Message( "Player out of range!", 1 );
  248. end
  249. return false;
  250. end
  251.  
  252. return true;
  253.  
  254. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement