Jump to content

[Req] Portal Gun


DakiLLa

Recommended Posts

Hi there! I have an idea: portal gun like in Portal game :)

i have made some script but it doesn not work, there is errors in code i think..i dont know, but i think that i have errors in get element positions of created markers too. can you help me to realise this script?

I think it can be a nice gamemode with diffrent maps in future if i'll finish this script.

delay = 10000 
  
function setDataOnJoin ( ) 
    setElementData ( source, "playerData", 1 ) 
    outputChatBox ( "Your data was set to 1", source, 255, 255, 0 ) 
end 
addEventHandler ( "onPlayerJoin", getRootElement (), setDataOnJoin ) 
  
function creating ( weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement ) 
    local getData = getElementData ( source, "playerData" ) 
    if ( getData == 1 ) then 
        if ( weapon == 27 ) then 
            enterMarker = createMarker ( hitX, hitY, hitZ, "ring", 255, 0, 0 ) 
            addEventHandler ( "onMarkerHit", enterMarker, teleporting ) 
            setElementData ( source, "playerData", 2 ) 
            outputChatBox ( "You have created a first portal!", source, 255, 0, 0 ) 
            if ( getData == 1 ) then 
                local hEhitX, hEhitY, hEhitZ = getElementPosition ( hitElement ) 
                exitMarker = createMarker ( hEhitX, hEhitY, hEhitZ, "ring", 0, 0, 255 ) 
                outputChatBox ( "You have created a second portal!", source, 255, 0, 0 ) 
                setElementData ( source, "playerData", 1 ) 
                addEventHandler ( "onMarkerHit", exitMarker, reTeleporting ) 
            end 
        end 
    end 
    setTimer ( destroyElement, delay, 1, enterMarker ) 
    setTimer ( destroyElement, delay, 1, exitMarker ) 
end 
addEventHandler ( "onClientPlayerWeaponFire", getRootElement(), creating ) 
  
function teleporting ( thePlayer, matchingDimension ) 
    local ExposX, ExPosY, ExPosZ = getElementPosition ( exitMarker ) 
    setElementPosition ( thePlayer, ExposX, ExPosY, ExPosZ ) 
end 
  
function reTeleporting ( thePlayer, matchingDimension ) 
    local EnposX, EnPosY, EnPosZ = getElementPosition ( enterMarker ) 
    setElementPosition ( thePlayer, EnposX, EnPosY, EnPosZ ) 
end 

Link to post

Just a thing: Isn't line 17 quite pointless? Isn't that like doing:

if ( something==0 ) then 
    if ( something==0 ) then 
        ... 
    end 
end 

Anyway, it's quite obvious why it doesn't work to be honest... It's only the problem that a lot of people forget it... (including me :P)

addEventHandler ( "onPlayerJoin", getRootElement (), setDataOnJoin ) 

2 things:

1. This event doesn't exist client-side... Didn't you mean onClientPlayerJoin? :P

2. If the command WOULD be right, why using onClientPlayerJoin and getRootElement()? That would make it trigger for every player... Except for the player self... =/ (see onClientPlayerJoin)

Link to post

oops. in line 17 i mean:

if ( getData == 1 ) then 
   ... 
      if ( getData == 2 ) then 
        ... 
  

"onClientPlayerJoin" ye, i have forgotten to use this function in client side :)

and all the same..i cant see a message in chatbox when i connect to the server, so, script doesnt work from first lines... :(

Link to post
"onClientPlayerJoin" ye, i have forgotten to use this function in client side :)

and all the same..i cant see a message in chatbox when i connect to the server, so, script doesnt work from first lines... :(

Let me remind you of something I already told you. :P

2 things:

1. This event doesn't exist client-side... Didn't you mean onClientPlayerJoin? :P

2. If the command WOULD be right, why using onClientPlayerJoin and getRootElement()? That would make it trigger for every player... Except for the player self... =/ (see onClientPlayerJoin)

This event is triggered when a player joins a server. It is triggered for all players other than the local player.

I'd suggest using onClientResourceStart, don't you think? :P

Link to post

ok..i think that element data's is not needed now, so, i deleted it. Script without data's

function creating ( weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement ) 
    if ( not isElement ( enterMarker ) ) and ( weapon == 27 ) then 
        enterMarker = createMarker ( hitX, hitY, hitZ, "ring", 2.0, 255, 0, 0, 150 ) 
        outputChatBox ( "You have created a first portal!", 255, 0, 0 ) 
    elseif ( isElement ( enterMarker ) ) then 
        exitMarker = createMarker ( hitX, hitY, hitZ, "ring", 2.0, 0, 0, 255, 150 ) 
        outputChatBox ( "You have created a second portal!", 255, 0, 0 ) 
    end 
end 
addEventHandler ( "onClientPlayerWeaponFire", getRootElement(), creating ) 

and now, i need code for teleporting from first marker to second. I have one, but it have errors in eventHandler, like bad argument "enterMarker" and "exitMarker". I dont need to teleport from all markers, so, i didnt wrote getRootElement.

  
function Teleporting ( thePlayer, matchingDimension ) 
    local EnposX, EnPosY, EnPosZ = getElementPosition ( enterMarker ) 
    setElementPosition ( thePlayer, EnposX, EnPosY, EnPosZ ) 
end 
addEventHandler ( "onClientMarkerHit", enterMarker, Teleporting ) 
  
function reteleporting ( thePlayer, matchingDimension ) 
    local ExposX, ExPosY, ExPosZ = getElementPosition ( exitMarker ) 
    setElementPosition ( thePlayer, ExposX, ExPosY, ExPosZ ) 
end 
addEventHandler ( "onClientMarkerHit", exitMarker, reteleporting ) 

Link to post
FROM VERSION DP3 ONWARDS

onClientMarkerHit

onClientMarkerLeave

Anyway, if you use addEventHandler outside a function the elements that you add this handler should exist. When resource starts it goes through the file (script), it tries to attach handler to "undefined" element because the element will be created when player shoots (which is after resource start and all the resource files are loaded).

Link to post
  • 11 months later...

as 50p pointed out, the element has to exist before you attach a handler to it.

The solution here is to attach your handler immediately after creating the marker:

function creating ( weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement )
if ( not isElement ( enterMarker ) ) and ( weapon == 27 ) then
       enterMarker = createMarker ( hitX, hitY, hitZ, "ring", 2.0, 255, 0, 0, 150 )
addEventHandler ( "onClientMarkerHit", enterMarker, Teleporting )
outputChatBox ( "You have created a first portal!", 255, 0, 0 )
elseif ( isElement ( enterMarker ) ) then
       exitMarker = createMarker ( hitX, hitY, hitZ, "ring", 2.0, 0, 0, 255, 150 )
addEventHandler ( "onClientMarkerHit", exitMarker, reteleporting )
outputChatBox ( "You have created a second portal!", 255, 0, 0 )
end
end
addEventHandler ( "onClientPlayerWeaponFire", getRootElement(), creating )
 
function Teleporting ( thePlayer, matchingDimension )
local EnposX, EnPosY, EnPosZ = getElementPosition ( enterMarker )
setElementPosition ( thePlayer, EnposX, EnPosY, EnPosZ )
end
 
function reteleporting ( thePlayer, matchingDimension )
local ExposX, ExPosY, ExPosZ = getElementPosition ( exitMarker )
setElementPosition ( thePlayer, ExposX, ExPosY, ExPosZ )
end

This will also fix an error you whould have run into where only the first enter/exit marker would work if you tried to do things otherwise.

Remember to remove your event handlers as you remove the markers too!

By the way, there are still errors here, especially in your teleporting code. but if I told you how to do everything, what would you learn? :P

EDIT: Damn, didn't notice the post date and that the previous post was a massive bump! :(

But maybe the developer might work on this again now 1.0 is released.

Link to post

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