Jump to content

Colshape


Recommended Posts

hi

i have colshape

i want it to give player data "R",true

this is my attempt

client

addEventHandler("onResourceStart", resourceRoot, 
function ()
	MyZone = createColCuboid(-2034.9541015625,321.2734375, 200.75479125977, 40, 90.2, 17.9)
end
)
function dimensionChecker (theElement, matchingDimension)
    if matchingDimension then
    	setElementData(localPlayer, "R", true)
    end
end
addEventHandler ("onClientColShapeHit", myZone, dimensionChecker)

 

Edited by Stevor
Link to post
  • Moderators
11 minutes ago, Stevor said:

this is my attempt

addEventHandler("onClientResourceStart", resourceRoot, 
function ()
	MyZone = createColCuboid(-2034.9541015625,321.2734375, 200.75479125977, 40, 90.2, 17.9)
	addEventHandler ("onClientColShapeHit", myZone, dimensionChecker)
end
)
function dimensionChecker (theElement, matchingDimension)
    if matchingDimension and theElement == localPlayer  then
    	setElementData(localPlayer, "R", true)
    end
end
  • onResourceStart > onClientResourceStart (onResourceStart is serverside only)
  • Moved addEventHandler directly after creating the element. The event onCientResourceStart is executed very late and therefore the element didn't exist when you tried to attach the addEventHandler.
  • Checking if the one hitting the colshape is the localPlayer.

 

Use code block for your code:

afbeelding.png.ca906fc3359aec20773398fe2df3a764.png

 

Link to post
17 minutes ago, IIYAMA said:

addEventHandler("onClientResourceStart", resourceRoot, 
function ()
	MyZone = createColCuboid(-2034.9541015625,321.2734375, 200.75479125977, 40, 90.2, 17.9)
	addEventHandler ("onClientColShapeHit", myZone, dimensionChecker)
end
)
function dimensionChecker (theElement, matchingDimension)
    if matchingDimension and theElement == localPlayer  then
    	setElementData(localPlayer, "R", true)
    end
end
  • onResourceStart > onClientResourceStart (onResourceStart is serverside only)
  • Moved addEventHandler directly after creating the element. The event onCientResourceStart is executed very late and therefore the element didn't exist when you tried to attach the addEventHandler.
  • Checking if the one hitting the colshape is the localPlayer.

 

Use code block for your code:

afbeelding.png.ca906fc3359aec20773398fe2df3a764.png

 

done , but colshape Not created

i use command showcol

Link to post
  • Moderators
35 minutes ago, Stevor said:

done , but colshape Not created

i use command showcol

Are you sure that the code is clientside?

-- put on top of script
iprint(triggerClientEvent and "serverside" or "clientside")
-- and check debugconsole

 

 

Link to post
2 minutes ago, IIYAMA said:

Are you sure that the code is clientside?


-- put on top of script
iprint(triggerClientEvent and "serverside" or "clientside")
-- and check debugconsole

 

 

Sorry, I didn't notice, because I have two copies of this

it's server 
 

Link to post
17 hours ago, IIYAMA said:

Are you sure that the code is clientside?


-- put on top of script
iprint(triggerClientEvent and "serverside" or "clientside")
-- and check debugconsole

 

 

what to do its server

Link to post
  • Moderators
2 hours ago, Stevor said:

what to do its server

 

1. changing the eventNames

onClientResourceStart > onResourceStart

onClientColShapeHit > onColShapeHit

 

2.

Getting rid of localPlayer, since that predefined variable does not exist there.

 

addEventHandler("onResourceStart", resourceRoot, 
function ()
	MyZone = createColCuboid(-2034.9541015625,321.2734375, 200.75479125977, 40, 90.2, 17.9)
	addEventHandler ("onColShapeHit", myZone, dimensionChecker)
end
)
function dimensionChecker (theElement, matchingDimension)
    if matchingDimension and getElementType(theElement) == "player" then
    	setElementData(theElement, "R", true)
    end
end

 

Link to post
Posted (edited)
3 hours ago, IIYAMA said:

 

1. changing the eventNames

onClientResourceStart > onResourceStart

onClientColShapeHit > onColShapeHit

 

2.

Getting rid of localPlayer, since that predefined variable does not exist there.

 



addEventHandler("onResourceStart", resourceRoot, 
function ()
	MyZone = createColCuboid(-2034.9541015625,321.2734375, 200.75479125977, 40, 90.2, 17.9)
	addEventHandler ("onColShapeHit", myZone, dimensionChecker)
end
)
function dimensionChecker (theElement, matchingDimension)
    if matchingDimension and getElementType(theElement) == "player" then
    	setElementData(theElement, "R", true)
    end
end

 

thank you its work

but how to getElementData For "R"

-- i do that

function D (theElement, matchingDimension)
	if (getElementData (theElement, "R") == true) then
			outputChatBox("true",root,0,255,0,true)
		else
			outputChatBox("false",root,0,255,0,true)
		end
	end
setTimer(D,15000,0)

and Get Bad Argument

Edited by Stevor
Link to post
  • Moderators
29 minutes ago, Stevor said:

and Get Bad Argument

You can't magically make data/elements out of nothing. You have to be very specific about what you are trying to do and where your data should come from.

  • Like 1
Link to post
18 hours ago, IIYAMA said:

You can't magically make data/elements out of nothing. You have to be very specific about what you are trying to do and where your data should come from.

 but From a player's , he has data true "R" now ?

Link to post
40 minutes ago, IIYAMA said:

In that case you could get all players and loop through them. See first example of this page:

https://wiki.multitheftauto.com/wiki/GetElementsByType

Oh , do you mean I have to check if Element = Ped Or Vehicle or .... ?

function D()
local players = getElementsByType ( "player" ) -- get a table of all the players in the server
for theKey,thePlayer in ipairs(players) do
	if (getElementData (thePlayer, "R") == true) then
			outputChatBox("true",root,0,255,0,true)
		else
			outputChatBox("false",root,0,255,0,true)
		end
	end
  		end
setTimer(D,15000,0)

 

Link to post
  • Moderators
51 minutes ago, Stevor said:

or .... ?

This function collects all elements of a given type and puts them in a table. You do not have to check afterwards which type they are.

 

 

Link to post
24 minutes ago, IIYAMA said:

This function collects all elements of a given type and puts them in a table. You do not have to check afterwards which type they are.

 

 

I intend to 

when player get Data "R" true

other Script give him something

my problem How do I check does he have have Data "R" true or false

Link to post
  • Moderators
11 minutes ago, Stevor said:

my problem How do I check does he have have Data "R" true or false

As you are already doing:

1 hour ago, Stevor said:

if (getElementData (thePlayer, "R") == true) then

 

  • Like 1
Link to post
Posted (edited)
19 minutes ago, xLive said:

Yes you can

thx it's work

19 minutes ago, xLive said:

Yes you can

how to send value from server to client ?

i get value from table

 what need ?

Edited by Stevor
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...