Super Networked

local _player = nil
local defAnimStance = nil


-- >> Follow Menu - spawn objects    << --
local _spawnObject = require( script:GetCustomProperty("ListObjects") )        -- spawnable objects
local _spawnObjects = _spawnObject._count

-- items to spawn

local coin_SpawnTemplate         = script:GetCustomProperty("CoinTemplate")

local companion_SpawnTemplate     = script:GetCustomProperty("CompanionCube")

local health1_SpawnTemplate     = script:GetCustomProperty("Loot_Bandages")

local health2_SpawnTemplate     = script:GetCustomProperty("spawnhealthcase")

local plant1_SpawnTemplate        = script:GetCustomProperty("spawnbush")

local rock_SpawnTemplate        = script:GetCustomProperty("spawnrock")

local tree1_SpawnTemplate        = script:GetCustomProperty("spawntree1")

local tree2_SpawnTemplate        = script:GetCustomProperty("spawntree2")

local tree3_SpawnTemplate        = script:GetCustomProperty("spawntree3")

local treestump_SpawnTemplate    = script:GetCustomProperty("spawntreestump")




-- broadcasting a world message
local propBroadcast = script:GetCustomProperty("Broadcast"):WaitForObject()         -- to hide/show
local propBroadcastText = script:GetCustomProperty("BroadcastText"):WaitForObject() -- to set text
propBroadcast.visibility = Visibility.FORCE_OFF


-- switch player's movement on/off
local _playerSwitch = {nil}
_playerSwitch[0] = MovementControlMode.NONE
_playerSwitch[1] = MovementControlMode.VIEW_RELATIVE



local _oOffset = nil -- spawn offset
function Build(player,data,pos)
    if(data == "ush" or data == "planta" or data == "plant1")then
        _oOffset = pos + Vector3.New(0,0,70)
        print ("[",data,"] @ ",_oOffset)
        World.SpawnAsset(plant1_SpawnTemplate, {position = _oOffset})

    elseif(data == "coins" or data == "gold" or data == "manticoin" or data == "coin")then
        _oOffset = pos + Vector3.New(0,0,140)
        print ("[",data,"] @ ",_oOffset)
        World.SpawnAsset(coin_SpawnTemplate, {position = _oOffset})
    
    elseif(data == "companion" or data == "weighted" or data == "aperture")then
        _oOffset = pos + Vector3.New(0,0,50)
        print ("[",data,"] @ ",_oOffset)
        --player:AddImpulse(Vector3.UP * player.mass * 1000) -- shoot player above the object
        Task.Wait(.2)
        World.SpawnAsset(companion_SpawnTemplate, {position = _oOffset})    
    
    elseif(data == "health1" or data == "health 1")then -- bandages
        _oOffset = pos + Vector3.New(0,0,55)
        --_oOffset = Vector3.New(-43407.246,-6570.674,3413.001) -- test plugging in stored values..    
        print ("[",data,"] @ ",_oOffset)
        World.SpawnAsset(health1_SpawnTemplate, {position = _oOffset})
    
    elseif(data == "health2" or data == "health 2")then -- level 1 health pack
        _oOffset = pos + Vector3.New(0,0,55)
        print ("[",data,"] @ ",_oOffset)
        World.SpawnAsset(health2_SpawnTemplate, {position = _oOffset})
    
    elseif(data == "rock" or data == "rocks")then
        _oOffset = pos + Vector3.New(0,0,127)
        print ("[",data,"] @ ",_oOffset)
        --player:AddImpulse(Vector3.UP * player.mass * 1000) -- shoot player above the object
        Task.Wait(.2)
        World.SpawnAsset(rock_SpawnTemplate, {position = _oOffset})

    elseif(data == "tree stump" or data == "stump" or data == "treestump")then
        _oOffset = pos + Vector3.New(0,0,20)
        print ("[",data,"] @ ",_oOffset)
        --player:AddImpulse(Vector3.UP * player.mass * 1000) -- shoot player above the object
        Task.Wait(.2)
        World.SpawnAsset(treestump_SpawnTemplate, {position = _oOffset})
        
    elseif(data == "tree1" or data == "tree" or data == "tree 1")then
        _oOffset = pos + Vector3.New(0,0,55)
        print ("[",data,"] @ ",_oOffset)        
        --player:AddImpulse(Vector3.UP * player.mass * 2000) -- shoot player above the object
        Task.Wait(.2)
        World.SpawnAsset(tree1_SpawnTemplate, {position = _oOffset})

    elseif(data == "tree2" or data == "tree 2")then
        _oOffset = pos + Vector3.New(0,0,55)
        print ("[",data,"] @ ",_oOffset)
        --player:AddImpulse(Vector3.UP * player.mass * 2000) -- shoot player above the object
        Task.Wait(.2)
        World.SpawnAsset(tree2_SpawnTemplate, {position = _oOffset})

    elseif(data == "tree3" or data == "tree 3")then
        _oOffset = pos + Vector3.New(0,0,55)
        print ("[",data,"] @ ",_oOffset)
        --player:AddImpulse(Vector3.FORWARD * player.mass * 1000) -- shoot player above the object
        Task.Wait(.2)
        World.SpawnAsset(tree3_SpawnTemplate, {position = _oOffset})        
    end
end



--[[ Receiving data from Client --]]
function OnConsoleToggle(player, data)
    if(data == 0)then --disable them
        --print("Player " .. player.name .. " sent  data = " .. tonumber(data))
        --player:ApplyDamage(Damage.New(11))
        --player.animationStance = "2hand_rifle_aim_shoulder" --"unarmed_sit_chair_upright"
        player.movementControlMode = _playerSwitch[0]
        player.canMount = false -- true/false => disallow mounting ability for now
        player.isCrouchEnabled = false -- true/false => disallow crouching for now
        player.maxJumpCount = 0 -- 0 or 1 -- disable jumping for now
    else -- enable them
        player.animationStance = defAnimStance
        player.movementControlMode = _playerSwitch[1]
        player.canMount = true -- true/false =>
        player.isCrouchEnabled = true -- true/false => 
        player.maxJumpCount = 1 -- 0 or 1    
    end
end


function FlyMode(player,data)
    if(data == 0)then
        player:ActivateWalking()
    else
        player:ActivateFlying()
    end
end

function HealPlayer(player,target)
    if(player.name == target)then -- self
        player.hitPoints = 100
    elseif(target == "all")then
        for _, p in pairs(Game.GetPlayers()) do
            p.hitPoints = 100
        end
    else
        for _, p in pairs(Game.GetPlayers()) do
           if(p.name == target)then
                   p.hitPoints = 100
                   break
           end
        end
    end
end

function KillPlayer(player,target)
    if(player.name == target)then -- self
        player:Die()
    elseif(target == "all")then
        for _, p in pairs(Game.GetPlayers()) do
            p:Die()
        end
    else
        for _, p in pairs(Game.GetPlayers()) do
           if(p.name == target)then
                   p:Die()
                   break
           end
        end
    end
end
function Broadcast(player,data)
    propBroadcast.visibility = Visibility.INHERIT
    propBroadcastText.text = data
end


local _lastAnimPoint = 0
local _lapSwitch = {nil}
_lapSwitch[0] = "unarmed_carry_object_high"
_lapSwitch[1] = "unarmed_carry_object_low"

function AnimatePlayer(player,data)
    if(data == "sit")then
        player.animationStance = "unarmed_sit_chair_upright"
    elseif(data == "default")then
        player.animationStance = defAnimStance
    elseif(data == "point")then -- toggle the point stances
        player.animationStance = _lapSwitch[_lastAnimPoint%2] -- 0 or 1
        _lastAnimPoint = _lastAnimPoint + 1
    end    
end


Events.ConnectForPlayer("AnimatePlayer", AnimatePlayer)
Events.ConnectForPlayer("Broadcast", Broadcast)
Events.ConnectForPlayer("Build", Build)
Events.ConnectForPlayer("FlyMode", FlyMode)
Events.ConnectForPlayer("HealPlayer", HealPlayer)
Events.ConnectForPlayer("KillPlayer", KillPlayer)
Events.ConnectForPlayer("PlayerEnabled", OnConsoleToggle)


Game.playerJoinedEvent:Connect(function(player)
    _player = player
    defAnimStance = player.animationStance
end)

Latest Posts