Jump to content

Script help


jkub

Recommended Posts

  • Replies 109
  • Created
  • Last Reply

Top Posters In This Topic

now about the setcamera function

is there a way i can set the camera to look at an element instead of typing in a specific location for it?

platform = createObject ( 18452, -1265, 6.0160622596741, 15.529356002808 ) -- creates the object 1842 (petrol hub) at the specified location 
    minigun = createObject ( 2985, 0, 0, 0 ) -- creates the object 2985 (minigun) at the specified location 
        theMarker = createMarker ( 0, 0, 0, "cylinder", 10, 255, 0, 0, 100 ) visibleTo = getRootElement() 
        attachElementToElement ( theMarker, minigun, 0, -1, 0, 0, 0, 0 ) --attaches the marker to the minigun 
        attachElementToElement ( minigun, platform, 0, -1, -2, 0, 0, 0 ) 
        function markerBlip ( sourcePlayer ) 
            if source == sourcePlayer then 
                setCameraMode ( sourcePlayer, "fixed" ) 
                setCameraLookAt ( sourcePlayer, -1265, 6.0, 16.0 ) 
            end 
        end 

Link to comment

Nice

Does that mean creating col shapes for markers is basically a waste of time then?

Unless.. is OnMarkerHit is a server-side only event? In which case clients would still need col shapes to detect the hit.. ?

That is correct. DP3 does have a client side equivalent but in DP2 you will have to create an additional client sided collision shape.

Link to comment

Nice

Does that mean creating col shapes for markers is basically a waste of time then?

Unless.. is OnMarkerHit is a server-side only event? In which case clients would still need col shapes to detect the hit.. ?

That is correct. DP3 does have a client side equivalent but in DP2 you will have to create an additional client sided collision shape.

Or make your own client-side marker event that is being triggered by the server one! xD

Link to comment

here is a script that creates a platform like object and is supposed to move it up when player steps into the marker. at first i made it at position 0 0 5 as a test and it worked perfectly. but when i changed the posistions it stoppped working here it is

elevator = createObject ( 5154, -1157.0510253906, 140.57569885254, -2.1713070869466 ) 
marker = createMarker ( -1157.0510253906, 140.57569885254, -1, "cylinder", 2, 0, 255, 0, 175 ) 
function MarkerHit ( hitPlayer, matchingDimension ) 
        if getElementType(hitPlayer)=="player" then 
            moveObject ( elevator, 10000, -1157.0510253906, 140.57569885254, 10 ) 
        end 
end 
addEventHandler("onMarkerHit", getRootElement (), MarkerHit) 

Link to comment

"cylinder" types only seem to recognize the hit if your feet are touching the base of the cylinder. Because cylinders snap to terrain level, at those coordinates it snaps to ocean level. If you lowered the platform to -3.25, the top surface would be just barely under water. In that setting, the platform works. At all above ocean level, it doesnt work.

One method is by changing the type to "checkpoint". However this has the problem that even once the platform raises, the checkpoint graphic still sticks through the platform, even though you cant interact with it.

You can fix it if you change it to type "corona" and set the Z coord at 1.25 instead of -1. It seems to work totally fine that way. Coronas do not snap to terrain level, and detect all hits.

Link to comment

Ok i got that strait now but got some probs...

1 i have made an outputchatbox message that says "going up" but it is server side. I tryed to make the message client only but couldent do it so here that is

outputChatBox ( "Going up", 255, 255, 255 ) 

and next how would i make it go back down. would i have to use another moveobject thing or what...????

Link to comment
Ok i got that strait now but got some probs...

1 i have made an outputchatbox message that says "going up" but it is server side. I tryed to make the message client only but couldent do it so here that is

outputChatBox ( "Going up", 255, 255, 255 ) 

and next how would i make it go back down. would i have to use another moveobject thing or what...????

The format of outputChatBox is (message, element, r, g, b, colorcoded)

So you were trying to display the message to the element '255' which obviously isn't going to work. I normally just do outputChatBox("message") for server-wide notices, which sends the message to the root element.

If you just wanted to tell the player who activated the lift, just use outputChatBox("Going up", hitPlayer)

It will be in white text anyway I think, so no need to worry about the 255, 255, 255. If you wanted colorization, then use outputChatBox("Going up", hitPlayer, 255, 255, 255, true)

As for a two way elevator.. try adding element data to both markers.

eg

  
  
upMarker = nil 
downMarker = nil 
  
platform = nil 
platformInUse = false 
  
-- elevator setup function. call this once.  
function setupElevator() 
  
  if not platform and not upMarker and not downMarker then 
    -- create platform 
    platform = createObject( 5154, -1157.0510253906, 140.57569885254, -2.1713070869466 ) 
  
    -- create markers 
    upMarker = createMarker( -1157.0510253906, 140.57569885254, 1.25, "corona", 2, 0, 255, 0, 175 ) 
    downMarker = createMarker( -1157.0510253906, 140.57569885254, 13.25, "corona", 2, 0, 255, 0, 175 ) 
  
    -- set direction of marker mechanism with setElementData 
    setElementData(upMarker, 'direction', 'up') 
    setElementData(downMarker, 'direction', 'down') 
  end 
  
end 
  
  
function MarkerHit ( hitPlayer, matchingDimension ) 
  if getElementType(hitPlayer)=="player" then 
  
    local direction = getElementData(source, "direction") 
  
    -- only activate if platform is not currently in use 
    if platformInUse == false and direction then 
  
        if direction == 'up' then 
  
            -- move platform up 
            moveObject ( platform, 10000, -1157.0510253906, 140.57569885254, 10 ) 
  
            -- set platorm in use status to true, and set timer to free the mechanism 
            platformInUse = true 
            setTimer(unlockPlatformMechanism, 10000, 1) 
  
            -- inform the player 
            outputChatBox("Going up", hitPlayer) 
  
        elseif direction == 'down' then 
  
            -- move platform down 
            moveObject ( platform, 10000, -1157.0510253906, 140.57569885254, -2.1713070869466 ) 
  
            platformInUse = true 
            setTimer(unlockPlatformMechanism, 10000, 1) 
  
            outputChatBox("Going down", hitPlayer) 
        end 
  
    end 
  
  end 
  
end 
addEventHandler("onMarkerHit", getRootElement (), MarkerHit) 
  
  
function unlockPlatformMechanism() 
    -- just set use flag 
    platformInUse = false 
end 
  
  
function onResourceStart( resourcename ) 
  
    setupElevator() 
  
    -- do whatever other setup stuff for this map 
end 
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), onResourceStart ) 
  
  

I have tested this code, it works.

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