Hallo Leute, ich bins mal wieder mit einem Problem. Ich habe ein Script umgeschrieben (ja es ist ursprünglich NICHT von mir, sonder eine Resource namens "stinger"), und alles funktioniert auch so wie es soll. Außer, dass jede Bestätigungsnachricht 4 mal ausgegeben wird.
Anfangs habe ich vermutet, es liegt daran, dass mein PC zu schnell ist, und während ich "x" drücke, die Funktion 4 mal durchgeht. Also habe ich an den verschiedensten Stellen Timer mit outputChatBox eingefügt, damit der PC "ausgebremst" wird. Klappt aber irgendwie nicht, der einzige Effekt ist, dass mir zu den 4 mal, die das Script eh schon abgelaufen ist, zeitverzögert noch 4 mal "test" ausgegeben wird. Ich habe auch schon probiert, alles innerhalb von dropStinger in einen Timer zu tun, selber Effekt. Langsam weiss ich nicht mehr weiter und hoffe, einer von euch könnte mir helfen. Diesmal kann ich Rechtschreibfehler auch zu 99% ausschliessen *:D*
Spoiler anzeigen
local thePlayer = getLocalPlayer()
local theStingers = {}
local theColShapes = {}
addEventHandler( "onClientResourceStart", getRootElement(),
function()
bindKey( "x", "down", dropStinger) -- bind the "x" key to the drop stinger function
end
)
--addEventHandler( "onClientPlayerJoin", getRootElement(), bindStingerKey )
--addEventHandler("onPlayerSpawn", getRootElement(), bindStingerKey)
function dropStinger( key, keyPress )
if( isPlayerInVehicle( thePlayer ) ) then -- is the player in a car?
local theTeam = getPlayerTeam ( thePlayer )
if getTeamName(theTeam) == "Polizei" then
local theVehicle = getPlayerOccupiedVehicle( thePlayer ) -- get the player's car
local id = getElementModel ( theVehicle )
if id == 596 or id == 427 then
if( isElement( theStingers[ thePlayer ] ) ) then
destroyElement( theStingers[ thePlayer ] )
destroyElement( theColShapes[ thePlayer ] )
end
local theVehicle = getPlayerOccupiedVehicle( thePlayer ) -- get the player's car
local x, y, z = getElementPosition( theVehicle ) -- get vehicle position
local rx, ry, rz = getVehicleRotation( theVehicle ) -- get vehicle rotation
local a = getPlayerRotation( thePlayer ) -- get player facing angle
x = x + math.sin( math.rad(a) ) * 4
y = y - math.cos( math.rad(a) ) * 4
rz = rz + 90
local groundZ = getGroundPosition( x, y, z )
if( groundZ ~= z ) then z = groundZ + 0.2 end
theStingers[ thePlayer ] = createObject( 2899, x, y, z, 0, 0, rz ) -- create the stinger (2892)
theColShapes[ thePlayer ] = createColRectangle( (x - 2.0), (y - 2.0), 4.0, 4.0 ) -- set a colshape to check when a car hits the stinger
setElementData( theColShapes[ thePlayer ], "amistinger", "yesplz" ) -- set the colshape as a stinger colshape
outputChatBox( "Nagelband gelegt!") -- output a chatbox message
else
outputChatBox( "Nur LSPD Autos und der Enforcer können Nagelbänder legen!", 255, 0, 0)
end
else
outputChatBox( "Du musst Polizist sein, um Nagelbänder zu legen!", 255, 0, 0)
end
else
outputChatBox( "Du musst in einem Auto sein, um Nagelbänder zu legen!", 255, 0, 0)
end
end
function clientHitStinger( theElement, matchingDimension )
local theTeam = getPlayerTeam ( thePlayer )
if( getElementType( theElement ) == "vehicle" and getElementData( source, "amistinger" ) == "yesplz" ) then
if not (getTeamName(theTeam) == "Polizei") then
setVehicleWheelStates( theElement, 1, 1, 1, 1 )
end
end
-- if the element is a vehicle and the colshape is the stinger's colshape, pop the vehicles tires
end
addEventHandler( "onClientColShapeHit", getRootElement(), clientHitStinger )
function destroyStinger( player, seat )
if( isElement( theStingers[ player ] ) ) then
destroyElement( theStingers[ player ] )
destroyElement( theColShapes[ player ] )
end
end
addEventHandler( "onClientPlayerQuit", getRootElement(), destroyStinger )
-- addEventHandler( "onClientVehicleExit", getRootElement(), destroyStinger )
Alles anzeigen