News: Welcome back to Bullworth! If you haven't already, you will need to reset your password..


Author Topic: Need Help With A Script  (Read 2093 times)

0 Members and 1 Guest are viewing this topic.

Offline JCrashBandicootF

  • Newbie
  • *
  • Posts: 1
    • View Profile
Need Help With A Script
« on: December 25, 2023, 03:21:12 PM »
So, I've been modding Bully via LUA scripting for a while, and I stuttered while writing a code which isn't working properly on my game... I'm not an expert on lua modding, just an amateur trying to learn as many as possible for a future mod...

Code: [Select]
-- test peds for something dunno
main = function()
  while not SystemIsReady() or AreaIsLoading() do
Wait(0)
  end
 
  repeat
if IsButtonBeingPressed(1,0) then
CreateThread("FindForPedSum")
end
Wait(0)
  until not Alive
end

FindForPedSum = function()
local PedFound = false
local gAllPeds = {PedFindInAreaXYZ(0,0,0,9999999)}
table.remove(gAllPeds,gPlayer)
Wait(10)
RdPed = gAllPeds[math.random(1,table.getn(gAllPeds))]
repeat
if PedIsValid(RdPed) and PedFound == false then
PedFound = true
elseif not PedIsValid(RdPed) and PedFound == false then
TextPrintString("Ped Not Found!",3,2)
TerminateThread("F_ControlRandomPed")
break
end
Wait(0)
until PedFound == true
TextPrintString("Ped Found!",3,2)
end

-- STimeCycle functions
F_AttendedClass = function()
  if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
    return
  end
  SetSkippedClass(false)
  PlayerSetPunishmentPoints(0)
end
 
F_MissedClass = function()
  if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
    return
  end
  SetSkippedClass(true)
  StatAddToInt(166)
end
 
F_AttendedCurfew = function()
  if not PedInConversation(gPlayer) and not MissionActive() then
    TextPrintString("You got home in time for curfew", 4)
  end
end
 
F_MissedCurfew = function()
  if not PedInConversation(gPlayer) and not MissionActive() then
    TextPrint("TM_TIRED5", 4, 2)
  end
end
 
F_StartClass = function()
  if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
    return
  end
  F_RingSchoolBell()
  local l_6_0 = PlayerGetPunishmentPoints() + GetSkippingPunishment()
end
 
F_EndClass = function()
  if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
    return
  end
  F_RingSchoolBell()
end
 
F_StartMorning = function()
  F_UpdateTimeCycle()
end
 
F_EndMorning = function()
  F_UpdateTimeCycle()
end
 
F_StartLunch = function()
  if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
    F_UpdateTimeCycle()
    return
  end
  F_UpdateTimeCycle()
end
 
F_EndLunch = function()
  F_UpdateTimeCycle()
end
 
F_StartAfternoon = function()
  F_UpdateTimeCycle()
end
 
F_EndAfternoon = function()
  F_UpdateTimeCycle()
end
 
F_StartEvening = function()
  F_UpdateTimeCycle()
end
 
F_EndEvening = function()
  F_UpdateTimeCycle()
end
 
F_StartCurfew_SlightlyTired = function()
  F_UpdateTimeCycle()
end
 
F_StartCurfew_Tired = function()
  F_UpdateTimeCycle()
end
 
F_StartCurfew_MoreTired = function()
  F_UpdateTimeCycle()
end
 
F_StartCurfew_TooTired = function()
  F_UpdateTimeCycle()
end
 
F_EndCurfew_TooTired = function()
  F_UpdateTimeCycle()
end
 
F_EndTired = function()
  F_UpdateTimeCycle()
end
 
F_Nothing = function()
end
 
F_ClassWarning = function()
  if IsMissionCompleated("3_08") and not IsMissionCompleated("3_08_PostDummy") then
    return
  end
  local l_23_0 = math.random(1, 2)
end
 
F_UpdateTimeCycle = function()
  if not IsMissionCompleated("1_B") then
    local l_24_0 = GetCurrentDay(false)
    if l_24_0 < 0 or l_24_0 > 2 then
      SetCurrentDay(0)
    end
  end
  F_UpdateCurfew()
end
 
F_UpdateCurfew = function()
  local l_25_0 = shared.gCurfewRules
  if not l_25_0 then
    l_25_0 = F_CurfewDefaultRules
  end
  l_25_0()
end
 
F_CurfewDefaultRules = function()
  local l_26_0 = ClockGet()
  if l_26_0 >= 23 or l_26_0 < 7 then
    shared.gCurfew = true
  else
    shared.gCurfew = false
  end
end

so basically what I tried to do here, it's a code that will try to find for a ped in the area and return a "Ped Found" text if there's one or more spawned and "No Ped Found" if there are no peds spawned... and I tried to use PedFindInAreaXYZ() and inserting it in a table so that another variable can choose randomly from the table...
However I tried to remove gPlayer from the table by using table.remove (so that the variable will not choose player as an existing ped, pretty sure it's useless) but still, even though I'm in an area with no peds spawned, the game always returns "Ped Found", basically it never reaches the "elseif" statment which returns the "Ped Not Found!" text...
I'm pretty sure I made a mistake somewhere but I can't seem to find it, and if there's any lua expert that can offer to help me on how to fix and even optimize my code (if possible), I would be glad... thanks in advance!