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?

3677124c9d4d768da64a55d5bebf578e.png
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

3677124c9d4d768da64a55d5bebf578e.png
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) 
  

CiTLh.png
Posted
local money = getPlayerMoney(getLocalPlayer()) 

local money = getPlayerMoney() 

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

function buyuzi(source) 

function buyuzi() 

CiTLh.png
  • 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

3677124c9d4d768da64a55d5bebf578e.png
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.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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

3677124c9d4d768da64a55d5bebf578e.png
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 

My ingame nickname : Ops!

-DeathMatch GameMode By Ops! : 5%

Posted

i dont get what you mean

you want if you type /sell every player can buy?

and when you type / buy every player can sell ?

My ingame nickname : Ops!

-DeathMatch GameMode By Ops! : 5%

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

3677124c9d4d768da64a55d5bebf578e.png
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?

My in-game name: Jaysds1

Retired CMG Scripter

World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode

Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/

 

sE5Qm.png

TiV3C.png

img.php?id=0&text=Lua%20Scripter

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 :/

3677124c9d4d768da64a55d5bebf578e.png

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