Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Any ideas on scripting a Damage and Reward script?

Asked by 6 years ago

Hi guys, I'm stuck with making a Damage/Reward script. I've found out the hard way that it can get extremely tedious with filtering enabled on.Here's what I've tried with a fireball tool:

upon clicking, server receives the Mouse.Hit hence the look vector of the fire ball, and fires out the fireball. Once the fireball hit a Npc target, i will fire to another server script which handles reward distribution, passing the value of: 1) Character of the shot NPC target 2) An IntValue (used to differentiate between similar NPC. It's kind of like their identity card) 3) Character of who shot the fire ball 4) dmg the spell did

Now the tedious part about this is that there could be more than 1 person hitting the NPC or there could also be other different NPC around making it really messy. When I coded this, my script have the problem of no being able to keep track between 2 NPC. If it's only 1, it's able to all the 4 given values right. Here's how the Reward handler server script look like:

RS = game:GetService("ReplicatedStorage")
culpriteremote = RS:FindFirstChild("CulpritRemote")
ReceivedInfo = {}

culpriteremote.Event:connect(function(VictimChar,VictimIndex,character,dmg)

    ReceivedInfo[#ReceivedInfo+1] = {VictimChar,VictimIndex,character,dmg}
    --1 Attacker
    if #ReceivedInfo == 1 then
        print (ReceivedInfo[#ReceivedInfo][2])

        --if there's 2 attackers ++
        elseif #ReceivedInfo > 1 then
        for i = #ReceivedInfo , 1 , -1 do
            if i~= 1 and ReceivedInfo[i][1] == ReceivedInfo[i - 1][1] and ReceivedInfo[i][2] == ReceivedInfo[i - 1][2] and ReceivedInfo[i][3] == ReceivedInfo[i - 1][3] then

                ReceivedInfo[#ReceivedInfo - 1][4] = (ReceivedInfo[#ReceivedInfo][4]) + (ReceivedInfo[#ReceivedInfo-1][4])  
                ReceivedInfo[#ReceivedInfo - 1][3] = (ReceivedInfo[#ReceivedInfo][3]) 
                ReceivedInfo[#ReceivedInfo - 1][2] = (ReceivedInfo[#ReceivedInfo][2]) 
                ReceivedInfo[#ReceivedInfo - 1][1] = (ReceivedInfo[#ReceivedInfo][1])
                --Clear away the current table
                ReceivedInfo[#ReceivedInfo] = nil

    end

After that I scratched that idea. Now I'm trying to:

upon taking damage, the server will fire to that npc's local script, giving out just the value of whose fireball hit the NPC. This way I wouldn't need to identify which NPC was hit and all the other messy stuff. The problem with this is I can't FireClient to a NPC right? Is there any way for a server script to communicate with a none player character like an NPC?

If you had any better ideas please enlighten me thanks!

0
None Player Characters are NPCs. ILikeTofuuJoe 1 — 6y
0
I think you have to identify which NPC is hit. Then in the NPC's script, identify hpw much damage was tken by the NPC, reward the players who had attacked it a certain amount of rewards. ILikeTofuuJoe 1 — 6y
0
That sounded like I'm gona head to my first approach. It's gona be super hard due to how hard it is to segment the data correctly, which is what I've been struggling for the past hours :P lesliesoon 86 — 6y

Answer this question