Jump to content

Help with a mod. Spider summoning


Recommended Posts

I am making a mod were you play as a spider queen and was wondering if it would be able for when you attach to summon spiders. I was also wondering if summoning a spider could be bound to a key.

Link to comment
Share on other sites

@finlach,

add this to your modmain and replace yourcharactersprefabname with your character's prefabname:

local function SpawnSpider(player)    local pos = GLOBAL.Vector3(player.Transform:GetWorldPosition())	local offset = (GLOBAL.FindWalkableOffset(pos,math.random()*GLOBAL.PI*2,0.5,false))	if offset == nil then		  if  player.components.talker then	      player.components.talker:Say("No Space!", 2.5)		  end		  return	end	pos=pos+offset	local unit=GLOBAL.SpawnPrefab("spider")	unit.Transform:SetPosition(pos:Get())	player.components.leader:AddFollower(unit) endAddModRPCHandler(modname, "SpawnSpider", SpawnSpider)GLOBAL.TheInput:AddKeyDownHandler(GLOBAL.KEY_X, function()local player=GLOBAL.ThePlayerif player and player.prefab=="yourcharactersprefabname" 	and not GLOBAL.IsPaused() and not GLOBAL.TheInput:IsKeyDown(GLOBAL.KEY_CTRL) and not GLOBAL.TheInput:IsKeyDown(GLOBAL.KEY_SHIFT)	and not player.HUD:IsChatInputScreenOpen() and not player.HUD:IsConsoleScreenOpen()then    SendModRPCToServer(MOD_RPC[modname]["SpawnSpider"])end end)
X is the Hotkey here to spawn them. Edited by Seiai
Link to comment
Share on other sites

@finlach,

add this to your modmain and replace yourcharactersprefabname with your character's prefabname:

 

local function SpawnSpider(player)    local pos = GLOBAL.Vector3(player.Transform:GetWorldPosition())	local offset = (GLOBAL.FindWalkableOffset(pos,math.random()*GLOBAL.PI*2,0.5,false))	if offset == nil then		  if  player.components.talker then	      player.components.talker:Say("No Space!", 2.5)		  end		  return	end	pos=pos+offset	local unit=GLOBAL.SpawnPrefab("spider")	unit.Transform:SetPosition(pos:Get())	player.components.leader:AddFollower(unit) endAddModRPCHandler(modname, "SpawnSpider", SpawnSpider)GLOBAL.TheInput:AddKeyDownHandler(GLOBAL.KEY_X, function()local player=GLOBAL.ThePlayerif player and player.prefab=="yourcharactersprefabname" 	and not GLOBAL.IsPaused() and not GLOBAL.TheInput:IsKeyDown(GLOBAL.KEY_CTRL) and not GLOBAL.TheInput:IsKeyDown(GLOBAL.KEY_SHIFT)	and not player.HUD:IsChatInputScreenOpen() and not player.HUD:IsConsoleScreenOpen()then    SendModRPCToServer(MOD_RPC[modname]["SpawnSpider"])end end)
X is the Hotkey here to spawn them.

 

I copied this code just to try it out with my character but i get an error every single time i press X saying that the variable "Player" is not declared 

Link to comment
Share on other sites

 

@codelyoko373,
did u add it to your modmain?
can u attach your modmain and the logfile?

 

 

Well this is my modmain:

 

local MakePlayerCharacter = require "prefabs/player_common"


local assets = {

Asset( "ANIM", "anim/player_basic.zip" ),
Asset( "ANIM", "anim/player_idles_shiver.zip" ),
Asset( "ANIM", "anim/player_actions.zip" ),
Asset( "ANIM", "anim/player_actions_axe.zip" ),
Asset( "ANIM", "anim/player_actions_pickaxe.zip" ),
Asset( "ANIM", "anim/player_actions_shovel.zip" ),
Asset( "ANIM", "anim/player_actions_blowdart.zip" ),
Asset( "ANIM", "anim/player_actions_eat.zip" ),
Asset( "ANIM", "anim/player_actions_item.zip" ),
Asset( "ANIM", "anim/player_actions_uniqueitem.zip" ),
Asset( "ANIM", "anim/player_actions_bugnet.zip" ),
Asset( "ANIM", "anim/player_actions_fishing.zip" ),
Asset( "ANIM", "anim/player_actions_boomerang.zip" ),
Asset( "ANIM", "anim/player_bush_hat.zip" ),
Asset( "ANIM", "anim/player_attacks.zip" ),
Asset( "ANIM", "anim/player_idles.zip" ),
Asset( "ANIM", "anim/player_rebirth.zip" ),
Asset( "ANIM", "anim/player_jump.zip" ),
Asset( "ANIM", "anim/player_amulet_resurrect.zip" ),
Asset( "ANIM", "anim/player_teleport.zip" ),
Asset( "ANIM", "anim/wilson_fx.zip" ),
Asset( "ANIM", "anim/player_one_man_band.zip" ),
Asset( "ANIM", "anim/shadow_hands.zip" ),
Asset( "SOUND", "sound/sfx.fsb" ),
Asset( "SOUND", "sound/wilson.fsb" ),
Asset( "ANIM", "anim/beard.zip" ),

Asset( "ANIM", "anim/esctemplate.zip" ),
}
local prefabs = {}
local start_inv = {
-- Custom starting items
}

local fn = function(inst)

-- choose which sounds this character will play
inst.soundsname = "willow"

-- Minimap icon
inst.MiniMapEntity:SetIcon( "esctemplate.tex" )

-- Stats
inst.components.health:SetMaxHealth(150)
inst.components.hunger:SetMax(150)
inst.components.sanity:SetMax(200)

-- Damage multiplier (optional)
inst.components.combat.damagemultiplier = 1

-- Hunger rate (optional)
inst.components.hunger.hungerrate = 1 * TUNING.WILSON_HUNGER_RATE

-- Movement speed (optional)
inst.components.locomotor.walkspeed = 4
inst.components.locomotor.runspeed = 6
end

local function SpawnSpider(player)
local pos = GLOBAL.Vector3(player.Transform:GetWorldPosition())
local offset = (GLOBAL.FindWalkableOffset(pos,math.random()*GLOBAL.PI*2,0.5,false))
if offset == nil then
if player.components.talker then
player.components.talker:Say("No Space!", 2.5)
end
return
end
pos=pos+offset
local unit=GLOBAL.SpawnPrefab("spider")
unit.Transform:SetPosition(pos:Get())
player.components.leader:AddFollower(unit)
end
AddModRPCHandler(modname, "SpawnSpider", SpawnSpider)

GLOBAL.TheInput:AddKeyDownHandler(GLOBAL.KEY_X, function()
local player=GLOBAL.ThePlayer
if player and player.prefab=="esctemplate"
and not GLOBAL.IsPaused() and not GLOBAL.TheInput:IsKeyDown(GLOBAL.KEY_CTRL) and not GLOBAL.TheInput:IsKeyDown(GLOBAL.KEY_SHIFT)
and not player.HUD:IsChatInputScreenOpen() and not player.HUD:IsConsoleScreenOpen()then
SendModRPCToServer(MOD_RPC[modname]["SpawnSpider"])
end
end
)

return MakePlayerCharacter("esctemplate", prefabs, assets, fn, start_inv)

Don't know where my logfile is... sorry :(

Edited by codelyoko373
Link to comment
Share on other sites

Don't know where my logfile is... sorry

then u should read a few tutorials, will also help u a lot with modding, i suggest this: http://forums.kleientertainment.com/topic/50811-guide-modding-practices-series-index/

and there's a lot of other good tutorials on the top areas of this forum and of the modforum for regular dont starve http://forums.kleientertainment.com/forum/26-dont-starve-mods-and-tools/

your logfile is in

Documents\Klei\DoNotStarveTogether\log.txt

and the file u posted is not your modmain but your character's prefabfile.

the modmain is called modmain.lua.

u have to add the code there.

Edited by Seiai
Link to comment
Share on other sites

then u should read a few tutorials, will also help u a lot with modding, i suggest this: http://forums.kleientertainment.com/topic/50811-guide-modding-practices-series-index/

and there's a lot of other good tutorials on the top areas of this forum and of the modforum for regular dont starve http://forums.kleientertainment.com/forum/26-dont-starve-mods-and-tools/

your logfile is in

Documents\Klei\DoNotStarveTogether\log.txt

and the file u posted is not your modmain but your character's prefabfile.

the modmain is called modmain.lua.

u have to add the code there.

Thanks for the tutorial links and i have no idea why i put it in my prefabfile XD... I swear i put it in the modmain but i guess i was getting confused with all the windows i had up at the same time.

Link to comment
Share on other sites

Is working fine.

 

Though when I was testing to add to me and my friend (mb's) mod. We could not find a way to add the birthing animation as well as putting a cap on the amount of spiders being spawned.

 

Thank you very much 

Link to comment
Share on other sites

@finlach,

to limit the spiders to 10, add this

	local spiders=0	for k,v in pairs(player.components.leader.followers) do	if k.prefab=="spider" then spiders=spiders+1	end	end	if spiders>=10 then 		if  player.components.talker then        player.components.talker:Say("Dude, I'm no damn spiderhorder!", 2.5)        end	return false	end
right after

local function SpawnSpider(player)
*there might be synthaxerror, didn't actually run it

with "adding the birthinganimation", do u mean a custom animation u made in spriter?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...