Jump to content

math.random refreshment


ThePCGuy

Recommended Posts

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?

Link to comment

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 ?

Link to comment

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 

Link to comment
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.

Link to comment

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
Link to comment

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...