Jump to content

Troll Script 2.


WolfPire

Recommended Posts

So i'm doing a special garage which will give your vehicle a random color every second aswell for your nametag.

All's going good, until we go to the serverside script. It will just give me 2 colors, and i want it to randomize R, G, B as i'm ordering. Any idea why this script is trolling me?

Client

WTF = createMarker(2610, 1451, 11, "cylinder", 3, 0, 0, 0, root) 
  
function randomiseMarkerColor() 
r = math.random(0,255) 
g = math.random(0,255) 
b = math.random(0,255) 
setMarkerColor( WTF, r, g, b, 255) 
end 
  
addEventHandler("onClientRender",root, randomiseMarkerColor) 
  
function WTFEnt( hitPlayer ) 
    if hitPlayer == localPlayer then 
        if not (nyan) then 
            if isPedOnGround( hitPlayer ) then 
                pVehicleSG = getPedOccupiedVehicle( hitPlayer ) 
                if pVehicleSG then 
                    fadeCamera( false, 1.0, 0, 0, 0 ) 
                    setElementFrozen(pVehicleSG,true) 
                    nyan = playSound("nyan.mp3",true) 
                    setTimer(fadeCamera, 2000, 1, true, 1.0 ) 
                    triggerServerEvent("carCol",root, pVehicleSG) 
                    setTimer(setElementFrozen,1300,1,pVehicleSG,false) 
                    setTimer(setElementPosition,2000, 1, pVehicleSG, 2611, 1431, 11) 
                    setTimer(destroyElement,1000000,1,nyan) 
                end 
            end 
            else 
            outputChatBox("Too much magic for you pal.", 255, 0, 0) 
        end 
    end 
end 
     
addEventHandler("onClientMarkerHit", root, WTFEnt) 

_____________________________________________________

Server

addEvent("carCol",true) 
addEventHandler("carCol",root, 
function(pVehicleSG) 
        setTimer(setVehicleColor, 1000, 1000, pVehicleSG, math.random(0,255), math.random(0,255), math.random(0,255)) 
        setTimer(setPlayerNametagColor, 1000, 1000, getVehicleController(pVehicleSG), math.random(0,255), math.random(0,255), math.random(0,255)) 
end 
) 

Link to comment

if you mean that the car and name get different color and you want the same for both — you need to assign the same color:

addEvent("carCol",true) 
addEventHandler("carCol",root, 
function(pVehicleSG) 
        local r,g,b = math.random(0,255), math.random(0,255), math.random(0,255) 
        setTimer(setVehicleColor, 1000, 1000, pVehicleSG, r,g,b) 
        setTimer(setPlayerNametagColor, 1000, 1000, getVehicleController(pVehicleSG), r,g,b) 
end 
) 

Link to comment

colors dont change because all the values for arguments passed to the timer/function are evaluated before timer starts.

so you need to randomize the color in the function that is called by timer.

function randomColors(pVehicleSG) 
  local r,g,b = math.random(0,255), math.random(0,255), math.random(0,255) 
  setVehicleColor(pVehicleSG, r, g, b) 
  setPlayerNametagColor(getVehicleController(pVehicleSG), r, g, b) 
end         
  
addEvent("carCol",true) 
addEventHandler("carCol", root,  
function(pVehicleSG) 
  setTimer(randomColors, 1000, 1000, pVehicleSG) 
end 
) 

Link to comment
colors dont change because all the values for arguments passed to the timer/function are evaluated before timer starts.

so you need to randomize the color in the function that is called by timer.

function randomColors(pVehicleSG) 
  local r,g,b = math.random(0,255), math.random(0,255), math.random(0,255) 
  setVehicleColor(pVehicleSG, r, g, b) 
  setPlayerNametagColor(getVehicleController(pVehicleSG), r, g, b) 
end         
  
addEvent("carCol",true) 
addEventHandler("carCol", root,  
function(pVehicleSG) 
  setTimer(randomColors, 1000, 1000, pVehicleSG) 
end 
) 

That was exactly on my mind, just that i didn't really know how to fix it, as i tried so many ways to update values.

Thanks, it works like a charm, Aibo =3 (Your name means "buddy" or "pal" in Japanese by the way, i think... n_n)

And, aswell thanks like always... Solid.

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