Jump to content

Recommended Posts

Hello, I need help :).

So, i'm trying to give the 1st two math randoms a 25% chance of happening & the rest of the math randoms a 12.5% chance of happening but sometimes when I activate this I don't get anything :shock:? I'm sure I did my math right... Why is this happening? How can I make it that one of these 100% will activate?

if math.random() < 0.25 then
	inst.components.lootdropper:SpawnLootPrefab("humanmeat")
    inst.components.lootdropper:SpawnLootPrefab("monstermeat")
	elseif math.random() < 0.25 then
	inst.components.lootdropper:SpawnLootPrefab("boneshard")
	inst.components.lootdropper:SpawnLootPrefab("humanmeat")
    inst.components.lootdropper:SpawnLootPrefab("monstermeat")
	elseif math.random() < 0.125 then
	inst.components.lootdropper:SpawnLootPrefab("humanmeat")
	inst.components.lootdropper:SpawnLootPrefab("humanmeat")
	elseif math.random() < 0.125 then
	inst.components.lootdropper:SpawnLootPrefab("monstermeat")
	inst.components.lootdropper:SpawnLootPrefab("monstermeat")
	elseif math.random() < 0.125 then
	inst.components.lootdropper:SpawnLootPrefab("boneshard")
	inst.components.lootdropper:SpawnLootPrefab("humanmeat")
	inst.components.lootdropper:SpawnLootPrefab("humanmeat")
	elseif math.random() < 0.125 then
	inst.components.lootdropper:SpawnLootPrefab("boneshard")
	inst.components.lootdropper:SpawnLootPrefab("monstermeat")
	inst.components.lootdropper:SpawnLootPrefab("monstermeat")
	end

Thanks for reading my problem :D!

EDIT: Other problem is below!

Edited by SuperDavid

This probably isn't exactly what you want but here is how spiders drop their random loot:

inst.components.lootdropper:AddRandomLoot("monstermeat", 1)
inst.components.lootdropper:AddRandomLoot("silk", .5)
inst.components.lootdropper:AddRandomLoot("spidergland", .5)
inst.components.lootdropper.numrandomloot = 1

the 2nd value being chance of the item dropping.

 

I have another problem if somebody could help me out that would be great :D!

So, here's the code. The problem is there's a chance of nothing happening when my char triggers this code while sane...

if act.target.components.sanity:IsSane() and math.random() < 0.25 then
   act.target.components.talker:Say("Uh–uh!")
                                                                 
   elseif act.target.components.sanity:IsSane() and math.random() < 0.25 then
   act.target.components.talker:Say("I can't believe you!")

   elseif act.target.components.sanity:IsSane() and math.random() < 0.25 then
   act.target.components.talker:Say("You're joking, right?!")
   act.target:PushEvent("emote", { anim = "emoteXL_facepalm", mounted = true })
                                                                        
   elseif act.target.components.sanity:IsSane() and math.random() < 0.25 then
   act.target.components.talker:Say("How dare you!")

   elseif not act.target.components.sanity:IsSane() then
   act.target.components.talker:Say("RaRArGH, NOoOooO!!!")
end

  And if I do something like...

Spoiler

if act.target.components.sanity:IsSane() and math.random() < 0.25 then
   act.target.components.talker:Say("Uh–uh!")
                                                                 
   elseif act.target.components.sanity:IsSane() and math.random() < 0.25 then
   act.target.components.talker:Say("I can't believe you!")

   elseif act.target.components.sanity:IsSane() and math.random() < 0.25 then
   act.target.components.talker:Say("You're joking, right?!")
   act.target:PushEvent("emote", { anim = "emoteXL_facepalm", mounted = true })
                                                                        
   elseif act.target.components.sanity:IsSane() and math.random() < 0.25 then
   act.target.components.talker:Say("How dare you!")

   else
   act.target.components.talker:Say("No!")

   elseif not act.target.components.sanity:IsSane() then
   act.target.components.talker:Say("RaRArGH, NOoOooO!!!")
end

It overrides this code, which's not good :|...

elseif not act.target.components.sanity:IsSane() then
act.target.components.talker:Say("RaRArGH, NOoOooO!!!")

So, can someone tell how I can prevent this :)?

Also, thanks so much for reading my problem, have a wonderful day/night :D!

Edited by SuperDavid

Try this.

local saychance = math.random(4)

if act.target.components.sanity:IsSane() and saychance == 1 then
   act.target.components.talker:Say("Uh–uh!")
                                                                 
   elseif act.target.components.sanity:IsSane() and saychance == 2 then
   act.target.components.talker:Say("I can't believe you!")

   elseif act.target.components.sanity:IsSane() and saychance == 3 then
   act.target.components.talker:Say("You're joking, right?!")
   act.target:PushEvent("emote", { anim = "emoteXL_facepalm", mounted = true })
                                                                        
   elseif act.target.components.sanity:IsSane() and saychance == 4 then
   act.target.components.talker:Say("How dare you!")

   elseif not act.target.components.sanity:IsSane() then
   act.target.components.talker:Say("RaRArGH, NOoOooO!!!")
end

 

Edited by DarkKingBoo
Fixed
local SACRIFICE = GLOBAL.Action()
SACRIFICE.str = "Sacrifice"
SACRIFICE.id = "SACRIFICE"
SACRIFICE.fn = function(act)
 if act.target.components.hunger.current <= 40 or act.target.components.health.currenthealth <= 100 then
   if act.target.components.sanity:IsSane() and math.random() < 0.25 then
   act.target.components.talker:Say("Uh–uh!")
   elseif act.target.components.sanity:IsSane() and math.random() < 0.25 then
   act.target.components.talker:Say("I can't believe you!")
   elseif act.target.components.sanity:IsSane() and math.random() < 0.25 then
   act.target.components.talker:Say("You're joking, right?!")
   act.target:PushEvent("emote", { anim = "emoteXL_facepalm", mounted = true })
   elseif act.target.components.sanity:IsSane() and math.random() < 0.25 then
   act.target.components.talker:Say("What are you, an sadist?")
   elseif not act.target.components.sanity:IsSane() then
   act.target.components.talker:Say("We pReSeRvE oUr LiFe, NoT eNd It, fOoL!!!")
   end

   elseif act.target.components.hunger.current >= 40 and act.target.components.health.currenthealth >= 100 then
   if act.target:HasTag("playerghost") or act.target.components.health:IsDead() or act.target.sg:HasStateTag("giving")
   or act.target.sg:HasStateTag("busy") or act.target.sg:HasStateTag("working") or act.target.sg:HasStateTag("fishing")
   or act.target.sg:HasStateTag("doing") or act.target.sg:HasStateTag("playing") or act.target.sg:HasStateTag("running")
   or act.target.components.inventory:IsHeavyLifting() then
   return
   end
   act.target.sg:GoToState("sacrifice")
 end
end

AddAction(SACRIFICE)

 

--Noticed that elseif check for the hunger was >= 40 and >= 100. You should probably just do > instead. It could cause a chance of nothing happening.
--For the meantime I just made it else.
--Sorry if this doesn't fix it, but I added some prints to let you know if the function is running properly when you don't say anything.

local SACRIFICE = GLOBAL.Action()
SACRIFICE.str = "Sacrifice"
SACRIFICE.id = "SACRIFICE"
SACRIFICE.fn = function(act)

local saychance = math.random(1,4)

 if act.target.components.hunger.current <= 40 or act.target.components.health.currenthealth <= 100 then
   print("hunger values and health values met")
   if act.target.components.sanity:IsSane() and saychance == 1 then
   act.target.components.talker:Say("Uh–uh!")
   elseif act.target.components.sanity:IsSane() and saychance == 2 then
   act.target.components.talker:Say("I can't believe you!")
   elseif act.target.components.sanity:IsSane() and saychance == 3 then
   act.target.components.talker:Say("You're joking, right?!")
   act.target:PushEvent("emote", { anim = "emoteXL_facepalm", mounted = true })
   elseif act.target.components.sanity:IsSane() and saychance == 4 then
   act.target.components.talker:Say("What are you, an sadist?")
   elseif not act.target.components.sanity:IsSane() then
   act.target.components.talker:Say("We pReSeRvE oUr LiFe, NoT eNd It, fOoL!!!")
   end

   else
   print("hunger values and health values NOT met")
   if act.target:HasTag("playerghost") or act.target.components.health:IsDead() or act.target.sg:HasStateTag("giving")
   or act.target.sg:HasStateTag("busy") or act.target.sg:HasStateTag("working") or act.target.sg:HasStateTag("fishing")
   or act.target.sg:HasStateTag("doing") or act.target.sg:HasStateTag("playing") or act.target.sg:HasStateTag("running")
   or act.target.components.inventory:IsHeavyLifting() then
   return
   end
   act.target.sg:GoToState("sacrifice")
 end
end

AddAction(SACRIFICE)
Edited by DarkKingBoo

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
×
  • Create New...