Jump to content

Problem with my GUI


CTCCoco

Recommended Posts

In your console enter this:

refresh all

And wait that he finished to refresh and restart your server and retry

If it's always NOT Loaded try this and I want you try this:

Client-Side:

--------------------------------- SE CREA LA VENTANA ----------------------------------------
addEvent( "setXMLFile", true )
function setXMLFile(casasxml2)
local casasxml = casasxml2
outputChatBox("Client:"..casasxml)
  crearComprarCasasWindow(casasxml)
outputChatBox("GoToCrearComprarCasasWindow")
end
addEventHandler("setXMLFile", getRootElement(),setXMLFile)
 
addEvent( "getXMLFile2", true )
function getXMLFile2()
outputChatBox("GetXMLFile2Begin")
triggerServerEvent( "getXMLFile", getLocalPlayer())
outputChatBox("GetXMLFile2Finished")
end
addEventHandler("getXMLFile2", getRootElement(),getXMLFile2)
 
function crearComprarCasasWindow(casasxml)
outputChatBox("CrearComprarCasasWindowBegin")
casasnum = 3
for houses=0 , casasnum do
outputChatBox("casasnum:"..casasnum)
local hEntrancex = xmlNodeGetAttribute ( casasxml, "hEntradax." .. houses )
outputChatBox(""..hEntrancex)
local hEntrancey = xmlNodeGetAttribute ( casasxml, "hEntraday." .. houses )
outputChatBox(""..hEntrancey)
local hEntrancez = xmlNodeGetAttribute ( casasxml, "hEntradaz." .. houses )
outputChatBox(""..hEntrancez)
local posicionjugS1 = createColSphere( hEntrancex, hEntrancey, hEntrancez, 3.0)
outputChatBox("ColSphereCreated")
local posicionjug1 = isElementWithinColShape ( thePlayer, posicionjugS1 )
outputChatBox("posicionjug1")
if(posicionjug1) then
outputChatBox("PassedIf")
		windowTituloCasa = guiCreateWindow(460,289,357,171,"Sistema de casas por CTCCoco",false)
local hOwner = xmlNodeGetAttribute (casasxml, "hOwner." .. houses )
outputChatBox("Owner"..hOwner)
		labelDuenoCasa = guiCreateLabel(10,29,335,18,"Dueno:" .. hOwner,false,windowTituloCasa)
guiLabelSetColor(labelDuenoCasa,255,255,255)
guiLabelSetVerticalAlign(labelDuenoCasa,"top")
guiLabelSetHorizontalAlign(labelDuenoCasa,"left",false)
local hDesc = xmlNodeGetAttribute (casasxml, "hDesc." .. houses )
outputChatBox("Desc"..hDesc)
		labelDescripcionCasa = guiCreateLabel(8,47,340,45,"Descripcion: " .. hDesc,false,windowTituloCasa)
guiLabelSetColor(labelDescripcionCasa,255,255,255)
guiLabelSetVerticalAlign(labelDescripcionCasa,"top")
guiLabelSetHorizontalAlign(labelDescripcionCasa,"left",false)
local hValue = xmlNodeGetAttribute (casasxml, "hValue." .. houses )
outputChatBox("Value".. hValue)
		labelPreAlqCasa = guiCreateLabel(8,94,334,34,"Precio: " .. hValue .. "$              Alquiler:",false,windowTituloCasa)
guiLabelSetColor(labelPreAlqCasa,255,255,255)
guiLabelSetVerticalAlign(labelPreAlqCasa,"top")
guiLabelSetHorizontalAlign(labelPreAlqCasa,"left",false)
		botonComprarCasa = guiCreateButton(10,136,89,25,"Comprar",false,windowTituloCasa)
		botonCancelarCasa = guiCreateButton(259,136,89,25,"Cancelar",false,windowTituloCasa)
guiSetVisible(windowTituloCasa, true)
outputChatBox("La ventana se creado bien!") 
return 1
outputChatBox("IfFinished")
else
outputChatBox("ElsePosicionjug1")
guiSetVisible(windowTituloCasa, false)
return 1
end
outputChatBox("AfterIf (posicionjug1)")
end
outputChatBox("CrearComprarCasasWindowFinished")
end
 
outputChatBox("You can tape the command (/crear)")
 
function crearLaVentana()
getXMLFile2()
outputChatBox("GoToFunctionGetXMLFile2")
end
addCommandHandler("crear", crearLaVentana)

Server-Side:

addEvent("getXMLFile" , true )
function getXMLFile()
outputChatBox("GetXMLFileBegin")
local casasxml2 = xmlLoadFile(":RLC/casas.xml")
outputChatBox("Server:"..casasxml2)
triggerClientEvent( "setXMLFile", getRootElement(), casasxml2)
outputChatBox("GetXMLFileFinished")
end
addEventHandler( "getXMLFile", getRootElement(), getXMLFile )

restart your server and enter /crear

Aswer me ALL the outputChatBox, the outputs of console (if there are) and all the clientscript.log !!

The Famas's brother

Link to comment
  • Replies 52
  • Created
  • Last Reply

Top Posters In This Topic

Why don't you check your meta.xml? If you want to open .xml file with xml function in client-side script you should make the file available for clients.

<file src="casas.xml" />
OR
<config src="casas.xml" type="client" />

Link to comment
Why don't you check your meta.xml? If you want to open .xml file with xml function in client-side script you should make the file available for clients.

<file src="casas.xml" />
OR
<config src="casas.xml" type="client" />

WTF?! Why you don't reply before?

omg .

thanks xD ( Specially you FAMAS :oops:xD )

Link to comment
Why don't you check your meta.xml? If you want to open .xml file with xml function in client-side script you should make the file available for clients.

<file src="casas.xml" />
OR
<config src="casas.xml" type="client" />

WTF?! Why you don't reply before?

omg .

thanks xD ( Specially you FAMAS :oops:xD )

Erh sorry xD

This doesn't work yet:

local posicionjugS1 = createColSphere( hEntrancex, hEntrancey, hEntrancez, 3.0)
local posicionjug1 = isElementWithinColShape ( source, posicionjugS1 )

[2010-03-06 00:42:37] - WARNING: guibotones.lua: Bad argument @ 'isElementWithinColShape'

[2010-03-06 00:42:37] - WARNING: guibotones.lua: Bad argument @ 'createColSphere'

[2010-03-06 00:42:37] - WARNING: guibotones.lua: Bad argument @ 'isElementWithinColShape'

and at

labelDuenoCasa = guiCreateLabel(10,29,335,18,"Dueno:" .. hOwner,false,windowTituloCasa)

say a ERROR : attempt to concatenate local 'hOwner' (a boolean value).

What's the problem? Thanks for all really

Link to comment

I haven't replied earlier simply because I didn't have access to internet.

Anyway, debug, debug, debug. You MUST to learn how to debug your scripts. It makes your life so much easier and happier without wasting time and waiting for someone to reply and tell you to debug. If you don't know how to debug, you will always ask why this and that doesn't work in your script when you could have fixed it yourself easier if you debugged it.

WARNING: guibotones.lua: Bad argument @ 'isElementWithinColShape'

Bad argument is one of the most frequent warnings you will always get in your scripts if you don't pay attention to what arguments you are passing to functions.

Another one is:

ERROR : attempt to concatenate local 'hOwner' (a boolean value).

You will get this error very often if you won't pay attention to variables when concatenating strings. At least this error tells you what is wrong. You know that hOwner is a boolean variable and you know what to look for. Find out (debug) why hOwner is bool not string.

Link to comment

THANKS i solve all Warnings and ERRORS!

But I have a little problem yet.

function windowCrCpCs(source)
local casasxml = xmlLoadFile("casas.xml")
for houses=0 , casasnumclient do
local hEntrancex = xmlNodeGetAttribute ( casasxml, "hEntradax." .. houses )
local hEntrancey = xmlNodeGetAttribute ( casasxml, "hEntraday." .. houses )
local hEntrancez = xmlNodeGetAttribute ( casasxml, "hEntradaz." .. houses )
local posicionjugS1 = createColSphere( hEntrancex, hEntrancey, hEntrancez, 3.0)
local posicionjug1 = isElementWithinColShape (source,posicionjugS1)
if(posicionjug1) then
windowTituloCasa = guiCreateWindow(460,289,357,171,"Sistema de casas por CTCCoco",false)
local hOwner = xmlNodeGetAttribute (casasxml, "hOwner." .. houses )
local hOwner = tostring(hOwner)
labelDuenoCasa = guiCreateLabel(10,29,335,18,"Dueno: " .. hOwner ,false,windowTituloCasa)
guiLabelSetColor(labelDuenoCasa,255,255,255)
guiLabelSetVerticalAlign(labelDuenoCasa,"top")
guiLabelSetHorizontalAlign(labelDuenoCasa,"left",false)
local hDesc = xmlNodeGetAttribute (casasxml, "hDesc." .. houses )
labelDescripcionCasa = guiCreateLabel(8,47,340,45,"Descripcion: ".. hDesc,false,windowTituloCasa)
guiLabelSetColor(labelDescripcionCasa,255,255,255)
guiLabelSetVerticalAlign(labelDescripcionCasa,"top")
guiLabelSetHorizontalAlign(labelDescripcionCasa,"left",false)
local hValue = xmlNodeGetAttribute (casasxml, "hValue." .. houses )
labelPreAlqCasa = guiCreateLabel(8,94,334,34,"Precio: " .. hValue .. "$              Alquiler:",false,windowTituloCasa)
guiLabelSetColor(labelPreAlqCasa,255,255,255)
guiLabelSetVerticalAlign(labelPreAlqCasa,"top")
guiLabelSetHorizontalAlign(labelPreAlqCasa,"left",false)
botonComprarCasa = guiCreateButton(10,136,89,25,"Comprar",false,windowTituloCasa)
botonCancelarCasa = guiCreateButton(259,136,89,25,"Cancelar",false,windowTituloCasa)
guiSetVisible(windowTituloCasa, true)
outputChatBox("Si",source)
return 1
else
guiSetVisible(windowTituloCasa, false)
outputChatBox("No",source)
return 1
end
end
end

Its always detect that the player isn't in the house. I have the SAME code in the server-side command and works perfect but don't works here.

What's the problem?

Thanks.

Edited by Guest
Link to comment

And this script work in server-side ? Because I see that you are comment "if(posicionjug1) then " but you don't have comment this:

else

guiSetVisible(windowTituloCasa, false)

outputChatBox("No",source)

return 1

end

Why ?? And if when you enter the command, the chatbox say "NO" that means that it's the else of "for houses=0 , casasnumclient do" so casasnumclient it's not defined in client-side ! Do you remember that you have say before that your are defined casasnumclient but in server-side ? Thats why in server-side he works and not in client-side ! Do you understand what I mean ?

So you must transfered the variable casasnumclient to the client-side ! And I showed you how to make that ! But you didn't make !

So I repeat how to do:

In server-side, just after that you have defined casasnumclient:

triggerClientEvent("recibircasasnum", getRootElement(), casasnumclient)

In client-side:

At the top of your script:

local casasnumclient

before your "function windowCrCpCs(source)":

addEvent( "recibircasasnum", true )
function recibircasanum(casasnum)
  casanumclient = casasnum
end
addEventHandler("recibircasasnum", getRootElement(),recibircasanum)

And only after the casasnumclient is defined, you can called windowCrCpCs() and not before !

I'm wright or not?(50p, answer if I'm wrong )

The Famas's brother

Link to comment

I know that I must define it in client-side... that's why its called casasnumclient. I define it in client side, this is not the problem, I don't have any warnings and nothing now :S

And the --if(posicionjug1) it is without " -- " its a fault when I copy it to the post but doesn't works.

I think " source " detect anything but not the player and this is why doesn't works , source its valid to detect the player client-side? :S

I mean: local posicionjug1 = isElementWithinColShape (source,posicionjugS1)

Maybe don't detect the player... because I use " source " before and doesn't works and I will define it in the SetTimer and in the fuction of the Timer and maybe don't detect a player, detect something that is nothing :S

Thanks

Link to comment

Ok good ! So now the problem is the player not detected. Mmmm

Show me your setTimer and your command please and precise if the command and the setTimer are in Server-Side or Client-Side please because you have surely modified somethings

Thanks

The Famas's brother

Link to comment

I'm confused now. CTCCoco, is the code you posted at the top the code you want to use in server-side script? If so, how do you want to use GUI functions in it? GUI functions are available for client-side script only. If your casas.xml is client-side file (as I explained before), then you can't access it from server-side script with xmlLoadFile. When is windowCrCpCs called and by who/what (function, event or command)? Remember GUI functions are not available in server-side script.

Link to comment
I'm confused now. CTCCoco, is the code you posted at the top the code you want to use in server-side script? If so, how do you want to use GUI functions in it? GUI functions are available for client-side script only. If your casas.xml is client-side file (as I explained before), then you can't access it from server-side script with xmlLoadFile. When is windowCrCpCs called and by who/what (function, event or command)? Remember GUI functions are not available in server-side script.

I don't use this script in server-side, I know GUI fuctions are only for client-side.

And what you say? I CAN use casas.xml in server-side and client-side and works fine.

The only problem that doesn't work now its that the

local posicionjugS1 = createColSphere( hEntrancex, hEntrancey, hEntrancez, 3.0)
local posicionjug1 = isElementWithinColShape (source,posicionjugS1)
if(posicionjug1) then

doesn't works and works in server-side ( the same

local posicionjugS1 = createColSphere( hEntrancex, hEntrancey, hEntrancez, 3.0)
local posicionjug1 = isElementWithinColShape (source,posicionjugS1)
if(posicionjug1) then

code )

Here its ALL the code:

Client-Side:

---------------------------------SCRIPT DE LOS BOTONES ( GUI ) CLIENT-SIDE
 
---------------------------------SE CREA LA VENTANA
casasnumclient = 1
function crearunamierdadegui()
setTimer(windowCrCpCs, 3000, 0, source)
--outputchatbox(" has been owned.", client)
end
addEvent( "crearunamierdadegui1", true )
addEventHandler( "crearunamierdadegui1", getRootElement(), crearunamierdadegui )
function windowCrCpCs(source)
local casasxml = xmlLoadFile("casas.xml")
for houses=0 , casasnumclient do
local hEntrancex = xmlNodeGetAttribute ( casasxml, "hEntradax." .. houses )
local hEntrancey = xmlNodeGetAttribute ( casasxml, "hEntraday." .. houses )
local hEntrancez = xmlNodeGetAttribute ( casasxml, "hEntradaz." .. houses )
local posicionjugS1 = createColSphere( hEntrancex, hEntrancey, hEntrancez, 3.0)
local posicionjug1 = isElementWithinColShape (source,posicionjugS1)
--if(posicionjug1) then
windowTituloCasa = guiCreateWindow(460,289,357,171,"Sistema de casas por CTCCoco",false)
local hOwner = xmlNodeGetAttribute (casasxml, "hOwner." .. houses )
local hOwner = tostring(hOwner)
labelDuenoCasa = guiCreateLabel(10,29,335,18,"Dueno: " .. hOwner ,false,windowTituloCasa)
guiLabelSetColor(labelDuenoCasa,255,255,255)
guiLabelSetVerticalAlign(labelDuenoCasa,"top")
guiLabelSetHorizontalAlign(labelDuenoCasa,"left",false)
local hDesc = xmlNodeGetAttribute (casasxml, "hDesc." .. houses )
labelDescripcionCasa = guiCreateLabel(8,47,340,45,"Descripcion: ".. hDesc,false,windowTituloCasa)
guiLabelSetColor(labelDescripcionCasa,255,255,255)
guiLabelSetVerticalAlign(labelDescripcionCasa,"top")
guiLabelSetHorizontalAlign(labelDescripcionCasa,"left",false)
local hValue = xmlNodeGetAttribute (casasxml, "hValue." .. houses )
labelPreAlqCasa = guiCreateLabel(8,94,334,34,"Precio: " .. hValue .. "$              Alquiler:",false,windowTituloCasa)
guiLabelSetColor(labelPreAlqCasa,255,255,255)
guiLabelSetVerticalAlign(labelPreAlqCasa,"top")
guiLabelSetHorizontalAlign(labelPreAlqCasa,"left",false)
botonComprarCasa = guiCreateButton(10,136,89,25,"Comprar",false,windowTituloCasa)
botonCancelarCasa = guiCreateButton(259,136,89,25,"Cancelar",false,windowTituloCasa)
guiSetVisible(windowTituloCasa, true)
showCursor ( true, true )
outputChatBox("Si",source)
return 1
else
guiSetVisible(windowTituloCasa, false)
outputChatBox("No",source)
return 1
end
end
end

server-side:

triggerClientEvent ( "crearunamierdadegui1", getRootElement())

in onPlayerJoin.

Thanks for FAMAS and 50p.

Please help .

Link to comment

It doesn't work because:

- You triggerClientEvent for everyone on the server and the source will be root element

- isElementWithinColshape will not work since you check if "root element" is within colshape which is invalid.

DO NOT use triggerClientEvent for player who joined the server in onPlayerJoin event because players have to download resource before you can triggerClientEvent. If player is downloading resources and you try to use triggerClientEvent you will get an error message saying you try to trigger client event which is not added client-side because client script hasn't been started yet and so event is not added.

If you want to create GUI for player who joins your server, use onClientResourceStart instead of onPlayerJoin and triggerClientEvent.

There is probably easier way of achieving what you want but we don't know what you're trying to do. What do you want the script to do?

Link to comment
It doesn't work because:

- isElementWithinColshape will not work since you check if "root element" is within colshape which is invalid.

What do you mean? :S I try with client, source, id , getLocalPlayer(), getRootPlayer() and nothing works :S

What I must change?

Sorry for all.

PD: I'm trying to do when a player go to a house entrance show a GUI to buy the house and all information and all things.

Link to comment

This is the same frequent problem with people not thinking logically.

If you want something to happen when you enter colshape then why don't you use onColShapeHit? Do you use it? I can't find code about onColShapeHit in your code. You check if source (root element) is within colshape when player joins the server, this is so wrong. You should consider rewriting your script and if your houses are in xml file then I wouldn't recommend to use them on client-side, just send the information about the house to a client when it's needed (when he enters col shape).

If you don't know what I meant by: "- isElementWithinColshape will not work since you check if "root element" is within colshape which is invalid." then you need to trace your code. I asked you to debug your scripts. Go and check what source is and you'll understand what I meant.

BTW, what is getRootPlayer or id? :?

I don't understand why people go straight to hard scripts without any knowledge how to do it.

Link to comment
This is the same frequent problem with people not thinking logically.

If you want something to happen when you enter colshape then why don't you use onColShapeHit? Do you use it? I can't find code about onColShapeHit in your code. You check if source (root element) is within colshape when player joins the server, this is so wrong. You should consider rewriting your script and if your houses are in xml file then I wouldn't recommend to use them on client-side, just send the information about the house to a client when it's needed (when he enters col shape).

If you don't know what I meant by: "- isElementWithinColshape will not work since you check if "root element" is within colshape which is invalid." then you need to trace your code. I asked you to debug your scripts. Go and check what source is and you'll understand what I meant.

BTW, what is getRootPlayer or id? :?

I don't understand why people go straight to hard scripts without any knowledge how to do it.

I am learning LUA on MTA that's why i am doing a gamemode and see how to do things and this is why i don't know how to do this shit.

Then you can't use isElementWithinColshape instead onColShapeHit? I think is more usefull use isElementWithinColshape if it can work.

Link to comment
....

Then you can't use isElementWithinColshape instead onColShapeHit? I think is more usefull use isElementWithinColshape if it can work.

How do you want to use it then? This is used to check if element is within collision shape. What do you need it for? You will never make GUI pop up without using events.

EDIT:

I am learning LUA on MTA that's why i am doing a gamemode and see how to do things and this is why i don't know how to do this :~.

....

That's fine, but you should learn from making simple things and get to harder and harder ones.. Most of beginners go straight to hard things and it makes them tear their hair out.

Link to comment
....

Then you can't use isElementWithinColshape instead onColShapeHit? I think is more usefull use isElementWithinColshape if it can work.

How do you want to use it then? This is used to check if element is within collision shape. What do you need it for? You will never make GUI pop up without using events.

EDIT:

I am learning LUA on MTA that's why i am doing a gamemode and see how to do things and this is why i don't know how to do this :~.

....

That's fine, but you should learn from making simple things and get to harder and harder ones.. Most of beginners go straight to hard things and it makes them tear their hair out.

I only need if a player is near of a X, Y , Z coordinate and if it is near the GUI appears. :S This is too easy to do in SAMP with a simple fuction :S

Link to comment

50p rightly! Why you don't use onColShapeHit ? And create the gui only when the player enter in the colshape ?

Because the client try to create the gui every 3 second and he continue to create this gui if a player is in colshape!

So you should open the xml and take all the datas in server-side and create the colshape(s) in the same time and use the event onColShapeHit to create your gui and use some triggerServerEvent and triggerClientEvent to take the datas of the home

This is what 50p thinks and try to say to you

Can you show an exemple of an xml's houses ? that will be easier for us to help you

I make for you a little code while using onColShapeHit

EDIT: I almost finished the little code but it misses an example of your sasas.xml

The Famas's brother

Link to comment

Yes !! I do it ! xD finally!

this is the code ( ALL CLIENT-SIDE ):

---------------------------------SCRIPT DE LOS BOTONES ( GUI ) CLIENT-SIDE
casasnumclient = 1
---------------------------------DETECTA SI EL JUGADOR ESTÁ EN EL COLSHAPE
function onColShapeHitCrCpCs( theElement, matchingDimension )
if ( theElement == getLocalPlayer() ) then
for houses=0 , casasnumclient do
if(source == posicionCasas[houses]) then
guiSetVisible(windowTituloCasa[houses], true)
end
end
end
end
addEventHandler("onClientColShapeHit",getRootElement(),onColShapeHitCrCpCs)
-------------------------------------DETECTA SI EL JUGADOR SE A IDO DEL COLSHAPE
function onColShapeLeaveCrCpCs( theElement, matchingDimension )
if ( theElement == getLocalPlayer() ) then  -- Checks whether the leaving element is the local player
--if( source == posicionjugS1 ) then
for houses=0 , casasnumclient do
if(source == posicionCasas[houses]) then
guiSetVisible(windowTituloCasa[houses], false)
end
end
--end
end
end
addEventHandler("onClientColShapeLeave",getRootElement(),onColShapeLeaveCrCpCs)
---------------------------------SE CREA LA VENTANA
function windowCrCpCs()
local casasxml = xmlLoadFile("casas.xml")
for houses=0 , casasnumclient do
local hEntrancex = { }
local hEntrancey = { }
local hEntrancez = { }
posicionCasas = { }
hEntrancex[houses] = xmlNodeGetAttribute ( casasxml, "hEntradax." .. houses )
hEntrancey[houses] = xmlNodeGetAttribute ( casasxml, "hEntraday." .. houses )
hEntrancez[houses] = xmlNodeGetAttribute ( casasxml, "hEntradaz." .. houses )
posicionCasas[houses] = createColSphere( hEntrancex[houses], hEntrancey[houses], hEntrancez[houses], 3.0)
local casasxml = xmlLoadFile("casas.xml")
windowTituloCasa = { }
labelDuenoCasa = { }
labelDescripcionCasa = { }
labelPreAlqCasa = { }
botonComprarCasa = { }
botonCancelarCasa = { }
windowTituloCasa[houses] = guiCreateWindow(460,289,357,171,"Sistema de casas por CTCCoco",false)
local hOwner = xmlNodeGetAttribute (casasxml, "hOwner." .. houses )
local hOwner = tostring(hOwner)
labelDuenoCasa[houses] = guiCreateLabel(10,29,335,18,"Dueno: " .. hOwner ,false,windowTituloCasa[houses])
guiLabelSetColor(labelDuenoCasa[houses],255,255,255)
guiLabelSetVerticalAlign(labelDuenoCasa[houses],"top")
guiLabelSetHorizontalAlign(labelDuenoCasa[houses],"left",false)
local hDesc = xmlNodeGetAttribute (casasxml, "hDesc." .. houses )
labelDescripcionCasa[houses] = guiCreateLabel(8,47,340,45,"Descripcion: ".. hDesc,false,windowTituloCasa[houses])
guiLabelSetColor(labelDescripcionCasa[houses],255,255,255)
guiLabelSetVerticalAlign(labelDescripcionCasa[houses],"top")
guiLabelSetHorizontalAlign(labelDescripcionCasa[houses],"left",false)
local hValue = xmlNodeGetAttribute (casasxml, "hValue." .. houses )
labelPreAlqCasa[houses] = guiCreateLabel(8,94,334,34,"Precio: " .. hValue .. "$              Alquiler:",false,windowTituloCasa[houses])
guiLabelSetColor(labelPreAlqCasa,255,255,255)
guiLabelSetVerticalAlign(labelPreAlqCasa[houses],"top")
guiLabelSetHorizontalAlign(labelPreAlqCasa[houses],"left",false)
botonComprarCasa[houses] = guiCreateButton(10,136,89,25,"Comprar",false,windowTituloCasa[houses])
botonCancelarCasa[houses] = guiCreateButton(259,136,89,25,"Cancelar",false,windowTituloCasa[houses])
guiSetVisible(windowTituloCasa[houses], false)
end
end
--------------------CUANDO EL JUGADOR SE CONECTA REPITE ESTO CADA SEG.
function PlayerSpawn ( )
setTimer(windowCrCpCs, 3000, 1)
end
-- add this function as a handler for any player that spawns
addEventHandler ( "onClientPlayerSpawn", getLocalPlayer(), PlayerSpawn )

I think all is correct isn't it?

Thanks.

Link to comment

Ok finally you left all in client-side.

I read all and it's correct but you should take the casasnumclient with the number of houses in your xml file if it's possible and not define it yourself ! Do you understand what I mean ? So you have just to add a new house with the informations required and the casasnum will be defined automatically! Ok ?

yesterday I made a thing of the same style but a part in the server-side and a part in the client-side

I showed you in PM if you it desired ^^

PS: I answered your message :wink:

The Fama's brother

Link to comment

We aren't more very far now !

Give me an exemple of line of the casas.xml !

I don't know if you are define an ID for each house but you should make that .

If you don't want put an exemple of your casas.xml in your post put it in PM

The Famas's brother

Link to comment
We aren't more very far now !

Give me an exemple of line of the casas.xml !

I don't know if you are define an ID for each house but you should make that .

If you don't want put an exemple of your casas.xml in your post put it in PM

The Famas's brother

Yes I have 2 houses. The first house have ID 0 and the second house have ID 1.

The loop do houses == 0 and == 1.

That's why when I call a house variable I call doing this : "hVar." .. houses. ( hVar.0 and hVar.1 , the .(number) are the house ID ).

You understand me? It will works but it didn't :S ( only works the last house ( ID 1 house ) )

And yes the ID 0 are called too and it will works but it didn't :S

Thanks men.

Link to comment
Thanks but now the problem its that ONLY create the LAST HOUSE window, then only the last house of the loop work...

What can i do?

Thanks.

You shouldn't be making loads of windows. It stays in player's RAM all the time until you destroyElement (destroy GUI elements) or stop resource. If you'll have 20 houses then you'll create 20 windows which is not recommended. It may even freeze your players' MTA to create the GUI elements. You should make just 1 window and change its label's text for different house to show different information.

Use break to stop loops (for or while loops).

function onColShapeLeaveCrCpCs( theElement, matchingDimension )
if ( theElement == getLocalPlayer() ) then  -- Checks whether the leaving element is the local player
for houses=0 , casasnumclient do
if(source == posicionCasas[houses]) then
guiSetVisible(windowTituloCasa[houses], false)
break; -- break the loop to save processing other houses when it's not needed
end
end
end
end

Link to comment

Hi I remake a big part of your system !

This code taken me a long time so try this please and keep side your system !

------------------------------------------------------------------------------------------------------
---------------------------------SCRIPT DE LOS BOTONES ( GUI ) CLIENT-SIDE ---------------------------
casasnumclient = 1
------------------- DETECTA SI EL JUGADOR ESTÁ EN EL COLSHAPE ----------------------------------------
function enterInColShapeOfHouse(thePlayer, matchingDimension )
if getElementType ( thePlayer ) == "player" then --Detect if the element in ColShape is a player
for k,i in ipairs (posicionCasas)do --Get all the ColSpheres
if k == source then --source it's the colshape so if a posicionCasas(of your table) coresponds to the source then:
outputChatBox("House: #"..k,thePlayer)--Check if the good house
			windowCrCpCs(k)--create the window of the house number "k"
end
end
end
end
addEventHandler ( "onColShapeHit", getRootElement(), enterInColShapeOfHouse)
-------------------- create ColSpheres -----------------------------------------------
function createColSphereOfHouse()
local casasxml = xmlLoadFile("casas.xml")
for houses=0 , casasnumclient do
local hEntrancex = { }
local hEntrancey = { }
local hEntrancez = { }
	posicionCasas = { }
	hEntrancex[houses] = xmlNodeGetAttribute ( casasxml, "hEntradax." .. houses )
	hEntrancey[houses] = xmlNodeGetAttribute ( casasxml, "hEntraday." .. houses )
	hEntrancez[houses] = xmlNodeGetAttribute ( casasxml, "hEntradaz." .. houses )
	posicionCasas[houses] = createColSphere( hEntrancex[houses], hEntrancey[houses], hEntrancez[houses], 3.0)
--The ColShpheres of all houses are created when the player spawn
end
end
addEventHandler ( "onClientPlayerSpawn", getLocalPlayer(), createColSphereOfHouse)
--------------------------- CANCELAR ----------------------------------
function CancelarCasa()
for k,i in ipairs (windowTituloCasa)do
if(guiGetVisible (windowTituloCasa[k]) == true) then --if the WindowTituloCasa it's the WindowTituloCasa in the screen then:
guiSetVisible(windowTituloCasa[k],false)--hide the windowTituloCasa in the screen
showCursor(false)--hide the cursor
end
end
end
addEventHandler("onClientColShapeLeave",getRootElement(),onColShapeLeaveCrCpCs)
---------------------- COMPRAR LA CASA ---------------------------------------------
function ComprarCasa()
for k,i in ipairs (windowTituloCasa)do
if(guiGetVisible (windowTituloCasa[k]) == true) then --if the WindowTituloCasa it's the WindowTituloCasa in the screen then:
outputChatBox("ComprarCasa numero "..k)--to check if it's the good house
--The actions for buy this house
end
end
end
--------------------------------- SE CREA LA VENTANA -------------------------------
function windowCrCpCs(house)
local casasxml = xmlLoadFile("casas.xml")
for houses=0 , casasnumclient do
if houses == house then --if the house is the house's colshape where the player is in then create only one windowTituloCasa:
local casasxml = xmlLoadFile("casas.xml")
		windowTituloCasa = { }
		labelDuenoCasa = { }
		labelDescripcionCasa = { }
		labelPreAlqCasa = { }
		botonComprarCasa = { }
		botonCancelarCasa = { }
		windowTituloCasa[houses] = guiCreateWindow(460,289,357,171,"Sistema de casas por CTCCoco",false)
local hOwner = xmlNodeGetAttribute (casasxml, "hOwner." .. houses )
local hOwner = tostring(hOwner)
		labelDuenoCasa[houses] = guiCreateLabel(10,29,335,18,"Dueno: " .. hOwner ,false,windowTituloCasa[houses])
guiLabelSetColor(labelDuenoCasa[houses],255,255,255)
guiLabelSetVerticalAlign(labelDuenoCasa[houses],"top")
guiLabelSetHorizontalAlign(labelDuenoCasa[houses],"left",false)
local hDesc = xmlNodeGetAttribute (casasxml, "hDesc." .. houses )
		labelDescripcionCasa[houses] = guiCreateLabel(8,47,340,45,"Descripcion: ".. hDesc,false,windowTituloCasa[houses])
guiLabelSetColor(labelDescripcionCasa[houses],255,255,255)
guiLabelSetVerticalAlign(labelDescripcionCasa[houses],"top")
guiLabelSetHorizontalAlign(labelDescripcionCasa[houses],"left",false)
local hValue = xmlNodeGetAttribute (casasxml, "hValue." .. houses )
		labelPreAlqCasa[houses] = guiCreateLabel(8,94,334,34,"Precio: " .. hValue .. "$              Alquiler:",false,windowTituloCasa[houses])
guiLabelSetColor(labelPreAlqCasa,255,255,255)
guiLabelSetVerticalAlign(labelPreAlqCasa[houses],"top")
guiLabelSetHorizontalAlign(labelPreAlqCasa[houses],"left",false)
		botonComprarCasa[houses] = guiCreateButton(10,136,89,25,"Comprar",false,windowTituloCasa[houses])
		botonCancelarCasa[houses] = guiCreateButton(259,136,89,25,"Cancelar",false,windowTituloCasa[houses])
addEventHandler("onClientGUIClick",botonComprarCasa[houses],ComprarCasa,false)
addEventHandler("onClientGUIClick",botonCancelarCasa[houses],CancelarCasa,false)
guiSetVisible(windowTituloCasa[houses], false)
showCursor(true)
break--Thanks 50p for the break I forget it ^^
end
end
end

And try this please ! If you say that it's work but the last house, this script should work

You don't have need the event onColShapeLeave because like the cursor is on, he don't can move !And when he click on buton Cancelar, the window and the cursor are hidden.

If you have an other problem with the system or any questions of the system, I'm here! and 50p too I suppose xD

You will tell me the result !

The Famas's brother

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