Jump to content

Arms dealer system


FWCentral

Recommended Posts

Posted

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?

Posted

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

Posted
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) 
  

Posted
local money = getPlayerMoney(getLocalPlayer()) 

local money = getPlayerMoney() 

==================================================

function buyuzi(source) 

function buyuzi() 

  • 6 months later...
Posted

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

Posted

Maybe posting the whole script would help.

P.S: Never use player names, players keep's changing their name, better use the player element itself.

Posted

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

Posted
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 

Posted

No i mean

1. I type /sell - It creates the marker and players can come and /buy

2. I stop selling the marker is destroyed

3. i try to /sell again - the marker comes but when a player types /buy they cant

Posted

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?

Posted

to get the players name that's selling to put it in the thearmsmark[seller] part and for some reason if a player stands in front of the seller then they type /sell they can /buy :/

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