My script that ive made doesnt work ingame.
the script is as followed:
Client sided,
RegisterNetEvent('Rpg')
RegisterNetEvent('Ak')
RegisterNetEvent('Sniper')
AddEventHandler('Rpg', function(number) --I also added the argument here
GiveWeaponToPed(GetPlayerPed(-1), GetHashKey("weapon_rpg"), 1000, true)
drawNotification(tostring(number))
end)
AddEventHandler('Ak', function(number) --I also added the argument here
GiveWeaponToPed(GetPlayerPed(-1), GetHashKey("weapon_assaultrifle"), 1000, true)
drawNotification(tostring(number))
end)
AddEventHandler('Sniper', function(number) --I also added the argument here
GiveWeaponToPed(GetPlayerPed(-1), GetHashKey("weapon_heavysniper"), 100, true)
drawNotification(tostring(number))
end)
function drawNotification(text) --Just Don't Edit!
SetNotificationTextEntry("STRING")
AddTextComponentString(text)
DrawNotification(false, false)
end
And server sided,
AddEventHandler('chatMessage', function(source, n, msg)
local Message = string.lower(msg)
local MessageParts = stringsplit(Message, " ") --The Seperator Is A Blank Space
if (MessageParts[1] == "/weapon") then
TriggerClientEvent('Rpg', source, MessageParts["rpg"]) --I added the second Argument, the **2** from the message
TriggerClientEvent('Ak', source, MessageParts["ak"]) --I added the second Argument, the **2** from the message
TriggerClientEvent('Sniper', source, MessageParts["sniper"]) --I added the second Argument, the **2** from the message
CancelEvent()
end
end)
function stringsplit(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t={} ; i=1
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
t[i] = str
i = i + 1
end
return t
end
Is there something wrong with it or did i make a mistake or something?
Hope to hear from you guys soon!
You are sending MessagePart[“weapon”], but you never define what the string equals in the array.
Also, why do you stringsplit if you don’t have any secondary if’s?
AddEventHandler('chatMessage', function(source, n, msg)
local Message = string.lower(msg)
if Message == "/weapon" then
TriggerClientEvent('Rpg', source)
TriggerClientEvent('Ak', source)
TriggerClientEvent('Sniper', source)
CancelEvent()
end
end)
Do you English? Do you read? It currently is a copy paste of your script, just not using any stringsplitter as you don’t need it anyways.
If you want “/weapon AK” you’d have to do args[1] == "/weapon" and args[2] == "AK".
Adding a broken array to your params won’t do anything but, break it.
Woahh sorry i saw i made a typing mistake, i mrnt that i wanted a /weapon “id” script. Indeed like your’e last message.
Im really sorry if i offended you!
If you want an “id” script, you’ll have to define that with different if statements like I said.
The param “MessagePart["weapon"]” is not how you do it.
AddEventHandler("chatMessage", function(source, n, message)
local cm = stringsplit(message, " ")
if cm[1] == "/weapon" then
if cm[2] == "ak" then
CancelEvent()
TriggerClientEvent("Ak", source)
elseif cm[2] == "rpg" then
CancelEvent()
TriggerClientEvent("Rpg", source)
elseif cm[2] == "sniper" then
CancelEvent()
TriggerClientEvent("Sniper", source)
elseif cm[2] == "" then
CancelEvent()
TriggerClientEvent("chatMessage", source, "^1WEAPON COMMANDS:^2 /weapon ak, /weapon sniper, /weapon rpg")
end
end
end)
function stringsplit(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t={} ; i=1
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
t[i] = str
i = i + 1
end
return t
end
thats what i got now, and still isnt working.
if i press t and type in /weapon ak nothing appears.
RegisterNetEvent("rpg")
AddEventHandler("rpg", function(number) --I also added the argument here
GiveWeaponToPed(GetPlayerPed(-1), GetHashKey("weapon_rpg"), 10, true)
end)
RegisterNetEvent("ak")
AddEventHandler("ak", function(number) --I also added the argument here
GiveWeaponToPed(GetPlayerPed(-1), GetHashKey("weapon_assaultrifle"), 1000, true)
end)
RegisterNetEvent("sniper")
AddEventHandler("sniper", function(number) --I also added the argument here
GiveWeaponToPed(GetPlayerPed(-1), GetHashKey("weapon_heavysniper"), 100, true)
end)
Server:
AddEventHandler("chatMessage", function(source, n, message)
local cm = stringsplit(message, " ")
if cm[0] == "/weapon" then
if cm[1] == "ak" then
TriggerClientEvent("ak", source)
elseif cm[1] == "rpg" then
TriggerClientEvent("rpg", source)
elseif cm[1] == "sniper" then
TriggerClientEvent("sniper", source)
elseif cm[1] == nil then
TriggerClientEvent("chatMessage", source, "^1WEAPON COMMANDS:^2 /weapon ak, /weapon sniper, /weapon rpg")
end
end
end)
function stringsplit(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t={} ; i=1
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
t[i] = str
i = i + 1
end
return t
end