Jump to content

Arms dealer system


FWCentral

Recommended Posts

Hey im creating an arms dealer script and im not sure how i can get the marker directly in front of the player that wants to sell at the moment its just inside the player using getElementPosition :P Also, I can take the players money but how do i give the other player that is selling money?

Link to comment

Meh i cant get it to work, Sorry to double post but no one will reply if i edit.

server:

  
function sell(source, commaneName) 
local x,y,z = getElementPosition(source) 
thearmsmark = createMarker( x, y, z, "cylinder", 1.5, 255, 255, 0, 170 ) 
--setElementData(thearmsmark, "owner", getPlayerName(source)) 
setElementParent(thearmsmark, source) 
end 
addCommandHandler("sell", sell) 
  
addEvent("buygunuzi",true) 
function buyuzi(source) 
 if isElementWithinMarker(source, thearmsmark) then 
 local seller = getElementParent(thearmsmark) 
takePlayerMoney(source, 170) 
giveWeapon(source,28,50,false) 
end 
end 
addEventHandler("buygunuzi",getRootElement(),buyuzi) 
  

Client:

  
local weapon = guiGridListGetItemText ( weapongridlist, guiGridListGetSelectedItem ( weapongridlist ),1) 
if weapon == "Uzi" then 
local money = getPlayerMoney(getLocalPlayer()) 
    if (money > 170) then     
triggerServerEvent("buygunuzi", getLocalPlayer()) 
else 
end 
end 
  

The client side works fine but i get an error at: if isElementWithinMarker(source, thearmsmark) then

Link to comment
local weapon = guiGridListGetItemText ( weapongridlist, guiGridListGetSelectedItem ( weapongridlist ),1) 
if weapon == "Uzi" then 
local money = getPlayerMoney() 
    if (money > 170) then     
triggerServerEvent("buygunuzi", getLocalPlayer()) 
else 
end 
end 

  
function sell(source, commaneName) 
local x,y,z = getElementPosition(source) 
thearmsmark = createMarker( x, y, z, "cylinder", 1.5, 255, 255, 0, 170 ) 
--setElementData(thearmsmark, "owner", getPlayerName(source)) 
setElementParent(thearmsmark, source) 
end 
addCommandHandler("sell", sell) 
  
addEvent("buygunuzi",true) 
function buyuzi() 
 if isElementWithinMarker(source, thearmsmark) then 
 local seller = getElementParent(thearmsmark) 
takePlayerMoney(source, 170) 
giveWeapon(source,28,50,false) 
end 
end 
addEventHandler("buygunuzi",getRootElement(),buyuzi) 
  

Link to comment
  • 6 months later...

Back to this again :P I got a problem, When i create the marker i made it like this trying to put it in a table:

  
thearmsmark = {} 
  
  
  
  
thearmsmark[getPlayerName(source)] = createMarker( x, y, z, "cylinder", 1.2, 255, 0, 0, 170 ) 
  

it creates the first marker and lets the player sell fine, but then when you try to do it a second time it wont let you, It will create the marker but you cant buy from the player and im not sure whats up with it because there is no errors

Link to comment

Selling:

  
  
thearmsmark = {} 
  
function sell(source, commaneName) 
setElementFrozen(source, true) 
local x,y,z = getElementPosition(source) 
thearmsmark[source] = createMarker( x, y, z, "cylinder", 1.2, 255, 0, 0, 170 ) 
setElementData(source,"SellingArms", true) 
setElementData(thearmsmark[source], "ownedby", getPlayerName(source)) 
end 
  
  

Buying:

  
  
function buy(source) 
local x,y,z = getElementPosition(source) 
local colshape1 = createColSphere(x-3,y+3,z-4,10) 
local players = getElementsWithinColShape ( colshape1, "player" ) 
for i,seller in ipairs(players) do 
if getElementData(seller, "SellingArms") == true then 
if isElementWithinMarker(source, thearmsmark[seller]) then 
setElementData(source,"BuyingArmsFrom", getPlayerName(seller)) 
    triggerClientEvent("showarmspanelARMS", source) 
    destroyElement(colshape1) 
    else 
 end 
 end 
 end 
 end 
  
  

changed it to the element too thanks

Link to comment
function buy() 
local x,y,z = getElementPosition(source) 
local colshape1 = createColSphere(x-3,y+3,z-4,10) 
local players = getElementsWithinColShape ( colshape1, "player" ) 
for i,seller in ipairs(players) do 
if getElementData(seller, "SellingArms") == true then 
if isElementWithinMarker(source, thearmsmark[seller]) then 
setElementData(source,"BuyingArmsFrom", getPlayerName(seller)) 
    triggerClientEvent("showarmspanelARMS", source) 
    destroyElement(colshape1) 
 end 
 end 
 end 
 end 

Link to comment

try this:

thearmsmark = {} 
function sell(source, commaneName) 
    setElementFrozen(source, true) 
    local x,y,z = getElementPosition(source) 
    thearmsmark[source] = createMarker( x, y, z, "cylinder", 1.2, 255, 0, 0, 170 ) 
    setElementData(source,"SellingArms", true) 
    setElementData(thearmsmark[source], "ownedby", getPlayerName(source)) 
end 
  
function buy(source) 
    local x,y,z = getElementPosition(source) 
    local colshape1 = createColSphere(x-3,y+3,z-4,10) 
    for i,seller in ipairs(getElementsWithinColShape ( colshape1, "player" )) do 
        if getElementData(seller, "SellingArms") == true then 
            if isElementWithinMarker(source, thearmsmark[seller]) then 
                setElementData(source,"BuyingArmsFrom", getPlayerName(seller)) 
                triggerClientEvent(source,"showarmspanelARMS",root) 
                destroyElement(colshape1) 
            else 
            end 
        end 
    end 
end 

BTW, Why do you need the colshape?

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