player vs player

No preview image

1 collaborator

Default-person Not Alive (Author)

Tags

(This model has yet to be categorized with any tags)
Model group SingaporeSST | Visible to everyone | Changeable by everyone
Model was written in NetLogo 5.0RC10 • Viewed 232 times • Downloaded 31 times • Run 0 times
Download the 'player vs player' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

breed [ humans human ]
breed [ zombies zombie ]
turtles-own [ user-id lives killed chrtype dead]
globals
[
 leader
 leaderpoints 
]

to setup
  clear-all
  hubnet-reset
  reset-ticks
end 

to go
  every .1
  [
    ask turtles with [user-id != "auto"] [
      updateclientdata
    ]
    listen-clients
    move
    tick
  ]
end 

to listen-clients 
  while [ hubnet-message-waiting? ]
  [
   hubnet-fetch-message
   
   ifelse ( hubnet-enter-message? ) 
   [ ;it's an enter message
     let type1 (random 100)
     ifelse (type1 < 50)[
     create-new-student-zombie
     ][
     create-new-student-human
     ]
   ]
   [
     ifelse (hubnet-exit-message?)
     [ ;it's an exit message
       ask turtles with [ user-id = hubnet-message-source ][ die ]
     ]
     [
       ;it's not either an enter or exit message...
       let handled false
       if (hubnet-message-tag = "front")[
         set handled true
         ask turtles with [ user-id = hubnet-message-source ] [
           fd 1
         ]
       ]
       if (hubnet-message-tag = "left")[
         set handled true
         ask turtles with [ user-id = hubnet-message-source ] [
           left 45
         ]
       ]
       if (hubnet-message-tag = "right")[
         set handled true
         ask turtles with [ user-id = hubnet-message-source ] [
           right 45
         ]
       ]
       if (hubnet-message-tag = "down")[
         set handled true
         ask turtles with [ user-id = hubnet-message-source ] [
           fd -1
         ]
       ]
       if (hubnet-message-tag = "attack")[
         set handled true
         ask turtles with [ user-id = hubnet-message-source ] [
           let xcor1 xcor
           let ycor1 ycor
           
           let victims other turtles in-radius (size * 3) with [user-id != "auto"]
           if any? victims
           [
             let poor-guy one-of victims
             ask poor-guy [
               hubnet-send user-id "ChatBox" (word "You were killed by " hubnet-message-source)
               setxy random-xcor random-ycor
               set lives (lives - 1)
               if (lives = 0)
               [
                 hubnet-send user-id "ChatBox" (word "You lost!")
                 
               ]
             ]
             set killed (killed + 1) 
             updateleader
           ]
         ]
       ]
       if (hubnet-message-tag = "ChatText")[
        set handled true
        ask turtles with [user-id != "auto"] [
        hubnet-send user-id "ChatBox" (word hubnet-message-source ": " hubnet-message)
        ]
       ]
       if (handled = false)[
      show ( word "Message from " hubnet-message-source " with tag = " hubnet-message-tag " and contents " hubnet-message )
       ]
     ]
   ]
  ]
end 

to create-new-student-zombie
  create-zombies 1
  [
   setxy random-xcor random-ycor 
   set user-id hubnet-message-source
   set heading 0
   set shape "turtle"
   set color red
   set lives 5
   set killed 0
   set chrtype "zombie"
   set dead false
  ]
end 

to create-new-student-human
  create-humans 1
  [
    setxy random-xcor random-ycor
    set user-id hubnet-message-source
    set heading 0
    set shape "turtle"
    set color blue
    set lives 5
    set killed 0
    set chrtype "human"
    set dead false
  ]
end 

to create-new-ai-zombie
  create-zombies 1
  [
    setxy random-xcor random-ycor
    set user-id "auto"
    set heading 0
    set shape "turtle"
    set color red
  ]
end 

to create-new-ai-human
  create-humans 1
  [
    setxy random-xcor random-ycor
    set user-id "auto"
    set heading 0
    set shape "turtle"
    set color blue
  ]
end 

to send-data-to [ a-user a-widget a-value ]
  show a-user
  show count turtles with [ user-id = a-user ]
  ask turtles with [ user-id = a-user ]
  [
    ;//hubnet-send client-id tag content
    hubnet-send user-id a-widget a-value
  ]
end 

to clientwatch
  ask turtles with [user-id != "auto"][ hubnet-send-watch user-id self]
end 

to clientfollow
  ask turtles with [user-id != "auto"][ hubnet-send-follow user-id self dist]
end 

to spawn
  repeat number-of-zombies[
    create-new-ai-zombie
  ]
  repeat number-of-humans[
    create-new-ai-human
  ]
end 

to kill-spawns
  ask turtles with [user-id = "auto"][ die ]
end 

to updateclientdata
  hubnet-send user-id "Killed" killed
  hubnet-send user-id "Lives left" lives
  hubnet-send user-id "Type" chrtype
  hubnet-send user-id "Leader" leader
  hubnet-send user-id "Leader points" leaderpoints
end 

to updateleader
  if any? turtles with [user-id != "auto"] [
   let leaders turtles with-max [ killed ]
   let number-leaders count leaders
   ifelse number-leaders > 1
   [set leader word number-leaders "-way tie"]
   [ ask one-of leaders [ set leader user-id ] ]
   set leaderpoints [killed] of one-of leaders 
  ]
end 

to move
  ask turtles with [user-id = "auto"][
  rt (random 11) - 5
  fd .2
  ]
end 

There is only one version of this model, created about 13 years ago by Not Alive.

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.