Jump to content

math.random refreshment


ThePCGuy

Recommended Posts

Posted

Hello,

I need some help with a Community Zombie script called: Zday.

You have 3 types of zombie walks that activates by a setting trough meta.xml

ZombieSpeed = get("zombies.Speed")

Since i want to change the walk randomly i did this:

ZombieSpeed = math.random( 1, 3 )

if ZombieSpeed == 1 then --super slow zombies (goofy looking)

chaseanim = "WALK_drunk"

checkspeed = 2000

elseif ZombieSpeed == 2 then -- normal speed

chaseanim = "run_old"

checkspeed = 1000

elseif ZombieSpeed == 3 then -- rocket zombies (possibly stressful on server)

chaseanim = "Run_Wuzi"

checkspeed = 680

end

It does work, only it doesnt refresh on each zombie spawn. The math.random only activates once at the resource startup or restart. Is it possible to refresh after each zombie spawn?

Posted

I just checked the whole resource (2 lua scripts) and didnt find something usefull about the spawns.

Zombies spawn randomly if you walk around with ofcourse the danger elementdata.

setTimer ( function (ped) if ( isElement ( ped ) ) then setPedAnimation ( ped, "ped", chaseanim, -1, true, true, true ) end end, 800, 1, ped )

''chaseanim'' is the animation, so is it possible to make the math.random refresh ?

Posted

Yes, I noticed why, I forgot to return the values, replace the last function ( getRandomZombieSpeed ) with this:

function getRandomZombieSpeed ( ) 
    local ZombieSpeed = math.random( 1, 3 ) 
    if ( ZombieSpeed == 1 ) then --super slow zombies (goofy looking) 
        chaseanim = "WALK_drunk" 
        checkspeed = 2000 
    elseif ( ZombieSpeed == 2 ) then -- normal speed 
        chaseanim = "run_old" 
        checkspeed = 1000 
    elseif ( ZombieSpeed == 3 ) then -- rocket zombies (possibly stressful on server) 
        chaseanim = "Run_Wuzi" 
        checkspeed = 680 
    end 
  
    return checkspeed, chaseanim 
end 

Posted
Yes, I noticed why, I forgot to return the values, replace the last function ( getRandomZombieSpeed ) with this:
function getRandomZombieSpeed ( ) 
    local ZombieSpeed = math.random( 1, 3 ) 
    if ( ZombieSpeed == 1 ) then --super slow zombies (goofy looking) 
        chaseanim = "WALK_drunk" 
        checkspeed = 2000 
    elseif ( ZombieSpeed == 2 ) then -- normal speed 
        chaseanim = "run_old" 
        checkspeed = 1000 
    elseif ( ZombieSpeed == 3 ) then -- rocket zombies (possibly stressful on server) 
        chaseanim = "Run_Wuzi" 
        checkspeed = 680 
    end 
  
    return checkspeed, chaseanim 
end 

Works now, only the animation changes every 1 second for all zombies in the game. Thats not what i meant if you thought it was. I want to randomly change the animation over time or even better each zombie that spawns have a different one.

Posted (edited)

How? I am confused. You are not getting any error but i am..

EDIT:

I think its cause of the elementData ''zombieData".

Also i am using slothbot and a other zombie spawn script so thats why its conflicting cause the zombie spawns on slothbot but it applies the animation cause of ''chaseanim'' can you make a way around the elementData "zombieData" ?

Edited by Guest
Posted

Indeed, as i am using the zombies gamemode for the animations, moaning etcetra. It only needs to set the ''chaseanim'' differently. So can you make a way around so you dont have to use that elementData?

Posted

Well in that case, i have a problem anyways now since the zombie script itself wont spawn zombies for some reason. Already stopped the resource scoreboard.

EDIT: Fixed now.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...