Jump to content

Gang system problem


FWCentral

Recommended Posts

Posted

I have made a gang system using element data and the gang saves in the players account and rejoins the player on login but the problem is if a player type /creategang Name then it will put them in the gang even if its allready been created and they are not the leader.

Posted

Yeah that is correct, but the create script only simply checks the player money, then it takes the player money then sets the players element data into the chosen gang but if the gang is allready created it still puts the player in the gang and i dont know how to stop this.

Posted

Nah it doesn't save the gang, It just saves the element data in the players account then when they reconnect it sets the element data again and when they open the gang gui it goes through the players and checks what players have the element data same as that player and puts the player names in a gridlist it seems to work apart from the create error.

  • MTA Team
Posted

bad scripting mehod! Save into SQLite or mysql or xml the gang names, and then save accoutn data of gang name. and check whn the gang is already made

Posted
So keep my method of loading and saving but change the creation of gangs to SQL ok ill try this.

Method of creation, saving, loading should be the same.

EDIT:

removeElementData 

Posted

ok so i tried making the creategang command using SQL, i created a database like this :

  
executeSQLCreateTable ( "Gangs", "Gangname TEXT, Leader TEXT" ) 
  

This worked fine

then for the create command:

  
function creategang(source, commandName, gangname) 
isgang = getElementData(source,"gang") 
if isgang then 
outputChatBox("Your allready in a gang /quitgang first", source, 255, 0, 0) 
else 
sourcename = getPlayerName ( source ) 
local gang = executeSQLSelect ( "Gangs", "Gangname", "Gangname = '" .. gangname .. "'" ) 
    if gang then 
    outputChatBox("This Gang is allready created!", source, 255, 0, 0) 
    else 
local money = getPlayerMoney(source) 
    if (money > 3000) then 
    takePlayerMoney(source, tonumber(3000)) 
    executeSQLInsert ( "Gangs", "'Gangname'", "'Leader'", "'".. gangname .."'", "'"..sourcename.."'" ) 
    outputChatBox("You have created the "..gangname..".", source, 0, 255, 0) 
    setElementData(source, "gang", gangname) 
    setElementData(source, "Rank", "Leader") 
end 
end 
end 
end 
addCommandHandler("creategang", creategang, gangname) 
  

It just says to me the gang is already created when it isn't and no errors in the debug either.

This is my first time using this SQL please go easy ;)

Posted
function creategang(source, commandName, gangname) 
isgang = getElementData(source,"gang") 
if isgang then 
outputChatBox("Your allready in a gang /quitgang first", source, 255, 0, 0) 
else 
sourcename = getPlayerName ( source ) 
local gang = executeSQLSelect ( "Gangs", "Gangname", "Gangname = '" .. gangname .. "'" ) 
    if gang and #gang > 0 then 
    outputChatBox("This Gang is allready created!", source, 255, 0, 0) 
    else 
local money = getPlayerMoney(source) 
    if (money > 3000) then 
    takePlayerMoney(source, tonumber(3000)) 
    executeSQLInsert ( "Gangs", "'Gangname','Leader'", "'".. gangname .."', '"..sourcename.."'" ) 
    outputChatBox("You have created the "..gangname..".", source, 0, 255, 0) 
    setElementData(source, "gang", gangname) 
    setElementData(source, "Rank", "Leader") 
end 
end 
end 
end 
addCommandHandler("creategang", creategang, gangname) 
  
  
  

Posted

Thanks JR10 but i got an error:

error is on this line,

executeSQLInsert ( "Gangs", "'Gangname','Leader'", "'".. gangname .."', '"..sourcename.."'" )

if i type /creategang FWCentral it says DB Query failed table Gangs has no column named FWCentral

and if i type /creategang FWC i get the error Query failed table Gangs has no column named FWC

It still takes the players money and sets the Element Data correctly.

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