Jump to content

Script help


jkub

Recommended Posts

It happens... I replied to the last page question and didn't notice this page exists.

Heh don't worry, I do it too... I was just being facetious.

jkub: Ok I will actually test it and see what the problem is and get back to you

Edit:

jkub: I have fixed the code, go back and copy it again from the last page. I updated my previous post instead of cluttering up this page with a duplicate script.

Sorry it was my fault, I forgot to name one of the variables correctly. I also added the onResourceStart call in case you hadn't done that yourself.

I tested it this time to make sure it works.

Link to comment
  • Replies 109
  • Created
  • Last Reply

Top Posters In This Topic

if I wanted to rotate an object such as a road >smoothly<. making it go up like a draw bridge, how would make it to where rotateobject is a smooth animation.

road = createObject ( 18450, -992.48059082031, 340.8141784668, 2.2976553440094 ) --creates the road object 
marker = createMarker ( -992.48059082031, 310.8141784668, 3, "corona", 2, 0, 255, 0, 100 ) -- creates the marker 
function MarkerHit ( hitPlayer, matchingDimension ) 
        if getElementType(hitPlayer)=="player" then 
            setObjectRotation ( road, 0, -1, 0 )  
        end 
end 
addEventHandler("onMarkerHit", getRootElement (), MarkerHit) 
  

and btw instead of using a marker to trigger it cant i just make a command handler like

addCommandHandler ( "roadup", MarkerHit )

Link to comment
if I wanted to rotate an object such as a road >smoothly<. making it go up like a draw bridge, how would make it to where rotateobject is a smooth animation.

...

and btw instead of using a marker to trigger it cant i just make a command handler like

addCommandHandler ( "roadup", MarkerHit )

Rotating an object smoothly will be a different matter since you will have to handle the entire rotation phase yourself, as far as I know there is no automatic rotation command similar to moveObject.

You will instead need one function to trigger the 'activation' of the bridge, and use a repeating timer call to another function to rotate the bridge in the specified direction one small modification at a time. The smaller and more frequent the increment of change each time, the more smooth looking the outcome will be. This means smoother rotations require smaller a smaller timer delay between each call. There is a limiting factor however, that the minimum timer delay is 50 ms.

You could use commands instead of markers, of course the functions construction would need to change slightly. In its current form I don't know whether simply changing it to a command handler would work.

Personally I don't like commands for interactions of this kind ... it just seems so anti-intuitive. Everyone knows what a marker is and could work out the raising/lowering mechanism themselves, whereas no one will know the command the operate the bridge. I suppose it really depends on what you actually want to use it for.

Link to comment
Actually there is. The moveObject function has three optional arguments controlling relative rotation over all axis.

Ah yes indeed. I must have been blind to miss that :P That's what I get for being too lazy to read the wiki most of the time.

I was rather expecting something like rotateObject. That fit better with my perception of naming convention in MTA.

Link to comment

for some reason it wants to move on the x axis when i move it even though i havent specified anymovement on the x axis?

road = createObject ( 18450, -992.48059082031, 340.8141784668, 2.2976553440094 ) --creates the road object 
function MarkerHit ( hitPlayer, matchingDimension ) 
        if getElementType(hitPlayer)=="player" then 
            moveObject ( road, 8000, -992.48059082031, 340.8141784668, 13.4976553440094, 0, 15, 0 ) 
        end 
end 
addCommandHandler ("roadup", MarkerHit ) 
  

Link to comment
for some reason it wants to move on the x axis when i move it even though i havent specified anymovement on the x axis?

It isn't actually moving along the x-axis. The effect you describe comes from the edge of the model moving away as a result of the rotation. Just play with the numbers a bit to compensate for the apparent drift.

  
road = createObject ( 18450, -992.48059082031, 340.8141784668, 2.2976553440094 )  
road2 = createObject ( 18450, -912.5, 340.8141784668, 2.2976553440094 )  
  
function roadup() 
    if road then 
        local posx, posy, posz = getElementPosition(road) 
             moveObject ( road, 8000, posx + 2, posy, posz + 10, 0, 15, 0 ) 
    end 
end 
  
addCommandHandler ("roadup", roadup ) 
  
function roaddown() 
    if road then 
        local posx, posy, posz = getElementPosition(road) 
             moveObject ( road, 8000, posx - 2, posy, posz - 10, 0, -15, 0 ) 
    end 
end 
  
addCommandHandler ("roaddown", roaddown ) 
  

That is a pretty close estimate. Could still be made a bit nicer though.

Link to comment

i have created a house at a certain location on my map (by plesure domes club) and I have created a marker at the door of the house wich is an arrow...

now when i walk in the arrow i want it to warp me to a certain interior. but it asks for an interior 0-255 are valid. i have looked at inteior ids on the wiki and some of them have the same number like 4 of them might have the same id. I found out the interior i wanted by using the admin panel to warp me to it. wich was world=5 SFHSB1

and how would i put that into a spawn player syntax correctly?

  
intMarker = createMarker ( -2633.8181152344, 1371.9820556641, 8, "arrow", 2, 255, 255, 0, 180 ) visibleTo = getRootElement() 
function interior ( hitPlayer, matchingDimension ) 
  if getElementType(hitPlayer)=="player" then 
    spawnPlayer ( hitPlayer, 0, 0, 0, 0, 0,  5, 5 ) 
  end 
end 

Link to comment

If you want to spawn in interior you need the interior ID and position. If I wanted to spawn inside Jizzy's Pleasure Domes for example the spawn parameters would be as follows:

  
ID = 3 
X = -2636.7190 
Y = 1402.9170 
Z = 906.4609 
  

  
spawnPlayer(source, -2636.7190, 1402.9170, 906.4609, 0, 0, 3, 0, nil) 
  

In case you don't want to spawn but rather "teleport" to the location use setElementInterior.

  
setElementInterior(source, 3, -2636.7190, 1402.9170, 906.4609) 
  

Link to comment

for some reason in this script when I attach the other car to the first car the attached car messes up and goes invisible???

car1 = createVehicle ( 421, 0, 15, 5, 0, 0, 0, BLUE ) 
car = createVehicle ( 421, 0, 20, 5, 0, 0, 0, BLUE ) 
         setVehicleColor ( car, 158, 158, 158, 158 ) 
         setVehicleColor ( car1, 158, 158, 158, 158 ) 
            attachElementToElement ( car1, car, 0, -7, 0, 0, 0, 0) 
function setSkin (playerSource) 
    id = getVehicleID ( theVehicle ) if id == 421 then 
        setPlayerSkin ( playerSource, 0 ) 
    end 
end 
  
addEventHandler ( "onPlayerVehicleEnter", getRootElement(), setSkin ) 

Link to comment
marker = createMarker ( -1090.3737792969, 402.10968017578, 14.5, "checkpoint", 20, 0, 255, 0, 255 ) visibleTo = getRootElement() 
function MarkerHit ( hitPlayer, matchingDimension ) 
        outputChatBox (" Won the race!", getRootElement(), 255, 255, 109 ) 
  
end 
  
  
addEventHandler("onMarkerHit", getRootElement (), MarkerHit) 

when the script outputs to the chatbox>>> how would I make it output the players name before "Won the race!" ive already tried using getClientName and addessing another name to it but it doesent seem to work

Link to comment
marker = createMarker ( -1090.3737792969, 402.10968017578, 14.5, "checkpoint", 20, 0, 255, 0, 255 ) visibleTo = getRootElement() 
function MarkerHit ( hitPlayer, matchingDimension ) 
        outputChatBox (getClientName(hitPlayer) .. " won the race!", getRootElement(), 255, 255, 109 ) 
  
end 
  
  
addEventHandler("onMarkerHit", getRootElement (), MarkerHit) 

This? ^^

EDIT: Thanks Ace, this way better? ^^

Edited by Guest
Link to comment

so the house inteiror script thing isnt much here is the code wich dosent seem to work

  
marker = createMarker ( -2633.8181152344, 1371.9820556641, 8, "arrow", 2, 255, 255, 0, 180 ) visibleTo = getRootElement() 
function MarkerHit ( source, matchingDimension ) 
  if getElementType(source)=="player" then 
    spawnPlayer(source, -2636.7190, 1402.9170, 906.4609, 0, 0, 3, 0, nil) 
  end 
end 

Link to comment

You can't have a call back without actually attaching a function handle to an event.

  
-- This is the marker thing that you see on your screen as the entrance. 
marker = createMarker ( -2633.8181152344, 1371.9820556641, 8, "arrow", 2, 255, 255, 0, 180 ) 
  
-- This is the function handle triggered by the call back. 
function MarkerHit ( hitPlayer, matchingDimension ) 
  -- Always check if the parameter is of the right type. In this case it is supposed to be 
  -- a player. But in some cases it can be a variety of types. 
  if getElementType(hitPlayer)=="player" then 
    -- Spawn player. 
    spawnPlayer(hitPlayer, -2636.7190, 1402.9170, 906.4609, 0, 0, 3, 0, nil) 
  end 
end 
  
-- This is the part where you actually attach the function handle to the event. 
-- We attach the handler to the marker element instead of the root element because 
-- there is no need to propagate down the entire tree (make sure to set the last parameter to false). 
addEventHandler("onMarkerHit", marker, MarkerHit, false) 
  

Link to comment

when i do this it activates when i hit any marker i have made in other scripts which i beilive i called "marker" also

shouldent i be able to eleminate that problem by renaming the marker of this script? example change it to "marker2" none of my other scripts have a marker with that name

Link to comment
when i do this it activates when i hit any marker i have made in other scripts which i beilive i called "marker" also

shouldent i be able to eleminate that problem by renaming the marker of this script? example change it to "marker2" none of my other scripts have a marker with that name

You don't give markers name, it's just a name of variable which holds a "pointer" to a marker. You should start from reading lua manual not ready scripts, find out what's a variable, table, function, how they work and then wiki will be usefull for you.

http://www.lua.org/manual/5.1/

http://www.lua.org/pil/index.html

Link to comment

this is a gate that opens when you hit the collision shape but when you leave the collision shape nothing happens even though i made a function to close it. I beilive the open function is right but ti dosent close? wat am i doin wrong

col = createColRectangle ( -722.6709, 964.2388, 15, 40 ) 
gate = createObject ( 976, -716.8275, 957.5919, 10.1554, 0, 0, 90 ) 
  
function gateOpen ( hitPlayer, matchingDimension ) 
    if getElementType(hitPlayer)=="player" then 
        moveObject ( gate, 3500, -716.8275, 951.4920, 10.1554 ) 
    end 
end 
  
addEventHandler ( "onColShapeHit", col, gateOpen ) 
  
function gateClose ( leavePlayer, matchingDimension ) 
    if getElementType (leavePlayer)=="player" then 
        moveObject ( gate, 3500, -716.8275, 957.5919, 10,1554, 0, 0, 90 ) 
    end 
end 
  
addEventHandler ( "OnColShapeLeave", col, gateClose ) 
  
  

Link to comment

Hy by parem I assume you mean paremeters wich i see wat you mean. On the number on the move object script I put a comma but I ment to put a period wich added a paremeter I c,

but I fixed that and it still didnt work, so instead of doing to differnt functions would i be able to just open the gate set the timer for moving back all in one function?

I assume that would be easier

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