Jump to content

Spwan text problem


xbenny2506x

Recommended Posts

Hi!

I have a respawn after death script and wanted add a text so that the player see after the death how long is the respawn time.

But i get a error :(

if (zufalldeath == 1) then
local x = -2225.376953125
local y = 2333.6584472656
local z = 7.546875
 
setTimer ( spawnPlayer, 10000, 1, source, x, y, z)
 
setTimer(setPlayerSkin, 10000, 1, source, zufallskin)
 
if ( spawntext ) then
destroyElement ( spawntext )
end
local spawntext = guiCreateLabel(0.20,0.03,0.94,0.2,"Respawn in 10 Seconds",true,wnd)
guiSetFont ( dummyGUIElement, "sa-header" )
setTimer ( destroyElement, 10000, 1, spawntext, source )
end
addEventHandler("onPlayerWasted", getRootElement(), deathHandler)

ERROR: ...r/mods/deathmatch/resourcecache/maps/playerdeath.lua:12: attempt to call global 'guiCreateLabel' (a nil value)

Can someone help me? THX :D

Link to comment

You should pay attention to functions, some are server-only others client-only. You will have to move the text stuff clientside and call it with triggerClientEvent when you spawn him. Check wiki for more info about how custom events work (addEvent). ;)

Link to comment

I have now a other problem.

When the player die all people see the text "Respawn in 10 Seconds" :(

Here is my script:

server:

function deathHandler( playerSource )
local zufalldeath = math.random(1, 4)
local zufallskin = math.random(7, 288)
 
triggerClientEvent ( "onGreeting", getRootElement())
 
if (zufalldeath == 1) then
local x = -2225.376953125
local y = 2333.6584472656
local z = 7.546875
setTimer ( spawnPlayer, 10000, 1, source, x, y, z)
setTimer(setElementModel, 10000, 1, source, zufallskin)
setTimer(giveWeapon, 10000, 1, source, 33, 50 ) 
setTimer(giveWeapon, 10000, 1, source, 31, 50 ) 
setTimer(giveWeapon, 10000, 1, source, 10 )
end
 
....
 
end
addEventHandler("onPlayerWasted", getRootElement(), deathHandler)

client:

function specialEventHandler ( spawntext )
 
if ( spawntext ) then
destroyElement ( spawntext )
end
 
local spawntext = guiCreateLabel(0.35,0.40,0.94,0.2,"Respawn in 10 Seconds",true)
guiSetFont ( spawntext, "sa-header" )
guiLabelSetColor ( spawntext, 255, 234, 0 )
setTimer ( destroyElement, 10000, 1, spawntext, source )
 
end
 
addEvent( "onGreeting", true )
addEventHandler( "onGreeting", getRootElement(), specialEventHandler )

I hope someone can say me how i can make it that only the player where die see the respawn text!?

THX :)

Link to comment

While 50p has their eyes examined,

local spawntext = guiCreateLabel(0.35,0.40,0.94,0.2,"Respawn in 10 Seconds",true)

I'll point out your mistake, and it's an easy one :)

You can trigger client events to only trigger on specific clients - which is what you want in this case. In your Server file you have:

function deathHandler( playerSource )
local zufalldeath = math.random(1, 4)
local zufallskin = math.random(7, 288)
 
triggerClientEvent ( "onGreeting", getRootElement())
...

and you can modify that triggerClientEvent call to only trigger for the one player you want - in your case, "playerSource". here's the triggerClientEvent syntax so you can see what we're dealing with:

bool triggerClientEvent ( [element triggerFor=getRootElement()], string name, element theElement, [arguments...] )

https://wiki.multitheftauto.com/index.ph ... lientEvent

so you modify your triggerClientEvent to:

triggerClientEvent ( playerSource,"onGreeting", getRootElement())    --who to trigger for, what event to trigger, who triggered it

Link to comment

When I read this topic it was 6:00am and I was asleep but whatever, I can see it easily :)

Why don't you simply use client-side event onClientPlayerWasted or onClientPedWasted? Make sure the dead person is you (getLocalPlayer()).

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