Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Give random item for Player
#2
1.Learn about scoping (global and local)
2.To random some value use proper function (built in rand in squirrel)
3.table_giveitems isn't table, it's array, in squirrel there is a slightly diffrerence between those two.
-Table: you can index table as you want, also you don't have insert numeric indexes in proper order (from 0 to x). To declare a table, you simply writing something like this: global_table <- {} or local local_table = {}
-Array: you are using methods, to manage array, like push, pop, etc. Array MUST BE indexed from 0 to x, and to add new value as last in the array, you simply using push method, read more in reference:
4.Don't use [] in array values, you have to write them without it, because there aren't indexes of table.

https://developer.electricimp.com/squirrel/array

Squirrel Script
  1. local items =
  2. [
  3. "ITMI_GOLD",
  4. "ITFO_APPLE",
  5. "ITFO_MILK",
  6. "ITFO_BEER", // this comma is optional
  7. ]
  8.  
  9. addEventHandler("onPlayerJoin",function(pid)
  10. { // below code will be executed when player join to the server
  11. local item = rand() % items.len()
  12.  
  13. giveItem(pid, Items.id(item), 1)
  14. })



Forgive me for my grammar mistakes, if i made any.
Reply


Messages In This Thread
Give random item for Player - by liegav - 12.02.2018, 22:13
RE: Give random item for Player - by Patrix - 12.02.2018, 23:20
RE: Give random item for Player - by liegav - 13.02.2018, 06:43
RE: Give random item for Player - by Patrix - 13.02.2018, 10:17
RE: Give random item for Player - by Patrix - 14.02.2018, 18:30

Possibly Related Threads…
Thread Author Replies Views Last Post
  Give- / Removeitems on Focus ItschiAtschiUtschi 3 2,424 10.06.2020, 16:04
Last Post: Patrix
  how do I Kill a player on the client side? demor140202 4 3,665 24.02.2020, 12:32
Last Post: Patrix
  Random spawn players demor140202 5 4,207 10.02.2020, 07:37
Last Post: Quarchodron
  Short question about Gold, how to give it ? Mattwell 2 3,430 26.01.2018, 00:12
Last Post: Mattwell
  Dev 8 item synchronisation HammelGammel 0 2,008 21.01.2017, 11:04
Last Post: HammelGammel
  Default world Item Xardas0327 1 2,162 21.03.2016, 13:51
Last Post: Bimbol
  Random Number Osmith 5 4,596 20.02.2016, 14:21
Last Post: Blacha

Forum Jump:


Users browsing this thread: 1 Guest(s)